Commit graph

49 commits

Author SHA1 Message Date
Eric Freese
f90d040784 cleanup: Use more idiomatic method of checking if var is set
We are already using this method in other places.

For example: `ZSH_AUTOSUGGEST_USE_ASYNC`
2020-01-25 07:46:20 -07:00
Eric Freese
6ec95379fa Call original widget before moving cursor when accepting suggestion
The check on length of `$POSTDISPLAY` is in support of the test for
`vi-delete` on the last char of the buffer with `dl`.

Fixes issue #482.
2019-12-15 08:33:20 -07:00
Eric Freese
54d7a9a84c cleanup: Switch to guard clause in accept widget handler 2019-12-15 07:01:39 -07:00
Eric Freese
5217ed5269 cleanup: Switch to arithmetic comparison 2019-12-15 07:01:39 -07:00
Eric Freese
ef657cb38c cleanup: Combine two arithmetic conditionals 2019-12-15 07:01:39 -07:00
Eric Freese
78e4379711 Fix moving cursor to end of buffer when suggestion accepted
$max_cursor_pos in this case was not the correct value to use. It was
calculated based on the old length of the $BUFFER. After the suggestion
is accepted, we need to recalculate the new max cursor length and use it
to set the $CURSOR.

Fixes issue #452. Follow-up to issue #302 (PR #450).
2019-06-23 12:37:08 -06:00
Eric Freese
676aebdf44 Fix deleting last character in vi mode (#302)
Typing `d` and then `l` runs `vi-delete` and then `vi-forward-char`.  However,
by default, `vi-forward-char` is configured to accept the suggestion. So in
that case, the suggestion was being accepted and the cursor set to the end of
the buffer before the deletion was run.

The reason the user doesn't see the suggestion accepted is that `vi-delete`
doesn't finish until the movement widget is run, so we're already inside of a
`modify` when `accept` is called. `modify` unsets `POSTDISPLAY` before calling
the original widget so when we get to the accept function, `POSTDISPLAY` is
empty and thus accepting the suggestion is a no-op.

The fix is to make sure we reset the cursor to the correct place before running
the original widget.

We skip the test for versions of zsh below 5.0.8 since there was a bug in
earlier versions where deleting the last char did not work.

See http://www.zsh.org/mla/workers/2014/msg01316.html
2019-06-22 16:34:42 -06:00
Eric Freese
474c577f3c Allow setting max size to empty string (GitHub #422)
Some people have gotten used to setting ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE
to an empty string rather than leaving it unset. This lets them continue
to do that without getting any warnings (e.g. "bad math expression:
operand expected at end of string").
2019-05-27 14:18:21 -06:00
Eric Freese
db290c518b cleanup: Leave max size config unset by default to match other options 2019-04-10 11:43:20 -06:00
Eric Freese
d8ba53678e cleanup: Use + param expansion flag in arithmetic context 2019-04-10 11:42:25 -06:00
Eric Freese
e405afab29 Refactor async mode to no longer use zpty
See technique used in `fast-syntax-highlighting`:
- ca2e18bbc9
- http://www.zsh.org/mla/users/2018/msg00424.html

Also see http://www.zsh.org/mla/users/2018/msg00432.html

In async response handler:
- We only want to read data in case of POLLIN or POLLHUP. Not POLLNVAL
  or select error.
- We always want to remove the handler, so it doesn't get called in an
  infinite loop when error is nval or err.

There is an upstream bug that prevents ctrl-c from resetting the prompt
immediately after a suggestion has been fetched asynchronously. A patch
has been submitted, but a workaround for now is to add `command true`
after the exec.

See https://github.com/zsh-users/zsh-autosuggestions/issues/364
2019-04-09 14:45:22 -06:00
Eric Freese
50579b3371 Move widget definitions inside anonymous function 2018-12-21 23:20:08 -07:00
dana
aee1b10db6 Avoid warn_create_global warnings 2018-12-19 13:38:06 -06:00
Eric Freese
e937e89267 Respect user's set options when running original widget
Fixes GitHub #379
2018-12-16 21:13:02 -07:00
Eric Freese
41657e3565 Revert async process substitution & completion strategy
They're not quite ready. Keep them on a feature branch for now.
2018-12-16 20:49:06 -07:00
Eric Freese
681ffc7b28 Reset opts in some functions affected by GLOB_SUBST
Should fix GitHub #334
2018-07-13 22:16:53 -06:00
Eric Freese
d7171232c3 Merge branch 'develop' into features/completion-suggestions 2018-06-11 02:34:24 -06:00
Eric Freese
9cb0101512 Refactor async mode to no longer use zpty
See technique used in `fast-syntax-highlighting`:
- ca2e18bbc9
- http://www.zsh.org/mla/users/2018/msg00424.html
2018-06-11 02:12:47 -06:00
Eric Freese
bcbdad83e9 Support fallback strategies by setting array in config 2018-06-06 22:03:56 -06:00
Eric Freese
393f7b8bb9 Fix vi-mode partial-accept
Issue #188. PR #324.

Thanks to @toadjaune and @IngoHeimbach.
2018-05-15 11:44:42 -06:00
Eric Freese
42f5a06f7f Need to reset the POSTDISPLAY if exiting early
Specific case where this matters is following:

Be in vi insert mode with some text in the buffer and the cursor at the
end of the buffer. Press `esc` to trigger `vi-cmd-mode widget`, then
before the cursor moves (KEYTIMEOUT), press `h` to trigger
`vi-backward-char` widget. When `vi-cmd-mode` original widget exits,
KEYS_QUEUED_COUNT will be non-zero and the suggestion will be lost.
2018-05-15 11:44:42 -06:00
Kaleb Elwert
940e10a691 Fix conditionals to use [[ and (( rather than [
This fixes a small issue in src/widgets.zsh which makes it so if you
alias [ to g[ (as is done in prezto if the gnu-utility module is loaded)
autosuggestions would fail.

The documentation for GNU test mentions that -o and -a should be avoided
if possible because it's not very clear. Also, with zsh and [[ -o
actually tests if an option is set, which makes this option even more
confusing.
2017-11-27 08:31:41 -07:00
Eric Freese
9f1f322979 Update comment about KEYS_QUEUED_COUNT support
Now that patch has released
2017-09-27 15:04:42 -06:00
Eric Freese
a2f0ffb122 Enabling suggestions should not fetch a suggestion if buffer is empty 2017-03-05 12:53:13 -05:00
Eric Freese
7d4a1d9a4a Add enable/disable/toggle widgets to disable suggestion functionality
[GitHub #219]

Intended to be helpful for folks using bracketed-paste-magic and other
widgets that use `zle -U`.
2017-03-03 18:43:17 -05:00
Eric Freese
e1959d0f61 Put in a general fix for #219 - Handling input from zle -U
Depends on patch to ZSH from workers/40702:

  http://www.zsh.org/mla/workers/2017/msg00414.html
2017-03-03 18:43:17 -05:00
Eric Freese
23ef16c297 Do not show suggestions if the buffer is empty 2017-02-17 18:26:34 -07:00
Eric Freese
ed8056c5e8 Lots of async changes 2017-02-16 19:19:30 -07:00
Eric Freese
2c465a932a Rename async pty name config var 2017-01-29 10:39:07 -07:00
Eric Freese
e3eb286ea2 Lots of little async cleanups 2017-01-27 15:18:26 -07:00
Eric Freese
54e1eee924 Optimize case where manually typing in a suggestion 2017-01-25 00:00:13 -07:00
Eric Freese
ab2742537f Quote the suggestion to support sh_split_word option 2017-01-24 22:27:47 -07:00
Eric Freese
ab8f295225 First pass at async functionality 2017-01-24 19:45:11 -07:00
Eric Freese
b377c39d0e Only fetch a new suggestion if buffer has changed 2016-07-31 20:10:22 -06:00
Eric Freese
a44aa59321 Remove unnecessary reset of POSTDISPLAy 2016-07-31 20:09:26 -06:00
Lorenzo Bolla
2450c95d8a Rename and document new config var 2016-07-18 10:55:19 +01:00
Lorenzo Bolla
7b81eb79b8 Disable autosuggest if buffer is too large
Make buffer max size configurable, defaulted to infinity
2016-07-18 08:56:00 +01:00
Eric Freese
e87bc74654 Fix 118: Clear suggestion before original widget to fix completions
See PR #149
2016-04-25 14:42:09 -06:00
Eric Freese
1d4f7e157e Keep track of return value from original widget (#135) 2016-04-06 17:13:04 -06:00
Eric Freese
15c5db898f Fix #137 2016-03-14 21:41:14 -06:00
Eric Freese
a314a01a6a Fix various bugs found while testing 2016-03-14 16:51:27 -06:00
Eric Freese
8c3fdea75d Call original accept-line widget when executing suggestion 2016-03-01 13:18:46 -07:00
Kordan Ou
aa597eea6d Add an autosuggest widget: autosuggest-execute. 2016-03-01 13:18:46 -07:00
Eric Freese
1b98af5b33 Fix suggestions when sh_split_words option is enabled 2016-02-16 07:57:44 -07:00
Eric Freese
5e419da326 Remove list of modify widgets and make 'modify' the default behavior. 2016-02-14 08:54:34 -07:00
Eric Freese
ebcfc46b72 Comment formatting 2016-02-14 00:29:43 -07:00
Eric Freese
51b39e210e Bound widgets now handle arguments correctly 2016-02-13 23:46:34 -07:00
Eric Freese
f154d25fb3 Fix typo when setting up autosuggest-clear widget. 2016-02-07 08:58:09 -07:00
Eric Freese
775dd20706 Rewrite 2016-02-06 21:05:02 -07:00