Commit Graph

362 Commits

Author SHA1 Message Date
Johannes Altmanninger
75ae172ba2 token search: replace only until the end of the token
Fixes #6774
2020-03-20 14:05:49 +01:00
Johannes Altmanninger
390647ae34 Suppress history autosuggestion for command lines prefixed with a space
Currently we do not add such command lines to the history, so there
won't be a suggestion from history anyway.

Fixes #6763 which occurs because midnight commander feeds fish commands
like this one (note the loading space)

` cd (printf '%b' '\0057home\0057johannes\0057git\0057fish\0055shell\0057build')`
2020-03-19 18:59:20 +01:00
Rosen Penev
39861d54c5 [cppcheck] add some std::move
Found with passedByValue

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
ridiculousfish
77ad459aae Pull char_input_style_t into a top-level enum
Review feedback from
https://github.com/fish-shell/fish-shell/pull/6713#pullrequestreview-369853776
2020-03-07 13:55:19 -08:00
ridiculousfish
f73e324618 Teach the reader fast path about self-insert-notfirst
This teaches the reader fast-path to use self-insert-notfirst, allowing
it to handle spaces. This greatly increases the performance of paste by
reducing redraws.

Fixes #6603. Somewhat improves #6704
2020-03-07 13:31:55 -08:00
ridiculousfish
b8a7cdacb6 Implement self-insert-notfirst in reader
This adds basic support for self-insert-notfirst. When we see a
self-insert-nonempty char event, we kick it back to the outer loop,
which only inserts the character if the cursor is not at the beginning.
2020-03-07 13:31:55 -08:00
ridiculousfish
2e4cb15880 Add self-insert-notfirst readline command
This adds a new readline command self-insert-notfirst, which is
analogous to self-insert, except that it does nothing if the cursor
is at the beginning. This will serve as a higher-performance implementation
for stripping leading spaces on paste.
2020-03-07 13:31:55 -08:00
ridiculousfish
e334becefb Adopt debounce for highlighting and autosuggestions
This prevents a thundering herd of threads for certain interactive
scenarios.
2020-03-06 17:15:23 -08:00
Norio Nomura
4f0fab04ad Clear cancellation_signal before firing fish_postexec event
Fix #2356
2020-03-03 21:35:29 -08:00
Johannes Altmanninger
8eadef81a4 Fix crash on escape in complete-and-search pager
Reproduce with `: <Shift+Tab><Escape>`.
Introduced in 8a033b9f3 Add undo
2020-02-29 21:19:28 +01:00
Johannes Altmanninger
99851c09b3 Fix selection going out of bounds
Which happened when starting the selection at the end of the commandline.
In this case, selections still interact weirdly with autosuggestions (the
first character of the suggestion appears to be part of the selection
when it's not).

Fixes #6680
2020-02-29 09:47:12 +01:00
Johannes Altmanninger
aa0e16b1a5 Skip variable assignments in status current command
Fixes #6635
2020-02-24 00:16:12 +01:00
Rosen Penev
a410dcb5c2 [clang-tidy] use empty() instead of comparing
Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:34:03 +01:00
ridiculousfish
05b8d4de97 Make hup_background_jobs accept the job list directly 2020-02-19 20:35:04 -07:00
ridiculousfish
59c6663a16 Migrate the "are you sure you want to exit" logic from parse_execution to exec
This feels more like the sort of logic that should live in the point where
jobs are executed, instead of where jobs are created from parse trees.
2020-02-19 18:25:36 -07:00
Johannes Altmanninger
4c66e69cd9 Fixup b31b52c2 which wasn't right for backward-delete-char 2020-02-09 10:27:27 +01:00
Johannes Altmanninger
b31b52c272 Fix another egregious regression from 8a033b9f3 Add undo
The first character in the commandline could not be deleted with ^D.
2020-02-09 05:17:27 +01:00
Johannes Altmanninger
12a9cb2940 Fix assertion failure on page up / page down
I had overlooked {beginning,end}-of-history which don't search.
2020-02-08 08:55:02 +01:00
Johannes Altmanninger
8a033b9f3d Add undo
Add the input function undo which is bound to `\c_` (control + / on
some terminals). Redoing the most recent chain of undos is supported,
redo is bound to `\e/` for now.

Closes #1367.
This approach should not have the issues discussed in #5897.

Every single modification to the commandline can be undone individually,
except for adjacent single-character inserts, which are coalesced,
so they can be reverted with a single undo. Coalescing is not done for
space characters, so each word can be undone separately.

When moving between history search entries, only the current history
search entry is reachable via the undo history. This allows to go back
to the original search string with a single undo, or by pressing the
escape key.
Similarly, when moving between pager entries, only the most recent
selection in the pager can be undone.
2020-02-07 17:15:17 +01:00
Johannes Altmanninger
14c6a12782 Use accessor functions for editable_line_t::{text,position}
This is paving the way for undo, where we want to have one central place
for modifying an editable_line_t.
2020-02-06 01:30:45 +01:00
ridiculousfish
1101cff566 Factor out some of the crazy logic in reader_interactive_init 2020-01-31 11:11:03 -08:00
ridiculousfish
28a8d0dbf7 Continued adoption of autoclose_fd_t and exec_close 2020-01-29 14:16:16 -08:00
ridiculousfish
376529a46d Clean up reader_read
Stop having reader_read close the input file descriptor. Make other
modernizations.
2020-01-28 11:39:26 -08:00
ridiculousfish
fc4557c784 Eliminate wopen()
It was large and mostly unnecessary. Prefer wopen() followed by
fdopen().
2020-01-28 10:43:37 -08:00
Fabian Homborg
3bb15defbb
Replace debug() with flog
PR #6511 

Flog has the advantage of having *categories*, not severities, so it'll be easier to get output for a certain subsystem now.
2020-01-26 14:13:17 +01:00
ridiculousfish
38f4330683 Rationalize $status and errors
Prior to this fix, fish was rather inconsistent in when $status gets set
in response to an error. For example, a failed expansion like "$foo["
would not modify $status.

This makes the following inter-related changes:

1. String expansion now directly returns the value to set for $status on
error. The value is always used.

2. parser_t::eval() now directly returns the proc_status_t, which cleans
up a lot of call sites.

3. We expose a new function exec_subshell_for_expand() which ignores
$status but returns errors specifically related to subshell expansion.

4. We reify the notion of "expansion breaking" errors. These include
command-not-found, expand syntax errors, and others.

The upshot is we are more consistent about always setting $status on
errors.
2020-01-25 17:28:41 -08:00
Fabian Homborg
8b1ac0912b Add reader flog category
For both input and reader, because the "reader" term is more general
and we don't have enough messages to justify multiple categories
2020-01-19 14:55:08 +01:00
Fabian Homborg
024e03ab1e Replace debug(1) with FLOGF(warning) 2020-01-19 14:22:39 +01:00
Fabian Homborg
384f18a51c Remove last remaining debug(0)
Replace with FLOGF.
2020-01-19 13:31:25 +01:00
ridiculousfish
1978ac87a1 Remove reader_test_should_cancel
Use cancel_checker more pervasively.
2020-01-16 15:21:45 -08:00
ridiculousfish
0f7bba5f0e Introduce operation_context_t
This commit recognizes an existing pattern: many operations need some
combination of a set of variables, a way to detect cancellation, and
sometimes a parser. For example, tab completion needs a parser to execute
custom completions, the variable set, should cancel on SIGINT. Background
autosuggestions don't need a parser, but they do need the variables and
should cancel if the user types something new. Etc.

This introduces a new triple operation_context_t that wraps these concepts
up. This simplifies many method signatures and argument passing.
2020-01-16 15:21:28 -08:00
ridiculousfish
db98ee13a9 Make complete() return the completion list directly
Returning it through a pointer was a remnant of pre C++-11 days.
2020-01-16 15:18:50 -08:00
ridiculousfish
4bb18eaf42 Use completion_list_t naming everywhere
std::vector<completion_t> -> completion_list_t
2020-01-16 15:18:49 -08:00
ridiculousfish
98e714f98f clang-format .cpp and .h files 2020-01-16 15:18:28 -08:00
ridiculousfish
7e1270ae70 Be more disciplined about cancellation signals
Rather than storing a "should cancel" flag in the parser, store the
actual signal which triggered cancellation.
2020-01-14 15:20:04 -08:00
Fabian Homborg
31e6ae0099 Ignore EPERM for setpgid
In case we are a session leader, we get a harmless EPERM, yet we used
to quit. Stop doing that.

Fixes #6499.
2020-01-13 18:57:19 +01:00
Rosen Penev
b1349f44f6
[clang-tidy] Add const to reference
Found with performance-unnecessary-copy-initialization
2019-12-26 21:37:15 -08:00
Rosen Penev
2ecc386121
[clang-tidy] Remove redundant c_str
Found with readability-redundant-string-cstr
2019-12-26 21:25:07 -08:00
Fabian Homborg
e986970f4d Remove vi_arg_digit and vi_delete_to
They don't do anything anymore.
2019-12-25 10:44:27 +01:00
Mathieu Duponchelle
15c1b3ed4b Place fish in its own process group when launched with -i
Fixes #5909
2019-12-23 10:32:37 +01:00
ridiculousfish
c19407ab0f Default parser_t::eval()'s block type to top
This is the parameter value at every call site except one. Just make it the
default.
2019-12-22 16:27:03 -08:00
ridiculousfish
a59f35a378 Make block_type_t an enum class 2019-12-22 15:37:14 -08:00
ridiculousfish
4529e7d183 Reverse the order of the block stack
Previously, the block stack was a true stack. However in most cases, you
want to traverse the stack from the topmost frame down. This is awkward
to do with range-based for loops.

Switch it to pushing new blocks to the front of the block list.
This simplifies some traversals.
2019-12-22 15:07:41 -08:00
Rosen Penev
7d1cc992e5 [clang-tidy] Simplify boolean expressions
Found with readability-simplify-boolean-expr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
4087b2ee15 [clang-tidy] Use bool literals
Found with modernize-use-bool-literals

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:50 -08:00
Rosen Penev
69d0bb7c0d io.h: Add missing override
Found with clang's -Winconsistent-missing-destructor-override

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
586ac3dfa7 [clang-tidy] Convert loops to range based
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
0dfa7421f3 [clang-tidy] Convert C casts to C++ ones
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
7f62e30731 [clang-tidy] Replace size comparisons with empty
Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00