branch: externals/mct commit d5a0c81915b8640a2f7c3c90e0064002c9c03581 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Reorganise the code of the minor mode --- mct.el | 86 ++++++++++++++++++++++++++++-------------------------------------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/mct.el b/mct.el index cd76d24697..3202a19bd3 100644 --- a/mct.el +++ b/mct.el @@ -1066,22 +1066,29 @@ Do this under any of the following conditions: (mct-focus-minibuffer) (mct--show-completions))) -(defun mct--setup-persistent-completions () - "Set up `mct-persist-completions-buffer'." - (let ((commands '(choose-completion minibuffer-complete minibuffer-force-complete))) - (if (bound-and-true-p mct-mode) - (dolist (fn commands) - (advice-add fn :after #'mct-persist-completions-buffer)) - (dolist (fn commands) - (advice-remove fn #'mct-persist-completions-buffer))))) - ;;;;; mct-mode declaration -(declare-function minibuf-eldef-setup-minibuffer "minibuf-eldef") +;; Adapted from Omar Antolín Camarena's live-completions library: +;; <https://github.com/oantolin/live-completions>. +(defun mct--honor-inhibit-message (&rest app) + "Honor variable `inhibit-message' while applying APP." + (unless (and (mct--minibuffer-p) inhibit-message) + (apply app))) + +;; Thanks to Omar Antolín Camarena for providing the messageless and +;; stealthily. Source: <https://github.com/oantolin/emacs-config>. +(defun mct--messageless (&rest app) + "Set `minibuffer-message-timeout' to 0 while applying APP." + (if (mct--minibuffer-p) + (let ((minibuffer-message-timeout 0)) + (apply app)) + (apply app))) (defvar mct-last-completions-sort-value (bound-and-true-p completions-sort) "Last value of `completions-sort'.") +(declare-function minibuf-eldef-setup-minibuffer "minibuf-eldef") + ;;;###autoload (define-minor-mode mct-mode "Set up opinionated default completion UI." @@ -1098,7 +1105,16 @@ Do this under any of the following conditions: (advice-add #'completing-read-multiple :filter-args #'mct--crm-indicator)) (advice-add #'minibuffer-completion-help :around #'mct--minibuffer-completion-help-advice) (advice-add #'minibuf-eldef-setup-minibuffer :around #'mct--stealthily) - (advice-add #'completion--insert-strings :after #'mct--completion--insert-strings)) + (advice-add #'completion--insert-strings :after #'mct--completion--insert-strings) + (dolist (fn '(choose-completion minibuffer-complete minibuffer-force-complete)) + (advice-add fn :after #'mct-persist-completions-buffer)) + (dolist (fn '(exit-minibuffer + choose-completion + minibuffer-force-complete + minibuffer-complete-and-exit + minibuffer-force-complete-and-exit)) + (advice-add fn :around #'mct--messageless)) + (advice-add #'minibuffer-message :around #'mct--honor-inhibit-message)) (setq completions-sort mct-last-completions-sort-value) (remove-hook 'completion-list-mode-hook #'mct--setup-completion-list) (remove-hook 'minibuffer-setup-hook #'mct--setup-passlist) @@ -1107,44 +1123,9 @@ Do this under any of the following conditions: (advice-remove #'completing-read-multiple #'mct--crm-indicator) (advice-remove #'minibuffer-completion-help #'mct--minibuffer-completion-help-advice) (advice-remove #'minibuf-eldef-setup-minibuffer #'mct--stealthily) - (advice-remove #'completion--insert-strings #'mct--completion--insert-strings)) - (mct--setup-persistent-completions) - (mct--setup-message-advices)) - -(define-obsolete-function-alias - 'mct-minibuffer-mode - 'mct-mode - "1.0.0") - -(make-obsolete 'mct-region-mode nil "1.0.0") - -;; Adapted from Omar Antolín Camarena's live-completions library: -;; <https://github.com/oantolin/live-completions>. -(defun mct--honor-inhibit-message (&rest app) - "Honor variable `inhibit-message' while applying APP." - (unless (and (mct--minibuffer-p) inhibit-message) - (apply app))) - -;; Thanks to Omar Antolín Camarena for providing the messageless and -;; stealthily. Source: <https://github.com/oantolin/emacs-config>. -(defun mct--messageless (&rest app) - "Set `minibuffer-message-timeout' to 0 while applying APP." - (if (mct--minibuffer-p) - (let ((minibuffer-message-timeout 0)) - (apply app)) - (apply app))) - -(defun mct--setup-message-advices () - "Silence the minibuffer and the Completions." - (if mct-mode - (progn - (dolist (fn '(exit-minibuffer - choose-completion - minibuffer-force-complete - minibuffer-complete-and-exit - minibuffer-force-complete-and-exit)) - (advice-add fn :around #'mct--messageless)) - (advice-add #'minibuffer-message :around #'mct--honor-inhibit-message)) + (advice-remove #'completion--insert-strings #'mct--completion--insert-strings) + (dolist (fn '(choose-completion minibuffer-complete minibuffer-force-complete)) + (advice-remove fn #'mct-persist-completions-buffer)) (dolist (fn '(exit-minibuffer choose-completion minibuffer-force-complete @@ -1153,5 +1134,12 @@ Do this under any of the following conditions: (advice-remove fn #'mct--messageless)) (advice-remove #'minibuffer-message #'mct--honor-inhibit-message))) +(define-obsolete-function-alias + 'mct-minibuffer-mode + 'mct-mode + "1.0.0") + +(make-obsolete 'mct-region-mode nil "1.0.0") + (provide 'mct) ;;; mct.el ends here