diff --git a/Makefile b/Makefile index 6f751971c..b70295533 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ MANPREFIX ?= ${PREFIX}/man VERSION = $(shell git describe --always --dirty 2>/dev/null || echo "0.2-git") +CONFIG_HELP ?= 1 CONFIG_LUA ?= 1 CONFIG_LPEG ?= 0 CONFIG_TRE ?= 0 @@ -34,6 +35,7 @@ CFLAGS_VIS = $(CFLAGS_AUTO) $(CFLAGS_TERMKEY) $(CFLAGS_CURSES) $(CFLAGS_ACL) \ $(CFLAGS_SELINUX) $(CFLAGS_TRE) $(CFLAGS_LUA) $(CFLAGS_LPEG) $(CFLAGS_STD) CFLAGS_VIS += -DVIS_PATH=\"${SHAREPREFIX}/vis\" +CFLAGS_VIS += -DCONFIG_HELP=${CONFIG_HELP} CFLAGS_VIS += -DCONFIG_LUA=${CONFIG_LUA} CFLAGS_VIS += -DCONFIG_LPEG=${CONFIG_LPEG} CFLAGS_VIS += -DCONFIG_TRE=${CONFIG_TRE} diff --git a/configure b/configure index 5255908f5..cefcc7b36 100755 --- a/configure +++ b/configure @@ -28,6 +28,7 @@ Optional features: --enable-tre build with TRE regex support [auto] --enable-selinux build with SELinux support [auto] --enable-acl build with POSIX ACL support [auto] + --enable-help build with built-in help texts [yes] Some influential environment variables: CC C compiler command [detected] @@ -114,6 +115,7 @@ BINDIR='$(EXEC_PREFIX)/bin' SHAREDIR='$(PREFIX)/share' MANDIR='$(PREFIX)/share/man' +help=yes lua=auto lpeg=auto tre=auto @@ -131,6 +133,8 @@ case "$arg" in --mandir=*) MANDIR=${arg#*=} ;; --environment-only) environmentonly=yes ;; --static) static=yes ;; +--enable-help|--enable-help=yes) help=yes ;; +--disable-help|--enable-help=no) help=no ;; --enable-lua|--enable-lua=yes) lua=yes ;; --disable-lua|--enable-lua=no) lua=no ;; --enable-lpeg|--enable-lpeg=yes) lpeg=yes ;; @@ -283,6 +287,12 @@ printf "checking for pkg-config... " cmdexists pkg-config && have_pkgconfig=yes printf "%s\n" "$have_pkgconfig" +if test "$help" = "yes" ; then + CONFIG_HELP=1 +else + CONFIG_HELP=0 +fi + # libcurses is a mandatory dependency printf "checking for libcurses...\n" @@ -585,6 +595,7 @@ CFLAGS_CURSES = $CFLAGS_CURSES LDFLAGS_CURSES = $LDFLAGS_CURSES CFLAGS_TERMKEY = $CFLAGS_TERMKEY LDFLAGS_TERMKEY = $LDFLAGS_TERMKEY +CONFIG_HELP = $CONFIG_HELP REGEX_SRC = $REGEX_SRC CONFIG_TRE = $CONFIG_TRE CFLAGS_TRE = $CFLAGS_TRE diff --git a/main.c b/main.c index 5e2401a4e..e4546764a 100644 --- a/main.c +++ b/main.c @@ -312,877 +312,877 @@ enum { static const KeyAction vis_action[] = { [VIS_ACTION_EDITOR_SUSPEND] = { "editor-suspend", - "Suspend the editor", + VIS_HELP("Suspend the editor") suspend, }, [VIS_ACTION_CURSOR_CHAR_PREV] = { "cursor-char-prev", - "Move cursor left, to the previous character", + VIS_HELP("Move cursor left, to the previous character") movement, { .i = VIS_MOVE_CHAR_PREV } }, [VIS_ACTION_CURSOR_CHAR_NEXT] = { "cursor-char-next", - "Move cursor right, to the next character", + VIS_HELP("Move cursor right, to the next character") movement, { .i = VIS_MOVE_CHAR_NEXT } }, [VIS_ACTION_CURSOR_LINE_CHAR_PREV] = { "cursor-line-char-prev", - "Move cursor left, to the previous character on the same line", + VIS_HELP("Move cursor left, to the previous character on the same line") movement, { .i = VIS_MOVE_LINE_CHAR_PREV } }, [VIS_ACTION_CURSOR_LINE_CHAR_NEXT] = { "cursor-line-char-next", - "Move cursor right, to the next character on the same line", + VIS_HELP("Move cursor right, to the next character on the same line") movement, { .i = VIS_MOVE_LINE_CHAR_NEXT } }, [VIS_ACTION_CURSOR_WORD_START_PREV] = { "cursor-word-start-prev", - "Move cursor words backwards", + VIS_HELP("Move cursor words backwards") movement, { .i = VIS_MOVE_WORD_START_PREV } }, [VIS_ACTION_CURSOR_WORD_START_NEXT] = { "cursor-word-start-next", - "Move cursor words forwards", + VIS_HELP("Move cursor words forwards") movement, { .i = VIS_MOVE_WORD_START_NEXT } }, [VIS_ACTION_CURSOR_WORD_END_PREV] = { "cursor-word-end-prev", - "Move cursor backwards to the end of word", + VIS_HELP("Move cursor backwards to the end of word") movement, { .i = VIS_MOVE_WORD_END_PREV } }, [VIS_ACTION_CURSOR_WORD_END_NEXT] = { "cursor-word-end-next", - "Move cursor forward to the end of word", + VIS_HELP("Move cursor forward to the end of word") movement, { .i = VIS_MOVE_WORD_END_NEXT } }, [VIS_ACTION_CURSOR_LONGWORD_START_PREV] = { "cursor-longword-start-prev", - "Move cursor WORDS backwards", + VIS_HELP("Move cursor WORDS backwards") movement, { .i = VIS_MOVE_LONGWORD_START_PREV } }, [VIS_ACTION_CURSOR_LONGWORD_START_NEXT] = { "cursor-longword-start-next", - "Move cursor WORDS forwards", + VIS_HELP("Move cursor WORDS forwards") movement, { .i = VIS_MOVE_LONGWORD_START_NEXT } }, [VIS_ACTION_CURSOR_LONGWORD_END_PREV] = { "cursor-longword-end-prev", - "Move cursor backwards to the end of WORD", + VIS_HELP("Move cursor backwards to the end of WORD") movement, { .i = VIS_MOVE_LONGWORD_END_PREV } }, [VIS_ACTION_CURSOR_LONGWORD_END_NEXT] = { "cursor-longword-end-next", - "Move cursor forward to the end of WORD", + VIS_HELP("Move cursor forward to the end of WORD") movement, { .i = VIS_MOVE_LONGWORD_END_NEXT } }, [VIS_ACTION_CURSOR_LINE_UP] = { "cursor-line-up", - "Move cursor line upwards", + VIS_HELP("Move cursor line upwards") movement, { .i = VIS_MOVE_LINE_UP } }, [VIS_ACTION_CURSOR_LINE_DOWN] = { "cursor-line-down", - "Move cursor line downwards", + VIS_HELP("Move cursor line downwards") movement, { .i = VIS_MOVE_LINE_DOWN } }, [VIS_ACTION_CURSOR_LINE_START] = { "cursor-line-start", - "Move cursor to first non-blank character of the line", + VIS_HELP("Move cursor to first non-blank character of the line") movement, { .i = VIS_MOVE_LINE_START } }, [VIS_ACTION_CURSOR_LINE_FINISH] = { "cursor-line-finish", - "Move cursor to last non-blank character of the line", + VIS_HELP("Move cursor to last non-blank character of the line") movement, { .i = VIS_MOVE_LINE_FINISH } }, [VIS_ACTION_CURSOR_LINE_BEGIN] = { "cursor-line-begin", - "Move cursor to first character of the line", + VIS_HELP("Move cursor to first character of the line") movement, { .i = VIS_MOVE_LINE_BEGIN } }, [VIS_ACTION_CURSOR_LINE_END] = { "cursor-line-end", - "Move cursor to end of the line", + VIS_HELP("Move cursor to end of the line") movement, { .i = VIS_MOVE_LINE_END } }, [VIS_ACTION_CURSOR_SCREEN_LINE_UP] = { "cursor-screenline-up", - "Move cursor screen/display line upwards", + VIS_HELP("Move cursor screen/display line upwards") movement, { .i = VIS_MOVE_SCREEN_LINE_UP } }, [VIS_ACTION_CURSOR_SCREEN_LINE_DOWN] = { "cursor-screenline-down", - "Move cursor screen/display line downwards", + VIS_HELP("Move cursor screen/display line downwards") movement, { .i = VIS_MOVE_SCREEN_LINE_DOWN } }, [VIS_ACTION_CURSOR_SCREEN_LINE_BEGIN] = { "cursor-screenline-begin", - "Move cursor to beginning of screen/display line", + VIS_HELP("Move cursor to beginning of screen/display line") movement, { .i = VIS_MOVE_SCREEN_LINE_BEGIN } }, [VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE] = { "cursor-screenline-middle", - "Move cursor to middle of screen/display line", + VIS_HELP("Move cursor to middle of screen/display line") movement, { .i = VIS_MOVE_SCREEN_LINE_MIDDLE } }, [VIS_ACTION_CURSOR_SCREEN_LINE_END] = { "cursor-screenline-end", - "Move cursor to end of screen/display line", + VIS_HELP("Move cursor to end of screen/display line") movement, { .i = VIS_MOVE_SCREEN_LINE_END } }, [VIS_ACTION_CURSOR_PERCENT] = { "cursor-percent", - "Move to count % of file or matching item", + VIS_HELP("Move to count % of file or matching item") percent }, [VIS_ACTION_CURSOR_BYTE] = { "cursor-byte", - "Move to absolute byte position", + VIS_HELP("Move to absolute byte position") movement, { .i = VIS_MOVE_BYTE } }, [VIS_ACTION_CURSOR_BYTE_LEFT] = { "cursor-byte-left", - "Move count bytes to the left", + VIS_HELP("Move count bytes to the left") movement, { .i = VIS_MOVE_BYTE_LEFT } }, [VIS_ACTION_CURSOR_BYTE_RIGHT] = { "cursor-byte-right", - "Move count bytes to the right", + VIS_HELP("Move count bytes to the right") movement, { .i = VIS_MOVE_BYTE_RIGHT } }, [VIS_ACTION_CURSOR_PARAGRAPH_PREV] = { "cursor-paragraph-prev", - "Move cursor paragraph backward", + VIS_HELP("Move cursor paragraph backward") movement, { .i = VIS_MOVE_PARAGRAPH_PREV } }, [VIS_ACTION_CURSOR_PARAGRAPH_NEXT] = { "cursor-paragraph-next", - "Move cursor paragraph forward", + VIS_HELP("Move cursor paragraph forward") movement, { .i = VIS_MOVE_PARAGRAPH_NEXT } }, [VIS_ACTION_CURSOR_SENTENCE_PREV] = { "cursor-sentence-prev", - "Move cursor sentence backward", + VIS_HELP("Move cursor sentence backward") movement, { .i = VIS_MOVE_SENTENCE_PREV } }, [VIS_ACTION_CURSOR_SENTENCE_NEXT] = { "cursor-sentence-next", - "Move cursor sentence forward", + VIS_HELP("Move cursor sentence forward") movement, { .i = VIS_MOVE_SENTENCE_NEXT } }, [VIS_ACTION_CURSOR_BLOCK_START] = { "cursor-block-start", - "Move cursor to the opening curly brace in a block", + VIS_HELP("Move cursor to the opening curly brace in a block") movement, { .i = VIS_MOVE_BLOCK_START } }, [VIS_ACTION_CURSOR_BLOCK_END] = { "cursor-block-end", - "Move cursor to the closing curly brace in a block", + VIS_HELP("Move cursor to the closing curly brace in a block") movement, { .i = VIS_MOVE_BLOCK_END } }, [VIS_ACTION_CURSOR_PARENTHESE_START] = { "cursor-parenthese-start", - "Move cursor to the opening parenthese inside a pair of parentheses", + VIS_HELP("Move cursor to the opening parenthese inside a pair of parentheses") movement, { .i = VIS_MOVE_PARENTHESE_START } }, [VIS_ACTION_CURSOR_PARENTHESE_END] = { "cursor-parenthese-end", - "Move cursor to the closing parenthese inside a pair of parentheses", + VIS_HELP("Move cursor to the closing parenthese inside a pair of parentheses") movement, { .i = VIS_MOVE_PARENTHESE_END } }, [VIS_ACTION_CURSOR_COLUMN] = { "cursor-column", - "Move cursor to given column of current line", + VIS_HELP("Move cursor to given column of current line") movement, { .i = VIS_MOVE_COLUMN } }, [VIS_ACTION_CURSOR_LINE_FIRST] = { "cursor-line-first", - "Move cursor to given line (defaults to first)", + VIS_HELP("Move cursor to given line (defaults to first)") gotoline, { .i = -1 } }, [VIS_ACTION_CURSOR_LINE_LAST] = { "cursor-line-last", - "Move cursor to given line (defaults to last)", + VIS_HELP("Move cursor to given line (defaults to last)") gotoline, { .i = +1 } }, [VIS_ACTION_CURSOR_WINDOW_LINE_TOP] = { "cursor-window-line-top", - "Move cursor to top line of the window", + VIS_HELP("Move cursor to top line of the window") movement, { .i = VIS_MOVE_WINDOW_LINE_TOP } }, [VIS_ACTION_CURSOR_WINDOW_LINE_MIDDLE] = { "cursor-window-line-middle", - "Move cursor to middle line of the window", + VIS_HELP("Move cursor to middle line of the window") movement, { .i = VIS_MOVE_WINDOW_LINE_MIDDLE } }, [VIS_ACTION_CURSOR_WINDOW_LINE_BOTTOM] = { "cursor-window-line-bottom", - "Move cursor to bottom line of the window", + VIS_HELP("Move cursor to bottom line of the window") movement, { .i = VIS_MOVE_WINDOW_LINE_BOTTOM } }, [VIS_ACTION_CURSOR_SEARCH_NEXT] = { "cursor-search-forward", - "Move cursor to next match", + VIS_HELP("Move cursor to next match") movement, { .i = VIS_MOVE_SEARCH_NEXT } }, [VIS_ACTION_CURSOR_SEARCH_PREV] = { "cursor-search-backward", - "Move cursor to previous match", + VIS_HELP("Move cursor to previous match") movement, { .i = VIS_MOVE_SEARCH_PREV } }, [VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD] = { "cursor-search-word-forward", - "Move cursor to next occurence of the word under cursor", + VIS_HELP("Move cursor to next occurence of the word under cursor") movement, { .i = VIS_MOVE_SEARCH_WORD_FORWARD } }, [VIS_ACTION_CURSOR_SEARCH_WORD_BACKWARD] = { "cursor-search-word-backward", - "Move cursor to previous occurence of the word under cursor", - movement, { .i = VIS_MOVE_SEARCH_WORD_BACKWARD } + VIS_HELP("Move cursor to previous occurence of the word under cursor") + movement, { .i = VIS_MOVE_SEARCH_WORD_BACKWARD } }, [VIS_ACTION_WINDOW_PAGE_UP] = { "window-page-up", - "Scroll window pages backwards (upwards)", + VIS_HELP("Scroll window pages backwards (upwards)") wscroll, { .i = -PAGE } }, [VIS_ACTION_WINDOW_HALFPAGE_UP] = { "window-halfpage-up", - "Scroll window half pages backwards (upwards)", + VIS_HELP("Scroll window half pages backwards (upwards)") wscroll, { .i = -PAGE_HALF } }, [VIS_ACTION_WINDOW_PAGE_DOWN] = { "window-page-down", - "Scroll window pages forwards (downwards)", + VIS_HELP("Scroll window pages forwards (downwards)") wscroll, { .i = +PAGE } }, [VIS_ACTION_WINDOW_HALFPAGE_DOWN] = { "window-halfpage-down", - "Scroll window half pages forwards (downwards)", + VIS_HELP("Scroll window half pages forwards (downwards)") wscroll, { .i = +PAGE_HALF } }, [VIS_ACTION_MODE_NORMAL] = { "vis-mode-normal", - "Enter normal mode", + VIS_HELP("Enter normal mode") switchmode, { .i = VIS_MODE_NORMAL } }, [VIS_ACTION_MODE_VISUAL] = { "vis-mode-visual-charwise", - "Enter characterwise visual mode", + VIS_HELP("Enter characterwise visual mode") switchmode, { .i = VIS_MODE_VISUAL } }, [VIS_ACTION_MODE_VISUAL_LINE] = { "vis-mode-visual-linewise", - "Enter linewise visual mode", + VIS_HELP("Enter linewise visual mode") switchmode, { .i = VIS_MODE_VISUAL_LINE } }, [VIS_ACTION_MODE_INSERT] = { "vis-mode-insert", - "Enter insert mode", + VIS_HELP("Enter insert mode") insertmode, { .i = VIS_MOVE_NOP } }, [VIS_ACTION_MODE_REPLACE] = { "vis-mode-replace", - "Enter replace mode", + VIS_HELP("Enter replace mode") replacemode, { .i = VIS_MOVE_NOP } }, [VIS_ACTION_DELETE_CHAR_PREV] = { "delete-char-prev", - "Delete the previous character", + VIS_HELP("Delete the previous character") delete, { .i = VIS_MOVE_CHAR_PREV } }, [VIS_ACTION_DELETE_CHAR_NEXT] = { "delete-char-next", - "Delete the next character", + VIS_HELP("Delete the next character") delete, { .i = VIS_MOVE_CHAR_NEXT } }, [VIS_ACTION_DELETE_LINE_BEGIN] = { "delete-line-begin", - "Delete until the start of the current line", + VIS_HELP("Delete until the start of the current line") delete, { .i = VIS_MOVE_LINE_BEGIN } }, [VIS_ACTION_DELETE_WORD_PREV] = { "delete-word-prev", - "Delete the previous WORD", + VIS_HELP("Delete the previous WORD") delete, { .i = VIS_MOVE_WORD_START_PREV } }, [VIS_ACTION_JUMPLIST_PREV] = { "jumplist-prev", - "Go to older cursor position in jump list", + VIS_HELP("Go to older cursor position in jump list") movement, { .i = VIS_MOVE_JUMPLIST_PREV } }, [VIS_ACTION_JUMPLIST_NEXT] = { "jumplist-next", - "Go to newer cursor position in jump list", + VIS_HELP("Go to newer cursor position in jump list") movement, { .i = VIS_MOVE_JUMPLIST_NEXT } }, [VIS_ACTION_CHANGELIST_PREV] = { "changelist-prev", - "Go to older cursor position in change list", + VIS_HELP("Go to older cursor position in change list") movement, { .i = VIS_MOVE_CHANGELIST_PREV } }, [VIS_ACTION_CHANGELIST_NEXT] = { "changelist-next", - "Go to newer cursor position in change list", + VIS_HELP("Go to newer cursor position in change list") movement, { .i = VIS_MOVE_CHANGELIST_NEXT } }, [VIS_ACTION_UNDO] = { "editor-undo", - "Undo last change", + VIS_HELP("Undo last change") undo, }, [VIS_ACTION_REDO] = { "editor-redo", - "Redo last change", + VIS_HELP("Redo last change") redo, }, [VIS_ACTION_EARLIER] = { "editor-earlier", - "Goto older text state", + VIS_HELP("Goto older text state") earlier, }, [VIS_ACTION_LATER] = { "editor-later", - "Goto newer text state", + VIS_HELP("Goto newer text state") later, }, [VIS_ACTION_MACRO_RECORD] = { "macro-record", - "Record macro into given register", + VIS_HELP("Record macro into given register") macro_record, }, [VIS_ACTION_MACRO_REPLAY] = { "macro-replay", - "Replay macro, execute the content of the given register", + VIS_HELP("Replay macro, execute the content of the given register") macro_replay, }, [VIS_ACTION_MARK_SET] = { "mark-set", - "Set given mark at current cursor position", + VIS_HELP("Set given mark at current cursor position") mark_set, }, [VIS_ACTION_MARK_GOTO] = { "mark-goto", - "Goto the position of the given mark", + VIS_HELP("Goto the position of the given mark") mark_motion, { .i = VIS_MOVE_MARK } }, [VIS_ACTION_MARK_GOTO_LINE] = { "mark-goto-line", - "Goto first non-blank character of the line containing the given mark", + VIS_HELP("Goto first non-blank character of the line containing the given mark") mark_motion, { .i = VIS_MOVE_MARK_LINE } }, [VIS_ACTION_REDRAW] = { "editor-redraw", - "Redraw current editor content", - call, { .f = vis_redraw } + VIS_HELP("Redraw current editor content") + call, { .f = vis_redraw } }, [VIS_ACTION_REPLACE_CHAR] = { "replace-char", - "Replace the character under the cursor", + VIS_HELP("Replace the character under the cursor") replace, }, [VIS_ACTION_TOTILL_REPEAT] = { "totill-repeat", - "Repeat latest to/till motion", + VIS_HELP("Repeat latest to/till motion") movement, { .i = VIS_MOVE_TOTILL_REPEAT } }, [VIS_ACTION_TOTILL_REVERSE] = { "totill-reverse", - "Repeat latest to/till motion but in opposite direction", + VIS_HELP("Repeat latest to/till motion but in opposite direction") movement, { .i = VIS_MOVE_TOTILL_REVERSE } }, [VIS_ACTION_PROMPT_SEARCH_FORWARD] = { "search-forward", - "Search forward", + VIS_HELP("Search forward") prompt_show, { .s = "/" } }, [VIS_ACTION_PROMPT_SEARCH_BACKWARD] = { "search-backward", - "Search backward", + VIS_HELP("Search backward") prompt_show, { .s = "?" } }, [VIS_ACTION_TILL_LEFT] = { "till-left", - "Till after the occurrence of character to the left", + VIS_HELP("Till after the occurrence of character to the left") movement_key, { .i = VIS_MOVE_LEFT_TILL } }, [VIS_ACTION_TILL_RIGHT] = { "till-right", - "Till before the occurrence of character to the right", + VIS_HELP("Till before the occurrence of character to the right") movement_key, { .i = VIS_MOVE_RIGHT_TILL } }, [VIS_ACTION_TO_LEFT] = { "to-left", - "To the first occurrence of character to the left", + VIS_HELP("To the first occurrence of character to the left") movement_key, { .i = VIS_MOVE_LEFT_TO } }, [VIS_ACTION_TO_RIGHT] = { "to-right", - "To the first occurrence of character to the right", + VIS_HELP("To the first occurrence of character to the right") movement_key, { .i = VIS_MOVE_RIGHT_TO } }, [VIS_ACTION_REGISTER] = { "register", - "Use given register for next operator", + VIS_HELP("Use given register for next operator") reg, }, [VIS_ACTION_OPERATOR_CHANGE] = { "vis-operator-change", - "Change operator", + VIS_HELP("Change operator") operator, { .i = VIS_OP_CHANGE } }, [VIS_ACTION_OPERATOR_DELETE] = { "vis-operator-delete", - "Delete operator", + VIS_HELP("Delete operator") operator, { .i = VIS_OP_DELETE } }, [VIS_ACTION_OPERATOR_YANK] = { "vis-operator-yank", - "Yank operator", + VIS_HELP("Yank operator") operator, { .i = VIS_OP_YANK } }, [VIS_ACTION_OPERATOR_SHIFT_LEFT] = { "vis-operator-shift-left", - "Shift left operator", + VIS_HELP("Shift left operator") operator, { .i = VIS_OP_SHIFT_LEFT } }, [VIS_ACTION_OPERATOR_SHIFT_RIGHT] = { "vis-operator-shift-right", - "Shift right operator", + VIS_HELP("Shift right operator") operator, { .i = VIS_OP_SHIFT_RIGHT } }, [VIS_ACTION_OPERATOR_CASE_LOWER] = { "vis-operator-case-lower", - "Lowercase operator", + VIS_HELP("Lowercase operator") operator, { .i = VIS_OP_CASE_LOWER } }, [VIS_ACTION_OPERATOR_CASE_UPPER] = { "vis-operator-case-upper", - "Uppercase operator", + VIS_HELP("Uppercase operator") operator, { .i = VIS_OP_CASE_UPPER } }, [VIS_ACTION_OPERATOR_CASE_SWAP] = { "vis-operator-case-swap", - "Swap case operator", + VIS_HELP("Swap case operator") operator, { .i = VIS_OP_CASE_SWAP } }, [VIS_ACTION_OPERATOR_FILTER] = { "vis-operator-filter", - "Filter operator", + VIS_HELP("Filter operator") operator_filter, }, [VIS_ACTION_OPERATOR_FILTER_FMT] = { "vis-operator-filter-format", - "Formating operator, filter range through fmt(1)", + VIS_HELP("Formating operator, filter range through fmt(1)") operator_filter, { .s = "|fmt" } }, [VIS_ACTION_COUNT] = { "vis-count", - "Count specifier", + VIS_HELP("Count specifier") count, }, [VIS_ACTION_INSERT_NEWLINE] = { "insert-newline", - "Insert a line break (depending on file type)", + VIS_HELP("Insert a line break (depending on file type)") call, { .f = vis_insert_nl } }, [VIS_ACTION_INSERT_TAB] = { "insert-tab", - "Insert a tab (might be converted to spaces)", + VIS_HELP("Insert a tab (might be converted to spaces)") call, { .f = vis_insert_tab } }, [VIS_ACTION_INSERT_VERBATIM] = { "insert-verbatim", - "Insert Unicode character based on code point", + VIS_HELP("Insert Unicode character based on code point") insert_verbatim, }, [VIS_ACTION_INSERT_REGISTER] = { "insert-register", - "Insert specified register content", + VIS_HELP("Insert specified register content") insert_register, }, [VIS_ACTION_WINDOW_NEXT] = { "window-next", - "Focus next window", + VIS_HELP("Focus next window") call, { .f = vis_window_next } }, [VIS_ACTION_WINDOW_PREV] = { "window-prev", - "Focus previous window", + VIS_HELP("Focus previous window") call, { .f = vis_window_prev } }, [VIS_ACTION_APPEND_CHAR_NEXT] = { "append-char-next", - "Append text after the cursor", + VIS_HELP("Append text after the cursor") insertmode, { .i = VIS_MOVE_LINE_CHAR_NEXT } }, [VIS_ACTION_APPEND_LINE_END] = { "append-line-end", - "Append text after the end of the line", + VIS_HELP("Append text after the end of the line") insertmode, { .i = VIS_MOVE_LINE_END }, }, [VIS_ACTION_INSERT_LINE_START] = { "insert-line-start", - "Insert text before the first non-blank in the line", + VIS_HELP("Insert text before the first non-blank in the line") insertmode, { .i = VIS_MOVE_LINE_START }, }, [VIS_ACTION_OPEN_LINE_ABOVE] = { "open-line-above", - "Begin a new line above the cursor", + VIS_HELP("Begin a new line above the cursor") openline, { .i = -1 } }, [VIS_ACTION_OPEN_LINE_BELOW] = { "open-line-below", - "Begin a new line below the cursor", + VIS_HELP("Begin a new line below the cursor") openline, { .i = +1 } }, [VIS_ACTION_JOIN_LINES] = { "join-lines", - "Join selected lines", + VIS_HELP("Join selected lines") join, { .s = " " } }, [VIS_ACTION_JOIN_LINES_TRIM] = { "join-lines-trim", - "Join selected lines, remove white space", + VIS_HELP("Join selected lines, remove white space") join, { .s = "" } }, [VIS_ACTION_PROMPT_SHOW] = { "prompt-show", - "Show editor command line prompt", + VIS_HELP("Show editor command line prompt") prompt_show, { .s = ":" } }, [VIS_ACTION_REPEAT] = { "editor-repeat", - "Repeat latest editor command", + VIS_HELP("Repeat latest editor command") repeat }, [VIS_ACTION_SELECTION_FLIP] = { "selection-flip", - "Flip selection, move cursor to other end", + VIS_HELP("Flip selection, move cursor to other end") selection_end, }, [VIS_ACTION_SELECTION_RESTORE] = { "selection-restore", - "Restore last selection", + VIS_HELP("Restore last selection") selection_restore, }, [VIS_ACTION_WINDOW_REDRAW_TOP] = { "window-redraw-top", - "Redraw cursor line at the top of the window", + VIS_HELP("Redraw cursor line at the top of the window") window, { .w = view_redraw_top } }, [VIS_ACTION_WINDOW_REDRAW_CENTER] = { "window-redraw-center", - "Redraw cursor line at the center of the window", + VIS_HELP("Redraw cursor line at the center of the window") window, { .w = view_redraw_center } }, [VIS_ACTION_WINDOW_REDRAW_BOTTOM] = { "window-redraw-bottom", - "Redraw cursor line at the bottom of the window", + VIS_HELP("Redraw cursor line at the bottom of the window") window, { .w = view_redraw_bottom } }, [VIS_ACTION_WINDOW_SLIDE_UP] = { "window-slide-up", - "Slide window content upwards", + VIS_HELP("Slide window content upwards") wslide, { .i = -1 } }, [VIS_ACTION_WINDOW_SLIDE_DOWN] = { "window-slide-down", - "Slide window content downwards", + VIS_HELP("Slide window content downwards") wslide, { .i = +1 } }, [VIS_ACTION_PUT_AFTER] = { "put-after", - "Put text after the cursor", + VIS_HELP("Put text after the cursor") operator, { .i = VIS_OP_PUT_AFTER } }, [VIS_ACTION_PUT_BEFORE] = { "put-before", - "Put text before the cursor", + VIS_HELP("Put text before the cursor") operator, { .i = VIS_OP_PUT_BEFORE } }, [VIS_ACTION_PUT_AFTER_END] = { "put-after-end", - "Put text after the cursor, place cursor after new text", + VIS_HELP("Put text after the cursor, place cursor after new text") operator, { .i = VIS_OP_PUT_AFTER_END } }, [VIS_ACTION_PUT_BEFORE_END] = { "put-before-end", - "Put text before the cursor, place cursor after new text", + VIS_HELP("Put text before the cursor, place cursor after new text") operator, { .i = VIS_OP_PUT_BEFORE_END } }, [VIS_ACTION_CURSOR_SELECT_WORD] = { "cursors-select-word", - "Select word under cursor", + VIS_HELP("Select word under cursor") cursors_select, }, [VIS_ACTION_CURSORS_NEW_LINE_ABOVE] = { "cursors-new-lines-above", - "Create a new cursor on the line above", + VIS_HELP("Create a new cursor on the line above") cursors_new, { .i = -1 } }, [VIS_ACTION_CURSORS_NEW_LINE_ABOVE_FIRST] = { "cursors-new-lines-above-first", - "Create a new cursor on the line above the first cursor", + VIS_HELP("Create a new cursor on the line above the first cursor") cursors_new, { .i = INT_MIN } }, [VIS_ACTION_CURSORS_NEW_LINE_BELOW] = { "cursor-new-lines-below", - "Create a new cursor on the line below", + VIS_HELP("Create a new cursor on the line below") cursors_new, { .i = +1 } }, [VIS_ACTION_CURSORS_NEW_LINE_BELOW_LAST] = { "cursor-new-lines-below-last", - "Create a new cursor on the line below the last cursor", + VIS_HELP("Create a new cursor on the line below the last cursor") cursors_new, { .i = INT_MAX } }, [VIS_ACTION_CURSORS_NEW_LINES_BEGIN] = { "cursors-new-lines-begin", - "Create a new cursor at the start of every line covered by selection", + VIS_HELP("Create a new cursor at the start of every line covered by selection") operator, { .i = VIS_OP_CURSOR_SOL } }, [VIS_ACTION_CURSORS_NEW_LINES_END] = { "cursors-new-lines-end", - "Create a new cursor at the end of every line covered by selection", + VIS_HELP("Create a new cursor at the end of every line covered by selection") operator, { .i = VIS_OP_CURSOR_EOL } }, [VIS_ACTION_CURSORS_NEW_MATCH_NEXT] = { "cursors-new-match-next", - "Select the next region matching the current selection", + VIS_HELP("Select the next region matching the current selection") cursors_select_next }, [VIS_ACTION_CURSORS_NEW_MATCH_SKIP] = { "cursors-new-match-skip", - "Clear current selection, but select next match", + VIS_HELP("Clear current selection, but select next match") cursors_select_skip, }, [VIS_ACTION_CURSORS_ALIGN] = { "cursors-align", - "Try to align all cursors on the same column", + VIS_HELP("Try to align all cursors on the same column") cursors_align, }, [VIS_ACTION_CURSORS_ALIGN_INDENT_LEFT] = { "cursors-align-indent-left", - "Left align all cursors/selections by inserting spaces", + VIS_HELP("Left align all cursors/selections by inserting spaces") cursors_align_indent, { .i = -1 } }, [VIS_ACTION_CURSORS_ALIGN_INDENT_RIGHT] = { "cursors-align-indent-right", - "Right align all cursors/selections by inserting spaces", + VIS_HELP("Right align all cursors/selections by inserting spaces") cursors_align_indent, { .i = +1 } }, [VIS_ACTION_CURSORS_REMOVE_ALL] = { "cursors-remove-all", - "Remove all but the primary cursor", + VIS_HELP("Remove all but the primary cursor") cursors_clear, }, [VIS_ACTION_CURSORS_REMOVE_LAST] = { "cursors-remove-last", - "Remove least recently created cursor", + VIS_HELP("Remove least recently created cursor") cursors_remove, }, [VIS_ACTION_CURSORS_REMOVE_COLUMN] = { "cursors-remove-column", - "Remove count cursor column", + VIS_HELP("Remove count cursor column") cursors_remove_column, { .i = 1 } }, [VIS_ACTION_CURSORS_REMOVE_COLUMN_EXCEPT] = { "cursors-remove-column-except", - "Remove all but the count cursor column", + VIS_HELP("Remove all but the count cursor column") cursors_remove_column_except, { .i = 1 } }, [VIS_ACTION_CURSORS_PREV] = { "cursors-prev", - "Move to the previous cursor", + VIS_HELP("Move to the previous cursor") cursors_navigate, { .i = -PAGE_HALF } }, [VIS_ACTION_CURSORS_NEXT] = { "cursors-next", - "Move to the next cursor", + VIS_HELP("Move to the next cursor") cursors_navigate, { .i = +PAGE_HALF } }, [VIS_ACTION_SELECTIONS_ROTATE_LEFT] = { "selections-rotate-left", - "Rotate selections left", + VIS_HELP("Rotate selections left") selections_rotate, { .i = -1 } }, [VIS_ACTION_SELECTIONS_ROTATE_RIGHT] = { "selections-rotate-right", - "Rotate selections right", + VIS_HELP("Rotate selections right") selections_rotate, { .i = +1 } }, [VIS_ACTION_SELECTIONS_TRIM] = { "selections-trim", - "Remove leading and trailing white space from selections", + VIS_HELP("Remove leading and trailing white space from selections") selections_trim }, [VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = { "text-object-word-outer", - "A word leading and trailing whitespace included", + VIS_HELP("A word leading and trailing whitespace included") textobj, { .i = VIS_TEXTOBJECT_OUTER_WORD } }, [VIS_ACTION_TEXT_OBJECT_WORD_INNER] = { "text-object-word-inner", - "A word leading and trailing whitespace excluded", + VIS_HELP("A word leading and trailing whitespace excluded") textobj, { .i = VIS_TEXTOBJECT_INNER_WORD } }, [VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER] = { "text-object-longword-outer", - "A WORD leading and trailing whitespace included", + VIS_HELP("A WORD leading and trailing whitespace included") textobj, { .i = VIS_TEXTOBJECT_OUTER_LONGWORD } }, [VIS_ACTION_TEXT_OBJECT_LONGWORD_INNER] = { "text-object-longword-inner", - "A WORD leading and trailing whitespace excluded", + VIS_HELP("A WORD leading and trailing whitespace excluded") textobj, { .i = VIS_TEXTOBJECT_INNER_LONGWORD } }, [VIS_ACTION_TEXT_OBJECT_SENTENCE] = { "text-object-sentence", - "A sentence", + VIS_HELP("A sentence") textobj, { .i = VIS_TEXTOBJECT_SENTENCE } }, [VIS_ACTION_TEXT_OBJECT_PARAGRAPH] = { "text-object-paragraph", - "A paragraph", + VIS_HELP("A paragraph") textobj, { .i = VIS_TEXTOBJECT_PARAGRAPH } }, [VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_OUTER] = { "text-object-square-bracket-outer", - "[] block (outer variant)", + VIS_HELP("[] block (outer variant)") textobj, { .i = VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_INNER] = { "text-object-square-bracket-inner", - "[] block (inner variant)", + VIS_HELP("[] block (inner variant)") textobj, { .i = VIS_TEXTOBJECT_INNER_SQUARE_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_PARANTHESE_OUTER] = { "text-object-parentheses-outer", - "() block (outer variant)", + VIS_HELP("() block (outer variant)") textobj, { .i = VIS_TEXTOBJECT_OUTER_PARANTHESE } }, [VIS_ACTION_TEXT_OBJECT_PARANTHESE_INNER] = { "text-object-parentheses-inner", - "() block (inner variant)", + VIS_HELP("() block (inner variant)") textobj, { .i = VIS_TEXTOBJECT_INNER_PARANTHESE } }, [VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_OUTER] = { "text-object-angle-bracket-outer", - "<> block (outer variant)", + VIS_HELP("<> block (outer variant)") textobj, { .i = VIS_TEXTOBJECT_OUTER_ANGLE_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_INNER] = { "text-object-angle-bracket-inner", - "<> block (inner variant)", + VIS_HELP("<> block (inner variant)") textobj, { .i = VIS_TEXTOBJECT_INNER_ANGLE_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_OUTER] = { "text-object-curly-bracket-outer", - "{} block (outer variant)", + VIS_HELP("{} block (outer variant)") textobj, { .i = VIS_TEXTOBJECT_OUTER_CURLY_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_INNER] = { "text-object-curly-bracket-inner", - "{} block (inner variant)", + VIS_HELP("{} block (inner variant)") textobj, { .i = VIS_TEXTOBJECT_INNER_CURLY_BRACKET } }, [VIS_ACTION_TEXT_OBJECT_QUOTE_OUTER] = { "text-object-quote-outer", - "A quoted string, including the quotation marks", + VIS_HELP("A quoted string, including the quotation marks") textobj, { .i = VIS_TEXTOBJECT_OUTER_QUOTE } }, [VIS_ACTION_TEXT_OBJECT_QUOTE_INNER] = { "text-object-quote-inner", - "A quoted string, excluding the quotation marks", + VIS_HELP("A quoted string, excluding the quotation marks") textobj, { .i = VIS_TEXTOBJECT_INNER_QUOTE } }, [VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_OUTER] = { "text-object-single-quote-outer", - "A single quoted string, including the quotation marks", + VIS_HELP("A single quoted string, including the quotation marks") textobj, { .i = VIS_TEXTOBJECT_OUTER_SINGLE_QUOTE } }, [VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_INNER] = { "text-object-single-quote-inner", - "A single quoted string, excluding the quotation marks", + VIS_HELP("A single quoted string, excluding the quotation marks") textobj, { .i = VIS_TEXTOBJECT_INNER_SINGLE_QUOTE } }, [VIS_ACTION_TEXT_OBJECT_BACKTICK_OUTER] = { "text-object-backtick-outer", - "A backtick delimited string (outer variant)", + VIS_HELP("A backtick delimited string (outer variant)") textobj, { .i = VIS_TEXTOBJECT_OUTER_BACKTICK } }, [VIS_ACTION_TEXT_OBJECT_BACKTICK_INNER] = { "text-object-backtick-inner", - "A backtick delimited string (inner variant)", + VIS_HELP("A backtick delimited string (inner variant)") textobj, { .i = VIS_TEXTOBJECT_INNER_BACKTICK } }, [VIS_ACTION_TEXT_OBJECT_ENTIRE_OUTER] = { "text-object-entire-outer", - "The whole text content", + VIS_HELP("The whole text content") textobj, { .i = VIS_TEXTOBJECT_OUTER_ENTIRE } }, [VIS_ACTION_TEXT_OBJECT_ENTIRE_INNER] = { "text-object-entire-inner", - "The whole text content, except for leading and trailing empty lines", + VIS_HELP("The whole text content, except for leading and trailing empty lines") textobj, { .i = VIS_TEXTOBJECT_INNER_ENTIRE } }, [VIS_ACTION_TEXT_OBJECT_LINE_OUTER] = { "text-object-line-outer", - "The whole line", - textobj, { .i = VIS_TEXTOBJECT_OUTER_LINE } + VIS_HELP("The whole line") + textobj, { .i = VIS_TEXTOBJECT_OUTER_LINE } }, [VIS_ACTION_TEXT_OBJECT_LINE_INNER] = { "text-object-line-inner", - "The whole line, excluding leading and trailing whitespace", + VIS_HELP("The whole line, excluding leading and trailing whitespace") textobj, { .i = VIS_TEXTOBJECT_INNER_LINE } }, [VIS_ACTION_TEXT_OBJECT_INDENTATION] = { "text-object-indentation", - "All adjacent lines with the same indentation level as the current one", + VIS_HELP("All adjacent lines with the same indentation level as the current one") textobj, { .i = VIS_TEXTOBJECT_INDENTATION } }, [VIS_ACTION_TEXT_OBJECT_SEARCH_FORWARD] = { "text-object-search-forward", - "The next search match in forward direction", + VIS_HELP("The next search match in forward direction") textobj, { .i = VIS_TEXTOBJECT_SEARCH_FORWARD } }, [VIS_ACTION_TEXT_OBJECT_SEARCH_BACKWARD] = { "text-object-search-backward", - "The next search match in backward direction", + VIS_HELP("The next search match in backward direction") textobj, { .i = VIS_TEXTOBJECT_SEARCH_BACKWARD } }, [VIS_ACTION_MOTION_CHARWISE] = { "motion-charwise", - "Force motion to be charwise", + VIS_HELP("Force motion to be charwise") motiontype, { .i = VIS_MOTIONTYPE_CHARWISE } }, [VIS_ACTION_MOTION_LINEWISE] = { "motion-linewise", - "Force motion to be linewise", + VIS_HELP("Force motion to be linewise") motiontype, { .i = VIS_MOTIONTYPE_LINEWISE } }, [VIS_ACTION_UNICODE_INFO] = { "unicode-info", - "Show Unicode codepoint(s) of character under cursor", + VIS_HELP("Show Unicode codepoint(s) of character under cursor") unicode_info, { .i = VIS_ACTION_UNICODE_INFO } }, [VIS_ACTION_UTF8_INFO] = { "utf8-info", - "Show UTF-8 encoded codepoint(s) of character under cursor", + VIS_HELP("Show UTF-8 encoded codepoint(s) of character under cursor") unicode_info, { .i = VIS_ACTION_UTF8_INFO } }, [VIS_ACTION_COMPLETE_WORD] = { "complete-word", - "Complete word in file", + VIS_HELP("Complete word in file") complete_word, }, [VIS_ACTION_COMPLETE_FILENAME] = { "complete-filename", - "Complete file name", + VIS_HELP("Complete file name") complete_filename, }, [VIS_ACTION_NOP] = { "nop", - "Ignore key, do nothing", + VIS_HELP("Ignore key, do nothing") nop, }, }; diff --git a/sam.c b/sam.c index fc41e5764..5747aa4e2 100644 --- a/sam.c +++ b/sam.c @@ -73,7 +73,7 @@ struct Command { struct CommandDef { const char *name; /* command name */ - const char *help; /* short, one-line help text */ + VIS_HELP_DECL(const char *help;) /* short, one-line help text */ enum { CMD_NONE = 0, /* standalone command without any arguments */ CMD_CMD = 1 << 0, /* does the command take a sub/target command? */ @@ -140,133 +140,133 @@ static const CommandDef cmds[] = { // name help // flags, default command, implemenation { - "a", "Append text after range", + "a", VIS_HELP("Append text after range") CMD_TEXT, NULL, cmd_append }, { - "c", "Change text in range", + "c", VIS_HELP("Change text in range") CMD_TEXT, NULL, cmd_change }, { - "d", "Delete text in range", + "d", VIS_HELP("Delete text in range") CMD_NONE, NULL, cmd_delete }, { - "g", "If range contains regexp, run command", + "g", VIS_HELP("If range contains regexp, run command") CMD_CMD|CMD_REGEX, "p", cmd_guard }, { - "i", "Insert text before range", + "i", VIS_HELP("Insert text before range") CMD_TEXT, NULL, cmd_insert }, { - "p", "Create selection covering range", + "p", VIS_HELP("Create selection covering range") CMD_NONE, NULL, cmd_print }, { - "s", "Substitute: use x/pattern/ c/replacement/ instead", + "s", VIS_HELP("Substitute: use x/pattern/ c/replacement/ instead") CMD_SHELL|CMD_ADDRESS_LINE, NULL, cmd_substitute }, { - "v", "If range does not contain regexp, run command", + "v", VIS_HELP("If range does not contain regexp, run command") CMD_CMD|CMD_REGEX, "p", cmd_guard }, { - "x", "Set range and run command on each match", + "x", VIS_HELP("Set range and run command on each match") CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT|CMD_ADDRESS_ALL_1CURSOR|CMD_LOOP, "p", cmd_extract }, { - "y", "As `x` but select unmatched text", + "y", VIS_HELP("As `x` but select unmatched text") CMD_CMD|CMD_REGEX|CMD_ADDRESS_ALL_1CURSOR|CMD_LOOP, "p", cmd_extract }, { - "X", "Run command on files whose name matches", + "X", VIS_HELP("Run command on files whose name matches") CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT|CMD_ADDRESS_NONE|CMD_ONCE, NULL, cmd_files }, { - "Y", "As `X` but select unmatched files", + "Y", VIS_HELP("As `X` but select unmatched files") CMD_CMD|CMD_REGEX|CMD_ADDRESS_NONE|CMD_ONCE, NULL, cmd_files }, { - ">", "Send range to stdin of command", + ">", VIS_HELP("Send range to stdin of command") CMD_SHELL|CMD_ADDRESS_LINE, NULL, cmd_pipeout }, { - "<", "Replace range by stdout of command", + "<", VIS_HELP("Replace range by stdout of command") CMD_SHELL|CMD_ADDRESS_POS, NULL, cmd_pipein }, { - "|", "Pipe range through command", + "|", VIS_HELP("Pipe range through command") CMD_SHELL|CMD_ADDRESS_POS, NULL, cmd_filter }, { - "!", "Run the command", + "!", VIS_HELP("Run the command") CMD_SHELL|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_launch }, { - "w", "Write range to named file", + "w", VIS_HELP("Write range to named file") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_ALL, NULL, cmd_write }, { - "r", "Replace range by contents of file", + "r", VIS_HELP("Replace range by contents of file") CMD_ARGV|CMD_ADDRESS_AFTER, NULL, cmd_read }, { - "{", "Start of command group", + "{", VIS_HELP("Start of command group") CMD_GROUP, NULL, NULL }, { - "}", "End of command group" , + "}", VIS_HELP("End of command group" ) CMD_NONE, NULL, NULL }, { - "e", "Edit file", + "e", VIS_HELP("Edit file") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_edit }, { - "q", "Quit the current window", + "q", VIS_HELP("Quit the current window") CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_quit }, { - "cd", "Change directory", + "cd", VIS_HELP("Change directory") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_cd }, /* vi(m) related commands */ { - "bdelete", "Unload file", + "bdelete", VIS_HELP("Unload file") CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_bdelete }, { - "help", "Show this help", + "help", VIS_HELP("Show this help") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_help }, { - "map", "Map key binding `:map `", + "map", VIS_HELP("Map key binding `:map `") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_map }, { - "map-window", "As `map` but window local", + "map-window", VIS_HELP("As `map` but window local") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_map }, { - "unmap", "Unmap key binding `:unmap `", + "unmap", VIS_HELP("Unmap key binding `:unmap `") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_unmap }, { - "unmap-window", "As `unmap` but window local", + "unmap-window", VIS_HELP("As `unmap` but window local") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_unmap }, { - "langmap", "Map keyboard layout `:langmap `", + "langmap", VIS_HELP("Map keyboard layout `:langmap `") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_langmap }, { - "new", "Create new window", + "new", VIS_HELP("Create new window") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_new }, { - "open", "Open file", + "open", VIS_HELP("Open file") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_open }, { - "qall", "Exit vis", + "qall", VIS_HELP("Exit vis") CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_qall }, { - "set", "Set option", + "set", VIS_HELP("Set option") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_set }, { - "split", "Horizontally split window", + "split", VIS_HELP("Horizontally split window") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_split }, { - "vnew", "As `:new` but split vertically", + "vnew", VIS_HELP("As `:new` but split vertically") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_vnew }, { - "vsplit", "Vertically split window", + "vsplit", VIS_HELP("Vertically split window") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_vsplit }, { - "wq", "Write file and quit", + "wq", VIS_HELP("Write file and quit") CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_ALL|CMD_DESTRUCTIVE, NULL, cmd_wq }, { - "earlier", "Go to older text state", + "earlier", VIS_HELP("Go to older text state") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_earlier_later }, { - "later", "Go to newer text state", + "later", VIS_HELP("Go to newer text state") CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_earlier_later }, - { NULL, NULL, CMD_NONE, NULL, NULL }, + { NULL, VIS_HELP(NULL) CMD_NONE, NULL, NULL }, }; static const CommandDef cmddef_select = { - NULL, NULL, CMD_NONE, NULL, cmd_select + NULL, VIS_HELP(NULL) CMD_NONE, NULL, cmd_select }; /* :set command options */ @@ -282,7 +282,7 @@ typedef struct { OPTION_FLAG_OPTIONAL = 1 << 0, /* value is optional */ OPTION_FLAG_WINDOW = 1 << 1, /* option requires an active window */ } flags; - const char *help; /* short, one line help text */ + VIS_HELP_DECL(const char *help;) /* short, one line help text */ } OptionDef; enum { @@ -309,89 +309,88 @@ static const OptionDef options[] = { [OPTION_SHELL] = { { "shell" }, OPTION_TYPE_STRING, OPTION_FLAG_NONE, - "Shell to use for external commands (default: $SHELL, /etc/passwd, /bin/sh)", + VIS_HELP("Shell to use for external commands (default: $SHELL, /etc/passwd, /bin/sh)") }, [OPTION_ESCDELAY] = { { "escdelay" }, OPTION_TYPE_NUMBER, OPTION_FLAG_NONE, - "Miliseconds to wait to distinguish from terminal escape sequences", + VIS_HELP("Miliseconds to wait to distinguish from terminal escape sequences") }, [OPTION_AUTOINDENT] = { { "autoindent", "ai" }, OPTION_TYPE_BOOL, OPTION_FLAG_NONE, - "Copy leading white space from previous line", + VIS_HELP("Copy leading white space from previous line") }, [OPTION_EXPANDTAB] = { { "expandtab", "et" }, OPTION_TYPE_BOOL, OPTION_FLAG_NONE, - "Replace entered with `tabwidth` spaces", + VIS_HELP("Replace entered with `tabwidth` spaces") }, [OPTION_TABWIDTH] = { { "tabwidth", "tw" }, OPTION_TYPE_NUMBER, OPTION_FLAG_NONE, - "Number of spaces to display (and insert if `expandtab` is enabled) for a tab", + VIS_HELP("Number of spaces to display (and insert if `expandtab` is enabled) for a tab") }, [OPTION_THEME] = { { "theme" }, OPTION_TYPE_STRING, OPTION_FLAG_NONE, - "Color theme to use filename without extension", + VIS_HELP("Color theme to use filename without extension") }, [OPTION_SYNTAX] = { { "syntax" }, OPTION_TYPE_STRING, OPTION_FLAG_WINDOW|OPTION_FLAG_OPTIONAL, - "Syntax highlighting lexer to use filename without extension", + VIS_HELP("Syntax highlighting lexer to use filename without extension") }, [OPTION_SHOW_SPACES] = { { "show-spaces" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Display replacement symbol instead of a space", + VIS_HELP("Display replacement symbol instead of a space") }, [OPTION_SHOW_TABS] = { { "show-tabs" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Display replacement symbol for tabs", + VIS_HELP("Display replacement symbol for tabs") }, [OPTION_SHOW_NEWLINES] = { { "show-newlines" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Display replacement symbol for newlines", + VIS_HELP("Display replacement symbol for newlines") }, [OPTION_NUMBER] = { { "numbers", "nu" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Display absolute line numbers", + VIS_HELP("Display absolute line numbers") }, [OPTION_NUMBER_RELATIVE] = { { "relativenumbers", "rnu" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Display relative line numbers", + VIS_HELP("Display relative line numbers") }, [OPTION_CURSOR_LINE] = { { "cursorline", "cul" }, OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, - "Highlight current cursor line", + VIS_HELP("Highlight current cursor line") }, [OPTION_COLOR_COLUMN] = { { "colorcolumn", "cc" }, OPTION_TYPE_NUMBER, OPTION_FLAG_WINDOW, - "Highlight a fixed column", + VIS_HELP("Highlight a fixed column") }, [OPTION_HORIZON] = { { "horizon" }, OPTION_TYPE_NUMBER, OPTION_FLAG_WINDOW, - "Number of bytes to consider for syntax highlighting", + VIS_HELP("Number of bytes to consider for syntax highlighting") }, [OPTION_SAVE_METHOD] = { { "savemethod" }, OPTION_TYPE_STRING, OPTION_FLAG_WINDOW, - "Save method to use for current file 'auto', 'atomic' or 'inplace'", + VIS_HELP("Save method to use for current file 'auto', 'atomic' or 'inplace'") }, [OPTION_CHANGE_256COLORS] = { { "change-256colors" }, OPTION_TYPE_BOOL, OPTION_FLAG_NONE, - "Change 256 color palette to support 24bit colors", + VIS_HELP("Change 256 color palette to support 24bit colors") }, - }; bool sam_init(Vis *vis) { diff --git a/vis-cmds.c b/vis-cmds.c index 5d0e230cb..43d2fed36 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -14,7 +14,7 @@ static void cmdfree(CmdUser *cmd) { if (!cmd) return; free((char*)cmd->def.name); - free((char*)cmd->def.help); + free(VIS_HELP_USE((char*)cmd->def.help)); free(cmd); } @@ -28,8 +28,10 @@ bool vis_cmd_register(Vis *vis, const char *name, const char *help, void *data, return false; if (!(cmd->def.name = strdup(name))) goto err; +#if CONFIG_HELP if (help && !(cmd->def.help = strdup(help))) goto err; +#endif cmd->def.flags = CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_ALL; cmd->def.func = cmd_user; cmd->func = func; @@ -564,7 +566,7 @@ static bool print_keybinding(const char *key, void *value, void *data) { KeyBinding *binding = value; const char *desc = binding->alias; if (!desc && binding->action) - desc = binding->action->help; + desc = VIS_HELP_USE(binding->action->help); return text_appendf(data, " %-18s\t%s\n", key[0] == ' ' ? "␣" : key, desc ? desc : ""); } @@ -575,14 +577,15 @@ static void print_mode(Mode *mode, Text *txt) { } static bool print_action(const char *key, void *value, void *data) { - KeyAction *action = value; - return text_appendf(data, " %-30s\t%s\n", key, action->help); + const char *help = VIS_HELP_USE(((KeyAction*)value)->help); + return text_appendf(data, " %-30s\t%s\n", key, help ? help : ""); } static bool print_cmd(const char *key, void *value, void *data) { - char help[256]; CommandDef *cmd = value; - snprintf(help, sizeof help, "%s%s%s%s%s%s%s", + const char *help = VIS_HELP_USE(cmd->help); + char usage[256]; + snprintf(usage, sizeof usage, "%s%s%s%s%s%s%s", cmd->name, (cmd->flags & CMD_FORCE) ? "[!]" : "", (cmd->flags & CMD_TEXT) ? "/text/" : "", @@ -590,7 +593,7 @@ static bool print_cmd(const char *key, void *value, void *data) { (cmd->flags & CMD_CMD) ? " command" : "", (cmd->flags & CMD_SHELL) ? (!strcmp(cmd->name, "s") ? "/regexp/text/" : " shell-command") : "", (cmd->flags & CMD_ARGV) ? " [args...]" : ""); - return text_appendf(data, " %-30s %s\n", help, cmd->help); + return text_appendf(data, " %-30s %s\n", usage, help ? help : ""); } static void print_symbolic_keys(Vis *vis, Text *txt) { @@ -693,26 +696,31 @@ static bool cmd_help(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso text_appendf(txt, "\n Marks\n\n"); text_appendf(txt, " a-z General purpose marks\n"); - for (size_t i = 0; i < LENGTH(vis_marks); i++) - text_appendf(txt, " %c %s\n", vis_marks[i].name, vis_marks[i].help); + for (size_t i = 0; i < LENGTH(vis_marks); i++) { + const char *help = VIS_HELP_USE(vis_marks[i].help); + text_appendf(txt, " %c %s\n", vis_marks[i].name, help ? help : ""); + } text_appendf(txt, "\n Registers\n\n"); text_appendf(txt, " a-z General purpose registers\n"); text_appendf(txt, " A-Z Append to corresponding general purpose register\n"); - for (size_t i = 0; i < LENGTH(vis_registers); i++) - text_appendf(txt, " %c %s\n", vis_registers[i].name, vis_registers[i].help); + for (size_t i = 0; i < LENGTH(vis_registers); i++) { + const char *help = VIS_HELP_USE(vis_registers[i].help); + text_appendf(txt, " %c %s\n", vis_registers[i].name, help ? help : ""); + } text_appendf(txt, "\n :set command options\n\n"); for (int i = 0; i < LENGTH(options); i++) { char names[256]; const OptionDef *opt = &options[i]; + const char *help = VIS_HELP_USE(opt->help); snprintf(names, sizeof names, "%s%s%s%s%s", opt->names[0], opt->names[1] ? "|" : "", opt->names[1] ? opt->names[1] : "", opt->type == OPTION_TYPE_BOOL ? " on|off" : "", opt->type == OPTION_TYPE_NUMBER ? " nn" : ""); - text_appendf(txt, " %-30s %s\n", names, opt->help ? opt->help : ""); + text_appendf(txt, " %-30s %s\n", names, help ? help : ""); } text_appendf(txt, "\n Key binding actions\n\n"); diff --git a/vis-core.h b/vis-core.h index bbfab36e8..a67fd6935 100644 --- a/vis-core.h +++ b/vis-core.h @@ -226,7 +226,7 @@ bool vis_event_emit(Vis*, enum VisEvents, ...); typedef struct { char name; - const char *help; + VIS_HELP_DECL(const char *help;) } MarkDef; typedef MarkDef RegisterDef; diff --git a/vis-modes.c b/vis-modes.c index 47d02c19a..00b99a7c4 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -8,7 +8,7 @@ static void keyaction_free(KeyAction *action) { if (!action) return; free((char*)action->name); - free((char*)action->help); + free(VIS_HELP_USE((char*)action->help)); free(action); } @@ -18,8 +18,10 @@ KeyAction *vis_action_new(Vis *vis, const char *name, const char *help, KeyActio return NULL; if (name && !(action->name = strdup(name))) goto err; +#if CONFIG_HELP if (help && !(action->help = strdup(help))) goto err; +#endif action->func = func; action->arg = arg; if (!array_add_ptr(&vis->actions_user, action)) diff --git a/vis.c b/vis.c index 303a5e619..8dfb38a39 100644 --- a/vis.c +++ b/vis.c @@ -29,29 +29,29 @@ #include "sam.h" const MarkDef vis_marks[] = { - [VIS_MARK_SELECTION_START] = { '<', "Last selection start" }, - [VIS_MARK_SELECTION_END] = { '>', "Last selection end" }, + [VIS_MARK_SELECTION_START] = { '<', VIS_HELP("Last selection start") }, + [VIS_MARK_SELECTION_END] = { '>', VIS_HELP("Last selection end") }, }; const RegisterDef vis_registers[] = { - [VIS_REG_DEFAULT] = { '"', "Unnamed register" }, - [VIS_REG_ZERO] = { '0', "Yank register" }, - [VIS_REG_1] = { '1', "1st sub-expression match" }, - [VIS_REG_2] = { '2', "2nd sub-expression match" }, - [VIS_REG_3] = { '3', "3rd sub-expression match" }, - [VIS_REG_4] = { '4', "4th sub-expression match" }, - [VIS_REG_5] = { '5', "5th sub-expression match" }, - [VIS_REG_6] = { '6', "6th sub-expression match" }, - [VIS_REG_7] = { '7', "7th sub-expression match" }, - [VIS_REG_8] = { '8', "8th sub-expression match" }, - [VIS_REG_9] = { '9', "9th sub-expression match" }, - [VIS_REG_AMPERSAND] = { '&', "Last regex match" }, - [VIS_REG_BLACKHOLE] = { '_', "/dev/null register" }, - [VIS_REG_CLIPBOARD] = { '*', "System clipboard register, see vis-clipboard(1)" }, - [VIS_REG_DOT] = { '.', "Last inserted text" }, - [VIS_REG_SEARCH] = { '/', "Last search pattern" }, - [VIS_REG_COMMAND] = { ':', "Last :-command" }, - [VIS_REG_SHELL] = { '!', "Last shell command given to either <, >, |, or !" }, + [VIS_REG_DEFAULT] = { '"', VIS_HELP("Unnamed register") }, + [VIS_REG_ZERO] = { '0', VIS_HELP("Yank register") }, + [VIS_REG_1] = { '1', VIS_HELP("1st sub-expression match") }, + [VIS_REG_2] = { '2', VIS_HELP("2nd sub-expression match") }, + [VIS_REG_3] = { '3', VIS_HELP("3rd sub-expression match") }, + [VIS_REG_4] = { '4', VIS_HELP("4th sub-expression match") }, + [VIS_REG_5] = { '5', VIS_HELP("5th sub-expression match") }, + [VIS_REG_6] = { '6', VIS_HELP("6th sub-expression match") }, + [VIS_REG_7] = { '7', VIS_HELP("7th sub-expression match") }, + [VIS_REG_8] = { '8', VIS_HELP("8th sub-expression match") }, + [VIS_REG_9] = { '9', VIS_HELP("9th sub-expression match") }, + [VIS_REG_AMPERSAND] = { '&', VIS_HELP("Last regex match") }, + [VIS_REG_BLACKHOLE] = { '_', VIS_HELP("/dev/null register") }, + [VIS_REG_CLIPBOARD] = { '*', VIS_HELP("System clipboard register, see vis-clipboard(1)") }, + [VIS_REG_DOT] = { '.', VIS_HELP("Last inserted text") }, + [VIS_REG_SEARCH] = { '/', VIS_HELP("Last search pattern") }, + [VIS_REG_COMMAND] = { ':', VIS_HELP("Last :-command") }, + [VIS_REG_SHELL] = { '!', VIS_HELP("Last shell command given to either <, >, |, or !") }, }; static Macro *macro_get(Vis *vis, enum VisRegister); diff --git a/vis.h b/vis.h index 31d6994e6..b6fb09ef6 100644 --- a/vis.h +++ b/vis.h @@ -14,6 +14,20 @@ typedef struct Win Win; #include "text-regex.h" #include "libutf.h" +#ifndef CONFIG_HELP +#define CONFIG_HELP 1 +#endif + +#if CONFIG_HELP +#define VIS_HELP_DECL(x) x +#define VIS_HELP_USE(x) x +#define VIS_HELP(x) (x), +#else +#define VIS_HELP_DECL(x) +#define VIS_HELP_USE(x) NULL +#define VIS_HELP(x) +#endif + /* simplify utility renames by distribution packagers */ #ifndef VIS_MENU #define VIS_MENU "vis-menu" @@ -66,7 +80,7 @@ typedef const char *KeyActionFunction(Vis*, const char *keys, const Arg*); typedef struct { /* a KeyAction can be bound to a key binding */ const char *name; /* aliases can refer to this action by means of a pseudo key */ - const char *help; /* short (one line) human readable description, displayed by :help */ + VIS_HELP_DECL(const char *help;) /* short (one line) human readable description, displayed by :help */ KeyActionFunction *func; /* action implementation */ Arg arg; /* additional arguments which will be passed as to func */ } KeyAction;