Skip to content

Commit

Permalink
edit: support rlfunc "paste-from-buffer" in more environments
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 24, 2024
1 parent c395eb3 commit 1764652
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 16 deletions.
9 changes: 5 additions & 4 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- edit: support `bleopt undo_point={first,last,near,auto}` `#D2303` xxxxxxxx
- keymap/vi: add readline-compatible widgets for `vi_imap` and `vi_nmap` (requested by excited-bore) `#D2304` xxxxxxxx
- edit: support bash-5.2 readline bindable function `vi-edit-and-execute-command` `#D2306` xxxxxxxx
- edit: support readline bindable function `paste-from-buffer` in more environments `#D2307` xxxxxxxx

## Changes

Expand All @@ -98,7 +99,7 @@
- highlight (`ble/syntax/highlight/vartype`): reference the saved states of variables `#D2268` 063249b4
- complete: attempt pathname expansions of incomplete pattern for `COMPV` (reported by mcepl) `#D2278` 6a426954
- make: save commit id and branch name with `git archive` (requested by LecrisUT, blackteahamburger) `#D2290` 31f264ad
- edit: revert edits with widget `discard-line` (reported by dezza) `#D2301` xxxxxxxx
- edit: revert edits with widget `discard-line` (reported by dezza) `#D2301` 3b2b4b81
- vi_nmap: fix cursor position after <kbd>C-o</kbd> `#D2302` xxxxxxxx

## Fixes
Expand Down Expand Up @@ -203,7 +204,7 @@
- mandb: hook into bash-completion's `_comp_command_offset` `#D2255` cbcce625
- canvas: update tables for Unicode 16.0.0 `#D2283` 5b43ca3f 25a10a6f
- complete: work around `mawk <= 1.3.4-20230525` type-inference bug (reported by KaKi87) `#D2295` 546499b5
- main: work around macOS sed (reported by Mossop) `#D2298` xxxxxxxx
- main: work around macOS sed (reported by Mossop) `#D2298` a16aa594

## Contrib

Expand Down Expand Up @@ -295,8 +296,8 @@
- util (`ble/util/is-stdin-ready`): check `$_ble_util_fd_tui_stdin` by default `#D2254` 29c00fd8
- decode (`ble-decode-key/bind`): reference the argument to check the widget name (contributed by musou1500) `#D2279` 21b1bb3d
- global: normalize quoting of function names of the form `prefix:$name` `#D2296` 3d7c98bb
- global: use `[:blank:]` instead of `[:space:]` `#D2299` xxxxxxxx
- global: rename `ret` not used as `REPLY` `#D2300` xxxxxxxx
- global: use `[:blank:]` instead of `[:space:]` `#D2299` e2fd8f0f
- global: rename `ret` not used as `REPLY` `#D2300` 86cbf78e

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel3
Expand Down
2 changes: 1 addition & 1 deletion lib/core-decode.vi_imap-rlfunc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ yank yank
yank-last-arg insert-last-argument
yank-nth-arg insert-nth-argument
yank-pop yank-pop
paste-from-clipboard -
paste-from-clipboard paste-from-clipboard
2 changes: 1 addition & 1 deletion lib/core-decode.vi_nmap-rlfunc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ yank yank
yank-last-arg -
yank-nth-arg -
yank-pop -
paste-from-clipboard -
paste-from-clipboard vi-rlfunc/paste-from-clipboard
15 changes: 15 additions & 0 deletions lib/keymap.vi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,21 @@ function ble/widget/vi_nmap/paste-before {
ble/widget/vi_nmap/paste.impl "$ARG" "$REG" 0
}

function ble/widget/vi-rlfunc/paste-from-clipboard {
ble/keymap:vi/clear-arg

local clipboard
if ! ble/edit/get-clipboard; then
ble/widget/.bell
return 1
fi

local _ble_edit_kill_ring=$clipboard
local _ble_edit_kill_type=
ble/widget/vi_nmap/paste.impl 1 '' 1
return 0
}

#------------------------------------------------------------------------------
# command: x s X C D

Expand Down
50 changes: 48 additions & 2 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1926,9 +1926,44 @@ bash_tips
- make_command.sh の整理 (scan 分離, char_width 分離)
- note.txt -> memo.txt

2024-12-23
2024-12-24

* vscode における初期化問題
https://github.com/akinomyoga/ble.sh/discussions/524

[ble-attach の問題]

ble-attach を呼び出すと venv が初期化されない。どうも変だと思ったら vscode
は .bashrc を shellIntegration-bash.sh 云々から読み込まれている様だ。単に
PS1 が反映されていないという事だった様である。これの対策についてはまた考え
なければならないだろうか。或いは、ユーザーに ble-attach ではなくそのまま書
く方式を試す様にお願いするか。wiki に記述しても良い。

或いは、既に VS Code の何かの Extension に対する対策を含めているのだから、
VS Code Python Extension に対する workaround も ble.sh の中に含めるべき? し
かしそうするとしてもどの様に処理したら良いか分からない。

a ble-attach を無効化するにしても、ble-attach をわざわざ記述した理由がある
のかもしれない。

b 或いは、ble-attach の時点で VSCODE_* の環境変数が存在して未処理の場合には
それを ble.sh の側で自前で処理して、その後で ble-attach する? 然し、そう
するにしても shellIntegration-bash.sh が変更されたらそれで動かなくなって
しまう。upstream を追跡するのは大変だし、追跡したとしてもどの version の
shellIntegration-bash.sh を使っているのかまで検出しなければならない。

c 或いは、呼び出し元が shellIntegration-bash.sh だと分かった時点で、それを
自前で呼び出してそれから ble-attach を実施する?

* vi_[in]map: rlfunc "paste-from-clipboard" の対応
[source .venv/bin/activate の問題]

一方で、これは結局報告者の問題とは関係ない様だ。報告者のビデオによると
source .venv/bin/activate が書き込まれてその後に C-c が送信されて、それから
実行スべきコマンドが書き込まれて実行されている様だ。然し、source ... C-c は
自分の環境では実行されている気配が全くない。そもそも .venv/bin/activate は
全く読み込まれていない様に見える。

2024-12-23

* vi_cmap: :marks の対応。ないと marks のデバグの時に不便

Expand Down Expand Up @@ -7693,6 +7728,17 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2024-12-24

* vi_[in]map: rlfunc "paste-from-clipboard" の対応 [#D2307]

vi_imap は paste-from-clipboard で良さそうな気がする。一方で、vi_nmap に関
しては特別な配慮が必要になる。面倒なので p を呼び出す様にすれば良い気がする。

今まで Cygwin 上でしか paste-from-clipboard を友好にしていなかったが、
rlfunc.txt にあるのに使えないというのも混乱の元なので全ての環境で widget は
定義する事にした。また、clipboard から抽出する様々の方法を追加する事にした。

2024-12-23

* 2022-04-13 bash が `vi-edit-and-execute-command' を追加している [#D2306]
Expand Down
66 changes: 58 additions & 8 deletions src/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4915,18 +4915,68 @@ function ble/widget/.insert-string {
))
_ble_edit_mark_active=
}

# One can find various ways to get the clipboard content in Ref. [1].
# [1] https://stackoverflow.com/questions/5130968
if [[ -c /dev/clipboard ]]; then
function ble/widget/paste-from-clipboard {
local clipboard
if ! ble/util/readfile clipboard /dev/clipboard; then
ble/widget/.bell
return 1
fi
# Cygwin and MSYS2 has a character device "/dev/clipboard".
function ble/edit/get-clipboard { ble/util/readfile clipboard /dev/clipboard; }
elif ble/base/is-wsl && ble/bin#freeze-utility-path powershell.exe; then
# WSL system may use "powershell.exe" if it exists
function ble/edit/get-clipboard { ble/util/assign clipboard 'powershell.exe -command Get-Clipboard 2>/dev/null'; }
elif ble/bin#freeze-utility-path pbpaste; then
# macOS seems to have "pbpaste" command.
function ble/edit/get-clipboard { ble/util/assign clipboard 'pbpaste 2>/dev/null'; }
elif ble/bin#freeze-utility-path xclip; then
# Linux with X Window system may also have the "xlip" command.
function ble/edit/get-clipboard { ble/util/assign clipboard 'xclip -selection clipboard -o 2>/dev/null'; }
elif ble/bin#freeze-utility-path xsel; then
# Linux with X Window system may have the "xsel" command.
function ble/edit/get-clipboard { ble/util/assign clipboard 'xsel --clipboard --output 2>/dev/null'; }
elif ble/bin#freeze-utility-path pbpaste; then
# wmaker-utils had "wxpaste", but it seems to have failed in recent versions
# of Linux?
# [2] https://askubuntu.com/questions/110347
function ble/edit/get-clipboard { ble/util/assign clipboard 'wxpaste 2>/dev/null'; }
elif ble/bin#freeze-utility-path pbpaste; then
# The xcb command seems to extract the cut buffer in the present xterm.
# [3] https://askubuntu.com/questions/237942
function ble/edit/get-clipboard { ble/util/assign clipboard 'xcb -p 0 2>/dev/null'; }
elif [[ ${TMUX-} && ${TMUX_PANE-} ]] && ble/bin#freeze-utility-path screen; then
# Tmux seems to have a similar mechanism of the paste buffer as GNU screen
# [4], though Ref. [4] describes the solution for the opposite purpose of
# setting the buffer. The way to extract the content of the buffer using a
# command is described in Ref. [5].
#
# [4] https://stackoverflow.com/questions/35509163
# [5] https://unix.stackexchange.com/questions/15715
function ble/edit/get-clipboard { ble/util/assign clipboard 'tmux save-buffer - 2>/dev/null'; }
elif [[ ${STY-} && ${WINDOW-} ]] && ble/bin#freeze-utility-path screen; then
# If we are inside GNU Screen, we might try to read a text from the
# bufferfile for the paste buffer [6-8]. The default location of the
# bufferfile seems to be "/tmp/screen-exchange", though a user might
# configure it to another directory. The user can press [C-a >] to save the
# current paste buffer content to "/tmp/screen-exchange". Then, one can read
# its content using "ble/edit/get-clipboard".
#
# [6] https://www.gnu.org/software/screen/manual/html_node/Screen-Exchange.html
# [7] https://superuser.com/questions/183051
# [8] https://qiita.com/k_ui/items/d0ae1e7b4d553830ccb9
function ble/edit/get-clipboard { ble/util/readfile clipboard /tmp/screen-exchange; }
else
function ble/edit/get-clipboard { return 1; }
fi

function ble/widget/paste-from-clipboard {
local clipboard
if ble/edit/get-clipboard; then
ble/widget/insert-string "$clipboard"
return 0
}
fi
else
ble/widget/.bell
return 1
fi
}

## @fn ble/widget/insert-arg.impl beg end index delta nth
## @param[in] beg end
Expand Down

0 comments on commit 1764652

Please sign in to comment.