about summary refs log tree commit diff stats
path: root/lisp/acdw-eshell.el
diff options
context:
space:
mode:
authorCase Duckworth2021-11-21 23:57:41 -0600
committerCase Duckworth2021-11-21 23:57:41 -0600
commita2657993bad828af6743c68931a0e848bfcdec53 (patch)
tree1e9220389184a0c68bc9f6bfe08edca3f2a362e6 /lisp/acdw-eshell.el
parentUn-stupidify org-mode filling (diff)
downloademacs-a2657993bad828af6743c68931a0e848bfcdec53.tar.gz
emacs-a2657993bad828af6743c68931a0e848bfcdec53.zip
I DECLARE BANKRUPTCY ... 8
Didn't think to do this till pretty .. written, so here we are.
Diffstat (limited to 'lisp/acdw-eshell.el')
-rw-r--r--lisp/acdw-eshell.el93
1 files changed, 0 insertions, 93 deletions
diff --git a/lisp/acdw-eshell.el b/lisp/acdw-eshell.el deleted file mode 100644 index eedcc8b..0000000 --- a/lisp/acdw-eshell.el +++ /dev/null
@@ -1,93 +0,0 @@
1;;; acdw-eshell.el -*- lexical-binding: t; coding: utf-8-unix -*-
2
3;; Author: Case Duckworth <(rot13-string "npqj@npqj.arg")>
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(defun eshell-quit-or-delete-char (arg)
26 "Delete the character to the right, or quit eshell on an empty line."
27 (interactive "p")
28 (if (and (eolp) (looking-back eshell-prompt-regexp))
29 (eshell-life-is-too-much)
30 (delete-forward-char arg)))
31
32;;;###autoload
33(defun eshell-pop-or-quit (&optional buffer-name)
34 "Pop open an eshell buffer, or if in an eshell buffer, bury it."
35 (interactive)
36 (if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*")))
37 (eshell-life-is-too-much)
38 (with-message "Starting eshell"
39 (eshell))))
40
41
42;;; Insert previous arguments
43;; Record arguments
44
45(defvar eshell-arg-history nil)
46(defvar eshell-arg-history-index nil)
47(add-to-list 'savehist-additional-variables 'eshell-arg-history)
48
49(defun eshell-record-args (&rest _)
50 "Record unique arguments onto the front of `eshell-arg-history'."
51 (setq eshell-arg-history
52 (cl-loop with history = eshell-arg-history
53 for arg in (reverse eshell-last-arguments)
54 do (setq history (cons arg (remove arg history)))
55 finally return history)))
56
57(defun eshell-insert-prev-arg ()
58 "Insert an argument from `eshell-arg-history' at point."
59 (interactive)
60 (if (eq last-command 'eshell-insert-prev-arg)
61 (progn
62 (let ((pos (point)))
63 (eshell-backward-argument 1)
64 (delete-region (point) pos))
65 (if-let ((text (nth eshell-arg-history-index
66 eshell-arg-history)))
67 (progn
68 (insert text)
69 (cl-incf eshell-arg-history-index))
70 (insert (cl-first eshell-arg-history))
71 (setq eshell-arg-history-index 1)))
72 (insert (cl-first eshell-arg-history))
73 (setq eshell-arg-history-index 1)))
74
75(add-hook 'eshell-mode-hook
76 (lambda ()
77 (add-hook 'eshell-post-command-hook
78 #'eshell-record-args nil t)
79 (local-set-key (kbd "M-.") #'eshell-insert-prev-arg)))
80
81;;;###autoload
82(define-minor-mode eshell-arg-hist-mode
83 "Minor mode to enable argument history, like bash/zsh with M-."
84 :lighter "$."
85 :keymap (let ((map (make-sparse-keymap)))
86 (define-key map (kbd "M-.") #'eshell-insert-prev-arg)
87 map)
88 (if eshell-arg-hist-mode
89 (add-hook 'eshell-post-command-hook #'eshell-record-args nil t)
90 (remove-hook 'eshell-post-command-hook #'eshell-record-args t)))
91
92(provide 'acdw-eshell)
93;;; acdw-eshell.el ends here