mode

package module
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2022 License: BSD-3-Clause Imports: 4 Imported by: 9

README

Mode

  • Detect an editor mode based on a given filename
  • Detect an editor mode based on the given contents
General info
  • License: BSD-3
  • Version: 0.6.4

Documentation

Index

Constants

View Source
const (
	Blank          = iota // No file mode found
	AIDL                  // Android-related: Android Interface Definition Language
	Ada                   // Ada
	Agda                  // Agda
	Amber                 // Amber templates
	Assembly              // Assembly
	Basic                 // FreeBasic, Gambas 3
	Bat                   // DOS and Windows batch files
	Battlestar            // Battlestar
	Bazel                 // Bazel and Starlark
	C                     // C
	CMake                 // CMake files
	CS                    // C#
	Clojure               // Clojure
	Config                // Config like yaml, yml, toml, and ini files
	Cpp                   // C++
	Crystal               // Crystal
	D                     // D
	Doc                   // asciidoctor, sdoc etc
	Email                 // For using o with ie. Mutt
	Elm                   // Elm
	Erlang                // Erlang
	Garnet                // Garnet
	Git                   // Git commits and interactive rebases
	Go                    // Go
	GoAssembly            // Go-style Assembly
	Gradle                // Gradle
	HIDL                  // Android-related: Hardware Abstraction Layer Interface Definition Language
	HTML                  // HTML
	Hare                  // Hare
	Haskell               // Haskell
	JSON                  // JSON and iPython notebooks
	Jakt                  // Jakt
	Java                  // Java
	JavaScript            // JavaScript
	Kotlin                // Kotlin
	Lisp                  // Common Lisp and Emacs Lisp
	Log                   // All sorts of log files
	Lua                   // Lua
	M4                    // M4 macros
	Make                  // Makefiles
	ManPage               // viewing man pages
	Markdown              // Markdown
	Nim                   // Nim
	Nroff                 // editing man pages
	OCaml                 // OCaml
	Oak                   // Oak
	ObjectPascal          // Object Pascal and Delphi
	Odin                  // Odin
	Perl                  // Perl
	PolicyLanguage        // SE Linux configuration files
	Prolog                // Prolog
	Python                // Python
	R                     // R
	ReStructured          // reStructuredText
	Rust                  // Rust
	SQL                   // Structured Query Language
	Scala                 // Scala
	Shell                 // Shell scripts and PKGBUILD files
	StandardML            // Standard ML
	Teal                  // Teal
	Terra                 // Terra
	Text                  // plain text documents
	TypeScript            // TypeScript
	V                     // V programming language
	Vim                   // Vim or NeoVim configuration, or .vim scripts
	XML                   // XML
	Zig                   // Zig
)

Variables

View Source
var DefaultTabsSpaces = TabsSpaces{4, true}

DefaultTabsSpaces is the default setting: 4 spaces

Functions

This section is empty.

Types

type Mode

type Mode int

Mode is a per-filetype mode, like for Markdown

func Detect

func Detect(filename string) Mode

Detect looks at the filename and tries to guess what could be an appropriate editor mode.

func DetectFromContentBytes added in v0.5.0

func DetectFromContentBytes(initial Mode, firstLine []byte, allBytesFunc func() []byte) (Mode, bool)

DetectFromContentBytes takes the first line of a file as a byte slice, and a function that can return the entire contents of the file as a byte slice, which will only be called if needed. Based on the contents, a Mode is detected and returned. Pass inn mode.Blank as the initial Mode if that is the best guess so far. Returns true if a mode is found. TODO: Create a generic function that handles both strings and bytes instead of maintaining both.

func DetectFromContents added in v0.1.0

func DetectFromContents(initial Mode, firstLine string, allTextFunc func() string) (Mode, bool)

DetectFromContents takes the first line of a file as a string, and a function that can return the entire contents of the file as a string, which will only be called if needed. Based on the contents, a Mode is detected and returned. Pass inn mode.Blank as the initial Mode if that is the best guess so far. Returns true if a mode is found. TODO: Create a generic function that handles both strings and bytes instead of maintaining both.

func SimpleDetect added in v0.3.1

func SimpleDetect(contents string) Mode

SimpleDetect tries to return a Mode given a string of file contents

func SimpleDetectBytes added in v0.5.0

func SimpleDetectBytes(contents []byte) Mode

SimpleDetectBytes tries to return a Mode given a byte slice of file contents

func (Mode) Spaces added in v0.2.0

func (m Mode) Spaces() bool

Spaces returns true if spaces should be used for the current mode

func (Mode) String

func (mode Mode) String() string

String will return a short lowercase string representing the given editor mode

func (Mode) TabsSpaces added in v0.2.0

func (m Mode) TabsSpaces() TabsSpaces

TabsSpaces tries to return the appropriate settings for tabs and spaces as a TabsSpaces struct

type TabsSpaces added in v0.2.0

type TabsSpaces struct {
	PerTab int  // number of spaces per tab/indentation
	Spaces bool // use spaces, or tabs?
}

TabsSpaces contains all info needed about tabs and spaces for a file

func (TabsSpaces) String added in v0.2.0

func (ts TabsSpaces) String() string

String returns the string for one indentation

func (TabsSpaces) WSLen added in v0.2.0

func (ts TabsSpaces) WSLen(whitespaceString string) int

WSLen will count the length of the given whitespace string, in terms of spaces

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL