~protesilaos/mct

47f1a4aa8397795cfe68dac75bd8007d8550bc6c — Protesilaos Stavrou 6 months ago cca3aaa
Rename mct-minibuffer-mode to mct-mode

Thanks to Daniel Mendler for informing me about this in issue 4 on the
GitHub mirror: <https://github.com/protesilaos/mct/issues/4>.
2 files changed, 41 insertions(+), 32 deletions(-)

M README.org
M mct.el
M README.org => README.org +15 -11
@@ 365,7 365,7 @@ If nil, do not try to fit the Completions' buffer to its window.

[[#h:1a85ed4c-f54d-482b-9915-563f60c64f15][Live completion]].

** Dynamic completion tables in mct-minibuffer-mode
** Dynamic completion tables in mct-mode
:PROPERTIES:
:CUSTOM_ID: h:28dc0355-c461-4e3a-bc3a-479d67827cac
:END:


@@ 399,7 399,7 @@ user selects a candidate with ~mct-choose-completion-no-exit~,
~mct-edit-completion~, ~minibuffer-complete~, ~minibuffer-force-complete~
(i.e. any command that does not exit the minibuffer).

[[#h:bb445062-2e39-4082-a868-2123bfb793cc][Selecting candidates with mct-minibuffer-mode]].
[[#h:bb445062-2e39-4082-a868-2123bfb793cc][Selecting candidates with mct-mode]].

The two  exceptions are (i) when the current completion
session runs a command or category that is blocked by the


@@ 466,9 466,9 @@ 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~.

#+findex: mct-minibuffer-mode
#+findex: mct-mode
The former scenario is what MCT has supported since its inception.
Enable ~mct-minibuffer-mode~ to get started.  There was a time where
Enable ~mct-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.



@@ 483,13 483,17 @@ For in-buffer completion, use the ~corfu~ package by Daniel Mendler
This section outlines the various patterns of interaction that MCT
establishes.

** Cyclic behaviour for mct-minibuffer-mode
** Cyclic behaviour for mct-mode
:PROPERTIES:
:CUSTOM_ID: h:68c61a76-1d64-4f62-a77a-52e7b66a68fe
:END:
#+cindex: Cyclic behaviour in the minibuffer

When ~mct-minibuffer-mode~ is enabled, some new keymaps are activated
[ As part of {{{development-version}}} the ~mct-minibuffer-mode~ is
  called ~mct-mode~.  The ~mct-region-mode~ (for in-buffer completion)
  is removed. ]

When ~mct-mode~ is enabled, some new keymaps are activated
which add commands for cycling between the minibuffer and the
completions.  Suppose the following standard layout:



@@ 540,14 544,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~).

** Selecting candidates with mct-minibuffer-mode
** Selecting candidates with mct-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 with
~mct-minibuffer-mode~.
~mct-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


@@ 702,7 706,7 @@ Minimal setup for the minibuffer and in-buffer completion:

#+begin_src emacs-lisp
(require 'mct)
(mct-minibuffer-mode 1)
(mct-mode 1)
#+end_src

And with more options:


@@ 739,7 743,7 @@ And with more options:
;; disables live completions altogether.
(setq mct-completion-blocklist nil)

(mct-minibuffer-mode 1)
(mct-mode 1)
#+end_src

Other useful extras from the Emacs source code (read their doc strings):


@@ 916,7 920,7 @@ Add this to your own configuration file instead:
;; Adaptation of `icomplete-fido-backward-updir'.
(defun my-backward-updir ()
  "Delete char before point or go up a directory."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (cond
   ((and (eq (char-before) ?/)
         (eq (mct--completion-category) 'file))

M mct.el => mct.el +26 -21
@@ 461,7 461,7 @@ Apply APP by first setting up the minibuffer to work with Mct."
;;;###autoload
(defun mct-focus-minibuffer ()
  "Focus the active minibuffer."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (when-let ((mini (active-minibuffer-window)))
    (select-window mini)))



@@ 496,7 496,7 @@ succession.

What constitutes a Completions window is ultimately determined
by `mct--completions-window-name'."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (let* ((mini (active-minibuffer-window))
         (completions (mct--get-completion-window)))
    (cond


@@ 508,7 508,7 @@ by `mct--completions-window-name'."
;;;###autoload
(defun mct-list-completions-toggle ()
  "Toggle the presentation of the Completions buffer."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (if (mct--get-completion-window)
      (minibuffer-hide-completions)
    (mct--show-completions)))


@@ 553,13 553,13 @@ by `mct--completions-window-name'."

(defun mct-switch-to-completions-top ()
  "Switch to the top of the Completions buffer."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (mct--switch-to-completions)
  (goto-char (mct--first-completion-point)))

(defun mct-switch-to-completions-bottom ()
  "Switch to the bottom of the Completions buffer."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (mct--switch-to-completions)
  (goto-char (point-max))
  (next-completion -1)


@@ 598,7 598,7 @@ ARG is a numeric argument for `next-completion', as described in
This performs a regular motion for optional ARG candidates, but
when point can no longer move in that direction it switches to
the minibuffer."
  (interactive "p" mct-minibuffer-mode)
  (interactive "p" mct-mode)
  (let ((count (or arg 1)))
    (if (mct--bottom-of-completions-p count)
        (mct-focus-minibuffer)


@@ 624,7 624,7 @@ ARG is a numeric argument for `previous-completion', as described in
This performs a regular motion for optional ARG candidates, but
when point can no longer move in that direction it switches to
the minibuffer."
  (interactive "p" mct-minibuffer-mode)
  (interactive "p" mct-mode)
  (let ((count (if (natnump arg) arg 1)))
    (if (mct--top-of-completions-p count)
        (mct-focus-minibuffer)


@@ 633,7 633,7 @@ the minibuffer."
(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)
  (interactive "p" mct-mode)
  (dotimes (_ (or arg 1))
    (when-let (group (save-excursion
                       (text-property-search-forward 'face


@@ 647,7 647,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)
  (interactive "p" mct-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)


@@ 670,14 670,14 @@ If ARG is supplied, move that many completion groups at a time."
;; choose-completion expands the directory and continues the session.
(defun mct-choose-completion-exit ()
  "Run `choose-completion' in the Completions buffer and exit."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (choose-completion)
  (when (active-minibuffer-window)
    (minibuffer-force-complete-and-exit)))

(defun mct-choose-completion-no-exit ()
  "Run `choose-completion' in the Completions without exiting."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (let ((completion-no-auto-exit t))
    (choose-completion)))



@@ 702,7 702,7 @@ If ARG is supplied, move that many completion groups at a time."
(defun mct-choose-completion-dwim ()
  "Append to minibuffer when at `completing-read-multiple' prompt.
In any other prompt use `mct-choose-completion-no-exit'."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (when-let* ((mini (active-minibuffer-window))
              (window (mct--get-completion-window))
              (buffer (window-buffer window)))


@@ 732,7 732,7 @@ determined as follows:

A candidate is recognised for as long as point is not past its
last character."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (when-let ((window (mct--get-completion-window))
             ((active-minibuffer-window)))
    (with-current-buffer (window-buffer window)


@@ 751,7 751,7 @@ last character."
This has the same effect as with
\\<mct-minibuffer-local-completion-map>\\[mct-edit-completion],
followed by exiting the minibuffer with that candidate."
  (interactive nil mct-minibuffer-mode)
  (interactive nil mct-mode)
  (mct-edit-completion)
  (exit-minibuffer))



@@ 761,7 761,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)
  (interactive nil mct-mode)
  (goto-char (mct--first-completion-point)))

(defun mct-keyboard-quit-dwim ()


@@ 772,7 772,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)
  (interactive nil mct-mode)
  (when (derived-mode-p 'completion-list-mode)
    (cond
     ((null (active-minibuffer-window))


@@ 942,22 942,22 @@ This value means that it is overriden by the active region.")
(defun mct--setup-dynamic-completion-persist ()
  "Set up `mct-persist-dynamic-completion'."
  (let ((commands '(choose-completion minibuffer-complete minibuffer-force-complete)))
    (if (bound-and-true-p mct-minibuffer-mode)
    (if (bound-and-true-p mct-mode)
        (dolist (fn commands)
          (advice-add fn :after #'mct--persist-dynamic-completion))
      (dolist (fn commands)
        (advice-remove fn #'mct--persist-dynamic-completion)))))

;;;;; mct-minibuffer-mode declaration
;;;;; mct-mode declaration

(declare-function minibuf-eldef-setup-minibuffer "minibuf-eldef")

;;;###autoload
(define-minor-mode mct-minibuffer-mode
(define-minor-mode mct-mode
  "Set up opinionated default completion UI."
  :global t
  :group 'mct
  (if mct-minibuffer-mode
  (if mct-mode
      (progn
        (add-hook 'completion-list-mode-hook #'mct--setup-completion-list)
        (add-hook 'minibuffer-setup-hook #'mct--setup-passlist)


@@ 974,6 974,11 @@ This value means that it is overriden by the active region.")
  (mct--setup-dynamic-completion-persist)
  (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:


@@ 994,7 999,7 @@ This value means that it is overriden by the active region.")

(defun mct--setup-message-advices ()
  "Silence the minibuffer and the Completions."
  (if mct-minibuffer-mode
  (if mct-mode
      (progn
        (dolist (fn '(exit-minibuffer
                      choose-completion