about summary refs log tree commit diff stats
path: root/init.el
diff options
context:
space:
mode:
Diffstat (limited to 'init.el')
-rw-r--r--init.el110
1 files changed, 22 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))