Update docs and add some comments

This commit is contained in:
Zachary Yedidia 2016-08-25 17:24:13 -04:00
parent d6da2dfeca
commit acc03e9707
5 changed files with 68 additions and 33 deletions

File diff suppressed because one or more lines are too long

View file

@ -64,15 +64,19 @@ func AddOption(name string, value interface{}) {
}
}
// GetOption returns the specified option. This is meant to be called by plugins to add options.
// GetGlobalOption returns the global value of the given option
func GetGlobalOption(name string) interface{} {
return globalSettings[name]
}
// GetLocalOption returns the local value of the given option
func GetLocalOption(name string, buf *Buffer) interface{} {
return buf.Settings[name]
}
// GetOption returns the value of the given option
// If there is a local version of the option, it returns that
// otherwise it will return the global version
func GetOption(name string) interface{} {
if GetLocalOption(name, CurView().Buf) != nil {
return GetLocalOption(name, CurView().Buf)
@ -81,6 +85,7 @@ func GetOption(name string) interface{} {
}
// DefaultSettings returns the default settings for micro
// Note that colorscheme is a global only option
func DefaultGlobalSettings() map[string]interface{} {
return map[string]interface{}{
"autoindent": true,
@ -100,6 +105,8 @@ func DefaultGlobalSettings() map[string]interface{} {
}
}
// DefaultLocalSettings returns the default local settings
// Note that filetype is a local only option
func DefaultLocalSettings() map[string]interface{} {
return map[string]interface{}{
"autoindent": true,
@ -172,6 +179,7 @@ func SetOption(option, value string) error {
return nil
}
// SetLocalOption sets the local version of this option
func SetLocalOption(option, value string, view *View) error {
buf := view.Buf
if _, ok := buf.Settings[option]; !ok {

View file

@ -15,8 +15,11 @@ Here are the possible commands that you can use.
Note that `search` must be a valid regex. If one of the arguments
does not have any spaces in it, you may omit the quotes.
* `set option value`: sets the option to value. Please see the next section for
a list of options you can set.
* `set option value`: sets the option to value. See the `options` help topic
for a list of options you can set.
* `setlocal option value`: sets the option to value locally (only in the current
buffer).
* `run sh-command`: runs the given shell command in the background. The
command's output will be displayed in one line when it finishes running.

View file

@ -10,6 +10,7 @@ Here are the options that you can set:
* `colorscheme`: loads the colorscheme stored in
$(configDir)/colorschemes/`option`.micro
This setting is `global only`.
default value: `default`
Note that the default colorschemes (default, solarized, and solarized-tc)
@ -43,6 +44,10 @@ Here are the options that you can set:
default value: ` `
* `filetype`: sets the filetype for the current buffer. This setting is `local only`
default value: this will be automatically set depending on the file you have open
* `ignorecase`: perform case-insensitive searches
default value: `off`
@ -116,3 +121,13 @@ Any option you set in the editor will be saved to the file
~/.config/micro/settings.json so, in effect, your configuration file will be
created for you. If you'd like to take your configuration with you to another
machine, simply copy the settings.json to the other machine.
# Global and local settings
You can set these settings either globally or locally. Locally means that the setting
won't be saved to `~/.config/micro/settings.json` and that it will only be set in
the current buffer. Setting an option globally is the default, and will set the option
in all buffers.
The `colorscheme` option is global only, and the `filetype` option is local only. To
set an option locally, use `setlocal` instead of `set`.

View file

@ -6,16 +6,19 @@ main script which is run at startup which should be placed in
There are a number of callback functions which you can create in your
plugin to run code at times other than startup. The naming scheme is
`onAction()`. For example a function which is run every time the user saves
`onAction(view)`. For example a function which is run every time the user saves
the buffer would be:
```lua
function onSave()
function onSave(view)
...
return false
end
```
The `view` variable is a reference to the view the action is being executed on.
This is almost always the current view, which you can get with `CurView()` as well.
All available actions are listed in the keybindings section of the help.
These functions should also return a boolean specifying whether the view
@ -32,42 +35,48 @@ There are a number of functions and variables that are available to you in
oder to access the inner workings of micro. Here is a list (the type signatures
for functions are given using Go's type system):
* OS: variable which gives the OS micro is currently running on (this is the same
* `OS`: variable which gives the OS micro is currently running on (this is the same
as Go's GOOS variable, so `darwin`, `windows`, `linux`, `freebsd`...)
* tabs: a list of all the tabs currently in use
* `tabs`: a list of all the tabs currently in use
* curTab: the index of the current tabs in the tabs list
* `curTab`: the index of the current tabs in the tabs list
* messenger: lets you send messages to the user or create prompts
* `messenger`: lets you send messages to the user or create prompts
* GetOption(name string): returns the value of the requested option
* `GetOption(name string)`: returns the value of the requested option
* AddOption(name string, value interface{}): sets the given option with the given
value (`interface{}` means any type in Go).
* `AddOption(name string, value interface{})`: sets the given option with the given
value (`interface{}` means any type in Go).
* BindKey(key, action string): binds `key` to `action`.
* `SetOption(option, value string)`: sets the given option to the value. This will
set the option globally, unless it is a local only option.
* MakeCommand(name, function string, completions ...Completion):
creates a command with `name` which will call `function` when executed.
Use 0 for completions to get NoCompletion.
* `SetLocalOption(option, value string, buffer *Buffer)`: sets the given option to
the value locally in the given buffer.
* CurView(): returns the current view
* `BindKey(key, action string)`: binds `key` to `action`.
* HandleCommand(cmd string): runs the given command
* `MakeCommand(name, function string, completions ...Completion)`:
creates a command with `name` which will call `function` when executed.
Use 0 for completions to get NoCompletion.
* HandleShellCommand(shellCmd string, interactive bool): runs the given shell
command
* `CurView()`: returns the current view
* JobStart(cmd string, onStdout, onStderr, onExit string, userargs ...string):
Starts running the given shell command in the background. `onStdout` `onStderr` and `onExit`
are callbacks to lua functions which will be called when the given actions happen
to the background process.
`userargs` are the arguments which will get passed to the callback functions
* `HandleCommand(cmd string)`: runs the given command
* JobSend(cmd *exec.Cmd, data string): send a string into the stdin of the job process
* `HandleShellCommand(shellCmd string, interactive bool)`: runs the given shell
command
* JobStop(cmd *exec.Cmd): kill a job
* `JobStart(cmd string, onStdout, onStderr, onExit string, userargs ...string)`:
Starts running the given shell command in the background. `onStdout` `onStderr` and `onExit`
are callbacks to lua functions which will be called when the given actions happen
to the background process.
`userargs` are the arguments which will get passed to the callback functions
* `JobSend(cmd *exec.Cmd, data string)`: send a string into the stdin of the job process
* `JobStop(cmd *exec.Cmd)`: kill a job
This may seem like a small list of available functions but some of the objects
returned by the functions have many methods. `CurView()` returns a view object