Commit Graph

182 Commits

Author SHA1 Message Date
Maxime Coste
27163106c7 Make register expansions expand to the full register content
Now that we have a nice standard way to express lists of strings,
registers can be fully exposed. An new $kak_main_reg_... env var
was added to provide the previous behaviour which is relied on by
doc.kak.
2018-07-05 07:54:28 +10:00
Maxime Coste
b548dd3a6f Change option lists to be specified as separate arguments on commands line
Option lists and maps are specified using separate arguments, avoiding
the need for additional escaping of their separator and reusing the
existing command line spliting logic instead.

As discussed on #2087, this should make it much easier to work with
list options, and make the general option system feel cleaner.
2018-07-05 07:54:28 +10:00
Maxime Coste
5eeec8bd4d Make expansion of strings support quoting of % by doubling up 2018-07-05 07:54:28 +10:00
Maxime Coste
c829595d01 Refactor command line parsing
Command line parsing now works as follow:

* Quoted strings ('...', "..." and %~...~ with '~' non nestable)
  use 'doubling-up' for escaping their delimiter, if the delimiter
  appears twice in a row, it is considered as part of the string and
  represent one delimiter character. So 'abc''def' == "abc'def". No
  other escaping takes place in those strings.

* Balanced strings (%{...}) do not support any kind of escaping, but
  finds the matching closing delimiter by taking nesting into account.
  So %{abc{def}} == "abc{def}".

* Non quoted words support escaping of `;` and whitespaces with `\`,
  `%`, `'` and '"` can be escaped with `\` at the start of the word,
  they do not need escaping (and will not be escaped) else where in
  a word where they are treated literally. Any other use of '\' is a
  literal '\'. So \%abc%\;\ def == "%abc%; def"

As discussed in #2046 this should make our command line syntax more
robust, provide a simple programmatic way to escape a string content
(s/<delim>/<delim><delim>/g), be well defined instead of ad-hoc
undocumented behaviour, and interact nicely with other common
escaping by avoiding escaping hell (:grep <regex> can in most case
be written with the regex unquoted).
2018-07-05 07:54:28 +10:00
Maxime Coste
ec16969609 Do not reparse %sh{...} strings
Automatic reparsing of %sh{...}, while convenient in many cases,
can be surprising as well, and can lead to security problems:

'echo %sh{ printf "foo\necho bar" }' runs 'echo foo', then 'echo bar'.
we make this danger explicit, and we fix the 'nop %sh{...}' pattern.

To reparse %sh{...} strings, they can be passed to evaluate-commands,
which has been fixed to work in every cases where %sh{...} reparsing
was used..
2018-07-05 07:54:28 +10:00
Maxime Coste
68fb3ba88f Rework fail command not to display command call stack
`fail` triggers "expected" errors, and hence should just display
the provided message.
2018-05-26 21:31:17 +10:00
Maxime Coste
54b62cbef7 Do not expose C++ typeid().name to user facing errors on wrong option type
Fixes #2079
2018-05-26 10:01:26 +10:00
Delapouite
cb02186c77 Make error messages more consistent 2018-04-06 16:56:53 +02:00
Maxime Coste
e8093a12a0 Simplify command debug code 2018-03-27 08:25:47 +11:00
Maxime Coste
7ba4ef897b Fix crash on expanding command line strings 2018-03-18 04:58:15 +11:00
Maxime Coste
a480e566dc ranges: Add transform overload taking directly a pointer to member
This overload will forward to the general transform implementation
using std::mem_fn to generate a callable.
2018-03-13 14:24:03 +11:00
Maxime Coste
6d111d4bd7 Re-introduce aliases in command name completion
Aliases are considered again in command name completion, but only
if they are more than 3 charactes long. This should prevent cluttering
with aliases while still letting long ones being completed.
2018-02-20 23:32:31 +11:00
Maxime Coste
76f5fb937c Fix bug in command parsing post refactoring
Fixes #1857
2018-02-19 08:29:04 +11:00
Maxime Coste
536fa29ed5 CommandManager: unescape % while parsing the string 2018-02-18 14:56:52 +11:00
Maxime Coste
bde1f5349d CommandManager: refactor parsing of commands to iterate through tokens
Avoid storing a big vector of tokens, read them one by one, and
store only the current command.
2018-02-15 23:24:19 +11:00
Maxime Coste
b7a3d80bde CommandManager: Use byte rather than columns for token positions
Not only are display columns rarely used to give error positions,
but they make the parsing much slower as for each token we need to
compute the column in the line.
2018-02-09 20:30:33 +11:00
Maxime Coste
e2c1d44a7f Fix parsing of percent tokens with unicode separators 2018-02-06 20:29:08 +11:00
Maxime Coste
05f57ace07 CommandManager: parse command lines as utf8 instead of ascii
Fixes #1829
2018-02-04 09:21:15 +11:00
Maxime Coste
6bac767124 CommandManager: tweak naming 2017-11-04 16:02:21 +08:00
Maxime Coste
ddc307b8e9 Optimize CommandManager::execute handling of tokens
Instead of walking a list of tokens and inserting eventual new
ones in the middle, use a stack of token and push new ones on top.
2017-10-17 10:25:20 +08:00
Maxime Coste
64183b1e4c Make Token a simple aggregate 2017-09-01 17:09:34 +07:00
Maxime Coste
ab6a999431 Rename containers.hh to ranges.hh (and Container to Range) 2017-08-29 15:23:03 +07:00
Maxime Coste
eb2984807c Remove some dead code 2017-06-29 07:43:20 +01:00
Frank LENORMAND
8d24768d5d src: Add a commands debug flag
This commit allows setting the `commands` flag to the `debug` option, in
order to have the engine write on the *debug* buffer the commands that are
being executed, along with their arguments.
2017-06-17 11:27:07 +03:00
Maxime Coste
575e6fe325 Remove unneeded unknown_expand exception type 2017-06-07 19:01:26 +01:00
Maxime Coste
a0d848da8d Do not allow whitespaces as % string delimiters 2017-06-07 13:09:45 +01:00
Maxime Coste
261e0fabcc Improve readability of command docstrings by changing formatting
Fixes #1378
2017-06-04 08:37:51 +01:00
Maxime Coste
f014eb7052 Fix command parsing bug when commenting after a command
When a comment was present directly on the same line after a command,
we did not correctly see the command as terminated and would join
continue parsing the next line.
2017-05-25 08:30:49 +01:00
Maxime Coste
6a97455b3b Do not push a final spurious command separators when parsing commands
Fixes #1336
2017-05-08 11:46:03 +01:00
Maxime Coste
3a3144f3f5 Fix use of invalidated iterator in the command map on exception
The command map can get mutated by command execution, so the iterators
can get invalidated (now that we use our curstom HashMap implementation,
all iterators are potentially invalidated by insert/removal)
2017-05-07 16:25:34 +01:00
Maxime Coste
5103b15b84 Safer code for parsing commands
Fix some possible past the end of target string reads
Fixes #1310 (maybe, probably, who knows)
2017-04-19 22:04:03 +01:00
Maxime Coste
c1c40a4b56 Remove some now unneeded uses of const String& params
HashMap supports finding String from StringView.
2017-04-10 21:33:20 +01:00
Maxime Coste
e44f95820e Fixes some clang-tidy warning and add a few missing meta.hh include 2017-03-16 23:34:02 +00:00
Maxime Coste
7d9f1df73a Small code tweaks regarding flags handling 2017-03-15 18:25:59 +00:00
Maxime Coste
6373338c50 Replace uses of UnorderedMap with HashMap 2017-03-07 01:03:26 +00:00
Maxime Coste
2052b225d9 Detect too deep command call stack
Fixes #1163
2017-01-29 13:56:05 +00:00
Maxime Coste
753f3a50d1 Make StringView and unit types trivial types 2017-01-29 13:49:45 +00:00
Maxime Coste
9f0bca53c4 Small code cleanups 2017-01-08 23:26:15 +00:00
Maxime Coste
dcd8f6ef01 Apply clang-tidy modernize to the codebase 2017-01-08 22:39:01 +00:00
Maxime Coste
84c2ca1cdc Merge remote-tracking branch 'leira/empty_param_crash' 2016-12-27 22:00:32 +00:00
Leira Hua
f79018cffd Added string length check when checking switch params
Fixes #1051
2016-12-24 17:42:31 -08:00
Maxime Coste
d17bed9b80 Display the command prompt in error face when the command is not found
Fixes #1021
2016-12-23 16:23:31 +00:00
Maxime Coste
03eb128536 Ensure content of expanded strings in modelinefmt is not interpreted as markup 2016-12-07 20:07:32 +00:00
Maxime Coste
2f704eab16 Small command parsing refactoring 2016-12-07 13:26:11 +00:00
Maxime Coste
47a82b9855 Make ArrayView::subrange size arguement optional 2016-11-20 11:15:15 +00:00
Maxime Coste
5249df78d4 Do not include aliases in command completion candidates anymore
Fuzzy matching makes it redundant.
Closes #817
2016-11-14 00:29:43 +00:00
Maxime Coste
025b91baca Convert some uses of lambda to more concise std::mem_fn 2016-10-10 23:44:18 +01:00
Maxime Coste
35559b65dd Support codepoints of variable width
Add a ColumnCount type and use it in place of CharCount whenever
more appropriate, take column size of codepoints into account for
vertical movements and docstring wrapping.

Fixes #811
2016-10-01 13:45:00 +01:00
Maxime Coste
d14c39ebdd Rewrite PerArgumentCommandCompleter to use compile time dispatching
No need to store these vectors of std::functions around anymore.
2016-09-18 16:07:00 +01:00
Maxime Coste
5b7b6eebaf Regenerate shell-candidates for each completion sessions
That should allow fixing the #665 issue while still avoiding to
run a potentially long shell command on each keystroke.
2016-08-05 13:53:19 +01:00