Commit Graph

64 Commits

Author SHA1 Message Date
Johannes Altmanninger
6af96a81a8 Default bindings for token movement commands
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
There is no natural default binding for token movements. Add the
alt-{left,right,backspace,delete}, breaking some existing behavior.

For example, backward-delete-word is no longer bound to alt-backspace but
only to ctrl-backspace.  Unfortunately some terminals (particularly tmux)
don't support distinguishing ctrl-backspace from ctrl-h yet, so the loss
of alt-backspace may be tragic.

---

I guess we could also add:

    bind alt-B backward-token
    bind alt-F forward-token
    bind ctrl-W backward-kill-token
    bind alt-D kill-token

Those might be intercepted by the terminal on Linux, but I don't know where
that happens.

Tested on foot, kitty, alacritty, xterm, tmux, konsole and gnome-terminal.

Closes #10766
2024-10-13 14:53:45 +02:00
Johannes Altmanninger
ff476eff2d Read \e prefix for escape sequences as alt modifier
The \e\e\[A style is bad but iTerm and putty (alt-left) use it.

The main motivation for this change is to improve fish_key_reader output.

Part of #10663
2024-08-11 11:31:13 +02:00
Johannes Altmanninger
d32825ba57 Decode formatOtherKeys=0 format (XTerm default) too
Part of #10663
2024-08-11 11:31:13 +02:00
Johannes Altmanninger
de7f39d627 builtin bind: make function keys lowercase (f1 instead of F1)
All other key names are lowercase so this inconsistency is weird.
2024-05-22 22:38:06 +02:00
ridiculousfish
efefeda392 Restore some iTerm2 default key bindings
c0bcd817ba removed some key bindings, including the bindings of
ESC ESC [ C for Alt-Right. the commit claimed that
"Sequences like \e\eOC are Escape followed by an SS3 arrow key which we
can already decode separately." but for whatever reason this doesn't work:
Alt-Right is broken in iTerm2 by default.

Restore the default ESC ESC [ X bindings for iTerm2 compatibility.
2024-05-19 11:01:14 -07:00
Johannes Altmanninger
d4ecea56df Fix regression spuriously expanding abbr with cursor outside token
Given "abbr foo something", the input sequence

    foo<space><ctrl-z><space>

would re-expand the abbreviation on the second space which is surprising
because the cursor is not at or inside the command token.  This looks to be
a regression from 00432df42 (Trigger abbreviations after inserting process
separators, 2024-04-13)

Happily, 69583f303 (Allow restricting abbreviations to specific commands
(#10452), 2024-04-24) made some changes that mean the bad commit seems no
longer necessary. Not sure why it works but I'll take it.
2024-05-03 08:39:05 +02:00
Johannes Altmanninger
0c413d0093 Use canonical key name in bind command 2024-05-01 12:53:00 +02:00
Johannes Altmanninger
c0bcd817ba Remove obsolete bindings
iTerm2 supports CSI u so the custom bindings are no longer needed. Sequences
like \e\eOC are Escape followed by an SS3 arrow key which we can already
decode separately.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
ec33550cff Fix detection of empty commandline in alt-d binding 2024-04-26 11:16:30 +02:00
Johannes Altmanninger
e571774c97 Make alt-d on empty commandline call dirh again
alt-d used to do that until evil merge[*] 213e90704 (Merge remote-tracking branch
'upstream/master' into bind_mode, 2014-01-15) which changed the order of
the \ed bindings such that the smart dirh version would be shadowed by the
simpler ones.

[*] git blame alone failed to find it because it skips merge commits.
2024-04-20 12:11:30 +02:00
Johannes Altmanninger
00432df420 Trigger abbreviations after inserting process separators
On

    a;

we don't expand the abbreviation because the cursor is right of semicolon,
not on the command token. Fix this by making sure that we call expand-abbr
with the cursor on the semicolon which is the end of the command token.
(Now that our bind command execution order is less surprising, this is doable.)

This means that we need to fix the cursor after successfully expanding
an abbreviation. Do this by setting the position explicitly even when no
--set-position is in effect.

An earlier version of this patch used

    bind space self-insert backward-char expand-abbr or forward-char

The problem with that (as a failing test shows) was that given "abbr m
myabbr", after typing "m space ctrl-z", the cursor would be after the "m",
not after the space.  The second space removes the space, not changing the
cursor position, which is weird.  I initially tried to fix this by adding
a hack to the undo group logic, to always restore the cursor position from
when begin-undo-group was used.

    bind space self-insert begin-undo-group backward-char expand-abbr end-undo-group or forward-char

However this made test_torn_escapes.py fail for mysterious reasons.
I believe this is because that test registers and triggers a SIGUSR1 handler;
since the signal handler will rearrange char events, that probably messes
with the undo group guards.

I resorted to adding a tailor-made readline cmd. We could probably remove
it and give the new behavior to expand-abbr, not sure.

Fixes #9730
2024-04-13 20:11:11 +02:00
Johannes Altmanninger
6858f1100a Remove redundant raw CSI u bindings 2024-04-13 14:36:11 +02:00
Johannes Altmanninger
1d98846e03 Remove some redundant raw bindings
We already decode these, see parse_csi() and parse_ss3().
2024-04-13 14:36:11 +02:00
Johannes Altmanninger
8bf8b10f68 Extended & human-friendly keys
See the changelog additions for user-visible changes.

Since we enable/disable terminal protocols whenever we pass terminal ownership,
tests can no longer run in parallel on the same terminal.

For the same reason, readline shortcuts in the gdb REPL will not work anymore.
As a remedy, use gdbserver, or lobby for CSI u support in libreadline.

Add sleep to some tests, otherwise they fall (both in CI and locally).

There are two weird failures on FreeBSD remaining, disable them for now
https://github.com/fish-shell/fish-shell/pull/10359/checks?check_run_id=23330096362

Design and implementation borrows heavily from Kakoune.

In future, we should try to implement more of the kitty progressive
enhancements.

Closes #10359
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
bffc9515a8 Fix bracketed paste regression from input event queue changes
We have

    bind --preset -M $mode --sets-mode paste \e\[200~ __fish_start_bracketed_paste

Commit c3cd68dda (Process shell commands from bindings like regular char
events, 2024-03-02) made it so __fish_start_bracketed_paste is no longer
executed before the bind mode is  updated.
This is a long-awaited fix but it broke __fish_start_bracketed_paste's
assumption that $fish_bind_mode is the mode before we entered paste mode.
This means we never exit paste mode.

Work around that. I forgot about this issue because I already replaced our
bracketed paste handling on my fork.
2024-03-23 14:08:55 +01:00
Johannes Altmanninger
789a280ee8 Fix {Alt,Shift}-Return bindings not expanding abbreviations
Today,

    bind foo "commandline -f expand-abbr; commandline -i \n"

does not work because this
1. enqueues an expand-abbr readline event
2. "commandline -i" inserts \n
3. processes the expand-abbr readline event

Since there is no abbreviation on the new line, this doesn't do anything.

PR https://github.com/fish-shell/fish-shell/pull/9398 would fix this
particular instance however it does not fix the issue that "commandline -i"
is run before the expand-abbr is processed by the reader. This is harmless
here but there would be a problem if "commandline" tried to read commandline
state that was created by a preceding command.

It's not super clear to me whether the above binding should work as one
would naively expect. That would imply that "commandline" would need to
drain all input events (at least all synthetic ones) from the input queue,
to ensure it sees the current state.

Fortunately the parent commit makes it so if we separate them

    bind foo "commandline -f expand-abbr" "commandline -i \n"

both will be separate events and the commandline state will be synced after
each of them. This fixes abbreviation expansion here.

Also, we can now mix readline cmds and shell commands, which makes it shorter.
2024-03-23 10:06:11 +01:00
Johannes Altmanninger
c1f601f31e Don't bind Alt-Return in Vi normal mode
It seems wrong because it's for text insertion; if someone actually wants
to use it we can add it back.
2024-03-23 09:54:18 +01:00
Johannes Altmanninger
865118e3b4 On Shift+Return, insert a newline instead of executing the commandline
Most chat programs I found use Shift+Return to insert a newline while plain
Return sends the message. One user reported having only tried Shift+Return
and not knowing about Alt+Return.

No release notes yet because this only works on a very small number of
terminals. Once we enable CSI u, this should work on most modern terminals.
2024-03-23 09:54:18 +01:00
Fabian Boehm
78c9482822 Reformat share/**.fish with newlines collapsed 2024-02-27 16:25:01 +01:00
Johannes Altmanninger
0627c9d9af Render control characters as Unicode Control Pictures
Inserting Tab or Backspace characters causes weird glitches. Sometimes it's
useful to paste tabs as part of a code block.

Render tabs as "␉" and so on for other ASCII control characters, see
https://unicode-table.com/en/blocks/control-pictures/. This fixes the
width-related glitches.

You can see it in action by inserting some control characters into the
command line:

	set chars
	for x in (seq 1 0x1F)
		set -a chars (printf "%02x\\\\x%02x" $x $x)
	end
	eval set chars $chars
	commandline -i "echo '" $chars

Fixes #6923
Fixes #5274
Closes #7295

We could extend this approach to display a fallback symbol for every unknown
nonprintable character, not just ASCII control characters.

In future we might want to support tab properly.
2024-02-15 01:39:45 +01:00
Fabian Boehm
c4ca1a68d3
Add a clear-screen bind function to clear the screen (#10044)
This can be bound like `bind \cl clear-screen`, and is, by default

In contrast to the current way it doesn't need the external `clear`
command that was always awkward.

Also it will clear the screen and first draw the old prompt to remove
flicker.
Then it will immediately trigger a repaint, so the prompt will be overwritten.
2023-10-08 11:41:30 +02:00
Johannes Altmanninger
052823c120 history pager: delete selected history entry with Shift-Delete
After accidentally running a command that includes a pasted password, I want
to delete command from history. Today we need to recall or type (part of)
that command and type "history delete".  Let's maybe add a shortcut to do
this from the history pager.

The current shortcut is Shift+Delete. I don't think that's very discoverable,
maybe we should use Delete instead (but only if the cursor is at the end of
the commandline, otherwise delete a char).

Closes #9454
2023-07-04 18:42:11 +02:00
Agatha Lovelace
e32e6daced support prepending please instead of sudo/doas 2023-03-05 12:49:27 +01:00
Johannes Altmanninger
29a3344226 Make bracketed paste add only one undo entry
Bracketed paste adds one undo entry unless the pasted text contains a '
or \.  This is because the "paste" bind-mode has bindings for those keys,
so they effectively start a new undo entry.

Let's fix this by adding an explicit undo group (our first use of this
feature!).
2023-01-24 20:32:13 +01:00
Johannes Altmanninger
9c0680070d Bind Shift+Return CSI u sequence to Return
I often hit Shift-Return accidentally, which makes my terminal echo a
weird escape sequence. Traditionally, terminals interpret Shift-Return
as Return, so let's follow that behavior.  Analoguous to commit 1dc526884
(Bind Shift+Space CSI u sequence to Space, 2022-04-24).
2022-12-17 11:12:40 +01:00
Fabian Boehm
478c8fb35e Remove "^" expand-abbr binding
This is no longer a special token, so it shouldn't expand abbreviations.
2022-12-16 17:06:03 +01:00
Guy Bolton King
1f130fbfe1 Remove invalid trailing period in CSI u shift-space binding 2022-07-04 19:43:03 +02:00
Jacob Panek
a57b09623e prepend doas; instead of sudo; if exists 2022-05-12 14:03:27 -05:00
Johannes Altmanninger
a8b3922a74 Work around to prevent premature Ctrl-D from inserting spaces
Pressing Ctrl-D while a command is running results in a null key code in
our input queue. That key code is bound to insert a space (without expanding
abbreviations). Make it only insert a space if the commandline is non-empty,
to accommodate this use case.

This probably affects other keys as well.

Closes #8871
2022-05-11 22:06:25 +02:00
Johannes Altmanninger
1dc5268847 Bind Shift+Space CSI u sequence to Space
Some terminals can be configured to send variuos escape sequences for keys
that could historically not be detected. Turns out some usage pattern rely
on those quirks.

Shift+Space is easy to mistype when wanting to insert a space (especially
when typing ALL CAPS). Map it to Space, to match user expectations.

Similarly for Control+Return, for which xterm can be configured to send
something other than \cr:

    echo 'XTerm.vt100.modifyOtherKeys: 1' | xrdb && xterm

I'm working on a change to builtin bind that allows to bind CSI sequences via
human-readable key names (#3018) but for now let's just map the raw sequences.

Closes #8874
2022-04-24 21:37:20 +02:00
Johannes Altmanninger
c34e694126 Share some key bindings with Vi's insert mode 2022-04-24 21:31:51 +02:00
Thom Chiovoloni
a770ff144e Make more of the functions in share/functions print error messages to stderr 2022-04-04 18:26:14 +02:00
Johannes Altmanninger
7c2dd694e0 Provide functions to toggle commandline prefix/suffix
This introduces two functions to
- toggle a process prefix, used for adding "sudo"
- add a job suffix, used for adding "&| less"

Not sure if they are very useful; we'll see.

Closes #7905
2021-06-23 20:51:20 +02:00
Fabian Homborg
9c413b039d Also fix tokenizer_state in bracketed paste path
Also removes our remaining use of
`__fish_commandline_is_singlequoted`.

See #7782.
2021-04-20 15:29:28 +02:00
Fabian Homborg
677e699a7a Stop repainting after paste
"repaint" here is a bit of a misnomer. It *doesn't* re-highlight, that
just happens on its own.

It re-runs the prompt, which can take quite a while (depending on the
configuration), and which is also useless in this context as this
isn't something the prompt will be reacting to (theoretically it
could, but I doubt the utility of displaying "PASTE" for a few milliseconds).
2020-08-07 21:06:16 +02:00
Fabian Homborg
eb35975c0f Make cancel-commandline actual bind function
This was always awkward as fish script, and had problems with
interrupting the autoloading.

Note that we still leave the old function intact to facilitate easier
upgrading for now.

Fixes #7145.
2020-07-01 20:56:56 +02:00
exploide
8025e80fdb new function __fish_preview_current_file to open file at the cursor in pager
bound to Alt+O by shared key bindings
created with help from @krobelus
fixes #6838
2020-04-07 22:30:05 +02:00
Fabian Homborg
8ddd512fba Refine when we expand abbreviations
- ctrl-space will insert a space without expanding abbrs
- ")" or alt-enter will expand abbrs

Fixes #6658
2020-03-21 13:55:15 +01:00
Fabian Homborg
463b9b99c6 Move ctrl-left/right forward-word to shared bindings
These also work in vim.

Fixes #6755.
2020-03-15 13:24:45 +01:00
Fabian Homborg
9367d4ff71 Reindent functions to remove useless quotes
This does not include checks/function.fish because that currently
includes a "; end" in a message that indent would remove, breaking the test.
2020-03-09 19:46:43 +01:00
ridiculousfish
29c2bce704 Use self-insert-notfirst on spaces during paste
This changes a5a643f854 to use the new self-insert-notfirst binding.
It also adds a test.
2020-03-07 13:31:55 -08:00
Greg Anders
0f802eaad8 Add default \es keybinding for "prepend sudo" 2019-10-06 15:17:49 +02:00
Greg Anders
e5fc8abefe Fix default Alt+W keybinding (#6110)
* Fix default Alt+W keybinding

The old keybinding would chop off the last line of the `whatis` output
when using a multi-line prompt. This fix corrects that.

* Make variable local and remove unneeded if statement

* Test that token is non-empty
2019-10-06 15:14:10 +02:00
Fabian Homborg
b5351bce1b Bind tmux focus reporting as --preset bindings
Purely cleanup, basically.

[ci skip]
2019-04-21 19:48:46 +02:00
Fabian Homborg
a5a643f854 Bracketed paste: Strip leading spaces if they'd trigger histignore
Similar to the last commit, only for the in-terminal-paste stuff.

Also cleans up the comments on bracketed paste a bit - nobody has
stepped forward to report problems with old emacsen or windows, so
there's no need for a TODO comment.

See #4327.
2019-03-13 12:39:08 +01:00
Fabian Homborg
60f162db19 Remove single-argument test
This is an awful bit of `test` functionality that only exists to have
a clever shortcut and confuse people.

[ci skip]
2019-03-05 17:57:50 +01:00
Aaron Gyes
0abcf9265e {forward,backward}-bigword on Shift-Left/Right
There was no way to do this at all without vi keybindings,
and it turns out shift-left/shift-right was available.

Fixes #1605
2019-02-07 13:11:34 -08:00
Fabian Homborg
a0fbb8dea7 Redraw vi cursor if tmux pane focus changes
Fixes #4788.
2019-01-26 19:38:28 +01:00
Fabian Homborg
444f9f8715 Add separation of "preset" bindings
This allows for marking certain bindings as part of a preset, which allows us to

- only erase those when switching presets
- go back to the preset binding when erasing a user binding
- only show user customization if requested
- make bare bind statements in config.fish work (!!!11elf!!!)

Fixes #5191.
Fixes #3699.
2018-09-30 16:54:56 +02:00
ridiculousfish
c4a12f90c1 Bind pager-toggle-search to control-s by default. 2018-01-30 09:58:08 -08:00