about summary refs log tree commit diff stats
path: root/lisp/acdw-eshell.el
diff options
context:
space:
mode:
authorCase Duckworth2021-05-30 00:07:02 -0500
committerCase Duckworth2021-05-30 00:07:02 -0500
commitc698dc986914d56851e68688164e5fe47599e4b4 (patch)
tree54aff6df2134585ce0cfd8c8f6544fe473c14ae4 /lisp/acdw-eshell.el
parentAdd PDFs to auto-mode-alist (diff)
downloademacs-c698dc986914d56851e68688164e5fe47599e4b4.tar.gz
emacs-c698dc986914d56851e68688164e5fe47599e4b4.zip
Move things from init.el to acdw.el and acdw-eshell.el
Probably should've been 2 commits...
Diffstat (limited to 'lisp/acdw-eshell.el')
-rw-r--r--lisp/acdw-eshell.el94
1 files changed, 94 insertions, 0 deletions
diff --git a/lisp/acdw-eshell.el b/lisp/acdw-eshell.el new file mode 100644 index 0000000..104b7d1 --- /dev/null +++ b/lisp/acdw-eshell.el
@@ -0,0 +1,94 @@
1;;; acdw-eshell.el -*- lexical-binding: t; coding: utf-8-unix -*-
2
3;; Author: Case Duckworth <acdw@acdw.net>
4;; Keywords: configuration
5;; URL: https://tildegit.org/acdw/emacs
6
7;; This file is NOT part of GNU Emacs.
8
9;;; License:
10;; Everyone is permitted to do whatever with this software, without
11;; limitation. This software comes without any warranty whatsoever,
12;; but with two pieces of advice:
13;; - Don't hurt yourself.
14;; - Make good choices.
15
16;;; Commentary:
17
18;;; Code:
19
20(require 'cl-lib)
21
22
23;;; Eshell starting and quitting
24
25;;;###autoload
26(defun eshell-quit-or-delete-char (arg)
27 "Delete the character to the right, or quit eshell on an empty line."
28 (interactive "p")
29 (if (and (eolp) (looking-back eshell-prompt-regexp))
30 (eshell-life-is-too-much)
31 (delete-forward-char arg)))
32
33;;;###autoload
34(defun eshell-pop-or-quit (&optional buffer-name)
35 "Pop open an eshell buffer, or if in an eshell buffer, bury it."
36 (interactive)
37 (if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*")))
38 (eshell-life-is-too-much)
39 (with-message "Starting eshell"
40 (eshell))))
41
42
43;;; Insert previous arguments
44;; Record arguments
45
46(defvar eshell-arg-history nil)
47(defvar eshell-arg-history-index nil)
48(add-to-list 'savehist-additional-variables 'eshell-arg-history)
49
50(defun eshell-record-args (&rest _)
51 "Record unique arguments onto the front of `eshell-arg-history'."
52 (setq eshell-arg-history
53 (cl-loop with history = eshell-arg-history
54 for arg in (reverse eshell-last-arguments)
55 do (setq history (cons arg (remove arg history)))
56 finally return history)))
57
58(defun eshell-insert-prev-arg ()
59 "Insert an argument from `eshell-arg-history' at point."
60 (interactive)
61 (if (eq last-command 'eshell-insert-prev-arg)
62 (progn
63 (let ((pos (point)))
64 (eshell-backward-argument 1)
65 (delete-region (point) pos))
66 (if-let ((text (nth eshell-arg-history-index
67 eshell-arg-history)))
68 (progn
69 (insert text)
70 (cl-incf eshell-arg-history-index))
71 (insert (cl-first eshell-arg-history))
72 (setq eshell-arg-history-index 1)))
73 (insert (cl-first eshell-arg-history))
74 (setq eshell-arg-history-index 1)))
75
76(add-hook 'eshell-mode-hook
77 (lambda ()
78 (add-hook 'eshell-post-command-hook
79 #'eshell-record-args nil t)
80 (local-set-key (kbd "M-.") #'eshell-insert-prev-arg)))
81
82;;;###autoload
83(define-minor-mode eshell-arg-hist-mode
84 "Minor mode to enable argument history, like bash/zsh with M-."
85 :lighter "$."
86 :keymap (let ((map (make-sparse-keymap)))
87 (define-key map (kbd "M-.") #'eshell-insert-prev-arg)
88 map)
89 (if eshell-arg-hist-mode
90 (add-hook 'eshell-post-command-hook #'eshell-record-args nil t)
91 (remove-hook 'eshell-post-command-hook #'eshell-record-args t)))
92
93(provide 'acdw-eshell)
94;;; acdw-eshell.el ends here