]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/comint.el (comint-complete-input-ring): New command (bug#74694).
authorJuri Linkov <juri@linkov.net>
Mon, 16 Dec 2024 18:12:25 +0000 (20:12 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:01:58 +0000 (16:01 +0100)
(comint-mode-map): Bind 'comint-complete-input-ring' to 'C-x <up>'.

(cherry picked from commit d2986e79b76d442f8620195a54120d8be3e4583c)

etc/NEWS
lisp/comint.el

index 1fb558ed5840619be329a58061e673eab8de1307..e70da6dca8840ff88943809a2d8173556fed736a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -250,6 +250,12 @@ It removes all the buttons in the specified region.
 +++
 *** Disabling 'button-mode' now removes all buttons in the current buffer.
 
+** Shell
+
+*** New command to complete the shell history.
+'comint-complete-input-ring' ('C-x <up>') is like 'minibuffer-complete-history'
+but completes on comint inputs.
+
 ** Eshell
 
 ---
index d80bc358881c3a37000e09f09653dd7839f3f439..64c5bec0ce9fe123d6ff1a79e3c6d3239feef364 100644 (file)
@@ -543,6 +543,7 @@ via PTYs.")
     (define-key map "\er"        'comint-history-isearch-backward-regexp)
     (define-key map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
     (define-key map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
+    (define-key map [?\C-x up]    'comint-complete-input-ring)
     (define-key map "\e\C-l"     'comint-show-output)
     (define-key map "\C-m"       'comint-send-input)
     (define-key map "\C-d"       'comint-delchar-or-maybe-eof)
@@ -1180,6 +1181,24 @@ See also `comint-read-input-ring'."
            (set-window-configuration conf)
          (push ch unread-command-events))))))
 
+(defun comint-complete-input-ring ()
+  "Complete a list of recent inputs entered into the current buffer.
+Like `minibuffer-complete-history' but completes on comint inputs.
+This function makes `comint-dynamic-list-input-ring' obsolete."
+  (interactive)
+  (let ((completions
+         (if (and (ring-p comint-input-ring)
+                  (not (ring-empty-p comint-input-ring)))
+             (ring-elements comint-input-ring)
+           (user-error "No history available")))
+        (completion-in-region-mode-predicate
+         (lambda () (get-buffer-window "*Completions*" 0))))
+    (completion-in-region
+     (comint-line-beginning-position) (point-max)
+     (completion-table-with-metadata
+      completions '((category . comint-input)
+                    (display-sort-function . identity)
+                    (cycle-sort-function . identity))))))
 
 (defun comint-regexp-arg (prompt)
   "Return list of regexp and prefix arg using PROMPT."