branch: externals/mct
commit 7ebf1826b511230babd9e6b661ae273bb0fae25d
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Put "continuous input" code in its own file
For a discussion about the ongoing development, see issue 25:
<https://gitlab.com/protesilaos/mct/-/issues/25>.
---
mct-tcm.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mct.el | 31 -------------------------------
2 files changed, 61 insertions(+), 31 deletions(-)
diff --git a/mct-tcm.el b/mct-tcm.el
new file mode 100644
index 0000000000..be82165a7a
--- /dev/null
+++ b/mct-tcm.el
@@ -0,0 +1,61 @@
+;;; mct-tcm.el --- MCT which Treats the Completions as the Minibuffer -*-
lexical-binding: t -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Protesilaos Stavrou <[email protected]>
+;; URL: https://gitlab.com/protesilaos/mct
+;; Version: 0.5.0
+;; Package-Requires: ((emacs "27.1"))
+
+;; This file is NOT part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at
+;; your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; An extension to MCT that intercepts single character keys in the
+;; Completions' buffer and send them as input in the minibuffer.
+
+;;; Code:
+
+;;;; General utilities
+
+;; NOTE 2022-02-22: This is highly experimental!
+
+(defun mct-tcm--redirect-self-insert (&rest _args)
+ "Redirect to the minibuffer per `mct-tcm-continuous-self-insert'."
+ (when-let* ((mct-tcm-mode)
+ (keys (this-single-command-keys))
+ (char (aref keys 0))
+ (mini (active-minibuffer-window)))
+ (when (and (char-or-string-p char)
+ (not (event-modifiers char)))
+ (select-window mini)
+ (insert char))))
+
+(defun mct-tcm--setup-redirect-self-insert ()
+ "Set up `mct-tcm-continuous-self-insert'."
+ (when (mct--minibuffer-p)
+ (add-hook 'pre-command-hook #'mct-tcm--redirect-self-insert nil t)))
+
+;; FIXME 2022-02-22: Silence message when key binding is undefined.
+(define-minor-mode mct-tcm-mode
+ "MCT extension to narrow through the Completions."
+ :global t
+ (if mct-tcm-mode
+ (add-hook 'completion-list-mode-hook
#'mct-tcm--setup-redirect-self-insert)
+ (remove-hook 'completion-list-mode-hook
#'mct-tcm--setup-redirect-self-insert)))
+
+(provide 'mct)
+;;; mct.el ends here
diff --git a/mct.el b/mct.el
index cec592cc22..ef044cbf0a 100644
--- a/mct.el
+++ b/mct.el
@@ -258,20 +258,6 @@ affairs."
:type 'boolean
:group 'mct)
-;; NOTE 2022-02-22: This is highly experimental!
-(defcustom mct-continuous-self-insert nil
- "Redirect self-insertions from the Completions to the minibuffer.
-When this variable is set to non-nil value, MCT will intercept
-any call to `self-insert-command' or single character key and
-send it to the minibuffer.
-
-This practically means that while typing in the Completions, the
-input is used to narrow the list of candidates (whereas the
-default is to let the Completions use their own keys and not try
-to send the input to the minibuffer)."
- :type 'boolean
- :group 'mct)
-
;;;; Completion metadata
(defun mct--this-command ()
@@ -315,22 +301,6 @@ to send the input to the minibuffer)."
;;;; Basics of intersection between minibuffer and Completions' buffer
-;; FIXME 2022-02-22: Silence message when key binding is undefined.
-(defun mct--redirect-self-insert (&rest _args)
- "Redirect to the minibuffer per `mct-continuous-self-insert'."
- (when-let* ((mct-continuous-self-insert)
- (keys (this-single-command-keys))
- (char (aref keys 0))
- (mini (active-minibuffer-window)))
- (when (and (char-or-string-p char)
- (not (event-modifiers char)))
- (select-window mini)
- (insert char))))
-
-(defun mct--setup-redirect-self-insert ()
- "Set up `mct-continuous-self-insert'."
- (add-hook 'pre-command-hook #'mct--redirect-self-insert nil t))
-
(define-obsolete-variable-alias
'mct-hl-line 'mct-highlight-candidate "0.3.0")
@@ -1200,7 +1170,6 @@ region.")
(mct--setup-appearance)
(mct--setup-completion-list-keymap)
(mct--setup-highlighting)
- (mct--setup-redirect-self-insert)
(mct--setup-line-numbers)
(cursor-sensor-mode)))