summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2024-01-06 18:04:34 -0500
committerKjetil Orbekk <kj@orbekk.com>2024-01-06 18:04:34 -0500
commit91f00f2e796d9352bc749a87d710039c4673cd07 (patch)
treeddf46f5ddee2890f203796ca6c83d04e300e130b
parent6422c49e2424ad8c064edcf00b5532049c5517ab (diff)
fix history
-rw-r--r--emacs/.config/emacs-kj/lisp/kj-history.el94
1 files changed, 48 insertions, 46 deletions
diff --git a/emacs/.config/emacs-kj/lisp/kj-history.el b/emacs/.config/emacs-kj/lisp/kj-history.el
index 2e90e81..debd23c 100644
--- a/emacs/.config/emacs-kj/lisp/kj-history.el
+++ b/emacs/.config/emacs-kj/lisp/kj-history.el
@@ -9,53 +9,55 @@
;; Command
(group (1+ (not "\n")))))
-(defun kj/get-shell-history ()
- (with-temp-buffer
- (unless (process-file
- "zsh"
- nil
- (current-buffer)
- nil
- "-c"
- kj/history-command)
- (error "Getting history failed: %s" (buffer-string)))
- (goto-char (point-min))
- (let ((result))
- (save-match-data
- (while (re-search-forward kj/history-regexp nil t)
- (let ((command
- ;; Fix up multi-line commands.
- (string-replace "\\\\n" "\\\n" (match-string-no-properties 1))))
- (push command result))))
- result)))
+(use-package consult
+ :config
+ (defun kj/get-shell-history ()
+ (with-temp-buffer
+ (unless (process-file
+ "zsh"
+ nil
+ (current-buffer)
+ nil
+ "-c"
+ kj/history-command)
+ (error "Getting history failed: %s" (buffer-string)))
+ (goto-char (point-min))
+ (let ((result))
+ (save-match-data
+ (while (re-search-forward kj/history-regexp nil t)
+ (let ((command
+ ;; Fix up multi-line commands.
+ (string-replace "\\\\n" "\\\n" (match-string-no-properties 1))))
+ (push command result))))
+ result)))
-(defun kj/consult-history ()
- (interactive)
- (if (not
- (or (and (minibufferp)
- (eq minibuffer-history-variable 'shell-command-history))
- (derived-mode-p '(term-mode shell-mode))
- ))
- (call-interactively 'consult-history)
- (pcase-let* ((bol
- (cond ((derived-mode-p 'eshell-mode) 'eshell-bol)
- ((derived-mode-p 'term-mode) 'term-bol)
- ((derived-mode-p 'comint-mode) 'comint-bol)))
- (`(,beg . ,end)
- (cond ((minibufferp)
+ (defun kj/consult-history ()
+ (interactive)
+ (if (not
+ (or (and (minibufferp)
+ (eq minibuffer-history-variable 'shell-command-history))
+ (derived-mode-p '(term-mode shell-mode))
+ ))
+ (call-interactively 'consult-history)
+ (pcase-let* ((bol
+ (cond ((derived-mode-p 'eshell-mode) 'eshell-bol)
+ ((derived-mode-p 'term-mode) 'term-bol)
+ ((derived-mode-p 'comint-mode) 'comint-bol)))
+ (`(,beg . ,end)
+ (cond ((minibufferp)
(cons (minibuffer-prompt-end) (point-max)))
- (bol (save-excursion
- (funcall bol)
- (cons (point) (pos-eol))))
- (t (cons (point) (point)))))
- (str (consult--read
- (kj/get-shell-history)
- :prompt "Shell history: "
- :history t
- :sort nil
- :initial (buffer-substring-no-properties beg end)
- :state (consult--insertion-preview beg end))))
- (delete-region beg end)
- (insert (substring-no-properties str)))))
+ (bol (save-excursion
+ (funcall bol)
+ (cons (point) (pos-eol))))
+ (t (cons (point) (point)))))
+ (str (consult--read
+ (kj/get-shell-history)
+ :prompt "Shell history: "
+ :history t
+ :sort nil
+ :initial (buffer-substring-no-properties beg end)
+ :state (consult--insertion-preview beg end))))
+ (delete-region beg end)
+ (insert (substring-no-properties str))))))
(provide 'kj-history)