Skip to content

Commit

Permalink
emacs: support "bleopt keymap_emacs_mode_string_multiline"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jun 19, 2022
1 parent 944d48e commit 8e9d273
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
26 changes: 25 additions & 1 deletion blerc
Expand Up @@ -755,9 +755,33 @@
#ble-bind -f C-w 'kill-region-or kill-uword'
#ble-bind -f M-w 'copy-region-or copy-uword'

##-----------------------------------------------------------------------------
## 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.

# default
#bleopt keymap_emacs_mode_string_multiline=$'\e[1m-- MULTILINE --\e[m'
# do not show mode string
#bleopt keymap_emacs_mode_string_multiline=


## 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
## syntactically completed.

#ble-bind -f C-m 'accept-line'
#ble-bind -f RET 'accept-line'

return
}
blehook/eval-after-load keymap_emacs blerc/emacs-load-hook

##-----------------------------------------------------------------------------
## Settings for vim-mode
## Settings for Vim mode

function blerc/vim-load-hook {
((_ble_bash>=40300)) && builtin bind 'set keyseq-timeout 1'
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -99,6 +99,7 @@
- util (blehook): support `hook!=handler` and `hook+-=handler` `#D1791` 0b8c097
- prompt: escape control characters in `\w` and `\W` `#D1798` 8940434 a9551e5
- prompt: fix wrongly escaped UTF-8 chars in `\w` and `\W` `#D1806` d340233
- emacs: support `bleopt keymap_emacs_mode_string_multiline` (motivated by ArianaAsl) `#D1818` XXXXXXX

## Changes

Expand Down
16 changes: 12 additions & 4 deletions keymap/emacs.sh
Expand Up @@ -18,6 +18,8 @@ ble/util/autoload "$_ble_base/keymap/vi.sh" \
ble/widget/vi-command/{forward,backward}-{v,u}word \
ble/widget/vi-command/forward-{v,u}word-end

bleopt/declare -v keymap_emacs_mode_string_multiline $'\e[1m-- MULTILINE --\e[m'

#------------------------------------------------------------------------------

_ble_keymap_emacs_white_list=(
Expand Down Expand Up @@ -84,22 +86,28 @@ _ble_keymap_emacs_modeline=::
ble/array#push _ble_textarea_local_VARNAMES \
_ble_keymap_emacs_modeline
function ble/keymap:emacs/update-mode-name {
local opt_multiline=; [[ $_ble_edit_str == *$'\n'* ]] && opt_multiline=1
local opt_multiline=
[[ $bleopt_keymap_emacs_mode_string_multiline && $_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=$'\e[1m-- MULTILINE --\e[m'
[[ $opt_multiline ]] && name=$bleopt_keymap_emacs_mode_string_multiline

local info=
[[ $_ble_edit_arg ]] &&
info=$info$' (arg: \e[1;34m'$_ble_edit_arg$'\e[m)'
[[ $_ble_edit_kbdmacro_record ]] &&
info=$info$' \e[1;31mREC\e[m'
[[ ! $info && $opt_multiline ]] &&
info=$' (\e[35mRET\e[m or \e[35mC-m\e[m: insert a newline, \e[35mC-j\e[m: run)'
if [[ ! $info && $opt_multiline ]]; 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)'
fi

[[ $name ]] || info=${info#' '}
name=$name$info
Expand Down
2 changes: 1 addition & 1 deletion make_command.sh
Expand Up @@ -1558,7 +1558,7 @@ function sub:first-defined {
return 1
}
function sub:first-defined/help {
printf ' first-defined KEYWORDS...\n'
printf ' first-defined ERE...\n'
}

#------------------------------------------------------------------------------
Expand Down
20 changes: 20 additions & 0 deletions note.txt
Expand Up @@ -6388,6 +6388,26 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-06-18

* emacs: MULTILINE mode メッセージの改善 (motivated by ArianaAsl) [#D1818]
https://github.com/akinomyoga/ble.sh/discussions/199

* done: Q&A に書く。

* done: MULTILINE モードの表示をしない様にする設定
→keymap_emacs_show_multiline という設定変数名を追加した。

* やはり MUTILINE モード名自体を設定する設定項目にする方が良い。
keymap_vi_mode_string_nmap との一貫性により。設定変数名は
keymap_emacs_mode_string_multiline に変更する事にした。

* done: MULTILINE モードの表示メッセージを binding によって変える

* rlvar enable-bracketed-paste の設定の alias bleopt を作成してそれを上書き
する。この方法はその他の補完設定に対しても適用するべきなのではないか。独
立した項目で全体的に対応する事にする。

2022-06-17

* util: erasedups 高速化 (motivated by SuperSandro2000) [#D1817]
Expand Down

0 comments on commit 8e9d273

Please sign in to comment.