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

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

[elpa] externals/mct f52ee53d39 20/21: DELETE mct-region-mode; remove re


From: ELPA Syncer
Subject: [elpa] externals/mct f52ee53d39 20/21: DELETE mct-region-mode; remove remaining extras
Date: Sat, 25 Mar 2023 15:59:02 -0400 (EDT)

branch: externals/mct
commit f52ee53d39ad4fc6ca3d9522aeae845bcf2f93bd
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    DELETE mct-region-mode; remove remaining extras
---
 README.org | 187 ++++---------------------------------------
 mct.el     | 267 +++++++------------------------------------------------------
 2 files changed, 44 insertions(+), 410 deletions(-)

diff --git a/README.org b/README.org
index 7b92c4f1d7..1dfedea18d 100644
--- a/README.org
+++ b/README.org
@@ -452,7 +452,7 @@ For example, if the user types =~/= after a long path name, 
everything
 preceding the =~/= is removed so the interactive selection process starts
 again from the user's =$HOME=.
 
-** MCT in the minibuffer and in regular buffers
+** MCT in the minibuffer and completion in regular buffers
 :PROPERTIES:
 :CUSTOM_ID: h:8109fe09-fcce-4212-88eb-943cc72f2c75
 :END:
@@ -466,29 +466,14 @@ Emacs draws a distinction between two types of completion 
sessions:
   minibuffer is not active.  We call this "in-buffer completion" or
   allude to the underlying function: ~completion-in-region~.
 
-The former scenario is what MCT has supported since its inception.
-Starting with version =0.4.0= it also covers the latter case, though only
-experimentally (please report any bugs or point towards areas of
-possible improvement).
-
 #+findex: mct-minibuffer-mode
-#+vindex: mct-minibuffer-mode
-#+findex: mct-region-mode
-#+vindex: mct-region-mode
-To let users fine-tune their setup, MCT provides the ~mct-minibuffer-mode~
-(formerly ~mct-mode~) as well as the global ~mct-region-mode~.
-
-The decoupling between the two modes makes it possible to configure
-interchangeable components in a variety of combinations, such as MCT for
-the minibuffer and the Corfu package for completion-in-region
-([[#h:03227254-d467-4147-b8cf-2fe05a2e279b][Extensions]]).  Or the Vertico 
package for the minibuffer and MCT for
-in-buffer completion 
([[#h:c9ddedea-e279-4233-94dc-f8d32367a954][Alternatives]]).
-
-We jokingly say that since the introduction of ~mct-region-mode~ the
-acronym "MCT" now stands for "Minibuffer Confines Transcended"---the
-original was "Minibuffer and Completions in Tandem".
+The former scenario is what MCT has supported since its inception.
+Enable ~mct-minibuffer-mode~ to get started.  There was a time where
+MCT also supported in-buffer completion but this was discontinued in
+version =1.0.0= of the package as it was not good enough.
 
-[[#h:97eb5898-1e52-4338-bd55-8c52f9d8ccd3][Interaction model of 
mct-region-mode]].
+For in-buffer completion, use the ~corfu~ package by Daniel Mendler
+([[#h:c9ddedea-e279-4233-94dc-f8d32367a954][Alternatives]]).
 
 * Usage
 :PROPERTIES:
@@ -496,12 +481,7 @@ original was "Minibuffer and Completions in Tandem".
 :END:
 
 This section outlines the various patterns of interaction that MCT
-establishes.  Note that completion covers two distinct cases, which are
-reflected in the design of MCT: (i) in the minibuffer and (ii) for
-in-buffer completion ([[#h:8109fe09-fcce-4212-88eb-943cc72f2c75][MCT in the 
minibuffer and in regular buffers]]).
-Most of this section is about the former scenario, which uses the
-~mct-minibuffer-mode~.  The ~mct-region-mode~ is less featureful by
-comparison.
+establishes.
 
 ** Cyclic behaviour for mct-minibuffer-mode
 :PROPERTIES:
@@ -560,19 +540,14 @@ The display of the =*Completions*= can be toggled at any 
time from inside
 the minibuffer with =C-l= (mnemonic is "[l]ist completions" and the
 command is ~mct-list-completions-toggle~).
 
-This is not the same for in-buffer completion performed by
-~mct-region-mode~ ([[#h:97eb5898-1e52-4338-bd55-8c52f9d8ccd3][Interaction 
model of mct-region-mode]]).
-
 ** Selecting candidates with mct-minibuffer-mode
 :PROPERTIES:
 :CUSTOM_ID: h:bb445062-2e39-4082-a868-2123bfb793cc
 :END:
 #+cindex: Candidate selection for minibuffer completion
 
-There are several ways to select a completion candidate.  These pertain
-to ~mct-minibuffer-mode~, as ~mct-region-mode~ only has the meaningful
-action of expanding the given candidate (with =RET= or =TAB= in the
-Completions' buffer ([[#h:97eb5898-1e52-4338-bd55-8c52f9d8ccd3][Cyclic 
behaviour for in-buffer completion]])).
+There are several ways to select a completion candidate with
+~mct-minibuffer-mode~.
 
 1. Suppose that you are typing =mod= with the intent to select the
    =modus-themes.el= buffer.  To complete the candidate follow up =mod= with
@@ -662,67 +637,6 @@ Completions' buffer 
([[#h:97eb5898-1e52-4338-bd55-8c52f9d8ccd3][Cyclic behaviour
    these commands do not cycle between the completions and the
    minibuffer: they stop at the first or last heading.
 
-** Interaction model of mct-region-mode
-:PROPERTIES:
-:CUSTOM_ID: h:97eb5898-1e52-4338-bd55-8c52f9d8ccd3
-:END:
-#+cindex: Interactions for in-buffer completion
-
-When ~mct-region-mode~ is enabled, MCT is used for in-buffer completion.
-In this scenario, the cyclic behaviour is less featureful than when the
-minibuffer is active (due to the specifics of the underlying commands),
-so we cover the differences ([[#h:68c61a76-1d64-4f62-a77a-52e7b66a68fe][Cyclic 
behaviour in the minibuffer]]).
-
-In terms of its interaction model, ~mct-region-mode~ only gets enabled
-manually either by pressing =TAB= or =C-M-i= (~complete-symbol~) in supporting
-major modes.  The =*Completions*= buffer pops up and is narrowed live to
-match any subsequent user input.  While the buffer is visible, we are
-performing ~completion-in-region~, which means that the Completions can be
-narrowed live by typing further.  Furthermore, =C-n= or =C-p= will move the
-point to the top/bottom of the Completions' buffer from where the user
-can select a candidate with =RET=.
-
-In-buffer completion is always invoked manually.  There is no minimum
-input threshold and no delay between updates while live-updating of the
-=*Completions*= buffer is performed.  If the Completions are not visible,
-then no ~completion-in-region~ takes place and thus ~mct-region-mode~ should
-have no effect.
-
-By default, the placement of the Completions for this type of
-interaction is below the current buffer (as opposed to the bottom of the
-frame for ~mct-minibuffer-mode~).  It looks like this:
-
-#+begin_example
-------------------------
-|               |      |
-| Current buffer| Buf  |
-|               |      |
-------------------------
-|               |      |
-|  Completions  | Buf  |
-|               |      |
-------------------------
-|        |      |      |
-|  Buf   | Buf  | Buf  |
-|        |      |      |
-------------------------
-#+end_example
-
-While inside the Completions' buffer, =C-n= and =C-p= move to the next and
-previous line, respectively.  When they reach the top/bottom boundaries
-of the Completions' buffer, they switch focus back to the buffer that
-started the completion.  However, and unlike ~mct-minibuffer-mode~, they
-do not keep the =*Completions*= window around.  This is because we cannot
-tell whether the user wanted to continue with a new completion upon
-returning to the buffer of origin or perform some other motion/command
-(in the minibuffer we can make that assumption because the minibuffer is
-purpose-specific, so for as long as it is active, the completion session
-goes on).  As such, ~completion-in-region~ must be restarted after cycling
-out of the =*Completions*=.
-
-To cancel in-buffer completion, type =C-g= either before switching to the
-Completions' buffer or while inside of it.
-
 * Installation
 :PROPERTIES:
 :CUSTOM_ID: h:1b501ed4-f16c-4118-9a4a-7a5e29143077
@@ -789,7 +703,6 @@ Minimal setup for the minibuffer and in-buffer completion:
 #+begin_src emacs-lisp
 (require 'mct)
 (mct-minibuffer-mode 1)
-(mct-region-mode 1)
 #+end_src
 
 And with more options:
@@ -797,7 +710,7 @@ And with more options:
 #+begin_src emacs-lisp
 (require 'mct)
 
-(setq mct-completion-window-size (cons #'mct--frame-height-fraction 1))
+(setq mct-completion-window-size (cons #'mct-frame-height-third 1))
 (setq mct-remove-shadowed-file-names t) ; works when `file-name-shadow-mode' 
is enabled
 (setq mct-hide-completion-mode-line t)
 (setq mct-minimum-input 3)
@@ -827,25 +740,6 @@ And with more options:
 (setq mct-completion-blocklist nil)
 
 (mct-minibuffer-mode 1)
-
-;; Optionally use MCT for in-buffer completion (though `corfu' is a
-;; better option).
-(mct-region-mode 1)
-
-;;; Integration with Oleh Krehel's `avy' package
-(require 'mct-avy)
-
-(dolist (map (list mct-minibuffer-local-completion-map
-                   mct-minibuffer-completion-list-map))
-  (define-key map (kbd "C-,") #'mct-avy-embark-act)
-  (define-key map (kbd "C-.") #'mct-avy-choose-completion-exit)
-  (define-key map (kbd "C-;") #'mct-avy-choose-completion-dwim))
-
-;; If you are using `mct-region-mode':
-(dolist (map (list mct-region-completion-list-map
-                   mct-region-buffer-map))
-  (define-key map (kbd "C-,") #'mct-avy-embark-act)
-  (define-key map (kbd "C-.") #'mct-avy-region-choose-completion))
 #+end_src
 
 Other useful extras from the Emacs source code (read their doc strings):
@@ -884,15 +778,11 @@ Other useful extras from the Emacs source code (read 
their doc strings):
 ;;; Minibuffer history
 (require 'savehist)
 (setq savehist-file (locate-user-emacs-file "savehist"))
-(setq history-length 10000)
+(setq history-length 500)
 (setq history-delete-duplicates t)
 (setq savehist-save-minibuffer-history t)
 (add-hook 'after-init-hook #'savehist-mode)
 
-;;; Indentation and the TAB key
-(setq-default tab-always-indent 'complete) ; useful for `mct-region-mode'
-(setq-default tab-first-completion 'word-or-paren-or-punct) ; Emacs 27
-
 ;;; Third-party extensions
 
 ;;;; Enable Consult previews in the Completions buffer.
@@ -924,16 +814,12 @@ Other useful extras from the Emacs source code (read 
their doc strings):
 #+cindex: Keymaps
 #+vindex: mct-completion-list-mode-map
 #+vindex: mct-minibuffer-local-completion-map
-#+vindex: mct-region-buffer-map
-#+vindex: mct-region-completion-list-map
 
 MCT defines its own keymaps, which extend those that are active in the
 minibuffer and the =*Completions*= buffer, respectively:
 
 + ~mct-completion-list-mode-map~
 + ~mct-minibuffer-local-completion-map~
-+ ~mct-region-buffer-map~
-+ ~mct-region-completion-list-map~
 
 You can invoke ~describe-keymap~ to learn more about them.
 
@@ -1077,9 +963,9 @@ these exceptionally well-crafted extras:
   make things prettier and/or more informative, while it can also be
   combined with Marginalia.
 
-MCT does support the use-case of ~completion-in-region~.  This is the kind
-of completion session that does not involve the minibuffer and is
-instead about in-buffer text expansion.  However, you may prefer:
+MCT does not support the use-case of ~completion-in-region~.  This is
+the kind of completion session that is done inside the buffer and does
+not involve the minibuffer.  However, you may prefer:
 
 + [[https://github.com/minad/corfu/][Corfu]] by Daniel Mendler :: An interface 
for the ~completion-in-region~
   which uses a child frame (basically a pop-up) at the position of the
@@ -1089,7 +975,7 @@ instead about in-buffer text expansion.  However, you may 
prefer:
 
 + [[https://github.com/minad/cape][Cape]] also by Daniel :: Additional 
~completion-at-point-functions~
   (CAPFs) that extend those of core Emacs.  These backends can be used
-  by packages that visualise ~completion-in-region~ such as Corfu and MCT.
+  by packages that visualise ~completion-in-region~.
 
 ** Enable Consult previews
 :PROPERTIES:
@@ -1104,28 +990,6 @@ preview the candidate at point.  All we need to enable it 
in the
 (add-hook 'completion-list-mode-hook #'consult-preview-at-point-mode)
 #+end_src
 
-** Avoid conflict between MCT and Corfu
-:PROPERTIES:
-:CUSTOM_ID: h:9b19911c-1dd7-4d4c-b513-feb77237e156
-:END:
-
-Daniel Mendler's =corfu= package provides an alternative to the
-~mct-region-mode~ ([[#h:8109fe09-fcce-4212-88eb-943cc72f2c75][MCT in the 
minibuffer and in regular buffers]]).  Given
-that MCT's implementation is a global minor-mode, chances are that users
-of both will run into weird issues with conflicting functionality.  The
-following snippet from Corfu's README can be added to user configuration
-files to avoid any potential trouble when using commands such as
-~eval-expression~ (bound to =M-:= by default):
-
-#+begin_src emacs-lisp
-(defun corfu-in-minibuffer ()
-  "Enable Corfu in the minibuffer only if Mct/Vertico are not active."
-  (unless (or (mct--minibuffer-p) vertico--input)
-    (corfu-mode 1)))
-
-(add-hook 'minibuffer-setup-hook #'corfu-in-minibuffer 1)
-#+end_src
-
 * Alternatives
 :PROPERTIES:
 :CUSTOM_ID: h:c9ddedea-e279-4233-94dc-f8d32367a954
@@ -1188,25 +1052,6 @@ They all make for a natural complement to the standard 
Emacs experience
   prefer MCT over Vertico in terms of the available functionality:
   Vertico is better.
 
-+ [[https://github.com/karthink/elmo][Elmo - Embark Live MOde for Emacs]] by 
Karthik Chikmagalur :: this
-  package is best described as a sibling of MCT both in terms of its
-  functionality and overall interaction model.  In fact, the cyclic
-  motions that are at the core of the MCT experience were first
-  developed as part of my personal Emacs setup to cycle between the
-  minibuffer and Embark's "live completions" buffer.  That was until
-  Emacs28 got some refinements to the presentation of the =*Completions*=
-  buffer which allowed for a vertical, single-column view.
-
-  Elmo can, in principle, have identical functionality with MCT, given
-  that the only substantive difference is that the former uses an Embark
-  buffer to show live-updating completions, while the latter relies on
-  the generic =*Completions*= buffer.
-
-  For users who are on Emacs 27 and who need a single-column view, Elmo
-  is a better choice because MCT can only display such a view on Emacs
-  28 or higher (though it has been meticulously tested with the grid
-  views of Emacs 27 and should work perfectly fine with them).
-
 + Icomplete and fido-mode (built-in, multiple authors) :: Icomplete is
   closer in spirit to Vertico, as it too uses the minibuffer to display
   completion candidates.  By default, it presents the list horizontally,
diff --git a/mct.el b/mct.el
index 0ef5cbc1dc..b743087c0a 100644
--- a/mct.el
+++ b/mct.el
@@ -430,11 +430,6 @@ Meant to be added to `after-change-functions'."
               (buf (window-buffer win)))
       (buffer-local-value 'mct--active buf)))
 
-(defun mct--region-p ()
-  "Return non-nil if Mct is completing in region."
-  (when-let ((buf (mct--region-current-buffer)))
-    (buffer-local-value 'mct-region-mode buf)))
-
 (defun mct--minibuffer-completion-help-advice (&rest app)
   "Prepare APP advice around `display-completion-list'."
   (if (mct--minibuffer-p)
@@ -458,26 +453,10 @@ Apply APP by first setting up the minibuffer to work with 
Mct."
 
 ;;;; Commands and helper functions
 
-;; TODO 2021-11-17: We must `autoload' instead of `declare-function' for
-;; things to work on Emacs 27.  Perhaps we should keep the latter but
-;; add (eval-when-compile (require 'text-property-search))?  That should
-;; work for packages, but not if we just `eval-buffer', right?
-
-(autoload 'text-property-search-backward "text-property-search")
-(autoload 'text-property-search-forward "text-property-search")
-(autoload 'prop-match-beginning "text-property-search")
-(autoload 'prop-match-end "text-property-search")
-
-;; (declare-function text-property-search-backward "text-property-search" 
(property &optional value predicate not-current))
-;; (declare-function text-property-search-forward "text-property-search" 
(property &optional value predicate not-current))
-;; (declare-function prop-match-beginning "text-property-search" (cl-x))
-;; (declare-function prop-match-end "text-property-search" (cl-x))
-
-;; We need this to make things work on Emacs 27.
-(defun mct--one-column-p ()
-  "Test if we have a one-column view available."
-  (and (eq mct-completions-format 'one-column)
-       (>= emacs-major-version 28)))
+(declare-function text-property-search-backward "text-property-search" 
(property &optional value predicate not-current))
+(declare-function text-property-search-forward "text-property-search" 
(property &optional value predicate not-current))
+(declare-function prop-match-beginning "text-property-search" (cl-x))
+(declare-function prop-match-end "text-property-search" (cl-x))
 
 ;;;;; Focus minibuffer and/or show completions
 
@@ -503,14 +482,7 @@ Apply APP by first setting up the minibuffer to work with 
Mct."
         (ring-bell-function #'ignore)
         (message-log-max nil)
         (inhibit-message t))
-    (save-excursion
-      (pcase (and completion-in-region-mode completion-in-region--data)
-        (`(,start ,end ,collection . ,plist)
-         (let ((minibuffer-completion-table collection)
-               (minibuffer-completion-predicate (plist-get plist :predicate))
-               (completion-extra-properties plist))
-           (minibuffer-completion-help start end)))
-        (_ (minibuffer-completion-help))))))
+    (minibuffer-completion-help)))
 
 ;;;###autoload
 (defun mct-focus-mini-or-completions ()
@@ -556,7 +528,7 @@ by `mct--completions-window-name'."
 (defun mct--arg-completion-point-p (arg)
   "Return non-nil if ARGth next completion exists."
   (save-excursion
-    (mct--next-completion arg)
+    (next-completion arg)
     (mct--completion-at-point-p)))
 
 (defun mct--first-completion-point ()
@@ -585,35 +557,21 @@ by `mct--completions-window-name'."
     (mct--show-completions))
   (switch-to-completions))
 
-(defun mct--restore-old-point-in-grid (line)
-  "Restore old point in window if LINE is on its line."
-  (unless (mct--one-column-p)
-    (let (old-line old-point)
-      (when-let ((window (mct--get-completion-window)))
-        (setq old-point (window-old-point window)
-              old-line (line-number-at-pos old-point))
-        (when (= (line-number-at-pos line) old-line)
-          (if (eq old-point (point-min))
-              (goto-char (mct--first-completion-point))
-            (goto-char old-point)))))))
-
 (defun mct-switch-to-completions-top ()
-  (interactive nil mct-minibuffer-mode mct-region-mode)
   "Switch to the top of the Completions buffer."
+  (interactive nil mct-minibuffer-mode)
   (mct--switch-to-completions)
-  (goto-char (mct--first-completion-point))
-  (mct--restore-old-point-in-grid (point)))
+  (goto-char (mct--first-completion-point)))
 
 (defun mct-switch-to-completions-bottom ()
-  (interactive nil mct-minibuffer-mode mct-region-mode)
   "Switch to the bottom of the Completions buffer."
+  (interactive nil mct-minibuffer-mode)
   (mct--switch-to-completions)
   (goto-char (point-max))
   (next-completion -1)
   (goto-char (line-beginning-position))
   (unless (mct--completion-at-point-p)
     (next-completion 1))
-  (mct--restore-old-point-in-grid (point))
   (recenter
    (- -1
       (min (max 0 scroll-margin)
@@ -650,7 +608,7 @@ the minibuffer."
   (let ((count (or arg 1)))
     (if (mct--bottom-of-completions-p count)
         (mct-focus-minibuffer)
-      (mct--next-completion count))))
+      (next-completion count))))
 
 (defun mct--motion-below-point-min-p (arg)
   "Return non-nil if backward ARG motion exceeds `point-min'."
@@ -676,12 +634,12 @@ the minibuffer."
   (let ((count (if (natnump arg) arg 1)))
     (if (mct--top-of-completions-p count)
         (mct-focus-minibuffer)
-      (mct--previous-completion count))))
+      (previous-completion count))))
 
 (defun mct-next-completion-group (&optional arg)
   "Move to the next completion group.
 If ARG is supplied, move that many completion groups at a time."
-  (interactive "p" mct-minibuffer-mode mct-region-mode)
+  (interactive "p" mct-minibuffer-mode)
   (dotimes (_ (or arg 1))
     (when-let (group (save-excursion
                        (text-property-search-forward 'face
@@ -695,7 +653,7 @@ If ARG is supplied, move that many completion groups at a 
time."
 (defun mct-previous-completion-group (&optional arg)
   "Move to the previous completion group.
 If ARG is supplied, move that many completion groups at a time."
-  (interactive "p" mct-minibuffer-mode mct-region-mode)
+  (interactive "p" mct-minibuffer-mode)
   (dotimes (_ (or arg 1))
     ;; skip back, so if we're at the top of a group, we go to the previous 
one...
     (forward-line -1)
@@ -809,7 +767,7 @@ followed by exiting the minibuffer with that candidate."
 ;; `cursor-sensor-functions'.
 (defun mct-beginning-of-buffer ()
   "Go to the top of the Completions buffer."
-  (interactive nil mct-minibuffer-mode mct-region-mode)
+  (interactive nil mct-minibuffer-mode)
   (goto-char (mct--first-completion-point)))
 
 (defun mct-keyboard-quit-dwim ()
@@ -820,7 +778,7 @@ If in a Completions buffer and unless the region is active, 
run
 
 If the region is active, deactivate it.  A second invocation of
 this command is then required to abort the session."
-  (interactive nil mct-minibuffer-mode mct-region-mode)
+  (interactive nil mct-minibuffer-mode)
   (when (derived-mode-p 'completion-list-mode)
     (cond
      ((null (active-minibuffer-window))
@@ -985,8 +943,6 @@ This value means that it is overriden by the active 
region.")
 
 ;;;;; Dynamic completion
 
-;; TODO 2022-01-29: Research how things work for relevant cases in
-;; completion-in-region and adapt accordingly.
 (defun mct--persist-dynamic-completion (&rest _)
   "Persist completion, per `mct-persist-dynamic-completion'."
   (when (and (not (mct--symbol-in-list mct-completion-blocklist))
@@ -1029,211 +985,44 @@ This value means that it is overriden by the active 
region.")
     (advice-remove #'minibuffer-completion-help 
#'mct--minibuffer-completion-help-advice)
     (advice-remove #'minibuf-eldef-setup-minibuffer #'mct--stealthily))
   (mct--setup-dynamic-completion-persist)
-  (mct--setup-shared))
-
-(define-obsolete-function-alias 'mct-mode 'mct-minibuffer-mode "0.4.0")
-
-;;;;; mct-region-mode declaration
-
-;;;;;; Live completions
-
-(defun mct--region-current-buffer ()
-  "Return current buffer of completion in region."
-  (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'."
-  (when-let (buf (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'."
-  (add-hook 'after-change-functions #'mct--region-live-completions nil t))
-
-;;;;;; Minor mode specification
-
-(defvar mct-region-buffer-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map [remap next-line] #'mct-switch-to-completions-top)
-    (define-key map [remap previous-line] #'mct-switch-to-completions-bottom)
-    ;; TODO: Either keep the TAB=completion-at-point binding or add our own
-    ;; command which is compatible with orderless completion.
-    (define-key map (kbd "TAB") #'ignore)
-    map)
-  "Derivative of `completion-in-region-map'.")
-
-(defun mct--region-setup-completion-in-region ()
-  "Set up Mct for `completion-in-region'."
-  (if completion-in-region-mode
-      (progn
-        (setcdr (assq #'completion-in-region-mode 
minor-mode-overriding-map-alist)
-                (make-composed-keymap mct-region-buffer-map 
completion-in-region-mode-map))
-        (mct--region-current-buffer)
-        ;; NOTE: Ignore the predicate in order to support orderless style.
-        ;; TODO: This override should be guarded by a customizable variable,
-        ;; since it is intrusive. See also `corfu-quit-at-boundary'.
-        (setq completion-in-region-mode--predicate (lambda () t))
-        (mct--region-live-update))
-    ;; Teardown
-    (remove-hook 'after-change-functions #'mct--region-live-completions t)))
-
-(defun mct-next-completion-or-quit (&optional arg)
-  "Move to next completion or bury the Completions' buffer.
-
-This performs a regular motion for optional ARG candidates, but
-when point can no longer move in that direction it buries the
-Completions' buffer.
-
-This is a counterpart of `mct-next-completion-or-mini' that is
-meant for the case of completion in region (i.e. not in the
-minibuffer)."
-  (interactive nil mct-region-mode)
-  (let ((count (or arg 1)))
-    (cond
-     ((mct--bottom-of-completions-p count)
-      (minibuffer-hide-completions))
-     (t
-      (mct--next-completion count)))))
-
-(defun mct-previous-completion-or-quit (&optional arg)
-  "Move to previous completion or bury the Completions' buffer.
-
-This performs a regular motion for optional ARG candidates, but
-when point can no longer move in that direction it buries the
-Completions' buffer.
+  (mct--setup-message-advices))
 
-This is a counterpart of `mct-previous-completion-or-mini' that
-is meant for the case of completion in region (i.e. not in the
-minibuffer)."
-  (interactive nil mct-region-mode)
-  (let ((count (if (natnump arg) arg 1)))
-    (cond
-     ((mct--top-of-completions-p count)
-      (minibuffer-hide-completions))
-     (t
-      (mct--previous-completion count)))))
-
-(defvar mct-region-completion-list-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map [remap next-line] #'mct-next-completion-or-quit)
-    (define-key map [remap previous-line] #'mct-previous-completion-or-quit)
-    (define-key map (kbd "n") #'mct-next-completion-or-quit)
-    (define-key map (kbd "p") #'mct-previous-completion-or-quit)
-    (define-key map [remap backward-paragraph] #'mct-previous-completion-group)
-    (define-key map [remap forward-paragraph] #'mct-next-completion-group)
-    (define-key map (kbd "M-n") #'mct-next-completion-group)
-    (define-key map (kbd "M-p") #'mct-previous-completion-group)
-    (define-key map (kbd "TAB") #'choose-completion)
-    (define-key map (kbd "RET") #'choose-completion)
-    (define-key map [remap beginning-of-buffer] #'mct-beginning-of-buffer)
-    map)
-  "Derivative of `completion-list-mode-map'.")
-
-(defun mct--region-setup-completion-list-keymap ()
-  "Set up completion list keymap."
-  (use-local-map
-   (make-composed-keymap mct-region-completion-list-map
-                         (current-local-map))))
-
-(defun mct--region-setup-completion-list ()
-  "Set up the completion-list for Mct."
-  (when (mct--region-p)
-    (setq-local completion-show-help nil
-                completion-wrap-movement nil ; Emacs 29
-                truncate-lines t)
-    (mct--setup-clean-completions)
-    (mct--setup-appearance)
-    (mct--region-setup-completion-list-keymap)
-    (mct--setup-highlighting)
-    (cursor-sensor-mode)))
-
-(defun mct--region-completion-done (&rest app)
-  "Apply APP before disabling completion in region."
-  (apply app)
-  (completion-in-region-mode -1))
-
-;; UPDATE 2022-01-01 13:12 +0200: Actually this is not related to mct.
-;; I can reproduce it in emacs -Q with just those:
-;;
-;; (electric-indent-mode 1)
-;; (setq-default tab-always-indent 'complete)
-;;
-;; FIXME 2022-01-01: I experienced a bug which is as follows:
-;;
-;; + (electric-indent-mode 1)
-;; + (setq-default tab-always-indent 'complete)
-;; + visit an Org file with an elisp src block that includes comments
-;; + go to the end of a comment's line and hit RET
-;; + the block temporarily changes background to secondary-selection
-;;   (same as when you type C-c '), seems to be trying to perform
-;;   completion, and then ultimately does what RET is supposed to do.
-;;
-;; Disabling electric-indent-mode fixes the issue, though that is beside
-;; the point.
-
-;; FIXME 2022-01-03: This does not work with either M-x shell or M-x
-;; eshell.  Not on Emacs 29, not on Emacs 27.  Try to tab-complete with
-;; 'cd' and it will not be possible to switch to the Completions'
-;; buffer, even if it works the first time.
-
-;;;###autoload
-(define-minor-mode mct-region-mode
-  "Set up interactivity over the default `completion-in-region'."
-  :global t
-  (if mct-region-mode
-      (progn
-        (advice-add #'completion--done :around #'mct--region-completion-done)
-        (advice-add #'minibuffer-completion-help :around 
#'mct--region-completion-help-advice)
-        (add-hook 'completion-list-mode-hook 
#'mct--region-setup-completion-list)
-        (add-hook 'completion-in-region-mode-hook 
#'mct--region-setup-completion-in-region))
-    (advice-remove #'completion--done #'mct--region-completion-done)
-    (advice-remove #'minibuffer-completion-help 
#'mct--region-completion-help-advice)
-    (remove-hook 'completion-list-mode-hook 
#'mct--region-setup-completion-list)
-    (remove-hook 'completion-in-region-mode-hook 
#'mct--region-setup-completion-in-region))
-  (mct--setup-shared))
+(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--shared-honor-inhibit-message (&rest app)
-  "Honor `inhibit-message' while applying APP."
-  (unless (and (or (mct--region-p) (mct--minibuffer-p)) inhibit-message)
+(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--shared-messageless (&rest app)
+(defun mct--messageless (&rest app)
   "Set `minibuffer-message-timeout' to 0 while applying APP."
-  (if (or (mct--region-p) (mct--minibuffer-p))
+  (if (mct--minibuffer-p)
       (let ((minibuffer-message-timeout 0))
         (apply app))
     (apply app)))
 
-(defun mct--setup-shared ()
+(defun mct--setup-message-advices ()
   "Silence the minibuffer and the Completions."
-  (if (or mct-region-mode mct-minibuffer-mode)
+  (if mct-minibuffer-mode
       (progn
-        ;; NOTE 2022-01-09: Only `choose-completion' is relevant for
-        ;; completion-in-region.
         (dolist (fn '(exit-minibuffer
                       choose-completion
                       minibuffer-force-complete
                       minibuffer-complete-and-exit
                       minibuffer-force-complete-and-exit))
-          (advice-add fn :around #'mct--shared-messageless))
-        (advice-add #'minibuffer-message :around 
#'mct--shared-honor-inhibit-message))
+          (advice-add fn :around #'mct--messageless))
+        (advice-add #'minibuffer-message :around #'mct--honor-inhibit-message))
     (dolist (fn '(exit-minibuffer
                   choose-completion
                   minibuffer-force-complete
                   minibuffer-complete-and-exit
                   minibuffer-force-complete-and-exit))
-      (advice-remove fn #'mct--shared-messageless))
-    (advice-remove #'minibuffer-message #'mct--shared-honor-inhibit-message)))
+      (advice-remove fn #'mct--messageless))
+    (advice-remove #'minibuffer-message #'mct--honor-inhibit-message)))
 
 (provide 'mct)
 ;;; mct.el ends here



reply via email to

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