-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: add "github499-append-to-last-modified"
- Loading branch information
1 parent
5aff5f6
commit c620f52
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# blesh/contrib/config/github499-append-to-last-modified.bash | ||
# (C) 2024, Koichi Murase <[email protected]> | ||
# | ||
# Example: | ||
# | ||
# # ~/.blerc | ||
# ble-import config/github499-append-to-last-modified | ||
# ble-bind -f 'M-insert' github499/append-to-last-modified | ||
# | ||
# References: | ||
# | ||
# https://github.com/akinomyoga/ble.sh/discussions/499 | ||
# | ||
|
||
_ble_contrib_github499_last_modified_index= | ||
function ble/contrib/config:github499/record-last-modified-index { | ||
local reason=${4-} | ||
[[ $reason == history ]] && return 0 | ||
local index | ||
ble/history/get-index | ||
_ble_contrib_github499_last_modified_index=$index | ||
} | ||
ble/array#push _ble_edit_dirty_observer ble/contrib/config:github499/record-last-modified-index | ||
|
||
function ble/widget/github499/append-to-last-modified { | ||
local ins=$_ble_edit_str | ||
[[ $ins ]] || return 1 | ||
|
||
local index=$_ble_contrib_github499_last_modified_index | ||
[[ $index ]] || ble/history/get-count -v index | ||
ble-edit/history/goto "$index" | ||
[[ $_ble_edit_str && $_ble_edit_str != *$'\n' ]] && ins=$'\n'$ins | ||
local p=${#_ble_edit_str} | ||
ble-edit/content/replace-limited "$p" "$p" "$ins" | ||
((_ble_edit_ind=${#_ble_edit_str})) | ||
return 0 | ||
} |