[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/capf-autosuggest 96394ca 48/63: Simplify accept and sen
From: |
ELPA Syncer |
Subject: |
[elpa] externals/capf-autosuggest 96394ca 48/63: Simplify accept and send menu-items |
Date: |
Wed, 27 Oct 2021 14:58:02 -0400 (EDT) |
branch: externals/capf-autosuggest
commit 96394ca05d2bbc11d08ffad4c471c4dd88671165
Author: jakanakaevangeli <jakanakaevangeli@chiru.no>
Commit: jakanakaevangeli <jakanakaevangeli@chiru.no>
Simplify accept and send menu-items
---
capf-autosuggest.el | 129 ++++++++++++++++++++++------------------------------
1 file changed, 55 insertions(+), 74 deletions(-)
diff --git a/capf-autosuggest.el b/capf-autosuggest.el
index 4926119..4c3917e 100644
--- a/capf-autosuggest.el
+++ b/capf-autosuggest.el
@@ -344,30 +344,6 @@ in order to skip the history element already shown by the
overlay."
(eshell-previous-matching-input-from-input n)
(setq this-command #'eshell-previous-matching-input-from-input))
-(defun capf-autosuggest-comint-send-input ()
- "`capf-autosuggest-accept' and `comint-send-input'."
- (interactive)
- (capf-autosuggest-accept)
- (call-interactively (or (command-remapping #'comint-send-input)
- #'comint-send-input))
- (setq this-command #'comint-send-input))
-
-(defun capf-autosuggest-eshell-send-input ()
- "`capf-autosuggest-accept' and `eshell-send-input'."
- (interactive)
- (capf-autosuggest-accept)
- (call-interactively (or (command-remapping #'eshell-send-input)
- #'eshell-send-input))
- (setq this-command #'eshell-send-input))
-
-(defun capf-autosuggest-minibuffer-send-input ()
- "`capf-autosuggest-accept' and `exit-minibuffer'."
- (interactive)
- (capf-autosuggest-accept)
- (call-interactively (or (command-remapping #'exit-minibuffer)
- #'exit-minibuffer))
- (setq this-command #'exit-minibuffer))
-
(defcustom capf-autosuggest-dwim-next-line t
"Whether `next-line' can accept and send current suggestion.
If t and point is on last line, `next-line' will accept the
@@ -395,6 +371,17 @@ If t and previous command wasn't a history matching command
suggestion and send input."
:type 'boolean)
+(defun capf-autosuggest--accept-and-remapping (cmd)
+ "Return a command that will accept input and run CMD."
+ ;; Avoid infinite recursion when searching for the command remapping
+ (let ((capf-autosuggest-active-mode nil))
+ (setq cmd (or (command-remapping cmd) cmd)))
+ (lambda ()
+ (interactive)
+ (capf-autosuggest-accept)
+ (setq this-command cmd)
+ (call-interactively cmd)))
+
(defvar capf-autosuggest-active-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [remap forward-word] #'capf-autosuggest-forward-word)
@@ -421,68 +408,62 @@ suggestion and send input."
#'capf-autosuggest-comint-previous-matching-input-from-input)
(define-key map [remap next-line]
- (list 'menu-item "" #'next-line :filter
- (lambda (cmd)
- (if (and capf-autosuggest-dwim-next-line
- (looking-at-p "[^\n]*\n?\\'"))
- (cond
- ((derived-mode-p 'comint-mode)
#'capf-autosuggest-comint-send-input)
- ((derived-mode-p 'eshell-mode)
#'capf-autosuggest-eshell-send-input)
- ((minibufferp) #'capf-autosuggest-minibuffer-send-input)
- (t cmd))
- cmd))))
+ (list 'menu-item "" nil :filter
+ (lambda (_cmd)
+ (and capf-autosuggest-dwim-next-line
+ (looking-at-p "[^\n]*\n?\\'"))
+ (when-let*
+ ((cmd (cond
+ ((derived-mode-p 'comint-mode) #'comint-send-input)
+ ((derived-mode-p 'eshell-mode) #'eshell-send-input)
+ ((minibufferp) #'exit-minibuffer))))
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap comint-next-prompt]
- (list 'menu-item "" #'comint-next-prompt :filter
+ (list 'menu-item "" #'comint-send-input :filter
(lambda (cmd)
- (if (and capf-autosuggest-dwim-next-prompt
- (comint-after-pmark-p))
- #'capf-autosuggest-comint-send-input
- cmd))))
+ (and capf-autosuggest-dwim-next-prompt
+ (comint-after-pmark-p)
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap eshell-next-prompt]
- (list 'menu-item "" #'eshell-next-prompt :filter
+ (list 'menu-item "" #'eshell-send-input :filter
(lambda (cmd)
- (if (and capf-autosuggest-dwim-next-prompt
- (>= (point) eshell-last-output-end))
- #'capf-autosuggest-eshell-send-input
- cmd))))
+ (and capf-autosuggest-dwim-next-prompt
+ (>= (point) eshell-last-output-end)
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap comint-next-input]
- (list 'menu-item "" #'comint-next-input :filter
+ (list 'menu-item "" #'comint-send-input :filter
(lambda (cmd)
- (if (or (not capf-autosuggest-dwim-next-input)
- (memq last-command
- '(comint-next-matching-input-from-input
- comint-previous-matching-input-from-input
- comint-next-input comint-previous-input)))
- cmd
- #'capf-autosuggest-comint-send-input))))
+ (and capf-autosuggest-dwim-next-input
+ (not (memq last-command
+ '(comint-next-matching-input-from-input
+ comint-previous-matching-input-from-input
+ comint-next-input comint-previous-input)))
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap eshell-next-input]
- (list 'menu-item "" #'eshell-next-input :filter
+ (list 'menu-item "" #'eshell-send-input :filter
(lambda (cmd)
- (if (or (not capf-autosuggest-dwim-next-input)
- (memq last-command
- '(eshell-next-matching-input-from-input
- eshell-previous-matching-input-from-input
- eshell-next-input eshell-previous-input)))
- cmd
- #'capf-autosuggest-eshell-send-input))))
+ (and capf-autosuggest-dwim-next-input
+ (not (memq last-command
+ '(eshell-next-matching-input-from-input
+ eshell-previous-matching-input-from-input
+ eshell-next-input eshell-previous-input)))
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap comint-next-matching-input-from-input]
- (list 'menu-item "" #'comint-next-matching-input-from-input :filter
+ (list 'menu-item "" #'comint-send-input :filter
(lambda (cmd)
- (if (or (not
capf-autosuggest-dwim-next-matching-input-from-input)
- (memq last-command
- '(comint-next-matching-input-from-input
- comint-previous-matching-input-from-input)))
- cmd
- #'capf-autosuggest-comint-send-input))))
+ (and capf-autosuggest-dwim-next-matching-input-from-input
+ (not (memq last-command
+ '(comint-next-matching-input-from-input
+ comint-previous-matching-input-from-input)))
+ (capf-autosuggest--accept-and-remapping cmd)))))
(define-key map [remap eshell-next-matching-input-from-input]
- (list 'menu-item "" #'eshell-next-matching-input-from-input :filter
+ (list 'menu-item "" #'eshell-send-input :filter
(lambda (cmd)
- (if (or (not
capf-autosuggest-dwim-next-matching-input-from-input)
- (memq last-command
- '(eshell-previous-matching-input-from-input
- eshell-next-matching-input-from-input)))
- cmd
- #'capf-autosuggest-eshell-send-input))))
+ (and capf-autosuggest-dwim-next-matching-input-from-input
+ (not (memq last-command
+ '(eshell-previous-matching-input-from-input
+ eshell-next-matching-input-from-input)))
+ (capf-autosuggest--accept-and-remapping cmd)))))
map)
"Keymap active when an auto-suggestion is shown.")
- [elpa] externals/capf-autosuggest 82c6851 25/63: Merge into one file, (continued)
- [elpa] externals/capf-autosuggest 82c6851 25/63: Merge into one file, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest bdc26ec 31/63: Typo, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 07cb937 32/63: Added dwim commands/menu-items, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest d5e1ce2 30/63: Rearrange, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest cf91a30 37/63: Added experimental support for minibuffer history, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest d72b37a 35/63: Added readme, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest f137fcb 39/63: Fix previous-matching-input if point isn't touching overlay, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 8f5d5fa 49/63: Fix last change, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 1333fb9 41/63: Override face text property, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 25ddce8 45/63: Fix compiler warning, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 96394ca 48/63: Simplify accept and send menu-items,
ELPA Syncer <=
- [elpa] externals/capf-autosuggest 6e702a7 47/63: Fix programming typo, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 54e9d1f 42/63: Fix cursor display issues if overlay text ends with a newline, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 4b2fbee 62/63: Release version 0.1, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest d8433bc 51/63: Suggest autoload instead of require, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest eb8bd98 52/63: Use while-no-input, make slow capfs slightly more bearable, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 39c9609 55/63: Eliminate the need for setup functions, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 2821a6a 63/63: Stylistic and checdoc documentation improvements, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 025afdf 53/63: Prevent capf functions from moving point, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 29d8651 56/63: Allow enabling capf-autosuggest-mode twice, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest e393440 57/63: Don't make doc strings wider than 80 characters, ELPA Syncer, 2021/10/27