mode

package module
v0.7.22 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: BSD-3-Clause Imports: 4 Imported by: 6

README

Mode

  • Detect an editor mode based on a given filename.
  • Detect an editor mode based on the given file contents.
  • Select the default indentation type (N tabs/N spaces) per language.
General info
  • License: BSD-3
  • Version: 0.7.22

Documentation

Overview

package mode tries to find the correct editor mode, given a filename and/or file data

Index

Constants

View Source
const (
	Blank          = iota // No file mode found
	AIDL                  // Android-related: Android Interface Definition Language
	Ada                   // Ada
	Agda                  // Agda
	Algol68               // ALGOL 68
	Amber                 // Amber templates
	Arduino               // Arduino
	ASCIIDoc              // ASCII doc
	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#
	CSS                   // CSS
	Clojure               // Clojure
	Config                // Config like yaml, yml, toml, and ini files
	Cpp                   // C++
	Crystal               // Crystal
	D                     // D
	Dart                  // Dart
	Docker                // For Dockerfiles
	Email                 // For using o with ie. Mutt
	Elm                   // Elm
	Erlang                // Erlang
	Fortran77             // Fortran 77
	Fortran90             // Fortran 90
	FSharp                // F#
	Garnet                // Garnet
	GDScript              // Godot Script
	Git                   // Git commits and interactive rebases
	Go                    // Go
	GoAssembly            // Go-style Assembly
	Gradle                // Gradle
	Haxe                  // Haxe: .hx and .hxml files
	HIDL                  // Android-related: Hardware Abstraction Layer Interface Definition Language
	HTML                  // HTML
	HTTP                  // .http files are used by IntelliJ and Visual Studio for testing HTTP services
	Hare                  // Hare
	Haskell               // Haskell
	Inko                  // Inko
	Ivy                   // Ivy
	JSON                  // JSON and iPython notebooks
	Jakt                  // Jakt
	Java                  // Java
	JavaScript            // JavaScript
	Just                  // Just
	Koka                  // Koka
	Kotlin                // Kotlin
	Lilypond              // Lilypond
	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 document
	Mojo                  // Mojo
	Nim                   // Nim
	Nroff                 // editing man pages
	OCaml                 // OCaml
	Oak                   // Oak
	ObjC                  // Objective-C
	ObjectPascal          // Object Pascal and Delphi
	Odin                  // Odin
	Ollama                // For Modelfiles
	Perl                  // Perl
	PolicyLanguage        // SE Linux configuration files
	Prolog                // Prolog
	Python                // Python
	R                     // R
	ReStructured          // reStructuredText
	Ruby                  // Ruby
	Rust                  // Rust
	Scala                 // Scala
	SCDoc                 // SC Doc
	Shader                // GLSL Shader
	Shell                 // Shell scripts and PKGBUILD files
	StandardML            // Standard ML
	SQL                   // Structured Query Language
	Subversion            // Subversion commits
	Swift                 // Swift
	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.

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.

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