Skip to content

Commit

Permalink
config: add "github499-append-to-last-modified"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 24, 2024
1 parent 5aff5f6 commit c620f52
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions config/github499-append-to-last-modified.bash
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
}

0 comments on commit c620f52

Please sign in to comment.