[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/completions-highlight-modifications 6db2c4a 17/18: Simplify and
From: |
Jimmy Aguilar Mena |
Subject: |
feature/completions-highlight-modifications 6db2c4a 17/18: Simplify and rely more in the post-command-hook |
Date: |
Wed, 18 Nov 2020 22:30:37 -0500 (EST) |
branch: feature/completions-highlight-modifications
commit 6db2c4a5d0cb2ab77b194a155e6f80ded1d641fe
Author: Jimmy Aguilar Mena <spacibba@aol.com>
Commit: Jimmy Aguilar Mena <spacibba@aol.com>
Simplify and rely more in the post-command-hook
* lisp/completions-highlight.el (completions-highlight-this-completion)
: Use the new function completions-highlight-select-near.
(completions-highlight-next-completion) : Removed
(completions-highlight-select-near) : New function to select and
highlight next candidate closer to point.
(completions-highlight-previous-completion) :
(completions-highlight-next-line-completion) :
(completions-highlight-previous-line-completion) : Removed as they are
not needed with the hook.
(with-minibuffer-scroll-window) : Add call to
completions-highlight-this-completion at the end.
(minibuffer-next-completion) :
(completions-highlight-previous-completion) :
(completions-highlight-next-line-completion) :
(minibuffer-previous-line-completion) : Remove reference to removed
functions.
(completions-highlight-completions-map) : Clear the bindings for the
removed functions.
(completions-highlight-setup) : Set
completions-highlight-this-completion in post-command-hook instead of
isearch-mode-end-hook.
---
lisp/completions-highlight.el | 116 ++++++++++++------------------------------
1 file changed, 32 insertions(+), 84 deletions(-)
diff --git a/lisp/completions-highlight.el b/lisp/completions-highlight.el
index d310068..e58d6f7 100644
--- a/lisp/completions-highlight.el
+++ b/lisp/completions-highlight.el
@@ -44,8 +44,6 @@
;; candidate in the arrow direction. The arrow produces the same
;; result either in the minibuffer or in *Completions* window.
-;; 4. isearch in the *Completions* buffer works as expected.
-
;; The package intents to implement such functionalities without using
;; hacks or complex functions, using the default Emacs *Completions*
;; infrastructure. The main advantage is that it is not needed to
@@ -87,59 +85,26 @@ buffer is shown and updated."
"Saves the the original value of completion-in-minibuffer-scroll-window.")
;; *Completions* side commands
-(defun completions-highlight-this-completion (&optional n)
- "Highlight the completion under point or near.
-N is set to 1 if not specified."
- (setq n (prefix-numeric-value n))
- (let ((sign (/ n (abs n))))
- (next-completion sign)
- (completions-highlight-next-completion (* -1 sign))))
-
-(defun completions-highlight-next-completion (n)
- "Move to and highlight the next item in the completion list.
-With prefix argument N, move N items (negative N means move backward).
-If completion highlight is enabled, highlights the selected candidate.
-Returns the completion string if available.
-If N is equal to zero returns the current candidate"
+(defun completions-highlight-this-completion ()
+ "Highlight the completion under point or near."
+ (next-completion -1)
+ (next-completion 1)
+ (completions-highlight-select-near))
+
+(defun completions-highlight-select-near ()
+ "Move to and highlight closer item in the completion list."
(interactive "p")
- (unless (zerop n)
- (next-completion n)
- (cond
- ((eobp) (next-completion -1))
- ((bobp) (next-completion 1))))
+ (cond
+ ((eobp) (next-completion -1))
+ ((bobp) (next-completion 1)))
(let* ((obeg (point))
(oend (next-single-property-change obeg 'mouse-face nil (point-max)))
(choice (buffer-substring-no-properties obeg oend)))
(move-overlay completions-highlight-overlay obeg oend)
- (minibuffer-completion-set-suffix choice)
-
- ;; Return the current completion
- choice))
-
-(defun completions-highlight-previous-completion (n)
- "Move to the previous N item in the completion list.
-See `completions-highlight-next-completion' for more details."
- (interactive "p")
- (completions-highlight-next-completion (- n)))
-
-(defun completions-highlight-next-line-completion (&optional arg try-vscroll)
- "Go to completion candidate in line above current.
-With prefix argument ARG, move to ARG candidate bellow current.
-TRY-VSCROLL is passed straight to `line-move'"
- (interactive "^p\np")
- (line-move arg t nil try-vscroll)
- (completions-highlight-this-completion arg))
-
-(defun completions-highlight-previous-line-completion (&optional arg
try-vscroll)
- "Go to completion candidate in line above current.
-With prefix argument ARG, move to ARG candidate above current.
-TRY-VSCROLL is passed straight to `line-move'"
- (interactive "^p\np")
- (completions-highlight-next-line-completion (- arg) try-vscroll))
-
+ (minibuffer-completion-set-suffix choice)))
;; Minibuffer side commands
(defmacro with-minibuffer-scroll-window (&rest body)
@@ -149,46 +114,40 @@ alive and active."
`(and (window-live-p minibuffer-scroll-window)
(eq t (frame-visible-p (window-frame minibuffer-scroll-window)))
(with-selected-window minibuffer-scroll-window
- ,@body)))
+ ,@body
+ (completions-highlight-this-completion))))
(defun minibuffer-next-completion (n)
- "Execute `completions-highlight-next-completion' in *Completions*.
+ "Execute `next-completion' in *Completions*.
The argument N is passed directly to
-`completions-highlight-next-completion', the command is executed
+`next-completion', the command is executed
in another window, but cursor stays in minibuffer."
(interactive "p")
(with-minibuffer-scroll-window
- (completions-highlight-next-completion n)))
-
+ (next-completion n)))
(defun minibuffer-previous-completion (n)
- "Execute `completions-highlight-previous-completion' in *Completions*.
-The argument N is passed directly to
-`completions-highlight-previous-completion', the command is
-executed in another window, but cursor stays in minibuffer."
+ "Execute `previous-completion' in *Completions*.
+The argument N is passed directly to `previous-completion', the
+command is executed in another window, but cursor stays in
+minibuffer."
(interactive "p")
(with-minibuffer-scroll-window
- (completions-highlight-previous-completion n)))
-
+ (previous-completion n)))
(defun minibuffer-next-line-completion (n)
- "Execute `completions-highlight-next-line-completion' in *Completions*.
-The argument N is passed directly to
-`completions-highlight-next-line-completion', the command is
+ "Execute `next-line' in *Completions*.
+The argument N is passed directly to `next-line', the command is
executed in another window, but cursor stays in minibuffer."
(interactive "p")
- (with-minibuffer-scroll-window
- (completions-highlight-next-line-completion n)))
-
+ (with-minibuffer-scroll-window (next-line n)))
(defun minibuffer-previous-line-completion (n)
- "Execute `completions-highlight-previous-line-completion' in *Completions*.
-The argument N is passed directly to
-`completions-highlight-previous-line-completion', the command is
-executed in another window, but cursor stays in minibuffer."
+ "Execute `previous-line' in *Completions*.
+The argument N is passed directly to `previous-line', the command
+is executed in another window, but cursor stays in minibuffer."
(interactive "p")
- (with-minibuffer-scroll-window
- (completions-highlight-previous-line-completion n)))
+ (with-minibuffer-scroll-window (previous-line n)))
;; General commands
(defun minibuffer-completion-set-suffix (choice)
@@ -231,22 +190,10 @@ suffix."
(defvar completions-highlight-completions-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map completion-list-mode-map)
- (define-key map [?\t] #'completions-highlight-next-completion)
(define-key map "\C-g" #'quit-window)
-
- (define-key map [up] #'completions-highlight-previous-line-completion)
- (define-key map "\C-p" #'completions-highlight-previous-line-completion)
- (define-key map [down] #'completions-highlight-next-line-completion)
- (define-key map "\C-n" #'completions-highlight-next-line-completion)
-
- (define-key map [right] #'completions-highlight-next-completion)
- (define-key map "\C-f" #'completions-highlight-next-completion)
- (define-key map [left] #'completions-highlight-previous-completion)
- (define-key map "\C-b" #'completions-highlight-previous-completion)
map)
"Keymap used in *Completions* while highlighting candidates.")
-
(defun completions-highlight-minibuffer-tab-through-completions ()
"Default action in `minibuffer-scroll-window' WINDOW.
This is called when *Completions* window is already visible and
@@ -284,7 +231,7 @@ It is called when showing the *Completions* buffer."
(add-hook 'pre-command-hook
#'completions-highlight-completions-pre-command-hook nil t)
- (add-hook 'isearch-mode-end-hook
+ (add-hook 'post-command-hook
#'completions-highlight-this-completion nil t)
;; Add completions-highlight-completions-map to *Completions*
@@ -294,7 +241,8 @@ It is called when showing the *Completions* buffer."
;; Autoselect candidate if enabled
(when completions-highlight-autoselect
(with-selected-window (get-buffer-window (current-buffer) 0)
- (completions-highlight-next-completion 1)))))
+ (next-completion 1)
+ (completions-highlight-select-near)))))
(add-hook 'pre-command-hook
#'completions-highlight-minibuffer-pre-command-hook nil t)
- feature/completions-highlight-modifications c6a25d8 01/18: Insert some modifications to implement completions highlighting., (continued)
- feature/completions-highlight-modifications c6a25d8 01/18: Insert some modifications to implement completions highlighting., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications f132cc3 02/18: Document the changes in the API for Completions., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications d812e76 05/18: Improve keymap handling., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 8647012 06/18: Fix recursive set-keymap-parent in completions-highlight., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 8f3e475 03/18: Add completions-highlight-mode initial implementation., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications a6e73e8 04/18: Fix initial comment in completions-highlight file., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 8a60d7d 08/18: Simplify numeric argument, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications a686211 10/18: Simplify overlay handling, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 34570e1 14/18: Improve completions-highlight description in file header., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications bfe4747 12/18: Add parent maps, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 6db2c4a 17/18: Simplify and rely more in the post-command-hook,
Jimmy Aguilar Mena <=
- feature/completions-highlight-modifications d397d2b 13/18: Add # to function bindings, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications cb02cb6 11/18: Add autoload decorator., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 9fe2441 15/18: Add custom variable completions-highlight-autoselect., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications ff46a8f 18/18: Add backtab commands., Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications 71f60b6 07/18: Fix corner case when going out of bounds, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications ac93fdb 16/18: Define completions-highlight face and group, Jimmy Aguilar Mena, 2020/11/18
- feature/completions-highlight-modifications f3ad5c1 09/18: Simplify setting keymaps., Jimmy Aguilar Mena, 2020/11/18