summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.el110
-rw-r--r--lisp/acdw-eshell.el94
-rw-r--r--lisp/acdw.el31
3 files changed, 147 insertions, 88 deletions
diff --git a/init.el b/init.el index d3cabc4..1eea127 100644 --- a/init.el +++ b/init.el
@@ -304,71 +304,31 @@
304 (require 'erc-hl-nicks)))) 304 (require 'erc-hl-nicks))))
305 305
306(setup eshell 306(setup eshell
307 (:option eshell-directory-name (acdw/dir "eshell/" t) 307 (:also-load acdw-eshell
308 eshell-aliases-file (acdw/dir "eshell/aliases" t) 308 em-smart)
309 eshell-kill-on-exit nil) 309
310 310 (:option eshell-aliases-file (acdw/dir "eshell/aliases" t)
311 (defun eshell-quit-or-delete-char (arg) 311 eshell-directory-name (acdw/dir "eshell/" t)
312 "Delete the character to the right, or quit eshell on an empty line." 312 eshell-kill-on-exit nil
313 (interactive "p") 313 eshell-review-quick-commands nil
314 (if (and (eolp) (looking-back eshell-prompt-regexp)) 314 eshell-smart-space-goes-to-end t
315 (eshell-life-is-too-much) 315 eshell-where-to-jump 'begin)
316 (delete-forward-char arg)))
317
318 (defun eshell-pop-or-quit (&optional buffer-name)
319 "Pop open an eshell buffer, or if in an eshell buffer, bury it."
320 (interactive)
321 (if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*")))
322 (eshell-life-is-too-much)
323 (with-message "Starting eshell"
324 (eshell))))
325 316
326 (:global "C-c s" eshell-pop-or-quit) 317 (:global "C-c s" eshell-pop-or-quit)
318
319 (defun eshell-mode@setup ()
320 "Set up `eshell' for use.
321Most customizations must go in this function since `eshell' loads
322like a dumbass."
323 ;; Define keys
324 (dolist (spec '(("C-d" . eshell-quit-or-delete-char)))
325 (define-key eshell-mode-map (kbd (car spec)) (function (cdr spec))))
326 ;; Etc.
327 (when (boundp 'simple-modeline--mode-line)
328 (setq mode-line-format '(:eval simple-modeline--mode-line))))
327 329
328 (add-hook 'eshell-mode-hook 330 (:hook eshell-mode@setup
329 (defun eshell-mode@setup () 331 eshell-arg-hist-mode))
330 (define-key eshell-mode-map (kbd "C-d")
331 #'eshell-quit-or-delete-char)
332 (when (boundp 'simple-modeline--mode-line)
333 (setq mode-line-format '(:eval simple-modeline--mode-line)))))
334
335 (with-eval-after-load 'eshell
336 ;; Record arguments
337 (defvar my-eshell-arg-history nil)
338 (defvar my-eshell-arg-history-index nil)
339 (add-to-list 'savehist-additional-variables 'my-eshell-arg-history)
340
341 (defun my-eshell-record-args (&rest _)
342 "Record unique arguments onto the front of `my-eshell-arg-history'."
343 (setq my-eshell-arg-history
344 (cl-loop with history = my-eshell-arg-history
345 for arg in (reverse eshell-last-arguments)
346 do (setq history (cons arg (remove arg history)))
347 finally return history)))
348
349 (defun my-eshell-insert-prev-arg ()
350 "Insert an argument from `my-eshell-arg-history' at point."
351 (interactive)
352 (if (eq last-command 'my-eshell-insert-prev-arg)
353 (progn
354 (let ((pos (point)))
355 (eshell-backward-argument 1)
356 (delete-region (point) pos))
357 (if-let ((text (nth my-eshell-arg-history-index
358 my-eshell-arg-history)))
359 (progn
360 (insert text)
361 (cl-incf my-eshell-arg-history-index))
362 (insert (cl-first my-eshell-arg-history))
363 (setq my-eshell-arg-history-index 1)))
364 (insert (cl-first my-eshell-arg-history))
365 (setq my-eshell-arg-history-index 1)))
366
367 (add-hook 'eshell-mode-hook
368 (lambda ()
369 (add-hook 'eshell-post-command-hook
370 #'my-eshell-record-args nil t)
371 (local-set-key (kbd "M-.") #'my-eshell-insert-prev-arg)))))
372 332
373(setup eww 333(setup eww
374 (:option eww-search-prefix "https://duckduckgo.com/html?q=" 334 (:option eww-search-prefix "https://duckduckgo.com/html?q="
@@ -578,32 +538,6 @@
578 recentf-auto-cleanup 'mode 538 recentf-auto-cleanup 'mode
579 (append recentf-exclude) (acdw/dir)) 539 (append recentf-exclude) (acdw/dir))
580 540
581 ;; Magic advice to rename entries in recentf when moving files in
582 ;; dired.
583 (defun rjs/recentf-rename-notify (oldname newname &rest args)
584 (if (file-directory-p newname)
585 (rjs/recentf-rename-directory oldname newname)
586 (rjs/recentf-rename-file oldname newname)))
587
588 (defun rjs/recentf-rename-file (oldname newname)
589 (setq recentf-list
590 (mapcar (lambda (name)
591 (if (string-equal name oldname)
592 newname
593 oldname))
594 recentf-list)))
595
596 (defun rjs/recentf-rename-directory (oldname newname)
597 ;; oldname, newname and all entries of recentf-list should already
598 ;; be absolute and normalised so I think this can just test whether
599 ;; oldname is a prefix of the element.
600 (setq recentf-list
601 (mapcar (lambda (name)
602 (if (string-prefix-p oldname name)
603 (concat newname (substring name (length oldname)))
604 name))
605 recentf-list)))
606
607 (advice-add 'dired-rename-file :after #'rjs/recentf-rename-notify) 541 (advice-add 'dired-rename-file :after #'rjs/recentf-rename-notify)
608 542
609 (recentf-mode +1)) 543 (recentf-mode +1))
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