Commit Graph

23 Commits

Author SHA1 Message Date
Johannes Altmanninger
d8d491741b edit_command_buffer: preserve external editor's cursor position
Unless the editor changed to a different file for some reason.

Note that the Kakoune integration uses -always to export the cursor even if
the user temporarily suppressed hooks - possibly a "fish_indent" hook.
2024-03-10 11:08:12 +01:00
Johannes Altmanninger
5fa743337c edit_command_buffer: also detect aliases with arguments
For example

    complete my-vim --wraps 'vim -x'
2024-03-10 11:06:38 +01:00
Johannes Altmanninger
47aa79813d Open command script in external editor on Alt+o
Fish functions are great for configuring fish but they don't integrate
seamlessly with the rest of the system. For tasks that can run outside fish,
writing scripts is the natural approach.

To edit my scripts I frequently run

    $EDITOR (which my-script)

Would be great to reduce the amount typing for this common case (the names
of editor and scripts are usually short, so that's a lot of typing spent on
the boring part).

Our Alt+o binding opens the file at the cursor in a pager.  When the cursor
is in command position, it doesn't do anything (unless the command is actually
a valid file path). Let's make it open the resolved file path in an editor.

In future, we should teach this binding to delegate to "funced" upon seeing
a function instead of a script. I didn't do it yet because funced prints
messages, so it will mess with the commandline rendering if used from
a binding.  (The fact that funced encourages overwriting functions that
ship with fish is worrysome. Also I'm not sure why funced doesn't open the
function's source file directly (if not sourced from stdin). Persisting the
function should probably be the default.)

Alternative approach: I think other shells expand "=my-script" to
"/path/to/my-script".  That is certainly an option -- if we do that we'd want
to teach fish to complete command names after "=".  Since I don't remember
scenarios where I care about the full path of a script beyond opening it in
my editor, I didn't look further into this.

Closes #10266
2024-02-07 00:07:47 +01:00
Johannes Altmanninger
5dfcfa336b 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.
2024-01-21 09:39:59 +01:00
Johannes Altmanninger
be781e9144 edit_command_buffer: ignore user remappings for vim
edit_command_buffer uses the "norm" command for moving the cursor to a column
with the "|" primitive.  The problem is that the user can remap "|".  Fix this
by using the "norm!" variant which ignores user mappings (see ":h norm").

Closes #8971
2022-05-26 13:15:15 +02:00
Chloe Kudryavtsev
8c7ba5efea fix: edit_command_buffer with micro without parsecursor
micro only parses the [FILE]:LINE:COL syntax
if the parsecursor option is enabed

in the meanwhile, the +LINE:COL syntax is unambiguous and always valid
2022-04-24 15:15:06 +02:00
Victor Diaz
8c09fc7a3a Prepend command to cat
*Problem:*
edit_command_buffer uses `cat` to return the modified content.
If a person has an alias for `cat` to a different command such `bat`** the editing will not be useful anymore since bat decorates the text with frames, line counts, etc

*Solution*
Appending command to cat, fish will ignore the alias and execute the real command according to this https://fishshell.com/docs/current/cmds/command.html

** https://github.com/sharkdp/bat
2021-09-12 22:11:01 +08:00
aca
321fd74de0 edit_command_buffer: use "command" to ignore any functions with the same name 2021-08-17 06:24:09 +02:00
Érico Rolim
31870e774a share/functions: account for the possibility of mktemp failure. 2020-11-14 15:57:42 +01:00
Jason Nader
bb65f81e64 edit_command_buffer: Add line:col support for micro 2020-05-08 20:00:07 +02:00
George Christou
2bc4228d42 edit_command_buffer: Add line:col support for Sublime Text 2020-04-28 08:48:31 +02:00
Johannes Altmanninger
651f3cf863 Fix VSCode not blocking in edit_command_buffer 2020-03-14 14:15:10 +01:00
Johannes Altmanninger
c5e4419097 Add "--" safeguards at string length [ci skip] 2020-03-10 21:01:00 +01:00
Johannes Altmanninger
87728c4d0d Pass cursor position to edit_command_buffer for some editors
Fixes #6138

Naturally this does not work for many other editors/aliases,
but it's still nice that we can make it work for some common
editors without requiring any configuration.

Of course this approach is not terribly flexible; but it's
alwyas possible to just wrap edit_command_buffer and set an
EDITOR that knows about the cursor position. It doesn't
feel important enough to add a configuration option.
2020-03-07 21:24:14 +01:00
Johannes Altmanninger
c3374ffd08 Use read --tokenize instead of eval for $BROWSER & $EDITOR 2019-12-03 12:19:16 +01:00
Fabian Homborg
1a3471fa7d Revert "edit_command_buffer: Use variable-as-command"
This reverts commit 3c6844d4f4.

See #5625.
2019-02-07 09:47:24 +01:00
Fabian Homborg
c78e6a3ccf edit_command_buffer: repaint
Thanks @amosbird on gitter.
2018-10-25 17:34:01 +02:00
Fabian Homborg
3c6844d4f4 edit_command_buffer: Use variable-as-command 2018-10-21 15:34:42 +02:00
Mahmoud Al-Qudsi
6d80ab8d74 Rename $pid (née %self) to $fish_pid 2018-03-24 11:54:27 -05:00
Mahmoud Al-Qudsi
b236ab6e5d Update %self references with $pid instead 2018-03-09 03:56:19 -06:00
Kurtis Rader
352cea1659 disable/enable bracketed paste by edit cmd buf
We need to disable/enable bracketed paste mode around running the editor
from within the `edit_command_buffer` function.
2017-06-05 11:32:06 -07:00
Kurtis Rader
176a291ed2 deal with multiline commands which have flags
Fixes #3758
2017-01-21 20:23:06 -08:00
Kurtis Rader
59fa04bd91 function for editing command line in ext editor
This implements a standard function and bindings for editing the command
line in an external editor. This feature has been requested multiple
times in the past year with various solutions cut and pasted into those
issues. This change combines the best aspects of those solutions.

Fixes #1215
2016-12-08 19:17:09 -08:00