.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

commit 93eb1631b6b590538eda3529ae347d161753e34f
parent 97e754da8b97b59dca643a11b920d0a68b651a46
Author: andsy10 <andsy1016@gmail.com>
Date:   Tue, 20 Oct 2026 10:46:12 +0800

Add history insertion commands for shell and eshell

Diffstat:
Mlisp/init-kbd-func.el | 9+++++++++
Mlisp/init-kbd.el | 8++++++++
Mlisp/init-package.el | 35++++++++++++++++++++++++++++++++++-
3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/lisp/init-kbd-func.el b/lisp/init-kbd-func.el @@ -123,6 +123,15 @@ there's a region, all lines that region covers will be duplicated." (defun enable-truncate-lines () (setq truncate-lines t)) +(defun my-eshell-input-from-history () + "Insert command from eshell input history." + (interactive) + (let ((history (append (cddr eshell-history-ring) nil))) + (insert + (completing-read + "Insert input from history: " + history)))) + (defun query-replace-case-sensitive () "Case-sensitive `query-replace'." (interactive) diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el @@ -198,6 +198,10 @@ "<left>" #'emms-seek-backward "<right>" #'emms-seek-forward) +;; eshell +(general-def eshell-mode-map + "C-c h" #'my-eshell-input-from-history) + ;; eww (general-def eww-mode-map "M-n" #'forward-paragraph @@ -342,6 +346,10 @@ "C-c TAB" #'pilish-open-input "C-c C-t" #'pilish-tree-browser) +;; shell +(general-def shell-mode-map + "C-c h" #'my-shell-input-from-history) + ;; sly (general-def (sly-mode-map sly-editing-mode-map) "M-p" #'backward-paragraph diff --git a/lisp/init-package.el b/lisp/init-package.el @@ -148,7 +148,40 @@ Like normal Emacs `C-k'. Kill to end of line and put content in kill-ring." (when (string= name "shell") (dolist (pair my-shell-setenv) (my-setenv-local (car pair) (cdr pair) buffer)))) - (advice-add #'comint-exec :before #'my-shell-setenv)) + (advice-add #'comint-exec :before #'my-shell-setenv) + + ;; from Protesilaos's Emacs configuration + (defun my-shell--build-input-history () + "Return `comint-input-ring' as a list." + (when (and (ring-p comint-input-ring) + (not (ring-empty-p comint-input-ring))) + (let (history) + (dotimes (index (ring-length comint-input-ring)) + (push (ring-ref comint-input-ring index) history)) + (delete-dups history)))) + + (defvar my-shell--input-history-completion-history nil + "Minibuffer history of `my-shell--input-history-prompt'. +Not to be confused with the shell input history, which is stored +in the `comint-input-ring' (see `my-shell--build-input-history').") + + (defun my-shell--input-history-prompt () + "Prompt for completion against `my-shell--build-input-history'." + (let* ((history (my-shell--build-input-history)) + (default (car history))) + (completing-read + (format-prompt "Insert input from history" default) + history nil :require-match nil + 'my-shell--input-history-completion-history + default))) + + (defun my-shell-input-from-history () + "Insert command from shell input history. +Only account for the history Emacs knows about, ignoring +`comint-input-ring-file-name' (e.g. ~/.bash_history)." + (declare (interactive-only t)) + (interactive) + (insert (my-shell--input-history-prompt)))) ;; eshell-syntax-highlighting (my-use-package eshell-syntax-highlighting