From 2b905f8fc642eb1523e9a3fca441fea97bffb7aa Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 12 Jul 2022 16:52:59 +0900 Subject: [PATCH] emacs,vi: support "bleopt prompt_{emacs,vi}_mode_indicator" --- blerc | 57 +++++++++++++------ contrib | 2 +- docs/ChangeLog.md | 11 ++-- keymap/emacs.sh | 87 ++++++++++++++++++++-------- keymap/vi.sh | 140 ++++++++++++++++++++++++++++++---------------- note.txt | 33 ++++++++++- src/edit.sh | 4 +- 7 files changed, 236 insertions(+), 98 deletions(-) diff --git a/blerc b/blerc index ea7b6fca..e467413f 100644 --- a/blerc +++ b/blerc @@ -840,15 +840,25 @@ ## Settings for Emacs mode function blerc/emacs-load-hook { - ## This option specifies the mode string shown in the information line in the - ## multiline editing mode. When an empty string is specified, the mode - ## string is not shown in the multiline editing mode. + #---------------------------------------------------------------------------- + # Settings for the mode indicator + + ## The following option specifies the content of the mode indicator shown in + ## the info line as a prompt sequence. + + #bleopt prompt_emacs_mode_indicator='\q{keymap:emacs/mode-indicator}' + + + ## The following option specifies the multiline mode name used in the prompt + ## sequence \q{keymap:emacs/mode-indicator} in the multiline editing mode. # default #bleopt keymap_emacs_mode_string_multiline=$'\e[1m-- MULTILINE --\e[m' - # do not show mode string + # do not show the mode name #bleopt keymap_emacs_mode_string_multiline= + #---------------------------------------------------------------------------- + # Keybindings ## With the following setting, RET and C-m always causes the execution of the ## command even in the multiline mode or when the command is not @@ -868,15 +878,25 @@ function blerc/vim-load-hook { ((_ble_bash>=40300)) && builtin bind 'set keyseq-timeout 1' #---------------------------------------------------------------------------- - # Settings for the mode name + # Settings for the mode indicator + + ## The following option specifies the content of the mode indicator shown in + ## the info line as a prompt sequence. + + #bleopt prompt_vi_mode_indicator='\q{keymap:vi/mode-indicator}' - ## The option "keymap_vi_mode_show" controls if the mode line is shown. When - ## this option has a non-empty value, the mode line is shown. + + ## The following option controls whether the prompt sequence + ## \q{keymap:vi/mode-indicator} is activated. When this option has a + ## non-empty value, \q{keymap:vi/mode-indicator} is expanded to the mode + ## indicator. Otherwise, \q{keymap:vi/mode-indicator} is expanded to the + ## empty string. #bleopt keymap_vi_mode_show=1 - ## The following settings specify the name of modes in the mode line. + ## The following options specify the name of modes in + ## \q{keymap:vi/mode-indicator}. #bleopt keymap_vi_mode_name_insert=INSERT #bleopt keymap_vi_mode_name_replace=REPLACE @@ -887,26 +907,29 @@ function blerc/vim-load-hook { #bleopt keymap_vi_mode_name_blockwise=BLOCK - ## This option specifies the string shown below the edited line in normal - ## mode. For example, if you want to show an explicit name of the mode like - ## in other modes, please use the following setting: + ## This option specifies the result of \q{keymap:vi/mode-indicator} in the + ## normal mode. For example, if you want to show an explicit name of the + ## normal mode like in other modes, please use the following setting: - #bleopt keymap_vi_mode_string_nmap:=$'\e[1m~\e[m' + #bleopt keymap_vi_mode_string_nmap:=$'\e[1m-- NORMAL --\e[m' - ## The setting "keymap_vi_mode_update_prompt" specifies that the prompt - ## should be recalculated on the mode change. When this option has a - ## non-empty value, the prompt will be recalculated. + ## This option specifies that all the prompts should be recalculated on the + ## mode change. When this option has a non-empty value, the prompt will be + ## recalculated. #bleopt keymap_vi_mode_update_prompt= #---------------------------------------------------------------------------- # Keybindings - - ## The following setting sets up the keymap settings with Meta modifiers + ## The following setting sets up the keymap settings with Meta modifiers. + ## With this setting, M-RET can be used to insert a newline in the + ## commandline. In this case, C-RET can be optionally configured so that it + ## forcibly executes the command. #ble-decode/keymap:vi_imap/define-meta-bindings + #ble-bind -m vi_imap -f 'C-RET' 'accept-line' ## The default mapping of C-o is vi_imap/single-command-mode. If you want to diff --git a/contrib b/contrib index 5fdf5560..4345a10a 160000 --- a/contrib +++ b/contrib @@ -1 +1 @@ -Subproject commit 5fdf55608c0db9d97c80cb8ab6c12e2b911786e8 +Subproject commit 4345a10a9484250fe9a4f83259c21e05c20a7153 diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 9e8a9127..5f76570e 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -103,6 +103,7 @@ - util: synchronize rlvars with `bleopt complete_{menu_color{,_match},skip_matched} term_bracketed_paste_mode` (motivated by ArianaAsl) `#D1819` 6d20f51 - util: suppress false warnings of `bind` inside non-interactive shells (reported by wukuan405) `#D1823` 1e19a67 - history: support `bleopt history_erasedups_limit` (motivated by SuperSandro2000) `#D1822` e4afb5a 3110967 +- prompt: support `bleopt prompt_{emacs,vi}_mode_indicator` (motivated by ferdinandyb) `#D1843` XXXXXXX ## Changes @@ -200,7 +201,7 @@ - global: fix declaration of associative arrays for `ble-reload` (reported by 0xC0ncord) `#D1471` 3cae6e4 - global: use a better workaround of bash-4.2 `declare -gA` by separating assignment `#D1567` 2408a20 - bind: work around broken `cmd_xmap` after switching the editing mode `#D1478` 8d354c1 - - decode (`encoding:C`): fix initialization for isolated ESC `#D1839` XXXXXXX + - decode (`encoding:C`): fix initialization for isolated ESC `#D1839` c3bba5b - edit: clear graphic rendition on newlines and external commands `#D1479` 18bb2d5 - decode (rlfunc): work around incomplete bytes in keyseq (reported by onelittlehope) `#D1483` 3559658 beb0383 37363be - main: fix a bug that unset `IFS` is not correctly restored `#D1489` 808f6f7 @@ -268,8 +269,8 @@ - edit: fix an unexpected leave from the command layout on `read` `#D1800` 4dbf16f - history: work around possible dirty prefix `*` in the history output `#D1808` 64a740d - decode (`ble-bind`): fix the printed definition of `-c`/`-x` bindings `#D1821` 94de078 -- command-help (`.read-man`): add missing `ble/util/assign/.rmtmp` `#D1840` XXXXXXX -- complete: fix wrong `COMP_POINT` with `progcomp_alias` `#D1841` XXXXXXX +- command-help (`.read-man`): add missing `ble/util/assign/.rmtmp` `#D1840` 937a164 +- complete: fix wrong `COMP_POINT` with `progcomp_alias` `#D1841` 369f7c0 ## Documentation @@ -369,8 +370,8 @@ - history: work around broken timestamps in `HISTFILE` (reported by johnyaku) `#D1831` 5ef28eb - progcomp: disable `command_not_found_handle` (reported by telometto, wisnoskij) `#D1834` 64d471a d5fe1d1 973ae8c - complete: add completion integration with `zoxide` (reported by ferdinandyb) `#D1838` a96bafe -- util (`modifyOtherKeys`): work around delayed terminal identification `#D1842` XXXXXXX - - util (`modifyOtherKeys`): fix a bug that kitty protocol is never activated `#D1842` XXXXXXX +- util (`modifyOtherKeys`): work around delayed terminal identification `#D1842` 14f3c81 + - util (`modifyOtherKeys`): fix a bug that kitty protocol is never activated `#D1842` 14f3c81 ## Internal changes and fixes diff --git a/keymap/emacs.sh b/keymap/emacs.sh index 6fd70d4c..483168f8 100644 --- a/keymap/emacs.sh +++ b/keymap/emacs.sh @@ -77,45 +77,86 @@ function ble/widget/emacs/revert { # mode name の更新は基本的に __after_widget__ で行う。 # 但し、_ble_decode_{char,key}__hook 経由で実行されると、 # __after_widget__ は実行されないので、 -# その様な編集コマンドについてだけは個別に update-mode-name を呼び出す。 +# その様な編集コマンドについてだけは個別に update-mode-indicator を呼び出す。 # -## @var _ble_keymap_emacs_mode -## 複数行モードかどうか。 -_ble_keymap_emacs_modeline=:: -ble/array#push _ble_textarea_local_VARNAMES \ - _ble_keymap_emacs_modeline -function ble/keymap:emacs/update-mode-name { +function ble/keymap:emacs/.get-emacs-keymap { + ble/prompt/unit/add-hash '$_ble_decode_keymap,${_ble_decode_keymap_stack[*]}' + local i=${#_ble_decode_keymap_stack[@]} + keymap=$_ble_decode_keymap + while [[ $keymap != vi_?map && $keymap != emacs ]]; do + ((i--)) || return 1 + keymap=${_ble_decode_keymap_stack[i]} + done + [[ $keymap == emacs ]] +} + +bleopt/declare -v prompt_emacs_mode_indicator '\q{keymap:emacs/mode-indicator}' +function bleopt/check:prompt_emacs_mode_indicator { + local bleopt_prompt_emacs_mode_indicator=$value + [[ $_ble_attached ]] && ble/keymap:emacs/update-mode-indicator + return 0 +} + +_ble_keymap_emacs_mode_indicator_data=() +function ble/prompt/unit:_ble_keymap_emacs_mode_indicator/update { + local trace_opts=truncate:relative:noscrc:ansi + local prompt_rows=1 + local prompt_cols=${COLUMNS:-80} + ((prompt_cols&&prompt_cols--)) + local "${_ble_prompt_cache_vars[@]/%/=}" # WA #D1570 checked + ble/prompt/unit:{section}/update _ble_keymap_emacs_mode_indicator "$bleopt_prompt_emacs_mode_indicator" "$trace_opts" +} + +function ble/keymap:emacs/update-mode-indicator { + local keymap + ble/keymap:emacs/.get-emacs-keymap || return 0 + + # prefilter by _ble_edit_str/_ble_edit_arg/_ble_edit_kbdmacro_record local opt_multiline= - [[ $bleopt_keymap_emacs_mode_string_multiline && $_ble_edit_str == *$'\n'* ]] && opt_multiline=1 + [[ $_ble_edit_str == *$'\n'* ]] && opt_multiline=1 local footprint=$opt_multiline:$_ble_edit_arg:$_ble_edit_kbdmacro_record - [[ $footprint == "$_ble_keymap_emacs_modeline" ]] && return 0 _ble_keymap_emacs_modeline=$footprint - local name= - [[ $opt_multiline ]] && name=$bleopt_keymap_emacs_mode_string_multiline + # prompt_emacs_mode_indicator + local version=$COLUMNS,$_ble_edit_lineno,$_ble_history_count,$_ble_edit_CMD + local prompt_hashref_base='$version' + ble/prompt/unit#update _ble_keymap_emacs_mode_indicator + ble/prompt/unit:{section}/get _ble_keymap_emacs_mode_indicator; local str=$ret - local info= [[ $_ble_edit_arg ]] && - info=$info$' (arg: \e[1;34m'$_ble_edit_arg$'\e[m)' + str=${str:+"$str "}$'(arg: \e[1;34m'$_ble_edit_arg$'\e[m)' [[ $_ble_edit_kbdmacro_record ]] && - info=$info$' \e[1;31mREC\e[m' - if [[ ! $info && $opt_multiline ]]; then + str=${str:+"$str "}$'\e[1;31mREC\e[m' + + ble/edit/info/default ansi "$str" +} +blehook PRECMD+=ble/keymap:emacs/update-mode-indicator + +## @fn ble/prompt/backslash:keymap:emacs/mode-indicator +function ble/prompt/backslash:keymap:emacs/mode-indicator { + ble/prompt/unit/add-hash '$_ble_edit_str' + [[ $_ble_edit_str == *$'\n'* ]] || return 0 + + ble/prompt/unit/add-hash '$bleopt_keymap_emacs_mode_string_multiline' + local str=$bleopt_keymap_emacs_mode_string_multiline + + # 他の付加情報がない時にだけ keybinding のヒントを出す + ble/prompt/unit/add-hash '${_ble_edit_arg:+1}${_ble_edit_kbdmacro_record:+1}' + if [[ ! ${_ble_edit_arg:+1}${_ble_edit_kbdmacro_record:+1} ]]; then local keybinding_C_m=${_ble_decode_emacs_kmap_[_ble_decode_Ctrl|0x6d]} local keybinding_C_j=${_ble_decode_emacs_kmap_[_ble_decode_Ctrl|0x6a]} [[ $keybinding_C_m == *:ble/widget/accept-single-line-or-newline ]] && [[ $keybinding_C_j == *:ble/widget/accept-line ]] && - info=$' (\e[35mRET\e[m or \e[35mC-m\e[m: insert a newline, \e[35mC-j\e[m: run)' + str=${str:+"$str "}$'(\e[35mRET\e[m or \e[35mC-m\e[m: insert a newline, \e[35mC-j\e[m: run)' fi - [[ $name ]] || info=${info#' '} - name=$name$info - ble/edit/info/default ansi "$name" + [[ ! $str ]] || ble/prompt/print "$str" } function ble/widget/emacs/__after_widget__ { - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator } # quoted-insert @@ -126,7 +167,7 @@ function ble/widget/emacs/quoted-insert-char { } function ble/widget/emacs/quoted-insert-char.hook { ble/widget/quoted-insert-char.hook - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator } function ble/widget/emacs/quoted-insert { _ble_edit_mark_active= @@ -135,7 +176,7 @@ function ble/widget/emacs/quoted-insert { } function ble/widget/emacs/quoted-insert.hook { ble/widget/quoted-insert.hook - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator } function ble/widget/emacs/bracketed-paste { @@ -145,7 +186,7 @@ function ble/widget/emacs/bracketed-paste { } function ble/widget/emacs/bracketed-paste.proc { ble/widget/bracketed-paste.proc "$@" - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator } #------------------------------------------------------------------------------ diff --git a/keymap/vi.sh b/keymap/vi.sh index c3b3a179..e504dc23 100644 --- a/keymap/vi.sh +++ b/keymap/vi.sh @@ -360,7 +360,7 @@ bleopt/declare -v keymap_vi_mode_show 1 function bleopt/check:keymap_vi_mode_show { local bleopt_keymap_vi_mode_show=$value [[ $_ble_attached ]] && - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } @@ -372,13 +372,13 @@ bleopt/declare -v keymap_vi_mode_name_visual 'VISUAL' bleopt/declare -v keymap_vi_mode_name_select 'SELECT' bleopt/declare -v keymap_vi_mode_name_linewise 'LINE' bleopt/declare -v keymap_vi_mode_name_blockwise 'BLOCK' -function bleopt/check:keymap_vi_mode_name_insert { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_replace { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_vreplace { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_visual { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_select { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_linewise { ble/keymap:vi/update-mode-name; } -function bleopt/check:keymap_vi_mode_name_blockwise { ble/keymap:vi/update-mode-name; } +function bleopt/check:keymap_vi_mode_name_insert { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_replace { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_vreplace { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_visual { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_select { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_linewise { ble/keymap:vi/update-mode-indicator; } +function bleopt/check:keymap_vi_mode_name_blockwise { ble/keymap:vi/update-mode-indicator; } ## @fn ble/keymap:vi/script/get-vi-keymap @@ -389,7 +389,7 @@ function ble/keymap:vi/script/get-vi-keymap { local i=${#_ble_decode_keymap_stack[@]} keymap=$_ble_decode_keymap - while [[ $keymap != vi_?map || $keymap == emacs ]]; do + while [[ $keymap != vi_?map && $keymap != emacs ]]; do ((i--)) || return 1 keymap=${_ble_decode_keymap_stack[i]} done @@ -440,11 +440,28 @@ _ble_keymap_vi_mode_name_dirty= function ble/keymap:vi/info_reveal.hook { [[ $_ble_keymap_vi_mode_name_dirty ]] || return 0 _ble_keymap_vi_mode_name_dirty= - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator } blehook info_reveal+=ble/keymap:vi/info_reveal.hook -function ble/keymap:vi/update-mode-name { +bleopt/declare -v prompt_vi_mode_indicator '\q{keymap:vi/mode-indicator}' +function bleopt/check:prompt_vi_mode_indicator { + local bleopt_prompt_vi_mode_indicator=$value + [[ $_ble_attached ]] && ble/keymap:vi/update-mode-indicator + return 0 +} + +_ble_keymap_vi_mode_indicator_data=() +function ble/prompt/unit:_ble_keymap_vi_mode_indicator/update { + local trace_opts=truncate:relative:noscrc:ansi + local prompt_rows=1 + local prompt_cols=${COLUMNS:-80} + ((prompt_cols&&prompt_cols--)) + local "${_ble_prompt_cache_vars[@]/%/=}" # WA #D1570 checked + ble/prompt/unit:{section}/update _ble_keymap_vi_mode_indicator "$bleopt_prompt_vi_mode_indicator" "$trace_opts" +} + +function ble/keymap:vi/update-mode-indicator { if [[ ! $_ble_attached ]] || ble/edit/is-command-layout; then _ble_keymap_vi_mode_name_dirty=1 return 0 @@ -471,18 +488,47 @@ function ble/keymap:vi/update-mode-name { [[ $bleopt_keymap_vi_mode_update_prompt ]] && ble/prompt/clear - local name= - if [[ $bleopt_keymap_vi_mode_show ]]; then - local show= overwrite= - if [[ $keymap == vi_imap ]]; then - show=1 overwrite=$_ble_edit_overwrite_mode - elif [[ $_ble_keymap_vi_single_command && ( $keymap == vi_nmap || $keymap == vi_omap ) ]]; then - show=1 overwrite=$_ble_keymap_vi_single_command_overwrite - elif [[ $keymap == vi_[xs]map ]]; then - show=x overwrite=$_ble_keymap_vi_single_command_overwrite - else - name=$bleopt_keymap_vi_mode_string_nmap - fi + # prompt_vi_mode_indicator + local prompt_vi_keymap=$keymap + local version=$COLUMNS,$_ble_edit_lineno,$_ble_history_count,$_ble_edit_CMD + local prompt_hashref_base='$version' + ble/prompt/unit#update _ble_keymap_vi_mode_indicator + ble/prompt/unit:{section}/get _ble_keymap_vi_mode_indicator; local mode=$ret + + local str=$mode + if [[ $_ble_keymap_vi_reg_record ]]; then + str=$str${str:+' '}$'\e[1;31mREC @'$_ble_keymap_vi_reg_record_char$'\e[m' + elif [[ $_ble_edit_kbdmacro_record ]]; then + str=$str${str:+' '}$'\e[1;31mREC\e[m' + fi + + ble/edit/info/default ansi "$str" # 6ms +} +blehook PRECMD+=ble/keymap:vi/update-mode-indicator + +## @fn ble/prompt/backslash:keymap:vi/mode-indicator +## @var[in,opt] prompt_vi_keymap +## ble/keymap:vi/script/get-vi-keymap のキャッシュ +function ble/prompt/backslash:keymap:vi/mode-indicator { + [[ $bleopt_keymap_vi_mode_show ]] || return 0 + + local keymap=${prompt_vi_keymap-} + if [[ $keymap ]]; then + ble/prompt/unit/add-hash '$_ble_decode_keymap,${_ble_decode_keymap_stack[*]}' + else + ble/keymap:vi/script/get-vi-keymap || return 0 + fi + + local name= show= overwrite= + ble/prompt/unit/add-hash '$_ble_edit_overwrite_mode,$_ble_keymap_vi_single_command,$_ble_keymap_vi_single_command_overwrite' + if [[ $keymap == vi_imap ]]; then + show=1 overwrite=$_ble_edit_overwrite_mode + elif [[ $_ble_keymap_vi_single_command && ( $keymap == vi_nmap || $keymap == vi_omap ) ]]; then + show=1 overwrite=$_ble_keymap_vi_single_command_overwrite + elif [[ $keymap == vi_[xs]map ]]; then + show=x overwrite=$_ble_keymap_vi_single_command_overwrite + else + name=$bleopt_keymap_vi_mode_string_nmap fi if [[ $show ]]; then @@ -499,6 +545,7 @@ function ble/keymap:vi/update-mode-name { fi if [[ $show == x ]]; then + ble/prompt/unit/add-hash '${_ble_edit_mark_active%+}' local mark_type=${_ble_edit_mark_active%+} local visual_name=$bleopt_keymap_vi_mode_name_visual [[ $keymap == vi_smap ]] && visual_name=$bleopt_keymap_vi_mode_name_select @@ -518,12 +565,7 @@ function ble/keymap:vi/update-mode-name { name=$'\e[1m-- '$name$' --\e[m' fi - if [[ $_ble_keymap_vi_reg_record ]]; then - name=$name${name:+' '}$'\e[1;31mREC @'$_ble_keymap_vi_reg_record_char$'\e[m' - elif [[ $_ble_edit_kbdmacro_record ]]; then - name=$name${name:+' '}$'\e[1;31mREC\e[m' - fi - ble/edit/info/default ansi "$name" # 6ms + [[ ! $name ]] || ble/prompt/print "$name" } function ble/widget/vi_imap/normal-mode.impl { @@ -549,7 +591,7 @@ function ble/widget/vi_imap/normal-mode { ble/keymap:vi/imap-repeat/process ble/keymap:vi/repeat/record-insert ble/widget/vi_imap/normal-mode.impl InsertLeave - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } function ble/widget/vi_imap/normal-mode-without-insert-leave { @@ -557,7 +599,7 @@ function ble/widget/vi_imap/normal-mode-without-insert-leave { ble/keymap:vi/imap-repeat/pop ble/keymap:vi/repeat/record-insert ble/widget/vi_imap/normal-mode.impl - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } function ble/widget/vi_imap/single-command-mode { @@ -570,7 +612,7 @@ function ble/widget/vi_imap/single-command-mode { ble/widget/vi_imap/normal-mode.impl _ble_keymap_vi_single_command=$single_command _ble_keymap_vi_single_command_overwrite=$single_command_overwrite - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } @@ -618,7 +660,7 @@ function ble/keymap:vi/adjust-command-mode { ble/widget/vi_nmap/.insert-mode 1 "$_ble_keymap_vi_single_command_overwrite" resume ble/keymap:vi/repeat/clear-insert elif [[ $kmap_popped ]]; then - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator fi return 0 @@ -646,7 +688,7 @@ function ble/widget/vi_nmap/.insert-mode { _ble_keymap_vi_single_command_overwrite= ble/keymap:vi/search/clear-matched ble/decode/keymap/pop - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator ble/keymap:vi/mark/start-edit-area if [[ :$opts: != *:resume:* ]]; then @@ -1094,7 +1136,7 @@ function ble/widget/vi_nmap/record-register { ble/keymap:vi/register#set "$_ble_keymap_vi_reg_record" q "$ret" _ble_keymap_vi_reg_record= - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator else _ble_decode_key__hook="ble/widget/vi_nmap/record-register.hook" fi @@ -1129,7 +1171,7 @@ function ble/widget/vi_nmap/record-register.hook { ble/util/c2s "$c" _ble_keymap_vi_reg_record=$reg _ble_keymap_vi_reg_record_char=$ret - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } # nmap @ @@ -1191,7 +1233,7 @@ function ble/widget/vi-command/operator { _ble_keymap_vi_oparg=$_ble_edit_arg _ble_keymap_vi_opfunc=$opname _ble_edit_arg= - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator elif [[ $_ble_decode_keymap == vi_omap ]]; then local opname1=${_ble_keymap_vi_opfunc%%:*} @@ -5721,7 +5763,7 @@ function ble/widget/vi-command/cancel { if [[ $_ble_keymap_vi_single_command ]]; then _ble_keymap_vi_single_command= _ble_keymap_vi_single_command_overwrite= - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator else local joblist; ble/util/joblist if ((${#joblist[*]})); then @@ -6712,7 +6754,7 @@ function ble/widget/vi-command/previous-visual-area { _ble_edit_ind=$end _ble_edit_mark=$beg _ble_edit_mark_active=$mark - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator else ble/keymap:vi/clear-arg ble/widget/vi-command/visual-mode.impl vi_xmap "$mark" @@ -6741,7 +6783,7 @@ function ble/widget/vi-command/visual-mode.impl { ((ARG)) && ble/widget/vi_xmap/.restore-visual-state "$ARG" ble/decode/keymap/push "$keymap" - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } function ble/widget/vi_nmap/charwise-visual-mode { @@ -6772,7 +6814,7 @@ function ble/widget/vi_xmap/exit { ble/keymap:vi/xmap/set-previous-visual-area _ble_edit_mark_active= ble/decode/keymap/pop - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator ble/keymap:vi/adjust-command-mode fi return 0 @@ -6797,7 +6839,7 @@ function ble/widget/vi_xmap/switch-visual-mode.impl { ble/widget/vi_xmap/cancel else ble/keymap:vi/xmap/switch-type "$visual_type" - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 fi @@ -6819,7 +6861,7 @@ function ble/widget/vi_xmap/switch-to-select { if [[ $_ble_decode_keymap == vi_xmap ]]; then ble/decode/keymap/pop ble/decode/keymap/push vi_smap - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator fi } # smap @@ -6827,7 +6869,7 @@ function ble/widget/vi_xmap/switch-to-visual { if [[ $_ble_decode_keymap == vi_smap ]]; then ble/decode/keymap/pop ble/decode/keymap/push vi_xmap - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator fi } # smap @@ -6839,7 +6881,7 @@ function ble/widget/vi_xmap/switch-to-visual-blockwise { if [[ ${_ble_edit_mark_active%+} != vi_block ]]; then ble/widget/vi_xmap/switch-to-blockwise else - xble/keymap:vi/update-mode-name + xble/keymap:vi/update-mode-indicator fi } @@ -7653,7 +7695,7 @@ function ble-decode/keymap:vi_smap/define { # vi_imap function ble/widget/vi_imap/__attach__ { - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } function ble/widget/vi_imap/__detach__ { @@ -7689,7 +7731,7 @@ function ble/widget/vi_imap/overwrite-mode { else _ble_edit_overwrite_mode=${_ble_keymap_vi_insert_overwrite:-R} fi - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator return 0 } @@ -8018,7 +8060,7 @@ function ble/keymap:vi/async-commandline-mode { # 初期化 ble/decode/keymap/push vi_cmap - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator # textarea _ble_textarea_panel=1 @@ -8069,7 +8111,7 @@ function ble/widget/vi_cmap/accept { ble/history/set-prefix "$_ble_keymap_vi_cmap_history_prefix" ble/decode/keymap/pop - ble/keymap:vi/update-mode-name + ble/keymap:vi/update-mode-indicator if [[ $hook ]]; then builtin eval -- "$hook \"\$result\"" else diff --git a/note.txt b/note.txt index 2694edd3..cbfc7e0b 100644 --- a/note.txt +++ b/note.txt @@ -6461,9 +6461,40 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2022-07-12 + + * wiki: named prompt sequences についても記述するべきなのではないか [#D1844] + + ./keymap/emacs.sh:138:function ble/prompt/backslash:keymap:emacs/mode-indicator { + ./keymap/vi.sh:512:function ble/prompt/backslash:keymap:vi/mode-indicator { + ./src/edit.sh:1016:function ble/prompt/backslash:position { + ./src/edit.sh:1024:function ble/prompt/backslash:row { + ./src/edit.sh:1031:function ble/prompt/backslash:column { + ./src/edit.sh:1038:function ble/prompt/backslash:point { + ./src/edit.sh:1042:function ble/prompt/backslash:mark { + ./src/edit.sh:1046:function ble/prompt/backslash:history-index { + ./src/edit.sh:1050:function ble/prompt/backslash:history-percentile { + + 取り敢えずユーザーも使える事を想定したものは記述した。vim-airline の物は本 + 来内部使用を意図して実装された物なので省略。 + + * vi: status_line ではなく mode indicator 自体を変更する方法を与える (motivated by ferdinandyb) [#D1843] + + mode indicator の部分をプロンプト設定として提供する事にした。 + + * done: うーん。vi のモードが変わった時にしか更新されないので、モード以外の + 情報を表示しようとしても次にモードが変更される時にしか更新が走らない。 + 仕方がないので PRECMD に update-mode-indicator を登録する事にした。 + * done: emacs の方も同様に設定できる様にするべきの気がする。 + + * done: blerc, wiki に記述 + * done: wiki: prompt_emacs_mode_indicator + * done: wiki: prompt_vi_mode_indicator + * done: wiki: pointers to prompt_*_mode_indicator in §Edit + 2022-07-11 - * kitty の keyboard protocol が有効になっていなかった [#D1842] + * term: kitty の keyboard protocol が有効になっていなかった [#D1842] https://github.com/akinomyoga/ble.sh/issues/209 返信を書いている時に kitty の振る舞いを確認していて気づいたのだがちゃんと diff --git a/src/edit.sh b/src/edit.sh index 3c99908b..9676a9be 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -7361,7 +7361,7 @@ function ble/widget/start-keyboard-macro { _ble_edit_kbdmacro_record=1 if [[ $_ble_decode_keymap == emacs ]]; then - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator elif [[ $_ble_decode_keymap == vi_nmap ]]; then ble/keymap:vi/adjust-command-mode fi @@ -7379,7 +7379,7 @@ function ble/widget/end-keyboard-macro { ble/decode/charlog#end-exclusive-depth1 _ble_edit_kbdmacro_last=("${ret[@]}") if [[ $_ble_decode_keymap == emacs ]]; then - ble/keymap:emacs/update-mode-name + ble/keymap:emacs/update-mode-indicator elif [[ $_ble_decode_keymap == vi_nmap ]]; then ble/keymap:vi/adjust-command-mode fi