martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.2k stars 258 forks source link

"M-x" for vis #958

Closed jgarte closed 1 year ago

jgarte commented 3 years ago

I am thinking of some command equivalent of emacs' M-x (execute-extended-command).

Is this feature out of the scope of this project, too emacsy, or succeptable to introducing bloat to the core of vis?

Is there currently a way of doing this that I missed from the man page?

What do you think are the pros and cons of having this feature?

I see for example that @ninewise calls vis-window-next in his config by using the vis:map function to bind the function to ;;:

vis:map(vis.modes.NORMAL, ";;", "<vis-window-next>")

I'd like to also be able to call vis-window-next something alongs the line of the following in command-mode:

:vis-window-next

Other commands I'd like to access from command-mode:

vis-append-char-next          ›   Append text after the cursor
  vis-append-line-end           ›   Append text after the end of the line
  vis-count                     ›   Count specifier
  vis-delete-char-next          ›   Delete the next character
  vis-delete-char-prev          ›   Delete the previous character
  vis-delete-line-begin         ›   Delete until the start of the current line
  vis-delete-word-prev          ›   Delete the previous WORD
  vis-earlier                   ›   Goto older text state
  vis-insert-line-start         ›   Insert text before the first non-blank in the line
  vis-insert-newline            ›   Insert a line break (depending on file type)
  vis-insert-register           ›   Insert specified register content
  vis-insert-tab                ›   Insert a tab (might be converted to spaces)
  vis-insert-verbatim           ›   Insert Unicode character based on code point
  vis-join-lines                ›   Join selected lines
  vis-join-lines-trim           ›   Join selected lines, remove white space
  vis-jumplist-next             ›   Go to newer cursor position in jump list
  vis-jumplist-prev             ›   Go to older cursor position in jump list
  vis-jumplist-save             ›   Save current selections in jump list
  vis-later                     ›   Goto newer text state
  vis-macro-record              ›   Record macro into given register
  vis-macro-replay              ›   Replay macro, execute the content of the given register
  vis-mark                      ›   Use given mark for next action
  vis-mode-insert               ›   Enter insert mode
  vis-mode-normal               ›   Enter normal mode
  vis-mode-normal-escape        ›   Reset count or remove all non-primary selections
  vis-mode-replace              ›   Enter replace mode
  vis-mode-visual-charwise      ›   Enter characterwise visual mode
  vis-mode-visual-escape        ›   Reset count or switch to normal mode
  vis-mode-visual-linewise      ›   Enter linewise visual mode
  vis-motion-bigword-end-next   ›   Move cursor forward to the end of WORD
  vis-motion-bigword-end-prev   ›   Move cursor backwards to the end of WORD
  vis-motion-bigword-start-next ›   Move cursor WORDS forwards
  vis-motion-bigword-start-prev ›   Move cursor WORDS backwards
  vis-motion-block-end          ›   Move cursor to the closing curly brace in a block
  vis-motion-block-start        ›   Move cursor to the opening curly brace in a block
  vis-motion-byte               ›   Move to absolute byte position
  vis-motion-byte-left          ›   Move count bytes to the left
  vis-motion-byte-right         ›   Move count bytes to the right
  vis-motion-char-next          ›   Move cursor right, to the next character
  vis-motion-char-prev          ›   Move cursor left, to the previous character
  vis-motion-codepoint-next     ›   Move to the next Unicode codepoint
  vis-motion-codepoint-prev     ›   Move to the previous Unicode codepoint
  vis-motion-column             ›   Move cursor to given column of current line
  vis-motion-line-begin         ›   Move cursor to first character of the line
  vis-motion-line-char-next     ›   Move cursor right, to the next character on the same line
vis-motion-line-char-prev     ›   Move cursor left, to the previous character on the same line
  vis-motion-line-down          ›   Move cursor line downwards
  vis-motion-line-end           ›   Move cursor to end of the line
  vis-motion-line-finish        ›   Move cursor to last non-blank character of the line
  vis-motion-line-first         ›   Move cursor to given line (defaults to first)
  vis-motion-line-last          ›   Move cursor to given line (defaults to last)
  vis-motion-line-start         ›   Move cursor to first non-blank character of the line
  vis-motion-line-up            ›   Move cursor line upwards
  vis-motion-paragraph-next     ›   Move cursor paragraph forward
  vis-motion-paragraph-prev     ›   Move cursor paragraph backward
  vis-motion-parenthesis-end    ›   Move cursor to the closing parenthesis inside a pair of parentheses
  vis-motion-parenthesis-start  ›   Move cursor to the opening parenthesis inside a pair of parentheses
  vis-motion-percent            ›   Move to count % of file or matching item
  vis-motion-screenline-begin   ›   Move cursor to beginning of screen/display line
  vis-motion-screenline-down    ›   Move cursor screen/display line downwards
  vis-motion-screenline-end     ›   Move cursor to end of screen/display line
  vis-motion-screenline-middle  ›   Move cursor to middle of screen/display line
  vis-motion-screenline-up      ›   Move cursor screen/display line upwards
  vis-motion-search-repeat      ›   Move cursor to next match
  vis-motion-search-repeat-backward›Move cursor to previous match in backward direction
  vis-motion-search-repeat-forward› Move cursor to next match in forward direction
  vis-motion-search-repeat-reverse› Move cursor to next match in opposite direction
  vis-motion-search-word-backward›  Move cursor to previous occurrence of the word under cursor
  vis-motion-search-word-forward›   Move cursor to next occurrence of the word under cursor
  vis-motion-sentence-next      ›   Move cursor sentence forward
  vis-motion-sentence-prev      ›   Move cursor sentence backward
  vis-motion-till-left          ›   Till after the occurrence of character to the left
  vis-motion-till-right         ›   Till before the occurrence of character to the right
  vis-motion-to-left            ›   To the first occurrence of character to the left
  vis-motion-to-right           ›   To the first occurrence of character to the right
  vis-motion-totill-repeat      ›   Repeat latest to/till motion
  vis-motion-totill-reverse     ›   Repeat latest to/till motion but in opposite direction
  vis-motion-window-line-bottom ›   Move cursor to bottom line of the window
  vis-motion-window-line-middle ›   Move cursor to middle line of the window
  vis-motion-window-line-top    ›   Move cursor to top line of the window
  vis-motion-word-end-next      ›   Move cursor forward to the end of word
  vis-motion-word-end-prev      ›   Move cursor backwards to the end of word
  vis-motion-word-start-next    ›   Move cursor words forwards
  vis-motion-word-start-prev    ›   Move cursor words backwards
  vis-nop                       ›   Ignore key, do nothing
  vis-open-line-above           ›   Begin a new line above the cursor
  vis-open-line-below           ›   Begin a new line below the cursor
  vis-operator-change           ›   Change operator
  vis-operator-delete           ›   Delete operator
  vis-operator-shift-left       ›   Shift left operator
  vis-operator-shift-right      ›   Shift right operator
  vis-operator-yank             ›   Yank operator
  vis-prompt-show               ›   Show editor command line prompt
  vis-put-after                 ›   Put text after the cursor
  vis-put-before                ›   Put text before the cursor
  vis-redo                      ›   Redo last change
  vis-redraw                    ›   Redraw current editor content
  vis-register                  ›   Use given register for next operator
  vis-repeat                    ›   Repeat latest editor command
 vis-replace-char              ›   Replace the character under the cursor
  vis-search-backward           ›   Search backward
  vis-search-forward            ›   Search forward
  vis-selection-flip            ›   Flip selection, move cursor to other end
  vis-selection-new-lines-above ›   Create a new selection on the line above
  vis-selection-new-lines-above-first›  Create a new selection on the line above the first selection
  vis-selection-new-lines-begin ›   Create a new selection at the start of every line covered by selection
  vis-selection-new-lines-below ›   Create a new selection on the line below
  vis-selection-new-lines-below-last›   Create a new selection on the line below the last selection
  vis-selection-new-lines-end   ›   Create a new selection at the end of every line covered by selection
  vis-selection-new-match-all   ›   Select all regions matching the current selection
  vis-selection-new-match-next  ›   Select the next region matching the current selection
  vis-selection-new-match-skip  ›   Clear current selection, but select next match
  vis-selection-next            ›   Move to the next selection
  vis-selection-prev            ›   Move to the previous selection
  vis-selections-align          ›   Try to align all selections on the same column
  vis-selections-align-indent-left› Left-align all selections by inserting spaces
  vis-selections-align-indent-right›Right-align all selections by inserting spaces
  vis-selections-complement     ›   Complement selections
  vis-selections-intersect      ›   Intersect with selections from mark
  vis-selections-minus          ›   Subtract selections from mark
  vis-selections-remove-all     ›   Remove all but the primary selection
  vis-selections-remove-column  ›   Remove count selection column
  vis-selections-remove-column-except›  Remove all but the count selection column
  vis-selections-remove-last    ›   Remove primary selection
  vis-selections-restore        ›   Restore selections from mark
  vis-selections-rotate-left    ›   Rotate selections left
  vis-selections-rotate-right   ›   Rotate selections right
  vis-selections-save           ›   Save currently active selections to mark
  vis-selections-trim           ›   Remove leading and trailing white space from selections
  vis-selections-union          ›   Add selections from mark
  vis-suspend                   ›   Suspend the editor
  vis-textobject-angle-bracket-inner›   <> block (inner variant)
  vis-textobject-angle-bracket-outer›   <> block (outer variant)
  vis-textobject-backtick-inner ›   A backtick delimited string (inner variant)
  vis-textobject-backtick-outer ›   A backtick delimited string (outer variant)
  vis-textobject-bigword-inner  ›   A WORD leading and trailing whitespace excluded
  vis-textobject-bigword-outer  ›   A WORD leading and trailing whitespace included
  vis-textobject-curly-bracket-inner›   {} block (inner variant)
  vis-textobject-curly-bracket-outer›   {} block (outer variant)
  vis-textobject-indentation    ›   All adjacent lines with the same indentation level as the current one
  vis-textobject-line-inner     ›   The whole line, excluding leading and trailing whitespace
  vis-textobject-line-outer     ›   The whole line
  vis-textobject-paragraph      ›   A paragraph
  vis-textobject-paragraph-outer›   A paragraph (outer variant)
  vis-textobject-parenthesis-inner› () block (inner variant)
  vis-textobject-parenthesis-outer› () block (outer variant)
  vis-textobject-quote-inner    ›   A quoted string, excluding the quotation marks
  vis-textobject-quote-outer    ›   A quoted string, including the quotation marks
  vis-textobject-search-backward›   The next search match in backward direction
  vis-textobject-search-forward ›   The next search match in forward direction
  vis-textobject-sentence       ›   A sentence
  vis-textobject-single-quote-inner›A single quoted string, excluding the quotation marks
  vis-textobject-single-quote-outer›A single quoted string, including the quotation marks
 vis-textobject-square-bracket-inner›  [] block (inner variant)
  vis-textobject-square-bracket-outer›  [] block (outer variant)
  vis-textobject-word-inner     ›   A word leading and trailing whitespace excluded
  vis-textobject-word-outer     ›   A word leading and trailing whitespace included
  vis-undo                      ›   Undo last change
  vis-unicode-info              ›   Show Unicode codepoint(s) of character under cursor
  vis-utf8-info                 ›   Show UTF-8 encoded codepoint(s) of character under cursor
  vis-window-halfpage-down      ›   Scroll window half pages forwards (downwards)
  vis-window-halfpage-up        ›   Scroll window half pages backwards (upwards)
  vis-window-next               ›   Focus next window
  vis-window-page-down          ›   Scroll window pages forwards (downwards)
  vis-window-page-up            ›   Scroll window pages backwards (upwards)
  vis-window-prev               ›   Focus previous window
  vis-window-redraw-bottom      ›   Redraw cursor line at the bottom of the window
  vis-window-redraw-center      ›   Redraw cursor line at the center of the window
  vis-window-redraw-top         ›   Redraw cursor line at the top of the window
  vis-window-slide-down         ›   Slide window content downwards
  vis-window-slide-up           ›   Slide window content upwards
ninewise commented 3 years ago

This feature isn't built-in, and it shouldn't be, because it's really easy to write it in Lua:

vis:command_register("mx", function(argv, force, cur_win, selection, range)
    vis:feedkeys("<"..argv[1]..">")
end, "emacs' M-x")

I'm not really sure how this would be useful though, all those things have handy keybindings attached to them.

Also you didn't have to copy-paste half the help page to make your point.

mizlan commented 3 years ago

It would also be cool to combine this with vis-complete to make a nice interactive selection menu, if that's what you're interested in.

jgarte commented 3 years ago

This feature isn't built-in, and it shouldn't be, because it's really easy to write it in Lua:

vis:command_register("mx", function(argv, force, cur_win, selection, range)
  vis:feedkeys("<"..argv[1]..">")
end, "emacs' M-x")

Also you didn't have to copy-paste half the help page to make your point.

@ninewise Thanks for showing that example! I added it to my config :)

:mx vis-mode-insert didn't work but :mx vis-window-next did work.

I'm not really sure how this would be useful though, all those things have handy keybindings attached to them.

I'm primarily interested in exploring that API interactively (that is, while using the editor instead of a repl) for study purposes at the moment without having to create a keybinding for each function, so your example helped.

jgarte commented 3 years ago

It would also be cool to combine this with vis-complete to make a nice interactive selection menu, if that's what you're interested in.

@mizlan I would definitely be interested in that to. I'll attempt that next.

mcepl commented 1 year ago

@ninewise OK, this bug is still opened, although in my opinion it just a chatting about something which has been resolved already.