[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/vcomplete dce24e895d 18/91: Replaced current completion va
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/vcomplete dce24e895d 18/91: Replaced current completion variables with a function |
Date: |
Tue, 24 May 2022 15:59:06 -0400 (EDT) |
branch: elpa/vcomplete
commit dce24e895d13b1c141cb544f63d2526c88e2468b
Author: Daniel Semyonov <cmstr@dsemy.com>
Commit: Daniel Semyonov <cmstr@dsemy.com>
Replaced current completion variables with a function
* vcomplete.el (vcomplete-current-completion-string)
(vcomplete-current-completion-index): Replace with
'vcomplete-current-completion'.
(vcomplete-current-completion): New function which gets the completion
at point in the completion list buffer.
(vcomplete--highlight-completion-at-point): Reimplement using
'vcomplete-current-completion'.
(vcomplete--move-n-completions): Remove step which set
'vcomplete-current-completion-index', and remove old handling of
incorrect highlighting occurring when moving to the end of the
completion list buffer.
(vcomplete--update-in-minibuffer, vcomplete--update-in-region): Remove
step which set 'vcomplete-current-completion-index'.
(vcomplete--reset-vars): Remove steps which reset
'vcomplete-current-completion-string' and
'vcomplete-current-completion-index'.
---
vcomplete.el | 73 +++++++++++++++++++++++++---------------------------------
vcomplete.texi | 17 ++++++++------
2 files changed, 42 insertions(+), 48 deletions(-)
diff --git a/vcomplete.el b/vcomplete.el
index 174c06b1e3..9078c5d55d 100644
--- a/vcomplete.el
+++ b/vcomplete.el
@@ -106,53 +106,48 @@ While evaluating body, BUFFER and WINDOW are locally
bound to the
"The ‘*Completions*’ buffer is set to an incorrect mode"))
,@body)))
-(defvar vcomplete-current-completion-string nil
- "Currently selected completion string.")
-
-(defvar vcomplete-current-completion-index 0
- "Index (in the ‘*Completions*’ buffer) of the current completion.")
+(defun vcomplete-current-completion (pos)
+ "Get the completion candidate at POS.
+The completion candidate is returned as a list of the form:
+ (COMPLETION-STRING . (BEGINNING . END))
+If no completion is found, return nil."
+ (unless (derived-mode-p 'completion-list-mode)
+ (error "Not in a valid completion list buffer"))
+ ;; Modified from code in ‘choose-completion’.
+ (let (beg end noop)
+ (cond
+ ((and (not (eobp)) (get-text-property pos 'mouse-face))
+ (setq end pos beg (1+ pos)))
+ ((and (not (bobp))
+ (get-text-property (1- pos) 'mouse-face))
+ (setq end (1- pos) beg pos))
+ (t (setq noop t)))
+ (unless noop
+ (setq beg (previous-single-property-change beg 'mouse-face))
+ (setq end (or (next-single-property-change end 'mouse-face)
+ (point-max)))
+ `(,(buffer-substring-no-properties beg end) . (,beg . ,end)))))
(defvar vcomplete--last-completion-overlay nil
"Last overlay created in the ‘*Completions*’ buffer.")
(defun vcomplete--highlight-completion-at-point ()
- "Highlight the completion at point in the ‘*Completions*’ buffer.
-The string of the current completion is saved in
-‘vcomplete-current-completion-string’."
+ "Highlight the completion at point in the ‘*Completions*’ buffer."
(while-no-input
(redisplay)
- (if (derived-mode-p 'completion-list-mode)
- ;; Modified from code in ‘choose-completion’.
- (let (beg end noop hl)
- (cond
- ((and (not (eobp)) (get-text-property (point) 'mouse-face))
- (setq end (point) beg (1+ (point))))
- ((and (not (bobp))
- (get-text-property (1- (point)) 'mouse-face))
- (setq end (1- (point)) beg (point)))
- (t (setq noop t)))
- (unless noop
- (setq beg (previous-single-property-change beg 'mouse-face))
- (setq end (or (next-single-property-change end 'mouse-face)
- (point-max)))
- (setq vcomplete-current-completion-string
- (buffer-substring-no-properties beg end))
- (overlay-put
- (setq hl (make-overlay beg end)) 'face 'highlight))
- (when vcomplete--last-completion-overlay
- (delete-overlay vcomplete--last-completion-overlay))
- (setq vcomplete--last-completion-overlay hl))
- (error "Not in a valid completion list buffer"))))
+ (let ((cur (vcomplete-current-completion (point))))
+ (when vcomplete--last-completion-overlay
+ (delete-overlay vcomplete--last-completion-overlay))
+ (when-let ((pos (cdr cur)))
+ (overlay-put
+ (setq vcomplete--last-completion-overlay
+ (make-overlay (car pos) (cdr pos)))
+ 'face 'highlight)))))
(defun vcomplete--move-n-completions (n)
- "Move N completions in the ‘*Completions*’ buffer.
-The index of the current completion is saved in
-‘vcomplete-current-completion-index’."
+ "Move N completions in the ‘*Completions*’ buffer."
(vcomplete-with-completions-buffer
(next-completion n)
- (setq vcomplete-current-completion-index
- (+ n vcomplete-current-completion-index))
- (when (= (point) (point-max)) (next-completion -1))
(set-window-point window (point))
(vcomplete--highlight-completion-at-point)))
@@ -192,7 +187,6 @@ With prefix argument N, move N items (negative N means move
forward)."
(while-no-input
(redisplay)
(unless (eq this-command 'vcomplete--no-update)
- (setq vcomplete-current-completion-index 0)
(minibuffer-completion-help))))
(defun vcomplete--update-in-region ()
@@ -202,14 +196,11 @@ With prefix argument N, move N items (negative N means
move forward)."
(unless (or (eq this-command 'vcomplete--no-update)
(eq this-command 'completion-at-point)
(null completion-in-region-mode))
- (setq vcomplete-current-completion-index 0)
(completion-help-at-point))))
(defun vcomplete--reset-vars ()
"Reset variables used by Vcomplete to their default values."
- (setq vcomplete-current-completion-string nil
- vcomplete-current-completion-index 0
- vcomplete--last-completion-overlay nil)
+ (setq vcomplete--last-completion-overlay nil)
(remove-hook 'post-command-hook #'vcomplete--update-in-region t)
(remove-hook 'post-command-hook #'vcomplete--update-in-minibuffer t))
diff --git a/vcomplete.texi b/vcomplete.texi
index 103ed4da86..fe3d8eb6be 100644
--- a/vcomplete.texi
+++ b/vcomplete.texi
@@ -211,13 +211,16 @@ Key map which holds key bindings to completion commands.
This key map
should be available whenever completion is initiated.
@end defvar
-@defvar vcomplete-current-completion-string
-String corresponding to the currently highlighted completion.
-@end defvar
-
-@defvar vcomplete-current-completion-index
-Index corresponding to the currently highlighted completion.
-@end defvar
+@defun vcomplete-current-completion pos
+Get the completion candidate at POS.
+The completion candidate is returned as a list of the form:
+@table @asis
+(COMPLETION-STRING . (BEGINNING . END))
+@end table
+If no completion is found, this function returns nil. Note that this
+function throws an error when the major mode of the buffer from which
+it is called isn't derived from @code{completion-list-mode}.
+@end defun
@defmac vcomplete-with-completions-buffer body...
Evaluate BODY with the @code{*Completions*} buffer temporarily
- [nongnu] elpa/vcomplete 3c00d732a2 51/91: Remove 'vcomplete--reset-vars', (continued)
- [nongnu] elpa/vcomplete 3c00d732a2 51/91: Remove 'vcomplete--reset-vars', ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 62428759ac 47/91: ; Change required Emacs version according to package-lint, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 9aa2d01fb9 52/91: ; Improvements to the manual, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete aa4bdbf080 11/91: * vcomplete.el (vcomplete-mode): Ensure variables are reset, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 556a6c2cff 08/91: ; Document recent changes in the NEWS file, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 8a921cf088 48/91: ; Optimize require's in vcomplete-embark.el, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete cbdde2fc09 61/91: Define a face for highlighting completions, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 0bbc9b391b 69/91: ; Improve docstrings and comments, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 18164dd260 71/91: ; Another small change to 'vcomplete-mode's docstring, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 6a3b02df46 76/91: * vcomplete.el (vcomplete-with-completions-buffer): Allow debugging body, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete dce24e895d 18/91: Replaced current completion variables with a function,
ELPA Syncer <=
- [nongnu] elpa/vcomplete 36ae2920e4 17/91: * vcomplete.el (vcomplete-kill-buffer): Remove to simplify the package, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 12def7b143 19/91: Highlight the completion at point in the completion list buffer, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete a7eb3b9365 25/91: ; Fixes and improvements to the Info node, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 6bc410d948 27/91: Handle cases where 'vcomplete-mode' starts before loading Embark, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete e37470eb13 05/91: ; Fix indentation, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 39f0aead10 13/91: Fix 'vcomplete--update-in-region' added to 'post-command-hook' globally, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete b6fd11b7c4 31/91: ; Update mail address, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 369a9fb9c4 03/91: ; Ignore Emacs' backup files, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete b1fa61dffd 16/91: Change the way the current completion is highlighted, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 14429ac79d 20/91: Exits 'completion-in-region-mode' when completions aren't visible, ELPA Syncer, 2022/05/24