emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/mct 6a1835cf00 48/64: Remove mct--region-buf


From: ELPA Syncer
Subject: [elpa] externals/mct 6a1835cf00 48/64: Remove mct--region-buf
Date: Thu, 30 Dec 2021 23:58:00 -0500 (EST)

branch: externals/mct
commit 6a1835cf006f13be05484f88fd7f6b685d851411
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Remove mct--region-buf
    
    We do not have to store this buffer since completion-reference-buffer 
exists.
    completion-in-region-mode is automatically left as soon as we leave the 
original
    buffer. This happens in the completion-in-region--postch hook function.
    
    Unfortunately this makes it hard to implement a command bound to TAB, which
    inserts the current candidate and proceeds with the completion in the buffer
    (mct-region-choose-completion-no-exit). It would be nice to have this for 
file
    path completion. There are these possibilities to achieve this goal:
    
    1) Remove the completion-in-region--postch from the post-command-hook list.
    Instead use our own hook which preserves the completion-in-region-mode. This
    approach is probably not such a good idea, since by definition of the
    completion-in-region-mode, the mode should be left as soon as we leave the
    buffer.
    
    2) Save the entire completion-in-region--data just before entering the
    *Completions* buffer. Use the saved data to restore the completion-in-region
    after mct-region-choose-completion-no-exit, such
    
    3) Try to restart the completion after 
mct-region-choose-completion-no-exit, by
    calling completion-at-point again or the appropriate completion-in-region
    command. I don't think it is easy to find a way which works in general.
    
    I would try to implement option 2.
---
 mct.el | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/mct.el b/mct.el
index 08b43b93aa..01c96af89f 100644
--- a/mct.el
+++ b/mct.el
@@ -304,7 +304,7 @@ Meant to be added to `after-change-functions'."
 ;; need to review this.
 (defun mct--region-p ()
   "Return non-nil if Mct is completing in region."
-  (and (bound-and-true-p mct-region-mode) mct--region-buf))
+  (and (bound-and-true-p mct-region-mode) (mct--region-current-buffer)))
 
 (defun mct--display-completion-list-advice (&rest app)
   "Prepare advice around `display-completion-list'.
@@ -1111,26 +1111,20 @@ region.")
 
 ;;;;;; Live completions
 
-;; TODO: Why do we need this variable?
-;; Can we not always call `mct--region-current-buffer'?
-(defvar mct--region-buf nil
-  "Current buffer where Mct performs completion in region.")
-
 (defun mct--region-current-buffer ()
   "Return current buffer of completion in region."
-  (setq mct--region-buf (and completion-in-region--data
-                             (marker-buffer (nth 0 
completion-in-region--data)))))
+  (and completion-in-region--data
+       (marker-buffer (nth 0 completion-in-region--data))))
 
 (defun mct--region-live-completions (&rest _)
   "Update the *Completions* buffer.
 Meant to be added to `after-change-functions'."
-  (let ((buf (window-buffer (mct--get-completion-window))))
-    (when (and mct--region-buf (not (eq (current-buffer) buf)))
-      (while-no-input
-        (condition-case nil
-            (save-match-data
-              (mct--show-completions))
-          (quit (keyboard-quit)))))))
+  (when (mct--region-current-buffer)
+    (while-no-input
+      (condition-case nil
+          (save-match-data
+            (mct--show-completions))
+        (quit (keyboard-quit))))))
 
 (defun mct--region-live-update ()
   "Hook up `mct--region-live-completions'."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]