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

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

[elpa] externals/mct b1f7ebf7aa: Fix incomplete sample code for completi


From: ELPA Syncer
Subject: [elpa] externals/mct b1f7ebf7aa: Fix incomplete sample code for completion-in-region
Date: Mon, 25 Sep 2023 03:58:40 -0400 (EDT)

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

    Fix incomplete sample code for completion-in-region
---
 CHANGELOG.org | 34 +++++++++++++++++++++++++++++++---
 README.org    | 34 +++++++++++++++++++++++++++++++---
 2 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 29b80b0cd7..d8de4dba6e 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -89,11 +89,39 @@ Nevertheless, users can still get an MCT-like experience 
with these
 settings, which affect the default UI (modify as you see fit):
 
 #+begin_src emacs-lisp
+;; Define the small wrapper functions
+(defun my-mct-next-line-or-completion (n)
+  "Select next completion or move to next line N times.
+Select the next completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-next-completion n)
+    (next-line n)))
+
+(defun my-mct-previous-line-or-completion (n)
+  "Select previous completion or move to previous line N times.
+Select the previous completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-previous-completion n)
+    (previous-line n)))
+
+(defun my-mct-return-or-choose-completion (n)
+  "Choose current completion or create N newlines.
+Choose the current completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-choose-completion)
+    (newline n :interactive)))
+
 ;; Get the key bindings
 (let ((map completion-in-region-mode-map))
-  (define-key map (kbd "C-n") #'minibuffer-next-completion)
-  (define-key map (kbd "C-p") #'minibuffer-previous-completion)
-  (define-key map (kbd "RET") #'minibuffer-choose-completion))
+  (define-key map (kbd "C-n") #'my-mct-next-line-or-completion)
+  (define-key map (kbd "C-p") #'my-mct-previous-line-or-completion)
+  (define-key map (kbd "RET") #'my-mct-return-or-choose-completion))
 
 ;; Tweak the appearance
 (setq completions-format 'one-column)
diff --git a/README.org b/README.org
index d18537cd5e..b4ffbd00e6 100644
--- a/README.org
+++ b/README.org
@@ -475,11 +475,39 @@ To get the familiar MCT key bindings for in-buffer 
completion, use
 these in your init file:
 
 #+begin_src emacs-lisp
+;; Define the small wrapper functions
+(defun my-mct-next-line-or-completion (n)
+  "Select next completion or move to next line N times.
+Select the next completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-next-completion n)
+    (next-line n)))
+
+(defun my-mct-previous-line-or-completion (n)
+  "Select previous completion or move to previous line N times.
+Select the previous completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-previous-completion n)
+    (previous-line n)))
+
+(defun my-mct-return-or-choose-completion (n)
+  "Choose current completion or create N newlines.
+Choose the current completion if `completion-in-region-mode' is
+active and the Completions window is on display."
+  (interactive "p")
+  (if (and completion-in-region-mode (mct--get-completion-window))
+      (minibuffer-choose-completion)
+    (newline n :interactive)))
+
 ;; Get the key bindings
 (let ((map completion-in-region-mode-map))
-  (define-key map (kbd "C-n") #'minibuffer-next-completion)
-  (define-key map (kbd "C-p") #'minibuffer-previous-completion)
-  (define-key map (kbd "RET") #'minibuffer-choose-completion))
+  (define-key map (kbd "C-n") #'my-mct-next-line-or-completion)
+  (define-key map (kbd "C-p") #'my-mct-previous-line-or-completion)
+  (define-key map (kbd "RET") #'my-mct-return-or-choose-completion))
 
 ;; Tweak the appearance
 (setq completions-format 'one-column)



reply via email to

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