Commit Graph

1984 Commits

Author SHA1 Message Date
Aaron Gyes
6e525cc5d9 wcsfilecmp: sort - after everything else
Before this change, - was sorted with other punctuation before
A-Z. Now, it sorts above the rest of the characters.

This has a practical effect on completions, where when there are
both -s and --long with the same description, the short option
is now before the long option in the pager, which is what is now
selected when navigating `foo -<TAB>`. The long options can be
picked out with `foo --<TAB>`. Before, short options which
duplicated a long option literally could not be selected by
any means from the pager.

Fixes #5634
2019-03-16 01:31:56 -07:00
Aaron Gyes
74a22ff426 wcsfilecmp: punctuation [\]^_` after A-Z.
This tweaks wcsfilecmp such that certain punctuation characters will
come after A-Z.

A big win with `set <TAB>` - the __prefixed fish junk now comes
after the stuff users should care about.
2019-03-16 01:18:16 -07:00
ridiculousfish
88d20e257b Remove some unused variables 2019-03-15 20:21:05 -07:00
Fabian Homborg
864bb1f7a6 Add string-replace-fewer-backslashes feature
This disables an extra round of escaping in the `string replace -r`
replacement string.

Currently, to add a backslash to an a or b (to "escape" it):

    string replace -ra '([ab])' '\\\\\\\$1' a

7 backslashes!

This removes one of the layers, so now 3 or 4 works (each one escaped
for the single-quotes, so pcre receives two, which it reads as one literal):

    string replace -ra '([ab])' '\\\\$1' a

This is backwards-incompatible as replacement strings will change
meaning, so we put it behind a feature flag.

The name is kinda crappy, though.

Fixes #5474.
2019-03-15 15:18:19 +01:00
Fabian Homborg
e7a964fdfa [count] Allow counting lines from stdin
As a simple replacement for `wc -l`.

This counts both lines on stdin _and_ arguments.

So if "file" has three lines, then `count a b c < file` will print 6.

And since it counts newlines, like wc, `echo -n foo | count` prints 0.
2019-03-15 14:31:36 +01:00
Aaron Gyes
cb36a9ca36 builtin.cpp: ensure builtin_get_desc returns something initialized 2019-03-14 21:45:31 -07:00
Aaron Gyes
9a5022514f builtin_argparse: use std::swap 2019-03-14 16:47:23 -07:00
Aaron Gyes
d837eee09d remove some wcstring -> wchar_t* -> wcstring conversions
Mostly related to usage _(L"foo"), keeping in mind the _
macro does a wcstring().c_str() already.

And a smattering of other trivial micro-optimizations certain
to not help tangibly.
2019-03-14 15:21:08 -07:00
Aaron Gyes
477b2e8d7c std::vector<wcstring> is wcstring_list_t 2019-03-14 11:17:26 -07:00
Aaron Gyes
0ee9862809 Write out backtrace in one debug(), add \n after it.
The goal here is to make fish -dn -Dn output a little easier
to scan visually.
2019-03-14 10:56:24 -07:00
Aaron Gyes
cf570d4b11 fixup previous commit 2019-03-14 10:37:13 -07:00
Aaron Gyes
2636876472 simplify append_yaml_to_buffer 2019-03-14 10:29:16 -07:00
Aaron Gyes
2bf554ae5e Simplify valid_var_name 2019-03-14 10:29:16 -07:00
Fabian Homborg
f798a02a2a Remove unused variable 2019-03-14 13:23:47 +01:00
Aaron Gyes
6fc542dfca Revert "simplify append_yaml_to_buffer"
This reverts commit f0998fed6a.
2019-03-13 14:05:23 -07:00
Aaron Gyes
f0998fed6a simplify append_yaml_to_buffer 2019-03-13 13:52:11 -07:00
Aaron Gyes
b879a2650c Fix 32-bit build
Fixes #5740
2019-03-13 07:44:05 -07:00
Fabian Homborg
05b9c07816 wcwidth: Return 0 for median/final jamo
Fixes #5729.
2019-03-13 12:39:08 +01:00
Fabian Homborg
5a9d153363 input: Use range-for
Also adds a couple of consts.
2019-03-13 12:39:08 +01:00
Aaron Gyes
f92c2921d2 Remove mini() and maxi()
C++11 provides std::min/std::max which we're using all over,
obviating the need for our own templates for this.

util.h now only provides two things: get_time and wcsfilecmp.
This commit removes everything that includes it which doesn't
use either; most because they no longer need mini or maxi from
it but some others were #including it unnecessarily.
2019-03-12 23:25:15 -07:00
Fabian Homborg
b318ab17d2 wcwidth: Classify some Hangul Jamo as combiners
Hangul uses three codepoints to combine to one glyph. The first has a
width of 2 (like the final glyph), but the second and third were
assigned a width of 1, which seems to match EastAsianWidth.txt:

> 1160..11FF;N # Lo [160] HANGUL JUNGSEONG FILLER..HANGUL JONGSEONG SSANGNIEUN

Instead, we override that and treat the middle and end codepoint as combiners,
always, because there's no way to figure out what the terminal will
think and that's the way it's supposed to work.

If they stand by themselves or in another combination, they'll indeed
show up with a width of 1 so we'll get it wrong, but that's less
likely and not expressible with wcwidth().

Fixes #5729.
2019-03-12 23:42:50 +01:00
Aaron Gyes
2e4948e1f4 Fix switch nesting in handler_matches
I guess this worked, but whoops.
2019-03-12 15:27:13 -07:00
Aaron Gyes
b7c069a765 Remove two duplicated #includes 2019-03-12 15:09:36 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
Fabian Homborg
ecfe4acd0c complete: Do fuzzy match for --do-complete
This only did prefix matching, which is generally less useful.

All existing users _should_ be okay with this since they want to
provide completions.

Fixes #5467.
Fixes #2318.
2019-03-12 20:27:20 +01:00
Aaron Gyes
66887ca4bc Fix OpenSUSE build
They treat -Wreturn-type as a critical thing apparently.
2019-03-12 09:45:39 -07:00
Aaron Gyes
2ae6e5a585 Explicitly handle all enum values in more switch statements
This addresses a few places where -Wswitch-enum showed one or two missing
case's for enum values.

It did uncover and fix one apparent oversight:

$ function asd -p 100
   echo foo
end

$ functions --handlers-type exit
Event exit
asd

It looks like this should be showing a PID before 'asd' just like
job_exit handlers show the job id. It was falling
through to default: which just printed the function name.

$ functions --handlers-type exit
Event exit
100 asd
2019-03-11 15:02:18 -07:00
Fabian Homborg
1cd5b2f4e1 Pass string length instead of recomputing
This called `writestr(char*)`, which then just called `writestr(char*,
strlen(char*))`, when it had the string length right there!
2019-03-07 10:04:18 +01:00
Fabian Homborg
2b0b3d3193 Outputter_t: Handle C locale like everything else
This tried to skip conversion if the locale had MB_CUR_MAX == 1, but
in doing so it just entered an infinite recursion (because
writestr(wchar_t*) called writestr(wchar_t*)).

Instead, just let wcstombs handle it.

Fixes #5724.
2019-03-07 10:04:18 +01:00
Fabian Homborg
c633c06e11 Guess emoji width via system wcwidth
Since Unicode 9, the width of some characters changed to 2.

Depending on the system, it might have support for it, or it might
not.

Instead of hardcoding specific glibc etc versions, we check what the
system wcwidth says to "😃", U+1F603 "Grinning Face With Big Eyes".

The intention is to, in most cases, make setting $fish_emoji_width
unnecessary, but since it sets the "guessed_emoji_width", that variable still takes precedence if it is set.

Unfortunately this approach has some caveats:

- It relies on the locale being set to a unicode-supporting one.
  (C.UTF-8 is unfortunately not standard, so we can't use it)
- It relies on the terminal's wcwidth having unicode9 support IFF the
  system wcwidth does.

This is like #5722, but at runtime.

The additional caveat is that we don't try to achieve a unicode
locale, but since we re-run the heuristic when the locale changes (and
we try to get a unicode locale), we should still often get the correct
value.

Plus if you use a C locale and your terminal still displays emoji,
you've misconfigured your system.

Fixes #5722.
2019-03-06 22:27:21 +01:00
David Adam
b443808452 event.cpp: die if invalid event type passed
Fixes the build with -Wreturn-type.
2019-03-05 07:27:56 +08:00
ridiculousfish
89a7cc5da3 Switch s_write to accepting const vector & instead of raw pointers 2019-03-03 18:49:57 -08:00
ridiculousfish
ccbc9d57f2 Remove reader_data_t::next
It's no longer used
2019-03-03 18:14:41 -08:00
ridiculousfish
9b9c1aa745 Fix some unused variable warnings 2019-03-03 18:06:31 -08:00
ridiculousfish
717ac9a8d5 Switch highlight_spec_t to a struct
Rather than a janky bitmask, use a real struct with real fields.
2019-03-03 18:04:22 -08:00
ridiculousfish
d165d1df27 Remove highlight_modifier_sloppy_background
It's no longer ever set
2019-03-03 17:56:08 -08:00
ridiculousfish
43a11af5e4 Reorganize reader.cpp to separate te current_data users from reader_data_t 2019-03-03 15:49:56 -08:00
ridiculousfish
c09544b288 Migrate more functions to instance methods on reader_data_t 2019-03-03 15:10:47 -08:00
ridiculousfish
29db076f4a exec_prompt to be an instance method on reader_data_t 2019-03-03 14:38:53 -08:00
ridiculousfish
7ff4b5e5fe Switch highlighting to instance methods on reader_data_t 2019-03-03 14:34:52 -08:00
ridiculousfish
e477b99a8b Switch more autosuggestions to instance methods on reader_data_t 2019-03-03 14:30:32 -08:00
ridiculousfish
b014c327a2 reader_data_t to become enable_shared_from_this
For background operations such as autosuggestions, we need a way for the
completion handler to keep the reader_data alive.
2019-03-03 14:21:15 -08:00
ridiculousfish
c334a41f96 Switch accept_autosuggestion to an instance method on reader_data_t 2019-03-03 14:11:09 -08:00
ridiculousfish
d7a156e7d9 Switch clear_pager to an instance method on reader_data_t 2019-03-03 14:09:23 -08:00
ridiculousfish
164c5b1c18 Migrate a lot of free functions in reader into reader_data_t 2019-03-03 14:02:27 -08:00
ridiculousfish
ecf51b575e Clean up input initialization and destruction 2019-03-03 12:59:55 -08:00
ridiculousfish
dc1073f905 reader_set_buffer_maintaining_pager to take reader_data directly 2019-03-03 12:19:46 -08:00
ridiculousfish
0bc08c6197 highlight_search to take reader_data directly 2019-03-03 12:11:32 -08:00
ridiculousfish
b07345ed18 set_command_line_and_position to take reader_data directly 2019-03-03 12:07:51 -08:00