Added dwim commands/menu-items
[emacs-capf-autosuggest.git] / capf-autosuggest.el
blob21f0544ac926ed9dcc014ee5b6f57a4a0cb0aace
1 ;;; capf-autosuggest.el --- Show first completion-at-point as an overlay -*- lexical-binding: t; -*-
3 ;; Filename: capf-autosuggest.el
4 ;; Description: Show first completion-at-point as an overlay
5 ;; Author: jakanakaevangeli <jakanakaevangeli@chiru.no>
6 ;; Created: 2021-07-13
7 ;; Version: 1.0
8 ;; URL: https://github.com/jakanakaevangeli/emacs-capf-autosuggest
10 ;; This file is not part of GNU Emacs.
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; capf-autosuggest lets you preview the most recent matching history element,
28 ;; similar to zsh-autosuggestions or fish. It works in eshell and in modes
29 ;; derived from comint-mode, for example M-x shell or M-x run-python
31 ;; Installation:
33 ;; Add the following to your Emacs init file:
35 ;; (add-to-list 'load-path "/path/to/emacs-capf-autosuggest")
36 ;; (require 'capf-autosuggest)
37 ;; (add-hook 'comint-mode-hook #'capf-autosuggest-setup-comint)
38 ;; (add-hook 'eshell-mode-hook #'capf-autosuggest-setup-eshell)
40 ;; Configuration:
42 ;; Use `capf-autosuggest-define-partial-accept-cmd' to make a command that can
43 ;; move point into an auto-suggested layer.
45 ;; Example: to make C-M-f (forward-sexp) movable into suggested text, put the
46 ;; following into you init file:
48 ;; (with-eval-after-load 'capf-autosuggest
49 ;; (capf-autosuggest-define-partial-accept-cmd
50 ;; movable-forward-sexp forward-sexp)
51 ;; (define-key capf-autosuggest-active-mode-map [remap forward-sexp]
52 ;; #'movable-forward-sexp))
54 ;; Details:
56 ;; capf-autosuggest provides a minor mode, capf-autosuggest-mode, that lets you
57 ;; preview the first completion candidate for in-buffer completion as an
58 ;; overlay. Instead of using the default hook `completion-at-point-functions',
59 ;; it uses its own hook `capf-autosuggest-capf-functions'. However, by
60 ;; default, this hook contains a function that reads the default hook, but only
61 ;; if point is at end of line, because an auto-suggested overlay can be
62 ;; annoying in the middle of a line. If you want, you can try enabling this
63 ;; minor mode in an ordinary buffer for previewing tab completion candidates at
64 ;; end of line.
66 ;; completion-at-point functions for comint and eshell history are also
67 ;; provided. Because they are less useful for tab completion and more useful
68 ;; for auto-suggestion preview, they should be added to
69 ;; `capf-autosuggest-capf-functions', which doesn't interfere with tab
70 ;; completion. The setup functions mentioned in "Installation" paragraph add
71 ;; them to this hook locally. By default, if there are no matches for history
72 ;; completion and point is at end of line, we fall back to previewing the
73 ;; default tab completion candidates, as described in the previous paragraph.
75 ;; You can customize this behaviour by customizing
76 ;; `capf-autosuggest-capf-functions'. For example, you could add
77 ;; `capf-autosuggest-orig-capf' to enable auto-suggestions of tab completion
78 ;; candidates in the middle of a line.
80 ;; Alternatives:
82 ;; There is also esh-autosuggest[1] with similar functionality. Differences:
83 ;; it optionally allows having a delay, it depends on emacs package company, it
84 ;; is implemented only for eshell.
86 ;; [1]: http://github.com/dieggsy/esh-autosuggest
88 ;;; Code:
90 (require 'ring)
91 (eval-when-compile
92 (require 'subr-x)
93 (require 'cl-lib))
95 (defvar comint-input-ring)
96 (defvar comint-accum-marker)
97 (defvar comint-use-prompt-regexp)
98 (defvar eshell-history-ring)
99 (defvar eshell-last-output-end)
100 (declare-function eshell-bol "esh-mode")
101 (declare-function comint-previous-matching-input-from-input "comint")
102 (declare-function eshell-previous-matching-input-from-input "em-hist")
104 (defgroup capf-autosuggest nil
105 "Show completion-at-point as an overlay."
106 :group 'completion
107 :prefix "capf-autosuggest-"
108 :link
109 '(url-link "https://github.com/jakanakaevangeli/emacs-capf-autosuggest"))
111 ;;; Auto-suggestion overlay
113 (defface capf-autosuggest-face '((t :inherit file-name-shadow))
114 "Face used for auto suggestions.")
116 (defvar capf-autosuggest-capf-functions '(capf-autosuggest-orig-if-at-eol-capf)
117 "`completion-at-point-functions', used by capf-autosuggest.
118 It is used instead of the standard
119 `completion-at-point-functions', but the default value contains
120 `capf-autosuggest-orig-if-at-eol-capf' which searches the
121 standard capf functions, if point is at the end of line.")
123 (defvar capf-autosuggest-all-completions-only-one nil
124 "Non-nil if only the first result of `all-completions' is of interest.
125 capf-autosuggest binds this to t around calls to
126 `all-completions'. A dynamic completion table can take this as a
127 hint to only return a list of one element for optimization.")
129 (defvar-local capf-autosuggest--overlay nil)
130 (defvar-local capf-autosuggest--str "")
131 (defvar-local capf-autosuggest--tick nil)
132 (defvar-local capf-autosuggest--region '(nil)
133 "Region of `completion-at-point'.")
135 (defun capf-autosuggest-orig-capf (&optional capf-functions)
136 "A capf that chooses from hook variable CAPF-FUNCTIONS.
137 CAPF-FUNCTIONS defaults to `completion-at-point-functions'.
138 Don't add this function to `completion-at-point-functions', as
139 this will result in an infinite loop. Useful for adding to
140 `capf-autosuggest-capf-functions', making it search the standard
141 capf functions."
142 (cdr (run-hook-wrapped (or capf-functions 'completion-at-point-functions)
143 #'completion--capf-wrapper 'all)))
145 (defun capf-autosuggest-orig-if-at-eol-capf ()
146 "`capf-autosuggest-orig-capf' if at the end of buffer.
147 Otherwise, return nil."
148 (when (eolp)
149 (capf-autosuggest-orig-capf)))
151 (defvar capf-autosuggest-active-mode)
153 (defun capf-autosuggest--post-h ()
154 "Create an auto-suggest overlay."
155 (when capf-autosuggest-active-mode
156 ;; `identity' is used to generate slightly faster byte-code
157 (pcase-let ((`(,beg . ,end) (identity capf-autosuggest--region)))
158 (unless (and (< beg (point) end)
159 (eq (buffer-modified-tick) capf-autosuggest--tick))
160 (capf-autosuggest-active-mode -1))))
162 (unless capf-autosuggest-active-mode
163 (pcase (capf-autosuggest-orig-capf 'capf-autosuggest-capf-functions)
164 (`(,beg ,end ,table . ,plist)
165 (let* ((pred (plist-get plist :predicate))
166 (string (buffer-substring-no-properties beg end))
167 ;; See `completion-emacs21-all-completions'
168 (base (car (completion-boundaries string table pred ""))))
169 (when-let*
170 ((completions
171 (let ((capf-autosuggest-all-completions-only-one t))
172 ;; Use `all-completions' rather than
173 ;; `completion-all-completions' to bypass completion styles
174 ;; and strictly match only on prefix. This makes sense here
175 ;; as we only use the string without the prefix for the
176 ;; overlay.
177 (all-completions string table pred)))
178 ;; `all-completions' may return strings that don't strictly
179 ;; match on our prefix. Ignore them.
180 ((string-prefix-p (substring string base) (car completions)))
181 (str (substring (car completions) (- end beg base)))
182 ((/= 0 (length str))))
183 (setq capf-autosuggest--region (cons beg end)
184 capf-autosuggest--str (copy-sequence str)
185 capf-autosuggest--tick (buffer-modified-tick))
186 (move-overlay capf-autosuggest--overlay end end)
187 (when (eq ?\n (aref str 0))
188 (setq str (concat " " str)))
189 (add-text-properties 0 1 (list 'cursor (length str)) str)
190 (add-face-text-property 0 (length str) 'capf-autosuggest-face t str)
191 (overlay-put capf-autosuggest--overlay 'after-string str)
192 (capf-autosuggest-active-mode)))))))
194 ;;;###autoload
195 (define-minor-mode capf-autosuggest-mode
196 "Auto-suggest first completion at point with an overlay."
197 :group 'capf-autosuggest
198 (if capf-autosuggest-mode
199 (progn
200 (setq capf-autosuggest--overlay (make-overlay (point) (point) nil t t))
201 (add-hook 'post-command-hook #'capf-autosuggest--post-h nil t)
202 (add-hook 'change-major-mode-hook
203 #'capf-autosuggest-active-mode-deactivate nil t))
204 (remove-hook 'change-major-mode-hook
205 #'capf-autosuggest-active-mode-deactivate t)
206 (remove-hook 'post-command-hook #'capf-autosuggest--post-h t)
207 (capf-autosuggest-active-mode -1)))
209 ;;; Various commands and menu-items
211 ;;;###autoload
212 (defmacro capf-autosuggest-define-partial-accept-cmd (name command)
213 "Define a command NAME.
214 It will call COMMAND interactively, allowing it to move point
215 into an auto-suggested overlay. COMMAND must not modify buffer.
216 NAME must not be called if variable
217 `capf-autosuggest-active-mode' is inactive. NAME is suitable for
218 binding in `capf-autosuggest-active-mode-map'."
219 `(defun ,name ()
220 ,(format "`%s', possibly moving point into an auto-suggested overlay."
221 command)
222 (interactive)
223 (capf-autosuggest-call-partial-accept-cmd #',command)))
225 (defun capf-autosuggest-call-partial-accept-cmd (command)
226 "Call COMMAND interactively, stepping into auto-suggested overlay.
227 Temporarily convert the overlay to buffer text and call COMMAND
228 interactively. Afterwards, the added text is deleted, but only
229 the portion after point. Additionally, if point is outside of
230 the added text, the whole text is deleted."
231 (let (beg end text)
232 (with-silent-modifications
233 (catch 'cancel-atomic-change
234 (atomic-change-group
235 (save-excursion
236 (goto-char (overlay-start capf-autosuggest--overlay))
237 (setq beg (point))
238 (insert-and-inherit capf-autosuggest--str)
239 (setq end (point)))
240 (call-interactively command)
241 (and (> (point) beg)
242 (<= (point) end)
243 (setq text (buffer-substring beg (point))))
244 (throw 'cancel-atomic-change nil))))
245 (when text
246 (if (= (point) beg)
247 (insert text)
248 (save-excursion
249 (goto-char beg)
250 (insert text))))))
252 (declare-function evil-forward-char "ext:evil-commands" nil t)
253 (declare-function evil-end-of-line "ext:evil-commands" nil t)
254 (declare-function evil-end-of-visual-line "ext:evil-commands" nil t)
255 (declare-function evil-end-of-line-or-visual-line "ext:evil-commands" nil t)
256 (declare-function evil-middle-of-visual-line "ext:evil-commands" nil t)
257 (declare-function evil-last-non-blank "ext:evil-commands" nil t)
258 (declare-function evil-forward-word-begin "ext:evil-commands" nil t)
259 (declare-function evil-forward-word-end "ext:evil-commands" nil t)
260 (declare-function evil-forward-WORD-begin "ext:evil-commands" nil t)
261 (declare-function evil-forward-WORD-end "ext:evil-commands" nil t)
263 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-forward-word forward-word)
264 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-forward-char forward-char)
265 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-forward-sexp forward-sexp)
266 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-end-of-line end-of-line)
267 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-move-end-of-line move-end-of-line)
268 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-end-of-visual-line end-of-visual-line)
269 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-forward-char evil-forward-char)
270 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-end-of-line evil-end-of-line)
271 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-end-of-visual-line evil-end-of-visual-line)
272 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-end-of-line-or-visual-line evil-end-of-line-or-visual-line)
273 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-middle-of-visual-line evil-middle-of-visual-line)
274 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-last-non-blank evil-last-non-blank)
275 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-forward-word-begin evil-forward-word-begin)
276 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-forward-word-end evil-forward-word-end)
277 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-forward-WORD-begin evil-forward-WORD-begin)
278 (capf-autosuggest-define-partial-accept-cmd capf-autosuggest-evil-forward-WORD-end evil-forward-WORD-end)
280 (defun capf-autosuggest-accept ()
281 "Accept current auto-suggestion.
282 Do not call this command if variable `capf-autosuggest-active-mode' is
283 inactive."
284 (interactive)
285 (capf-autosuggest-call-partial-accept-cmd
286 (lambda ()
287 (interactive)
288 (goto-char (overlay-start capf-autosuggest--overlay)))))
290 (defun capf-autosuggest-comint-previous-matching-input-from-input (n)
291 "Like `comint-previous-matching-input-from-input'.
292 But increase arument N by 1, if positive, but not on command
293 repetition."
294 (interactive "p")
295 (and (not (memq last-command '(comint-previous-matching-input-from-input
296 comint-next-matching-input-from-input)))
297 (> n 0)
298 (setq n (1+ n)))
299 (comint-previous-matching-input-from-input n)
300 (setq this-command #'comint-previous-matching-input-from-input))
302 (defun capf-autosuggest-eshell-previous-matching-input-from-input (n)
303 "Like `eshell-previous-matching-input-from-input'.
304 But increase arument N by 1, if positive, but not on command
305 repetition."
306 (interactive "p")
307 (and (not (memq last-command '(eshell-previous-matching-input-from-input
308 eshell-next-matching-input-from-input)))
309 (> n 0)
310 (setq n (1+ n)))
311 (eshell-previous-matching-input-from-input n)
312 (setq this-command #'eshell-previous-matching-input-from-input))
314 (defun capf-autosuggest-comint-send-input ()
315 "`capf-autosuggest-accept' and `comint-send-input'."
316 (interactive)
317 (capf-autosuggest-accept)
318 (call-interactively (or (command-remapping #'comint-send-input)
319 #'comint-send-input))
320 (setq this-command #'comint-send-input))
322 (defun capf-autosuggest-eshell-send-input ()
323 "`capf-autosuggest-accept' and `eshell-send-input'."
324 (interactive)
325 (capf-autosuggest-accept)
326 (call-interactively (or (command-remapping #'eshell-send-input)
327 #'eshell-send-input))
328 (setq this-command #'eshell-send-input))
330 (defcustom capf-autosuggest-dwim-next-line t
331 "Whether `next-line' can accept and send current suggestion.
332 If t and point is on last line, `next-line' will accept the
333 current suggestion and send input."
334 :type 'boolean)
335 (defcustom capf-autosuggest-dwim-next-prompt nil
336 "Whether next-prompt commands can send current suggestion.
337 If t and point is after the last prompt, `comint-next-prompt' and
338 `eshell-next-prompt' will accept the current suggestion and send
339 input."
340 :type 'boolean)
341 (defcustom capf-autosuggest-dwim-next-input nil
342 "Whether next-input commands can send current suggestion.
343 If t and previous command wasn't a history command
344 (next/previous-input or previous/next-matching-input-from-input),
345 `comint-next-input' and `eshell-next-input' will accept the
346 current suggestion and send input."
347 :type 'boolean)
348 (defcustom capf-autosuggest-dwim-next-matching-input-from-input nil
349 "Whether next-input commands can send current suggestion.
350 If t and previous command wasn't a history matching command
351 (previous or next-matching-input-from-input),
352 `comint-next-matching-input-from-input' and
353 `eshell-next-matching-input-from-input' will accept the current
354 suggestion and send input."
355 :type 'boolean)
357 (defvar capf-autosuggest-active-mode-map
358 (let ((map (make-sparse-keymap)))
359 (define-key map [remap forward-word] #'capf-autosuggest-forward-word)
360 (define-key map [remap forward-char] #'capf-autosuggest-forward-char)
361 (define-key map [remap forward-sexp] #'capf-autosuggest-forward-sexp)
362 (define-key map [remap end-of-line] #'capf-autosuggest-end-of-line)
363 (define-key map [remap move-end-of-line] #'capf-autosuggest-move-end-of-line)
364 (define-key map [remap end-of-visual-line] #'capf-autosuggest-end-of-visual-line)
366 (define-key map [remap evil-forward-char] #'capf-autosuggest-evil-forward-char)
367 (define-key map [remap evil-end-of-line] #'capf-autosuggest-evil-end-of-line)
368 (define-key map [remap evil-end-of-visual-line] #'capf-autosuggest-evil-end-of-visual-line)
369 (define-key map [remap evil-end-of-line-or-visual-line] #'capf-autosuggest-evil-end-of-line-or-visual-line)
370 (define-key map [remap evil-middle-of-visual-line] #'capf-autosuggest-evil-middle-of-visual-line)
371 (define-key map [remap evil-last-non-blank] #'capf-autosuggest-evil-last-non-blank)
372 (define-key map [remap evil-forward-word-begin] #'capf-autosuggest-evil-forward-word-begin)
373 (define-key map [remap evil-forward-word-end] #'capf-autosuggest-evil-forward-word-end)
374 (define-key map [remap evil-forward-WORD-begin] #'capf-autosuggest-evil-forward-WORD-begin)
375 (define-key map [remap evil-forward-WORD-end] #'capf-autosuggest-evil-forward-WORD-end)
377 (define-key map [remap eshell-previous-matching-input-from-input]
378 #'capf-autosuggest-eshell-previous-matching-input-from-input)
379 (define-key map [remap comint-previous-matching-input-from-input]
380 #'capf-autosuggest-comint-previous-matching-input-from-input)
382 (define-key map [remap next-line]
383 (list 'menu-item "" #'next-line :filter
384 (lambda (cmd)
385 (if (and capf-autosuggest-dwim-next-line
386 (looking-at-p "[^\n]*\n?\\'"))
387 (cond ((derived-mode-p 'comint-mode)
388 #'capf-autosuggest-comint-send-input)
389 ((derived-mode-p 'eshell-mode)
390 #'capf-autosuggest-eshell-send-input)
391 (t cmd))
392 cmd))))
393 (define-key map [remap comint-next-prompt]
394 (list 'menu-item "" #'comint-next-prompt :filter
395 (lambda (cmd)
396 (if (and capf-autosuggest-dwim-next-prompt
397 (comint-after-pmark-p))
398 #'capf-autosuggest-comint-send-input
399 cmd))))
400 (define-key map [remap eshell-next-prompt]
401 (list 'menu-item "" #'eshell-next-prompt :filter
402 (lambda (cmd)
403 (if (and capf-autosuggest-dwim-next-prompt
404 (>= (point) eshell-last-output-end))
405 #'capf-autosuggest-comint-send-input
406 cmd))))
407 (define-key map [remap comint-next-input]
408 (list 'menu-item "" #'comint-next-input :filter
409 (lambda (cmd)
410 (if (or (not capf-autosuggest-dwim-next-input)
411 (memq last-command
412 '(comint-next-matching-input-from-input
413 comint-previous-matching-input-from-input
414 comint-next-input comint-previous-input)))
416 #'capf-autosuggest-comint-send-input))))
417 (define-key map [remap eshell-next-input]
418 (list 'menu-item "" #'eshell-next-input :filter
419 (lambda (cmd)
420 (if (or (not capf-autosuggest-dwim-next-input)
421 (memq last-command
422 '(eshell-next-matching-input-from-input
423 eshell-previous-matching-input-from-input
424 eshell-next-input eshell-previous-input)))
426 #'capf-autosuggest-eshell-send-input))))
427 (define-key map [remap comint-next-matching-input-from-input]
428 (list 'menu-item "" #'comint-next-matching-input-from-input :filter
429 (lambda (cmd)
430 (if (or (not capf-autosuggest-dwim-next-matching-input-from-input)
431 (memq last-command
432 '(comint-next-matching-input-from-input
433 comint-previous-matching-input-from-input)))
435 #'capf-autosuggest-comint-send-input))))
436 (define-key map [remap eshell-next-matching-input-from-input]
437 (list 'menu-item "" #'eshell-next-matching-input-from-input :filter
438 (lambda (cmd)
439 (if (or (not capf-autosuggest-dwim-next-matching-input-from-input)
440 (memq last-command
441 '(eshell-previous-matching-input-from-input
442 eshell-next-matching-input-from-input)))
444 #'capf-autosuggest-eshell-send-input))))
445 map)
446 "Keymap active when an auto-suggestion is shown.")
448 (define-minor-mode capf-autosuggest-active-mode
449 "Active when auto-suggested overlay is shown."
450 :group 'capf-autosuggest
451 (unless capf-autosuggest-active-mode
452 (delete-overlay capf-autosuggest--overlay)))
454 (defun capf-autosuggest-active-mode-deactivate ()
455 "Deactivate `capf-autosuggest-active-mode'."
456 (capf-autosuggest-active-mode -1))
458 ;;;; History completion function
460 ;;;###autoload
461 (defun capf-autosuggest-comint-capf ()
462 "Completion-at-point function for comint input history.
463 Is only applicable if point is after the last prompt."
464 (let ((ring comint-input-ring)
465 (beg nil))
466 (and ring (ring-p ring) (not (ring-empty-p ring))
467 (or (and (setq beg comint-accum-marker)
468 (setq beg (marker-position beg)))
469 (and (setq beg (get-buffer-process (current-buffer)))
470 (setq beg (marker-position (process-mark beg)))))
471 (>= (point) beg)
472 (list beg (if comint-use-prompt-regexp
473 (line-end-position)
474 (field-end))
475 (capf-autosuggest--completion-table ring)
476 :exclusive 'no))))
478 ;;;###autoload
479 (defun capf-autosuggest-eshell-capf ()
480 "Completion-at-point function for eshell input history.
481 Is only applicable if point is after the last prompt."
482 (let ((ring eshell-history-ring)
483 (beg nil))
484 (and ring (ring-p ring) (not (ring-empty-p ring))
485 (setq beg eshell-last-output-end)
486 (setq beg (marker-position beg))
487 (>= (point) beg)
488 (list (save-excursion (eshell-bol) (point)) (point-max)
489 (capf-autosuggest--completion-table ring)
490 :exclusive 'no))))
492 (defun capf-autosuggest--completion-table (ring)
493 "Return a completion table to complete on RING."
494 (let (self)
495 (setq
496 self
497 (lambda (input predicate action)
498 (cond
499 ((eq action t)
500 (cl-loop
501 with only-one = capf-autosuggest-all-completions-only-one
502 with regexps = completion-regexp-list
503 for i below (ring-size ring)
504 for elem = (ring-ref ring i)
505 if (string-prefix-p input elem)
506 if (cl-loop for regex in regexps
507 always (string-match-p regex elem))
508 if (or (null predicate)
509 (funcall predicate elem))
510 if only-one
511 return (list elem)
512 else collect elem))
513 ((eq action nil)
514 (complete-with-action
515 nil (let ((capf-autosuggest-all-completions-only-one nil))
516 (funcall self input predicate t))
517 input predicate))
518 ((eq action 'lambda)
519 (and (ring-member ring input)
520 (or (null predicate)
521 (funcall predicate input))
522 (cl-loop for regex in completion-regexp-list
523 always (string-match-p regex input))))
524 (t (complete-with-action
525 action (ring-elements ring) input predicate)))))))
527 ;;;###autoload
528 (defun capf-autosuggest-setup-comint ()
529 "Setup capf-autosuggest for history suggestion in comint."
530 (capf-autosuggest-mode)
531 (add-hook 'capf-autosuggest-capf-functions #'capf-autosuggest-comint-capf nil t))
533 ;;;###autoload
534 (defun capf-autosuggest-setup-eshell ()
535 "Setup capf-autosuggest for history suggestion in eshell."
536 (capf-autosuggest-mode)
537 (add-hook 'capf-autosuggest-capf-functions #'capf-autosuggest-eshell-capf nil t))
540 (provide 'capf-autosuggest)
541 ;;; capf-autosuggest.el ends here