[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/vcomplete 6c7ea30339 73/91: Fix and cleanup Embark integra
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/vcomplete 6c7ea30339 73/91: Fix and cleanup Embark integration |
Date: |
Tue, 24 May 2022 15:59:10 -0400 (EDT) |
branch: elpa/vcomplete
commit 6c7ea30339cc8f0976626f1f7139f8709e32454d
Author: Daniel Semyonov <daniel@dsemy.com>
Commit: Daniel Semyonov <daniel@dsemy.com>
Fix and cleanup Embark integration
* vcomplete-embark.el (vcomplete-embark--eliminate-delay)
(vcomplete-embark--advise-commands): Remove as they have no effect
due to a change in the implementation of auto updating.
(vcomplete-embark--reset-auto-update)
(vcomplete-embark--inhibit-auto-update): New functions which disable
'vcomplete-auto-update' temporarily while performing an Embark action.
'vcomplete-embark--inhibit-auto-update' serves as ':around' advice for
'embark--prompt-for-action' when 'vcomplete-embark-mode' is enabled.
(vcomplete-embark-collect-candidates): Remove as it is unnecessary.
(vcomplete-embark-mode): New (auto loaded) mode which enables
Vcomplete's Embark integration.
---
NEWS | 8 +++++
vcomplete-embark.el | 93 +++++++++++++++++++++++++++++++++--------------------
vcomplete.el | 2 +-
vcomplete.texi | 10 +++++-
4 files changed, 77 insertions(+), 36 deletions(-)
diff --git a/NEWS b/NEWS
index b1c114ded0..769835c67f 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,14 @@ See the end of the file for an explanation of the versioning
scheme.
* 1.2 (in development)
+** Improve Embark integration.
+Fix Embark 'non-edit commands' not immediately exiting when
+'vcomplete-auto-update' is t.
+Add (auto loaded) 'vcomplete-embark-mode' which enables Embark
+integration.
+It is no longer required to explicitly load 'vcomplete-embark.el' to
+enable this integration.
+
** Add 'vcomplete-search-range'.
This custom variable is used to control in which frames the completion
list buffer is searched for during completion.
diff --git a/vcomplete-embark.el b/vcomplete-embark.el
index 0a19ce7a83..293e8c5a3a 100644
--- a/vcomplete-embark.el
+++ b/vcomplete-embark.el
@@ -27,7 +27,26 @@
;;; Commentary:
;; Embark integration for Vcomplete.
-;; This integration is not tested regularly, and might have issues.
+;;
+;; Usage:
+;;
+;; Enable `vcomplete-embark-mode':
+;;
+;; (vcomplete-embark-mode)
+;;
+;; For use-package users:
+;;
+;; (use-package vcomplete
+;; :config
+;; (vcomplete-mode)
+;; (vcomplete-embark-mode))
+;;
+;; When `vcomplete-embark-mode' is active:
+;; - Embark commands (like `embark-act') will operate on the
+;; highlighted completion in the completion list buffer (when
+;; available).
+;;
+;; For more information see the (Vcomplete) and (Embark) info nodes.
;;; Code:
@@ -35,25 +54,24 @@
(require 'vcomplete))
(declare-function embark-target-completion-at-point "ext:embark")
-(declare-function embark-completions-buffer-candidates "ext:embark")
-(defun vcomplete-embark--eliminate-delay (fun &rest args)
- "Call FUN with ARGS and `minibuffer-message-timeout' locally set to `0'."
- (let ((minibuffer-message-timeout 0))
- (apply fun args)))
-
-(defun vcomplete-embark--advise-commands ()
- "Advise Embark commands with `vcomplete-embark--eliminate-delay'."
- (dolist (cmd '(embark-act embark-default-action))
- (if vcomplete-mode
- (advice-add cmd :around #'vcomplete-embark--eliminate-delay)
- (advice-remove cmd #'vcomplete-embark--eliminate-delay))))
-
-(add-hook 'vcomplete-mode-hook
- #'vcomplete-embark--advise-commands)
-
-;; In case `vcomplete-mode' is enabled already.
-(vcomplete-embark--advise-commands)
+(defun vcomplete-embark--reset-auto-update ()
+ "Re-enable `vcomplete-auto-update'."
+ (setq vcomplete-auto-update t)
+ (remove-hook 'embark-post-action-hook #'vcomplete-embark--reset-auto-update))
+
+(defun vcomplete-embark--inhibit-auto-update (fun &rest args)
+ "Inhibit `vcomplete-auto-update' while performing Embark actions.
+When `vcomplete-auto-update' is nil, just call FUN with ARGS."
+ (if (not vcomplete-auto-update)
+ (apply fun args)
+ (setq vcomplete-auto-update nil)
+ ;; This hook is needed because the last part of this function will not
+ ;; run if an Embark action has been performed (marked below).
+ (add-hook 'embark-post-action-hook #'vcomplete-embark--reset-auto-update)
+ (apply fun args)
+ ;; If an action has been performed this part will not run.
+ (vcomplete-embark--reset-auto-update)))
(defun vcomplete-embark-current-completion (&optional relative)
"Call `embark-target-completion-at-point' in the `*Completions*' buffer.
@@ -62,21 +80,28 @@ relative path."
(when (and vcomplete-mode
(or (minibufferp) completion-in-region-mode))
(vcomplete-with-completions-buffer
- (embark-target-completion-at-point relative))))
-
-(defun vcomplete-embark-collect-candidates ()
- "Call `embark-completions-buffer-candidates' in the `*Completions*' buffer.
-If the completions are file names and RELATIVE is non-nil, return
-relative path."
- (when (and vcomplete-mode
- (or (minibufferp) completion-in-region-mode))
- (vcomplete-with-completions-buffer
- (embark-completions-buffer-candidates))))
-
-(add-hook 'embark-target-finders
- #'vcomplete-embark-current-completion)
-(add-hook 'embark-candidate-collectors
- #'vcomplete-embark-collect-candidates)
+ (embark-target-completion-at-point relative))))
+
+;;;###autoload
+(define-minor-mode vcomplete-embark-mode
+ "Toggle Vcomplete's Embark integration.
+
+When Vcomplete's Embark integration is enabled, Embark commands (like
+`embark-act') will operate on the highlighted completion in the
+`*Completions*' buffer."
+ :global t
+ :group 'vcomplete
+ (require 'embark)
+ (if vcomplete-embark-mode
+ (progn
+ (add-hook 'embark-target-finders
+ #'vcomplete-embark-current-completion)
+ (advice-add 'embark--prompt-for-action :around
+ #'vcomplete-embark--inhibit-auto-update))
+ (remove-hook 'embark-target-finders
+ #'vcomplete-embark-current-completion)
+ (advice-remove 'embark--prompt-for-action
+ #'vcomplete-embark--inhibit-auto-update)))
(provide 'vcomplete-embark)
diff --git a/vcomplete.el b/vcomplete.el
index 0de61ec5ac..15939a0b3d 100644
--- a/vcomplete.el
+++ b/vcomplete.el
@@ -41,7 +41,7 @@
;; :config
;; (vcomplete-mode))
;;
-;; When vcomplete-mode is active:
+;; When `vcomplete-mode' is active:
;; - The completion list buffer opens and updates automatically (see
;; `vcomplete-auto-update').
;; - The completion list buffer can be controlled through the
diff --git a/vcomplete.texi b/vcomplete.texi
index 19437ed1f0..606c3908f3 100644
--- a/vcomplete.texi
+++ b/vcomplete.texi
@@ -178,6 +178,14 @@ You may use these commands without enabling
@code{vcomplete-mode}
@xref{Completion commands} for information regarding defining new
commands.
+Vcomplete also comes with (optional) support for Embark. To enable it:
+
+@cindex vcomplete-embark-mode
+@table @asis
+@item @kbd{M-x vcomplete-embark-mode RET}
+You can also add @code{(vcomplete-embark-mode)} to your init file, instead.
+@end table
+
@node Customization
@chapter Customization
@@ -190,7 +198,7 @@ be done through the customize interface:
@defopt vcomplete-auto-update
Whether the @code{*Completions*} buffer should open and update
-automatically. Non-nil means automatically open and
+automatically. Non-nil means automatically open and
update. Otherwise, operate according to
@code{completion-auto-help}. By default, @code{t} is used. Note that
with @code{completions-detailed} (introduced in Emacs 28) enabled, the
- [nongnu] elpa/vcomplete 695b22e213 79/91: ; Indentation fix and docstring change, (continued)
- [nongnu] elpa/vcomplete 695b22e213 79/91: ; Indentation fix and docstring change, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete e139895b51 66/91: Fix reference to void variable, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 40ac892aa6 67/91: ; Consistently mark lisp variables and functions in NEWS, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 3fe8f92f16 75/91: ; Remove unnecessary '; ' from lexical binding declaration, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete c66599c7a4 84/91: ; Update copyright years, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 1106acfc5b 02/91: ; Fix various erroneous references to swsw, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete e59690bd71 58/91: * vcomplete.el (vcomplete-no-update-commands): Add 'choose-completion', ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete b4f5326ad8 57/91: ; Fix required Emacs version vcomplete-pkg.el, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete a280ce2c59 62/91: ; Bump to version 1.1, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete fdb366a898 63/91: Allow controlling where to search for the completion list buffer, ELPA Syncer, 2022/05/24
- [nongnu] elpa/vcomplete 6c7ea30339 73/91: Fix and cleanup Embark integration,
ELPA Syncer <=
- [nongnu] elpa/vcomplete acf575c8af 88/91: Remove Embark integration, ELPA Syncer, 2022/05/24