edit_command_buffer: if aliasee is a recognized editor, pass cursor position too

If I alias "e" to "emacsclient" it will probably accept the same options.
Let's dereference the alias so we can detect support for passing the cursor
position in more cases.

This does not solve the problem for recursive cases (e.g. alias of another
alias). If we want to handle that we would need cycle detection.
This commit is contained in:
Johannes Altmanninger 2024-01-21 06:50:31 +01:00
parent f7b541af99
commit 5dfcfa336b
2 changed files with 28 additions and 18 deletions

View File

@ -33,6 +33,7 @@ Interactive improvements
- :kbd:`Control-C` during command input no longer prints ``^C`` and a new prompt but merely clears the command line. This restores the behavior from version 2.2. To revert to the old behavior use ``bind \cc __fish_cancel_commandline`` (:issue:`10213`).
- Command-specific tab completions may now offer results whose first character is a period. For example, it is now possible to tab-complete ``git add`` for files with leading periods. The default file completions hide these files, unless the token itself has a leading period (:issue:`3707`).
- The :kbd:`Control-R` history search now uses glob syntax (:issue:`10131`).
- :kbd:`Alt-E` now passes the cursor position to the external editor also if the editor aliases a supported editor (via ``complete --wraps``).
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -41,24 +41,33 @@ function edit_command_buffer --description 'Edit the command buffer in an extern
end
set col (math $offset + 1)
set -l basename (string match -r '[^/]*$' -- $editor[1])
switch $basename
case vi vim nvim
set -a editor +$line +"norm! $col|" $f
case emacs emacsclient gedit kak
set -a editor +$line:$col $f
case nano
set -a editor +$line,$col $f
case joe ee
set -a editor +$line $f
case code code-oss
set -a editor --goto $f:$line:$col --wait
case subl
set -a editor $f:$line:$col --wait
case micro
set -a editor $f +$line:$col
case '*'
set -a editor $f
set -l basename (string match -r '[^/]+$' -- $editor[1])
set -l wrap_targets (complete -- $basename | string replace -rf '^complete [^/]+ --wraps (.+)$' '$1')
set -l found false
for alias in $basename $wrap_targets
switch $alias
case vi vim nvim
set -a editor +$line +"norm! $col|" $f
case emacs emacsclient gedit kak
set -a editor +$line:$col $f
case nano
set -a editor +$line,$col $f
case joe ee
set -a editor +$line $f
case code code-oss
set -a editor --goto $f:$line:$col --wait
case subl
set -a editor $f:$line:$col --wait
case micro
set -a editor $f +$line:$col
case '*'
continue
end
set found true
break
end
if not $found
set -a editor $f
end
__fish_disable_bracketed_paste