Skip to content

Commit

Permalink
edit: support "bleopt editor line_limit_{type,length} history_limit_l…
Browse files Browse the repository at this point in the history
…ength"
  • Loading branch information
akinomyoga committed Mar 12, 2020
1 parent e835b0d commit 2f9a000
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 67 deletions.
54 changes: 46 additions & 8 deletions blerc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
#bleopt input_encoding=UTF-8


## The following setting specifies the pager used by ble.sh.
## The following setting specifies the pager used by ble.sh. This is used to
## show the help of commands (f1).

#bleopt pager=less

## The following setting specifies the editor used by ble.sh. This is used for
## the widget edit-and-execute (C-x C-e) and editor for a large amount of
## command line texts. Possible values are e.g. "vim", "emacs -nw" or "nano".

#bleopt editor=vim


## The following settings sets the behavior of visible bells (vbell).
## "vbell_duration" sets the time duration to show the vbell. "vbell_align"
Expand Down Expand Up @@ -142,16 +149,47 @@
#bleopt history_share=


## The following setting controls the behavior of the widget "accept-single-"
## line-or-newline" in the single-line editing mode. The value is a subject of
## arithmetic evaluation. When it evaluates to negative integers, the line is
## always accepted. When it evaluates to 0, it enters the multiline editing
## mode when there is any unprocessed user inputs, or otherwise the line is
## accepted. When it evaluates to a positive integer "n", it enters the
## multiline editing mode when there is more than "n"unprocessed user inputs.
## The following setting controls the behavior of the widget
## "accept-single-line-or-newline" in the single-line editing mode. The value
## is a subject of arithmetic evaluation. When it evaluates to negative
## integers, the line is always accepted. When it evaluates to 0, it enters the
## multiline editing mode when there is any unprocessed user inputs, or
## otherwise the line is accepted. When it evaluates to a positive integer "n",
## it enters the multiline editing mode when there is more than "n"unprocessed
## user inputs.

#bleopt accept_line_threshold=5


## The following option controls the behavior when the number of characters
## exceeds the capacity specified by `line_limit_length`. The value `none`
## means that the number of characters will not be checked. The value
## `discard` means that the characters cannot be inserted when the number of
## characters exceeds the capacity. The value `truncate` means that the
## command line is truncated from its end to fit into the capacity. The value
## `editor` menas that the widget `edit-and-execute` will be invoked to open an
## editor to edit the command line contents.

#bleopt line_limit_type=none


## The following option specifies the capacity of the command line in the
## number of characters. The number 0 or negative numbers means the unlimited
## capacity.

#bleopt line_limit_length=10000


## The following option specifies the maximal number of characters
## which can be appended into the history. When this option has a
## positive value, commands with the length longer than the value is
## not appended to the history. When this option has a non-positive
## value, commands are always appended to the history regardless of
## their length.

#bleopt history_limit_length=10000


##-----------------------------------------------------------------------------
## Terminal state control

Expand Down
1 change: 1 addition & 0 deletions keymap/emacs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function ble-decode/keymap:emacs/define {
ble-bind -f __attach__ safe/__attach__
ble-bind -f __before_widget__ emacs/__before_widget__
ble-bind -f __after_widget__ emacs/__after_widget__
ble-bind -f __line_limit__ __line_limit__

# accept/cancel
ble-bind -f 'C-c' discard-line
Expand Down
26 changes: 25 additions & 1 deletion keymap/vi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5536,6 +5536,7 @@ function ble-decode/keymap:vi_omap/define {
ble/keymap:vi/setup-map

ble-bind -f __default__ vi_omap/__default__
ble-bind -f __line_limit__ nop
ble-bind -f 'ESC' vi_omap/cancel
ble-bind -f 'C-[' vi_omap/cancel
ble-bind -f 'C-c' vi_omap/cancel
Expand Down Expand Up @@ -5723,11 +5724,21 @@ function ble/widget/vi_nmap/decrement {
local ARG FLAG REG; ble/keymap:vi/get-arg 1
ble/widget/vi_nmap/increment.impl $((-ARG))
}
function ble/widget/vi_nmap/__line_limit__.edit {
ble/keymap:vi/clear-arg
ble/widget/vi_nmap/.insert-mode
ble/keymap:vi/repeat/clear-insert
ble/widget/edit-and-execute-command.impl "$1"
}
function ble/widget/vi_nmap/__line_limit__ {
ble/widget/__line_limit__ vi_nmap/__line_limit__.edit
}

function ble-decode/keymap:vi_nmap/define {
ble/keymap:vi/setup-map

ble-bind -f __default__ vi-command/decompose-meta
ble-bind -f __default__ vi-command/decompose-meta
ble-bind -f __line_limit__ vi_nmap/__line_limit__
ble-bind -f 'ESC' vi-command/bell
ble-bind -f 'C-[' vi-command/bell
ble-bind -f 'C-c' vi-command/cancel
Expand Down Expand Up @@ -7754,6 +7765,7 @@ function ble-decode/keymap:vi_imap/define {
ble-bind -f __attach__ vi_imap/__attach__
ble-bind -f __default__ vi_imap/__default__
ble-bind -f __before_widget__ vi_imap/__before_widget__
ble-bind -f __line_limit__ __line_limit__

ble-bind -f 'ESC' 'vi_imap/normal-mode'
ble-bind -f 'C-[' 'vi_imap/normal-mode'
Expand Down Expand Up @@ -7942,6 +7954,17 @@ function ble/widget/vi_cmap/__before_widget__ {
fi
}

function ble/widget/vi_cmap/__line_limit__.edit {
local content=$1
ble/widget/edit-and-execute-command.edit "$content" no-newline; local ext=$?
((ext==127)) && return "$ext"
ble-edit/content/reset "$ret"
ble/widget/vi_cmap/accept
}
function ble/widget/vi_cmap/__line_limit__ {
ble/widget/__line_limit__ vi_cmap/__line_limit__.edit
}

function ble-decode/keymap:vi_cmap/define {
#----------------------------------------------------------------------------
# common bindings + modifications
Expand All @@ -7954,6 +7977,7 @@ function ble-decode/keymap:vi_cmap/define {
#----------------------------------------------------------------------------

ble-bind -f __before_widget__ vi_cmap/__before_widget__
ble-bind -f __line_limit__ vi_cmap/__line_limit__

# accept/cancel
ble-bind -f 'ESC' vi_cmap/cancel
Expand Down
1 change: 1 addition & 0 deletions keymap/vi_digraph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function ble/widget/vi_digraph/default {
function ble-decode/keymap:vi_digraph/define {
ble-bind -f __defchar__ vi_digraph/defchar
ble-bind -f __default__ vi_digraph/default
ble-bind -f __line_limit__ nop

local lines; ble/util/mapfile lines < "$_ble_base/keymap/vi_digraph.txt"

Expand Down
37 changes: 22 additions & 15 deletions lib/core-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ function ble-decode/keymap:menu/define {
# ble-bind -f __defchar__ menu_complete/self-insert
# ble-bind -f __default__ 'menu_complete/exit-default'
ble-bind -f __default__ 'bell'
ble-bind -f __line_limit__ nop
ble-bind -f C-m 'menu/accept'
ble-bind -f RET 'menu/accept'
ble-bind -f C-g 'menu/cancel'
Expand Down Expand Up @@ -3332,7 +3333,7 @@ function ble/complete/menu-complete.class/onselect {
ble/complete/cand/unpack "${_ble_complete_menu_items[nsel]}"
insert=$INSERT
fi
ble-edit/content/replace "$_ble_complete_menu0_beg" "$_ble_edit_ind" "$insert"
ble-edit/content/replace-limited "$_ble_complete_menu0_beg" "$_ble_edit_ind" "$insert"
((_ble_edit_ind=_ble_complete_menu0_beg+${#insert}))
}

Expand Down Expand Up @@ -4578,6 +4579,7 @@ function ble/widget/menu_complete/exit-default {
function ble-decode/keymap:menu_complete/define {
# ble-bind -f __defchar__ menu_complete/self-insert
ble-bind -f __default__ 'menu_complete/exit-default'
ble-bind -f __line_limit__ nop
ble-bind -f C-m 'menu_complete/accept'
ble-bind -f RET 'menu_complete/accept'
ble-bind -f C-g 'menu_complete/cancel'
Expand Down Expand Up @@ -4716,6 +4718,14 @@ function ble/complete/auto-complete/.setup-auto-complete-mode {
ble-decode/keymap/push auto_complete
ble-decode-key "$_ble_complete_KCODE_ENTER" # dummy key input to record keyboard macros
}
## 関数 ble/complete/auto-complete/.insert ins
## @param[in] ins
## @var[in,out] _ble_edit_ind _ble_edit_mark
function ble/complete/auto-complete/.insert {
local insert=$1
ble-edit/content/replace-limited "$_ble_edit_ind" "$_ble_edit_ind" "$insert" nobell
((_ble_edit_mark=_ble_edit_ind+${#insert}))
}

## 関数 ble/complete/auto-complete/.check-history opts
## @param[in] opts
Expand All @@ -4732,11 +4742,8 @@ function ble/complete/auto-complete/.check-history {
local COMP1=0 COMPS=$_ble_edit_str
[[ $word == "$COMPS" ]] && return 1
local insert=$word suffix=

local type=h
local ins=${insert:${#COMPS}}
ble-edit/content/replace "$_ble_edit_ind" "$_ble_edit_ind" "$ins"
((_ble_edit_mark=_ble_edit_ind+${#ins}))
ble/complete/auto-complete/.insert "${insert:${#COMPS}}"

# vars: type COMP1 cand word insert suffix
ble/complete/auto-complete/.setup-auto-complete-mode
Expand Down Expand Up @@ -4783,18 +4790,15 @@ function ble/complete/auto-complete/.check-context {
[[ ${comp_text:COMP1} == "$word"* ]] && return 1

type=c
local ins=${insert:${#COMPS}}
ble-edit/content/replace "$_ble_edit_ind" "$_ble_edit_ind" "$ins"
((_ble_edit_mark=_ble_edit_ind+${#ins}))
ble/complete/auto-complete/.insert "${insert:${#COMPS}}"
else
case :$comp_type: in
(*:a:*) type=a ;;
(*:m:*) type=m ;;
(*:A:*) type=A ;;
(*) type=r ;;
esac
ble-edit/content/replace "$_ble_edit_ind" "$_ble_edit_ind" " [$insert] "
((_ble_edit_mark=_ble_edit_ind+4+${#insert}))
ble/complete/auto-complete/.insert " [$insert] "
fi

# vars: type COMP1 cand word insert suffix
Expand Down Expand Up @@ -4944,8 +4948,8 @@ function ble/widget/auto_complete/self-insert {
local comps_fixed= comps_filter_pattern
ble/complete/candidates/filter:"$comp_filter_type"/init "$compv_new"
if ble/complete/candidates/filter:"$comp_filter_type"/test "$_ble_complete_ac_cand"; then
ble-edit/content/replace "$_ble_edit_ind" "$_ble_edit_ind" "$ins"
((_ble_edit_ind+=${#ins},_ble_edit_mark+=${#ins}))
local insert; ble-edit/content/replace-limited "$_ble_edit_ind" "$_ble_edit_ind" "$ins"
((_ble_edit_ind+=${#insert},_ble_edit_mark+=${#insert}))
[[ $_ble_complete_ac_cand == "$compv_new" ]] &&
ble/widget/auto_complete/cancel
processed=1
Expand Down Expand Up @@ -4999,7 +5003,7 @@ function ble/widget/auto_complete/insert-word {
blehook/invoke complete_insert
return 0
fi
elif [[ $_ble_complete_ac_type == [ra] ]]; then
elif [[ $_ble_complete_ac_type == [ramA] ]]; then
local ins=$_ble_complete_ac_insert
[[ $ins =~ $rex ]]
if [[ $BASH_REMATCH == "$ins" ]]; then
Expand All @@ -5012,6 +5016,7 @@ function ble/widget/auto_complete/insert-word {
# <C>hll<I> [hello world] <M> → <C>hello <I>world<M>
# (<C> = comp1, <I> = _ble_edit_ind, <M> = _ble_edit_mark)
_ble_complete_ac_type=c
# Note: 内容としては短くなるので replace-limited は使わなくて良い。
ble-edit/content/replace "$_ble_complete_ac_comp1" "$_ble_edit_mark" "$_ble_complete_ac_insert"
((_ble_edit_ind=_ble_complete_ac_comp1+${#ins},
_ble_edit_mark=_ble_complete_ac_comp1+${#_ble_complete_ac_insert}))
Expand Down Expand Up @@ -5039,6 +5044,7 @@ function ble/widget/auto_complete/notify-enter {
function ble-decode/keymap:auto_complete/define {
ble-bind -f __defchar__ auto_complete/self-insert
ble-bind -f __default__ auto_complete/cancel-default
ble-bind -f __line_limit__ nop
ble-bind -f 'C-g' auto_complete/cancel
ble-bind -f 'C-x C-g' auto_complete/cancel
ble-bind -f 'C-M-g' auto_complete/cancel
Expand Down Expand Up @@ -5479,8 +5485,8 @@ function ble/complete/dabbrev/.search.fib {

local rec=$_ble_complete_dabbrev_index,$_ble_complete_dabbrev_pos,$_ble_edit_ind,$_ble_edit_mark
ble/array#push _ble_complete_dabbrev_stack "$rec:$_ble_edit_str"
ble-edit/content/replace "$_ble_edit_mark" "$_ble_edit_ind" "$dabbrev_match"
((_ble_edit_ind=_ble_edit_mark+${#dabbrev_match}))
local insert; ble-edit/content/replace-limited "$_ble_edit_mark" "$_ble_edit_ind" "$dabbrev_match"
((_ble_edit_ind=_ble_edit_mark+${#insert}))

((index>_ble_complete_dabbrev_index)) &&
ble/widget/.bell # 周回
Expand Down Expand Up @@ -5565,6 +5571,7 @@ function ble/widget/dabbrev/accept-line {
}
function ble-decode/keymap:dabbrev/define {
ble-bind -f __default__ 'dabbrev/exit-default'
ble-bind -f __line_limit__ nop
ble-bind -f 'C-g' 'dabbrev/cancel'
ble-bind -f 'C-x C-g' 'dabbrev/cancel'
ble-bind -f 'C-M-g' 'dabbrev/cancel'
Expand Down
1 change: 1 addition & 0 deletions lib/init-cmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# 2019-05-04 実験的に mouse, mouse_move を追加した。
# 2019-05-06 ble-update 関連でバグがあったのを潰したので更新。
# 2020-01-31 @ESC, @NUL を追加した。
# 2020-03-12 __line_limit__ を追加

function ble/init:cmap/bind-single-csi {
ble-bind -k "ESC [ $1" "$2"
Expand Down
4 changes: 4 additions & 0 deletions memo/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

2020-01-12 -- (#D1215... ) c74abc5...

- edit: support `bleopt editor line_limit_{type,length} history_limit_length` `#D1295` 0000000
- complete: fix a bug that insert-word does not for with ambiguous candidates `#D1295` 0000000
- edit (edit-and-execute): disable highlighting of old command line content `#D1295` 0000000

## New features

- complete: support `bleopt complete_auto_wordbreaks` (suggestion by dylankb) `#D1219` c294e31
Expand Down

0 comments on commit 2f9a000

Please sign in to comment.