Add show command to show the value of an option

This commit is contained in:
Zachary Yedidia 2016-08-28 21:48:03 -04:00
parent da98a2e9ec
commit 00e385b871
5 changed files with 46 additions and 5 deletions

View file

@ -30,6 +30,7 @@ To see more screenshots of micro, showcasing all of the default colorschemes, se
* Cross platform (It should work on all the platforms Go runs on) * Cross platform (It should work on all the platforms Go runs on)
* Note that while Windows is supported, there are still some bugs that need to be worked out * Note that while Windows is supported, there are still some bugs that need to be worked out
* Plugin system (plugins are written in Lua) * Plugin system (plugins are written in Lua)
* Persistent undo
* Automatic linting and error notifications * Automatic linting and error notifications
* Syntax highlighting (for over [75 languages](runtime/syntax)!) * Syntax highlighting (for over [75 languages](runtime/syntax)!)
* Colorscheme support * Colorscheme support
@ -73,7 +74,7 @@ Make sure that you have Go version 1.5 or greater (Go 1.4 will work if your vers
go get -u github.com/zyedidia/micro/... go get -u github.com/zyedidia/micro/...
``` ```
### Clipboard support ### Linux clipboard support
On Linux, clipboard support requires 'xclip' or 'xsel' command to be installed. On Linux, clipboard support requires 'xclip' or 'xsel' command to be installed.
@ -85,6 +86,13 @@ sudo apt-get install xclip
If you don't have xclip or xsel, micro will use an internal clipboard for copy and paste, but it won't work with external applications. If you don't have xclip or xsel, micro will use an internal clipboard for copy and paste, but it won't work with external applications.
### Windows colors
Many of the Windows terminals don't support more than 16 colors, which means
that micro's default colorscheme won't look very good. You can either set
the colorscheme to `simple`, or download a better terminal emulator, like
mintty or cmder.
# Usage # Usage
Once you have built the editor, simply start it by running `micro path/to/file.txt` or simply `micro` to open an empty buffer. Once you have built the editor, simply start it by running `micro path/to/file.txt` or simply `micro` to open an empty buffer.

View file

@ -92,6 +92,15 @@ func HelpComplete(input string) (string, []string) {
return chosen, suggestions return chosen, suggestions
} }
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// OptionComplete autocompletes options // OptionComplete autocompletes options
func OptionComplete(input string) (string, []string) { func OptionComplete(input string) (string, []string) {
var suggestions []string var suggestions []string
@ -102,7 +111,7 @@ func OptionComplete(input string) (string, []string) {
} }
} }
for option := range localSettings { for option := range localSettings {
if strings.HasPrefix(option, input) { if strings.HasPrefix(option, input) && !contains(suggestions, option) {
suggestions = append(suggestions, option) suggestions = append(suggestions, option)
} }
} }

View file

@ -27,6 +27,7 @@ var commands map[string]Command
var commandActions = map[string]func([]string){ var commandActions = map[string]func([]string){
"Set": Set, "Set": Set,
"SetLocal": SetLocal, "SetLocal": SetLocal,
"Show": Show,
"Run": Run, "Run": Run,
"Bind": Bind, "Bind": Bind,
"Quit": Quit, "Quit": Quit,
@ -70,6 +71,7 @@ func DefaultCommands() map[string]StrCommand {
return map[string]StrCommand{ return map[string]StrCommand{
"set": {"Set", []Completion{OptionCompletion, NoCompletion}}, "set": {"Set", []Completion{OptionCompletion, NoCompletion}},
"setlocal": {"SetLocal", []Completion{OptionCompletion, NoCompletion}}, "setlocal": {"SetLocal", []Completion{OptionCompletion, NoCompletion}},
"show": {"Show", []Completion{OptionCompletion, NoCompletion}},
"bind": {"Bind", []Completion{NoCompletion}}, "bind": {"Bind", []Completion{NoCompletion}},
"run": {"Run", []Completion{NoCompletion}}, "run": {"Run", []Completion{NoCompletion}},
"quit": {"Quit", []Completion{NoCompletion}}, "quit": {"Quit", []Completion{NoCompletion}},
@ -168,6 +170,7 @@ func NewTab(args []string) {
// Set sets an option // Set sets an option
func Set(args []string) { func Set(args []string) {
if len(args) < 2 { if len(args) < 2 {
messenger.Error("Not enough arguments")
return return
} }
@ -177,8 +180,10 @@ func Set(args []string) {
SetOptionAndSettings(option, value) SetOptionAndSettings(option, value)
} }
// SetLocal sets an option local to the buffer
func SetLocal(args []string) { func SetLocal(args []string) {
if len(args) < 2 { if len(args) < 2 {
messenger.Error("Not enough arguments")
return return
} }
@ -191,10 +196,27 @@ func SetLocal(args []string) {
} }
} }
// Show shows the value of the given option
func Show(args []string) {
if len(args) < 1 {
messenger.Error("Please provide an option to show")
return
}
option := GetOption(args[0])
if option == nil {
messenger.Error(args[0], " is not a valid option")
return
}
messenger.Message(option)
}
// Bind creates a new keybinding // Bind creates a new keybinding
func Bind(args []string) { func Bind(args []string) {
if len(args) != 2 { if len(args) < 2 {
messenger.Error("Incorrect number of arguments") messenger.Error("Not enough arguments")
return return
} }
BindKey(args[0], args[1]) BindKey(args[0], args[1])

View file

@ -375,7 +375,7 @@ func runtimeHelpColorsMd() (*asset, error) {
return a, nil return a, nil
} }
var _runtimeHelpCommandsMd = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x54\xc1\xb2\xe4\x34\x0c\xbc\xe7\x2b\xba\x1e\x87\x05\xea\xcd\x7c\xc0\xdc\x28\x2e\x50\x45\x51\xc0\xee\x85\x9b\x9d\x44\x99\xb8\xc6\xb1\xb2\x96\x9c\xd9\xe1\xeb\x29\xd9\x99\x3c\xd8\xc7\x81\x5b\x62\xb5\xd4\x2d\xa9\xed\x6f\xf0\x1b\x8b\x84\x3e\x12\x06\x5e\x16\x9f\x46\xe9\xba\x3f\xb9\x60\xf0\x09\xf4\x85\x86\xa2\x04\xfb\x1c\x83\x72\x7e\x62\xd0\x3f\xb0\x66\x12\x09\xe9\x0a\xf7\xa3\xe6\x78\x22\x87\x89\x63\xe4\x3b\xd5\xa8\xce\x47\xc1\x73\xf7\x13\x65\x82\xcf\x54\x4f\xd7\xaf\xf9\xa0\xb3\x57\x3c\x76\xce\x22\x74\xee\xba\xef\xe1\x3e\x97\xa0\xee\x82\xdf\x4b\x50\xc1\x12\x86\xcc\xed\x5c\xfc\x46\xee\x82\x8f\x7e\x23\x69\x34\x25\x67\x4a\x8a\xbe\x4c\x13\xe5\x06\xca\xb4\x46\x3f\x10\x5e\x84\x7c\x1e\xe6\x17\xbc\x6c\x3e\x16\x7a\xc1\x14\xfd\x55\xdc\x05\x9f\xe6\x20\xb8\x87\x18\xf1\x84\xba\x06\x75\xb8\x07\x9d\xe1\x2a\xde\x9d\xd1\x01\xf8\x34\x13\x5c\xcb\xac\x6d\xf0\xaa\x81\x93\x8f\x67\x0b\xfe\xa0\x50\x2b\xb6\x72\x48\xfa\x6a\x8a\x32\x21\x08\x38\xc5\x07\x38\x51\xa5\xbc\xc0\x0d\xee\x15\xf7\x39\x0c\x33\x28\xf9\x3e\x92\xc0\x0d\x33\x0d\x37\x87\x85\x47\xaa\x3c\x2d\xec\xe5\x26\x08\x93\x4d\xe4\xc3\x88\x18\x6e\x04\x65\xac\x94\x27\xce\x4b\xed\x78\x97\xbc\x58\xd7\xe4\x87\x19\x1a\x16\xea\xac\xc2\xaf\xac\xd4\xe6\x79\xb4\xb3\x14\x51\xf4\x04\x8f\xcd\xc7\x30\x22\xd3\x95\xbe\x9c\x81\x9f\xa7\xaa\x8e\xa7\x5a\xd2\xe7\x6b\xb1\x7a\x62\x55\x46\x26\x41\x62\xc5\xec\x37\xdb\xfe\x03\xb2\xfa\x81\x04\x21\x21\xe8\x6b\xdd\xd5\xe2\x1f\xe0\x25\x68\xcd\xfe\x5c\x58\x49\xf6\xfd\x90\xee\x03\x42\x9b\xe1\x05\x42\xda\x56\xb5\x9f\x2b\xb7\xd0\x19\x1f\xa9\x99\xc2\xb5\x88\x38\xcc\x14\x57\x28\xaf\x61\x30\x25\x13\x67\x78\xc4\x20\x6a\x42\x77\xd0\xe1\x15\x21\x3d\x38\x23\x0f\x3e\xfe\x5f\x62\x54\x74\x7c\xe0\xdb\xba\xa5\x90\xfe\x69\x24\xe3\x6d\x5e\xfa\x6e\x37\x53\x49\x90\xf9\xb4\xfb\xd5\x5d\x90\x4b\x6a\x65\xaf\x61\x23\x8b\x51\x8c\xc7\xd5\xd8\x8b\xf5\x7e\xb8\x5d\x33\x97\x34\x9e\xab\x7f\xac\xea\x0e\xf9\x20\xe0\xa2\x6b\xd1\x66\xc0\x9e\x30\x06\x59\xa3\x7f\x50\xcd\xb6\xad\xc4\x90\x08\xf7\x99\x6c\xde\x98\x42\x0a\x32\x93\x18\x6f\x0a\xe9\xda\x54\xf5\x21\x8d\xb8\xd1\x03\x7e\xb0\xde\xdc\x05\x43\x26\xaf\x24\xf0\x76\x6c\x61\xbb\x9d\x53\xe6\xa5\xc2\x94\x77\xe4\xdb\xd4\x85\x86\x36\x50\x4e\x26\xef\x2d\x4b\xe0\x7b\xde\xa8\x8e\x7f\x61\xf3\x73\x9a\xd8\xce\x4c\xb3\xb9\xeb\x46\x0f\x81\x75\xeb\xf7\x0a\x76\x2d\xfc\xe6\x43\x34\x6b\x37\x81\x9b\xac\xb1\xaa\x8f\x94\xfc\x62\xeb\xe0\x95\x0c\x8a\x8d\xb2\x06\x5b\x57\x43\xb4\x0b\x77\xe0\xce\x66\xcd\xc4\x47\x22\x42\x35\xe5\x9a\x79\x0b\x23\x8d\xaf\xef\x0b\xd8\x6d\x5b\x29\xd1\xd8\x4a\xd9\x73\xb5\xac\xfa\xd8\xb7\x58\xc5\xcc\xef\xc4\x88\x95\xf6\xf2\xd4\xe9\xd0\x17\x3d\x14\xce\x9c\xc3\x5f\x9c\xf4\x8d\x22\x89\x92\x1f\xc1\x93\x69\xf9\x5a\x41\xa5\x50\xdf\xbf\x6f\xf6\xcd\x25\x16\xb2\xf5\x7a\x24\xba\x43\x7d\x7f\xee\xba\xd3\xe9\xd4\x75\xe6\x8e\xf6\x74\xda\xbe\x8e\x57\xd1\x26\xfa\xec\xf9\xf9\xa2\x8e\x34\xf9\x12\x15\x6b\x2c\xd7\x90\xe4\x52\x79\x63\x48\xf6\x50\xfe\x12\x92\xfe\xeb\x3d\xac\x84\xb6\x41\xca\x99\xf3\x7e\x3b\xaf\x3c\x2d\x86\xfe\xa3\x24\xd4\x6f\x70\x7a\x97\xf5\x84\x86\x65\xe5\xac\x72\xc0\xf7\xff\xff\x4e\xf9\x3b\x00\x00\xff\xff\x19\x8b\xa2\xea\x4a\x06\x00\x00") var _runtimeHelpCommandsMd = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x54\xc1\x8e\xe4\x34\x10\xbd\xe7\x2b\x9e\x86\xc3\x02\x9a\xe9\x0f\xe8\x1b\xe2\x02\x12\x42\xc0\xee\x85\x5b\x9c\xa4\xd2\xb1\xda\x71\x65\x5d\xe5\xf4\x36\x5f\x8f\xca\x76\x67\x76\x67\x38\x70\x4b\xec\xe7\x57\xaf\xfc\x5e\xf9\x3b\xfc\xc1\x22\x7e\x08\x84\x91\xd7\xd5\xc5\x49\xba\xee\x6f\xce\x18\x5d\x04\x7d\xa1\x31\x2b\xc1\x3e\x27\xaf\x9c\x1e\x18\x0c\x77\x6c\x89\x44\x7c\xbc\xa0\xff\x59\x53\x78\xa1\x1e\x33\x87\xc0\x37\x2a\xbb\xba\x1c\x84\xa7\xee\x17\x4a\x04\x97\xa8\xac\x6e\x6f\xeb\x41\x17\xa7\xb8\xb7\x9a\x59\xe8\xd4\x75\x3f\xa2\xff\x9c\xbd\xf6\x67\xfc\x99\xbd\x0a\x56\x3f\x26\xae\xeb\xe2\x76\xea\xcf\xf8\xe8\x76\x92\x5a\x26\xa7\x44\x51\x31\xe4\x79\xa6\x54\x41\x89\xb6\xe0\x46\xc2\x93\x90\x4b\xe3\xf2\x84\xa7\xdd\x85\x4c\x4f\x98\x83\xbb\x48\x7f\xc6\xa7\xc5\x0b\x6e\x3e\x04\x3c\xa0\x7d\x85\xf6\xb8\x79\x5d\xd0\x17\x7c\x7f\x42\x07\xe0\xd3\x42\xe8\xeb\xc9\xd2\x06\x6f\xea\x39\xba\x70\xb2\xcd\x9f\x14\x6a\x64\x1b\xfb\xa8\xcf\xa6\x28\x11\xbc\x80\x63\xb8\x83\x23\x95\x92\x67\xf4\x63\xff\x8c\xdb\xe2\xc7\x05\x14\xdd\x10\x48\xd0\x8f\x0b\x8d\xd7\x1e\x2b\x4f\x54\xea\xd4\x6d\x27\x57\x81\x9f\xed\x46\x3e\x4c\x08\xfe\x4a\x50\xc6\x46\x69\xe6\xb4\x96\x8e\x9b\xe4\xd5\xba\x26\x37\x2e\x50\xbf\x52\x67\x0c\xbf\xb3\x52\xbd\xcf\xa3\x9d\x35\x8b\x62\x20\x38\xec\x2e\xf8\x09\x89\x2e\xf4\xe5\x04\xfc\x3a\x17\x75\x3c\x17\x4a\x97\x2e\xd9\xf8\xc4\x58\x26\x26\x41\x64\xc5\xe2\x76\x73\xff\x0e\xd9\xdc\x48\x02\x1f\xe1\xf5\xb9\x78\xb5\xba\x3b\x78\xf5\x5a\x4e\x7f\xce\xac\x24\xcd\x1f\xd2\x76\x41\xa8\x77\x78\x86\x90\x56\xab\xda\xba\x72\xdd\x3a\xe1\x23\xd5\x50\xf4\x75\x47\x7a\x2c\x14\x36\x28\x6f\x7e\x34\x25\x33\x27\x38\x04\x2f\x6a\x42\x1b\xe8\xc8\x8a\x90\x1e\x35\x03\x8f\x2e\xfc\xdf\xc2\x28\xe8\x70\xc7\xf7\xc5\x25\x1f\xbf\x0e\x92\xd5\xad\x59\xfa\xa1\xb1\x2f\x7c\x6b\x0c\xc6\xb9\xf0\xed\xdb\xe0\x55\xca\x76\x91\x17\xbf\x53\x6c\xe8\x96\xc5\x1c\x21\xcb\x4b\x8b\x7b\x7f\x46\xca\x51\xbe\xc2\xca\x42\x21\x1c\x93\xd5\xb4\x0c\x6e\xbc\x5e\x12\xe7\x38\x9d\x4a\xfc\x4c\x54\x83\x7c\x10\x70\xd6\x2d\x6b\xcd\xef\x40\x98\xbc\x6c\xc1\xdd\xa9\x9c\x36\x53\x83\x8f\x84\xdb\x42\x66\x17\x66\x1f\xbd\x2c\x24\x56\x37\xfa\x78\xa9\xaa\x06\x1f\x27\x5c\xe9\x0e\x37\xb6\xc6\xc6\x44\x4e\x49\xe0\x6c\xd9\xb6\x6d\xb8\xe7\xc4\x6b\x81\x29\x37\xe4\xab\x69\x42\x63\xf5\x83\xa3\xc9\x7b\x3d\x25\x70\x03\xef\x54\xdc\x5b\xd9\xc6\x21\xce\x6c\x6b\xa6\xd9\xc2\x79\xa5\xbb\xc0\xba\x75\x8d\xc1\xa6\xca\xed\xce\x07\x9b\x8c\x2a\x70\x97\x2d\x14\xf5\x81\xa2\x5b\xcd\x4d\xde\xc8\xa0\xd8\x29\xa9\x37\xb7\x2b\xa2\xce\xeb\x81\x3b\x59\xb2\x23\x1f\x07\xe1\x4b\xa6\xb7\xc4\xbb\x9f\x68\x7a\x7e\x4f\x60\xc3\xba\x51\xa4\xa9\x52\xd9\x6b\xb7\x6e\x7a\x6f\x21\x28\x62\x96\x77\x62\xc4\xa8\x9d\x3c\x74\xf6\x18\xb2\x1e\x0a\x17\x4e\xfe\x1f\x8e\xfa\x5a\x22\x8a\x92\x9b\xc0\xb3\x69\x79\xab\xa0\x94\x50\x37\xbc\x6f\xf6\x35\x25\xb6\x65\xf6\x3a\x44\xba\x41\xdd\x70\xea\xba\x97\x97\x97\xae\xb3\x74\xd4\x97\xd7\xfc\x3a\x1e\x55\xbb\xd1\x47\xcf\x8f\x07\x79\xa2\xd9\xe5\xa0\xd8\x42\xbe\xf8\x28\xe7\x52\x37\xf8\x68\xef\xec\x6f\x3e\xea\x37\xa9\x2e\x05\xcd\x41\x4a\x89\x53\x1b\xee\x0b\xcf\xab\xa1\xff\xca\x11\xe5\x1b\x1c\xdf\x9d\x7a\x40\xfd\xba\x71\x52\x39\xe0\xed\xff\xbf\x8f\xfc\x1b\x00\x00\xff\xff\x15\x3d\x5d\xe1\x89\x06\x00\x00")
func runtimeHelpCommandsMdBytes() ([]byte, error) { func runtimeHelpCommandsMdBytes() ([]byte, error) {
return bindataRead( return bindataRead(

View file

@ -21,6 +21,8 @@ Here are the possible commands that you can use.
* `setlocal option value`: sets the option to value locally (only in the current * `setlocal option value`: sets the option to value locally (only in the current
buffer). buffer).
* `show option`: shows the current value of the given option.
* `run sh-command`: runs the given shell command in the background. The * `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. command's output will be displayed in one line when it finishes running.