Commit Graph

2352 Commits

Author SHA1 Message Date
Fabian Homborg
1259b32ecc Mark some variables as unused
These triggered warnings.
2019-05-29 20:50:35 +02:00
Fabian Homborg
39099ceb10 Remove R_BEGIN_INPUT_FUNCTIONS
The enum starts at 0 (defined to be!), so we can eliminate this one.

That allows us to remove a reliance on the position of
beginning_of_line, and it would trigger a "type-limits" warning.

Also leave a comment because I actually hit that.
2019-05-29 20:50:35 +02:00
Fabian Homborg
4a6a354675 Placate compiler warnings 2019-05-29 20:50:35 +02:00
Fabian Homborg
364bc3fd63 test: Fix return type
This just returns a success signifier, not an error code.
2019-05-29 20:50:35 +02:00
Fabian Homborg
a5b633d3a5 env: Correct type
We'd be comparing "int" and "mode_t", and "mode_t" might be unsigned.

Found via GCC warning.
2019-05-29 20:50:35 +02:00
Fabian Homborg
e895cef245 tinyexpr: Correct pi type 2019-05-29 20:50:35 +02:00
Fabian Homborg
97507a24a2 Increase default read limit to 100MiB
Someone has hit the 10MiB limit (and of course it's the number of
javascript packages), and we don't handle it fantastically currently.

And even though you can't pass a variable of that size in one go, it's
plausible that someone might do it in multiple passes.

See #5267.
2019-05-29 11:01:45 +02:00
Fabian Homborg
66e238fad0 More wide IO for FLOG
This widens the remaining ones that don't take a char
anywhere.

The rest either use a char _variable_ or __FUNCTION__, which from my
reading is narrow and needs to be widened manually. I've been unable
to test it, though.

See #5900.
2019-05-29 08:07:04 +02:00
Fabian Homborg
32949eefbe src/exec: Use wide IO for FLOG
Another step towards #5900.
2019-05-28 23:08:35 +02:00
Fabian Homborg
7c1a40fe86 flog: Use wide literals with wide chars
This solves the main part of (careful linebreak)
issue #5900.

I'm betting all the errors that do use narrow IO are broken, including
a bunch of asserts.
2019-05-28 22:39:47 +02:00
David Adam
7fe93c7518 src/expand: update comment for fallthrough to GCC standard
As suggested in 75db3b4ff4 (r33153119)
2019-05-28 23:20:20 +08:00
David Adam
b5cf9e52ca wcsfilecmp: be clearer about sorting "-" after letters 2019-05-28 22:05:23 +08:00
David Adam
c848787107 add extra test for wcsfilecmp
Test changes added for #5634 in 6e525cc5d9.
2019-05-28 22:03:03 +08:00
David Adam
ba4f4bfce2 Convert further debug(0) calls to FLOG
Follow on from ea9d1ad82f.
2019-05-28 21:06:42 +08:00
ridiculousfish
29c627d020 Stop calling principal_parser() inside parse_execution.cpp 2019-05-27 19:56:35 -07:00
ridiculousfish
835c6ffa67 clang-format all files 2019-05-27 19:47:13 -07:00
ridiculousfish
0150d505de Allow underscores to be treated as dashes in debug categories 2019-05-27 17:38:09 -07:00
ridiculousfish
ea9d1ad82f Convert debug(0) calls to FLOG 2019-05-27 17:31:17 -07:00
ridiculousfish
6282ac5713 Convert locale variable changes from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
46a9da83e8 Convert terminal ownership logging from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
d9676bb2a8 Convert fork events from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
8774860468 Convert job logging from debug to FLOG 2019-05-27 17:24:52 -07:00
ridiculousfish
63a16befd4 Introduce the fish log, a replacement for debug()
This adds a new mechanism for logging, intended to replace debug().

The entry points are FLOG and FLOGF. FLOG can be used to log a sequence of
arguments, FLOGF is for printf-style formatted strings.

Each call to FLOG and FLOGF requires a category. If logging for a category
is not enabled, there is no effect (and arguments are not evaluated).

Categories may be enabled on the command line via the -d option.
2019-05-27 17:24:52 -07:00
ridiculousfish
b405b979ec Eliminate the CHECK() macro
This thing was pretty useless.
2019-05-27 17:24:19 -07:00
Fabian Homborg
9ae3b345c8 Handle empty strings in compare_completions_by_tilde
Fixes #5895.
2019-05-27 08:17:05 +02:00
ridiculousfish
d5f2d472d0 Thread a parser into reader
Eliminates uses of principal_parser
2019-05-26 18:51:47 -07:00
ridiculousfish
7ed1022cf4 Latch signal handlers
Now that our interactive signal handlers are a strict superset of
non-interactive ones, there is no reason to "reset" signals or take action
when becoming non-interactive. Clean up how signal handlers get installed.
2019-05-26 18:04:03 -07:00
ridiculousfish
ead7f28026 Unify the SIGQUIT handlers and remove set_non_interactive_handlers
Interactive signal handlers are now a strict superset of non-interactive
ones. Remove set_non_interactive_handlers()
2019-05-26 13:18:06 -07:00
ridiculousfish
d729d57d94 Unify the interactive and non-interactive signal handlers
The signal handlers for interactive and non-interactive SIGINT were distinct
and talked to the reader. This wasn't really justified and will complicate
having multiple threads. Unify these into a single signal handler.
2019-05-26 00:32:11 -07:00
ridiculousfish
5a4df9dd3a Use sigint_checker_t in debug_thread_error 2019-05-25 19:19:03 -07:00
ridiculousfish
ea3ad0c099 Introduce sigint_checker_t and use it in wait
Allow a simpler way to check for sigint via sigint_checker_t.
Adopt it in builtin_wait, instead of hooking into the reader.
2019-05-25 19:08:04 -07:00
ridiculousfish
f8ba0ac5bf Remove is_interactive_read
is_interactive_read is a suspicious flag which prevents a call to
parser_t::skip_all_blocks from a ^C signal handler. However we end
up skipping the blocks later when we exit the read loop.

This flag seems unnecessary. Bravely remove it.
2019-05-25 18:46:03 -07:00
ridiculousfish
2924751488 Correct priority of universal and global variable setting
When setting a variable without a specified scope, we should give priority
to an existing local or global above an existing universal variable with
the same name.

In 16fd780484 there was a regression that
made universal variables have priority.

Fixes #5883
2019-05-25 17:35:19 -07:00
Fabian Homborg
e339e0f389 fish_indent: Fix pygments 2019-05-25 11:38:05 +02:00
Fabian Homborg
6c0ae7477e reader: Only abort history search on cancel
Otherwise we'd undo the history search when you press e.g. execute,
which means you'd execute the search term.

Only `cancel` should walk it back, like it previously did hardcoded to
escape.

Fixes #5891.
2019-05-25 08:32:50 +02:00
ridiculousfish
a5a5ccb73d Revert "exec: If a job includes a builtin, it stays in our pgroup"
This reverts commit 711260593c.

This ended up breaking the tests; moreover it may have other problems
like preventing backgrounding.

Reopens #5855
2019-05-24 18:00:31 -07:00
ridiculousfish
43e3d3bcf2 Fix the argparse tests 2019-05-24 16:51:40 -07:00
ridiculousfish
a379e9ffeb Make the expect tests run again
These were inadvertently disabled by a bug which was introduced in
cd7e8f4103 . Fix the bug so the tests run
again.

They don't all pass yet; they regressed during the period they were
disabled.
2019-05-24 16:10:44 -07:00
Fabian Homborg
1fd627ebd3 reader: Don't handle escape specially
Escape is just another ordinary character that you can bind, or not.
2019-05-24 19:02:53 +02:00
Fabian Homborg
dd4e0a3b6d Actually end history search
Fixes #5818.
2019-05-24 19:01:24 +02:00
Fabian Homborg
d0bd238657 Don't hardcode enum numbers
"1" in the context of `escape_string(..., 1)` is referring to
`ESCAPE_ALL`, so we should use that.
2019-05-24 18:19:11 +02:00
Fabian Homborg
711260593c exec: If a job includes a builtin, it stays in our pgroup
Fixes #5855.
2019-05-24 18:04:20 +02:00
Fabian Homborg
f2bb1c8c1f expand: Simplify expand_escape_variable 2019-05-24 17:03:43 +02:00
ridiculousfish
84febe8f2e Make disowned pid reaping thread-safe 2019-05-22 17:10:33 -07:00
ridiculousfish
4d929720ce Clean up and rename io_transmorgrify 2019-05-22 16:36:22 -07:00
ridiculousfish
7915831939 Wrap setenv() and unsetenv() calls in a lock 2019-05-22 16:13:31 -07:00
ridiculousfish
e91d68266c Eliminate reader_current_filename
Store this in the parser libdata instead.
2019-05-22 13:51:27 -07:00
ridiculousfish
686b84396c Migrate the return bool outside of block_t
This is a flag that gets set by the return function. But we only need one,
not per-block. Move it into libdata.
2019-05-22 13:51:27 -07:00
Fabian Homborg
9a541d9ed4 expand: Use wcstring for the abbr prefix
This mainly is conceptually a bit simpler. The comment about making it
cheaper is entirely misplaced since this is quite far away from being
important.

Even expanding 1000 abbrs, it doesn't show up in the profile.
2019-05-22 22:31:45 +02:00
Fabian Homborg
212246ecaa fish_indent: Fix reading from stdin for 0 args
I have no idea why this passes the tests, we *have* tests reading from
stdin!
2019-05-22 22:21:28 +02:00
Fabian Homborg
1faffa515e Don't crash if CDPATH is "./"
Fixes #5887.
2019-05-22 21:48:40 +02:00
ridiculousfish
363652ad76 debug_thread_error to wait for a signal instead of sleep
Allows for control-C out of it
2019-05-21 20:15:59 -07:00
Fabian Homborg
6d20b3984a Revert "src/screen: Stop falling back to wchar_t"
This was, under some circumstances, apparently off by one.

If a suggestion was really long, like

```fish
infocmp | string split , | string trim | string match -re . | while read -d = -l key val; test -z "$val"; and continue; string match -q '*%*' -- $val; and continue; test (string replace -ra '\e([\[\]]|\(B).*[\comJKsu]' '' -- a(tput $key)b) = ab; or echo $key $val; end > xterm
```

(I'm assuming longer than $COLUMNS), it would staircase like with a wrong wcwidth.

This reverts commit 15a5c0ed5f.
2019-05-21 23:35:31 +02:00
ridiculousfish
11209b7553 Switch the block stack to a deque instead of vector of shared pointers
That makes the block stack easier to copy.
2019-05-21 10:25:48 -07:00
ridiculousfish
ad57133c7f Switch parser_t to hold its variables via shared_ptr
Preparation for variable stacks with finite lifetimes.
2019-05-21 10:25:48 -07:00
Aaron Gyes
714b8420a9 %s -> %ls for wchar_t
I noticed my debug output for 24bit color mode was garbled due to
this being wrong. I spent a little time trying to get the compiler
to tell us about these, but -Wformat doesn't do anything for wchar
printf functions, and __attribute__((format(printf, n, m))) will
cause an error with wchar_t's, so I gave up and decided to manually
check out every '%s' in the entire project. I found (only) one
more.

debug(0, "%s", wchars) will report warnings for incorrect
specifiers but debug(0, L"%s", wchars) is unable. Thus there may
be reason to prefer not using L"..." as an argument if all else
is equal and it's not necessary.
2019-05-20 13:48:35 -07:00
Fabian Homborg
c2b7e9b2e6 fish_indent: Allow multiple file arguments
Allows `fish_indent -w **.fish` to restyle all fish files under the
current directory.

(This also has the sideeffect of reducing style.fish time by ~10s, as
we only need to invoke `fish_indent` once, instead of once per-file)
2019-05-20 21:04:51 +02:00
ridiculousfish
8e640cdcc5 fish_indent to stop stripping quotes from keywords 2019-05-19 20:56:28 -07:00
ridiculousfish
159d6d669a Remove all block_t subclasses 2019-05-19 14:44:40 -07:00
ridiculousfish
eff4873eca Stop creating subclasses of block_t
Move all block_t creation methods to static methods, and stop creating
subclasses (all of which are now empty).
2019-05-19 14:40:35 -07:00
ridiculousfish
cf92b7626c Migrate event_block's event into block_t 2019-05-19 13:07:06 -07:00
ridiculousfish
8697fa063b Migrate source_block's source_file into block_t
Continue to work towards flattening this hierarchy.
2019-05-19 13:01:59 -07:00
ridiculousfish
fec0e40b5e Migrate function_block name and args into block_t
The goal is to eliminate this block hierarchy.
2019-05-19 12:56:07 -07:00
ridiculousfish
cd7e8f4103 Migrate loop status from blocks into libdata
Blocks will soon need to be shared across parsers. Migrate the loop status
(like break or continue) from the block into the libdata. It turns out we
only ever need one, we don't need to track this per-block.

Make it an enum class.
2019-05-19 12:50:05 -07:00
Fabian Homborg
3efa2ad93b Replace wcslen with math 2019-05-19 18:23:33 +02:00
Fabian Homborg
1e9d41f2c1 Remove now-useless code for detecting {}
This can't happen anymore.
2019-05-19 18:23:33 +02:00
Fabian Homborg
967c1d51ee Only do brace expansion if they contain a variable or ","
Brace expansion with single words in it is quite useless - `HEAD@{0}`
expanding to `HEAD@0` breaks git.

So we complicate the rule slightly - if there is no variable expansion
or "," inside of braces, they are just treated as literal braces.

Note that this is technically backwards-incompatible, because

    echo foo{0}

will now print `foo{0}` instead of `foo0`. However that's a
technicality because the braces were literally useless in that case.

Our tests needed to be adjusted, but that's because they are meant to
exercise this in weird ways.

I don't believe this will break any code in practice.

Fixes #5869.
2019-05-19 18:23:27 +02:00
Fabian Homborg
15a5c0ed5f src/screen: Stop falling back to wchar_t
wcstring is perfectly capable of doing this.
2019-05-19 17:32:09 +02:00
Dawid Dziurla
0b3bb0e7c1 Underline every valid entered path (#5872)
* src/highlight: Underline every valid entered path

* update CHANGELOG

* fix highlight test
2019-05-19 10:03:56 +02:00
ridiculousfish
c42eb0eb4f Remove the process from function_block_t
Prior to this fix, a function_block stored a process_t, which was only used
when printing backtraces. Switch this to an array of arguments, and make
various other cleanups around null terminated argument arrays.
2019-05-18 21:09:04 -07:00
ridiculousfish
508c3a8005 Make is_event and other globals part of parser_t libdata 2019-05-18 19:03:45 -07:00
ridiculousfish
c44dae2d73 Migrate certain runtime flags to atomics hidden behind functions 2019-05-18 18:50:28 -07:00
ridiculousfish
4fcb9d1fed Hide no_exec behind a function 2019-05-18 18:50:28 -07:00
ridiculousfish
be41407610 Make have_proc_stat an ordinary function
Removes a mutable global variable.
2019-05-18 18:50:28 -07:00
ridiculousfish
5158ee812b Eliminate the job from block_t
This exists only to support the '--on-job-exit caller' feature.
Just store the calling job ID directly in the parser's libdata.
2019-05-18 18:50:28 -07:00
Fabian Homborg
0aead5caf8 Repaint-mode to reexecute the rest if mode-prompt output is empty
We previously checked if fish_mode_prompt existed as a function, but
that's a bad change for those who already set it to an empty function
to have a mode display elsewhere.
2019-05-14 19:26:52 +02:00
ridiculousfish
005e6f2ab8 Revert "Don't service ioport completions if data is available on stdin"
This reverts commit 0453023f7b.

This broke the history tests. Reverting this while I sort it out.
2019-05-14 09:52:49 -07:00
Fabian Homborg
a7b1c2f76a Drop wcwidth ASCII check
Updated widechar_width takes care of it.

Technically, this does ~3 comparisons more per-character (because it
checks variation selectors and such), but that shouldn't really matter.
2019-05-14 09:49:51 +02:00
Fabian Homborg
2d37bc9bd1 Update widechar_width
This includes the change to check ASCII chars first, so we can now
drop our workaround.
2019-05-14 09:49:51 +02:00
Fabian Homborg
752b5362ee Only widen string if necessary
This tried a bunch of times, but only the final one is important.
2019-05-14 09:49:51 +02:00
Fabian Homborg
87b93cd4ca src/history: Only widen bash history lines once
This did str2wcs when checking, then again when adding.
2019-05-14 09:49:51 +02:00
Fabian Homborg
2aaf7fda27 src/history: Stop renarrowing a string in a for-loop
Classic case of doing stuff in a loop that doesn't change. No idea if
the compiler caught it, but I sleep easier now.
2019-05-14 09:49:50 +02:00
ridiculousfish
0453023f7b Don't service ioport completions if data is available on stdin
This defers certain autosuggestions and syntax highlighting until after
large pastes are complete.
2019-05-13 14:16:43 -07:00
ridiculousfish
277db64804 Force termsize back to valid in get_current_winsize()
get_current_winsize() is intended to be lazy. It does the following:

1. Gets the termsize from the kernel
2. Compares it against the current value
3. If changed, sets COLUMNS and LINES variables

Upon setting these variables, we notice that the termsize has changed
and invalidate the termsize. Thus we were doing this work multiple times
on every screen repaint.

Put back an old hack that just marked the termsize as valid at the end
of get_current_winsize().
2019-05-13 14:05:42 -07:00
Fabian Homborg
e22422c073 Don't do fish_setlocale that early
This just sets some special characters that we use in the reader, so
it only needs to be done before the reader is set up.

Which, as it stands, is in env_init().
2019-05-13 16:09:37 +02:00
ridiculousfish
234c97e6d2 Remove some unused variables 2019-05-12 18:23:00 -07:00
ridiculousfish
1719d6f136 Make $status and $pipestatus per-parser
Another step towards allowing multiple parsers to execute in parallel.
2019-05-12 14:00:44 -07:00
ridiculousfish
8031fa3bdb Stop using atomic types for non-primitives
atomic<winsize> requires linking libatomic on some platforms which is
annoying. Remove the one use.

Fixes #5865
2019-05-12 13:07:37 -07:00
ridiculousfish
1e4ebfa470 Make electric variables a real thing
Use an actual struct to describe electric variables and what is special
about each one.
2019-05-11 19:17:33 -07:00
ridiculousfish
16fd780484 Reimplement the whole variable stack
The variable stack is a mess - confused locking, surprising callouts, and
unclear division of labor. Just reimplement the whole thing.
2019-05-11 19:17:16 -07:00
ridiculousfish
cfddd881ef Make PWD a per-processor variable
Handle this variable specially.
2019-05-11 17:13:34 -07:00
ridiculousfish
ee250aba82 Factor some environment setting into set_scoped_internal
Breaks up a monolith function.
2019-05-11 17:13:34 -07:00
ridiculousfish
15a52d0f0d Centralize some of the logic for walking the environment stack
Prepare to introduce a new node for per-process variables.
2019-05-11 17:13:34 -07:00
Fabian Homborg
adcc70d0b3 wcwidth: Return early for simple ASCII
Characters from space to before DEL are width 1, and they
appear *often*.

So it's quite a good idea to return early for them.

Fixes #5866.
2019-05-11 21:40:35 +02:00
Fabian Homborg
4462f6d600 src/screen: Skip a wcswidth
This stops trying to see if the previous line is wider if it is a
prefix of the current one.

Which turns out to be true often enough that it's a net benefit.
2019-05-11 10:43:38 +02:00
Fabian Homborg
ac983f6c4b src/screen: Stop recomputing wcwidth
This passes character width as an argument for a few functions.

In particular, it hardcodes a width of "1" for a space literal.
There's no reason to compute wcwidth for the length of the prompt.
2019-05-11 10:43:38 +02:00
Fabian Homborg
567b6ed2b5 src/screen: Stop doing a bunch of unnecessary work
This measured *all* the characters on the commandline, and saved all
of them in another wcstring_list_t, just to then do... nothing with
that info.

Also, it did wcslen for something that we already have as wcstring,
reserved a vector and did a bunch of work for autosuggestions that
isn't necessary if we have more than one line.

Instead, we do what we need, which is to figure out if we are
multiline and how wide the first line is.

Fixes #5866.
2019-05-10 17:43:46 +02:00
Fabian Homborg
d2b02a8a61 src/screen: Only check for combining marks if necessary
line_shared_prefix explains in its comment that

> If the prefix ends on a combining character, do not include the
  previous character in the prefix.

But that's not what it does.

Instead, what it appears to do is to return idx for *every* combining
mark. This seems wrong to begin with, and it also requires checking
wcwidth for *every* character.

So instead we don't do that. If we find the mismatch, we check if it's
a combining mark, and then go back to the previous character (i.e. the
one before the one that the combining mark is for).

My tests found no issues with this, other than a 20% reduction in
pasting time.
2019-05-10 17:43:46 +02:00
Fabian Homborg
eb41965ac3 reader: Remove superfluous while-loop
It's possible this was useful at some point, but now it just always
inserts the string the first time.
2019-05-10 17:43:46 +02:00
Mahmoud Al-Qudsi
097d6c3c5b Fix order of operations in tilde comparison
The previous form of the statement evaluated to a constant comparison
and couldn't have been what was actually intended.
2019-05-09 01:22:23 -05:00