summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-eshell.el94
-rw-r--r--lisp/acdw.el31
2 files changed, 125 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
diff --git a/lisp/acdw.el b/lisp/acdw.el index 94f3e64..f227c94 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -474,6 +474,37 @@ Then, build `browse-url-button-regexp' with the new protocol."
474 (add-to-list 'acdw/button-protocols proto) 474 (add-to-list 'acdw/button-protocols proto)
475 (setq-default browse-url-button-regexp (acdw/build-button-url-regexp))) 475 (setq-default browse-url-button-regexp (acdw/build-button-url-regexp)))
476 476
477
478;;; Recentf renaming with dired
479;; from ... somewhere. 'rjs', apparently?
480;; I'm throwing these here because they look better here than in init.el.
481;; Comments are "rjs"'s.
482
483;; Magic advice to rename entries in recentf when moving files in
484;; dired.
485(defun rjs/recentf-rename-notify (oldname newname &rest args)
486 (if (file-directory-p newname)
487 (rjs/recentf-rename-directory oldname newname)
488 (rjs/recentf-rename-file oldname newname)))
489
490(defun rjs/recentf-rename-file (oldname newname)
491 (setq recentf-list
492 (mapcar (lambda (name)
493 (if (string-equal name oldname)
494 newname
495 oldname))
496 recentf-list)))
497
498(defun rjs/recentf-rename-directory (oldname newname)
499 ;; oldname, newname and all entries of recentf-list should already
500 ;; be absolute and normalised so I think this can just test whether
501 ;; oldname is a prefix of the element.
502 (setq recentf-list
503 (mapcar (lambda (name)
504 (if (string-prefix-p oldname name)
505 (concat newname (substring name (length oldname)))
506 name))
507 recentf-list)))
477 508
478 509
479;;; Minor modes 510;;; Minor modes