Move things from init.el to acdw.el and acdw-eshell.el
Probably should've been 2 commits...
This commit is contained in:
parent
b6d56777f5
commit
c698dc9869
110
init.el
110
init.el
|
@ -304,71 +304,31 @@
|
|||
(require 'erc-hl-nicks))))
|
||||
|
||||
(setup eshell
|
||||
(:option eshell-directory-name (acdw/dir "eshell/" t)
|
||||
eshell-aliases-file (acdw/dir "eshell/aliases" t)
|
||||
eshell-kill-on-exit nil)
|
||||
|
||||
(defun eshell-quit-or-delete-char (arg)
|
||||
"Delete the character to the right, or quit eshell on an empty line."
|
||||
(interactive "p")
|
||||
(if (and (eolp) (looking-back eshell-prompt-regexp))
|
||||
(eshell-life-is-too-much)
|
||||
(delete-forward-char arg)))
|
||||
|
||||
(defun eshell-pop-or-quit (&optional buffer-name)
|
||||
"Pop open an eshell buffer, or if in an eshell buffer, bury it."
|
||||
(interactive)
|
||||
(if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*")))
|
||||
(eshell-life-is-too-much)
|
||||
(with-message "Starting eshell"
|
||||
(eshell))))
|
||||
(:also-load acdw-eshell
|
||||
em-smart)
|
||||
|
||||
(:option eshell-aliases-file (acdw/dir "eshell/aliases" t)
|
||||
eshell-directory-name (acdw/dir "eshell/" t)
|
||||
eshell-kill-on-exit nil
|
||||
eshell-review-quick-commands nil
|
||||
eshell-smart-space-goes-to-end t
|
||||
eshell-where-to-jump 'begin)
|
||||
|
||||
(:global "C-c s" eshell-pop-or-quit)
|
||||
|
||||
(defun eshell-mode@setup ()
|
||||
"Set up `eshell' for use.
|
||||
Most customizations must go in this function since `eshell' loads
|
||||
like a dumbass."
|
||||
;; Define keys
|
||||
(dolist (spec '(("C-d" . eshell-quit-or-delete-char)))
|
||||
(define-key eshell-mode-map (kbd (car spec)) (function (cdr spec))))
|
||||
;; Etc.
|
||||
(when (boundp 'simple-modeline--mode-line)
|
||||
(setq mode-line-format '(:eval simple-modeline--mode-line))))
|
||||
|
||||
(add-hook 'eshell-mode-hook
|
||||
(defun eshell-mode@setup ()
|
||||
(define-key eshell-mode-map (kbd "C-d")
|
||||
#'eshell-quit-or-delete-char)
|
||||
(when (boundp 'simple-modeline--mode-line)
|
||||
(setq mode-line-format '(:eval simple-modeline--mode-line)))))
|
||||
|
||||
(with-eval-after-load 'eshell
|
||||
;; Record arguments
|
||||
(defvar my-eshell-arg-history nil)
|
||||
(defvar my-eshell-arg-history-index nil)
|
||||
(add-to-list 'savehist-additional-variables 'my-eshell-arg-history)
|
||||
|
||||
(defun my-eshell-record-args (&rest _)
|
||||
"Record unique arguments onto the front of `my-eshell-arg-history'."
|
||||
(setq my-eshell-arg-history
|
||||
(cl-loop with history = my-eshell-arg-history
|
||||
for arg in (reverse eshell-last-arguments)
|
||||
do (setq history (cons arg (remove arg history)))
|
||||
finally return history)))
|
||||
|
||||
(defun my-eshell-insert-prev-arg ()
|
||||
"Insert an argument from `my-eshell-arg-history' at point."
|
||||
(interactive)
|
||||
(if (eq last-command 'my-eshell-insert-prev-arg)
|
||||
(progn
|
||||
(let ((pos (point)))
|
||||
(eshell-backward-argument 1)
|
||||
(delete-region (point) pos))
|
||||
(if-let ((text (nth my-eshell-arg-history-index
|
||||
my-eshell-arg-history)))
|
||||
(progn
|
||||
(insert text)
|
||||
(cl-incf my-eshell-arg-history-index))
|
||||
(insert (cl-first my-eshell-arg-history))
|
||||
(setq my-eshell-arg-history-index 1)))
|
||||
(insert (cl-first my-eshell-arg-history))
|
||||
(setq my-eshell-arg-history-index 1)))
|
||||
|
||||
(add-hook 'eshell-mode-hook
|
||||
(lambda ()
|
||||
(add-hook 'eshell-post-command-hook
|
||||
#'my-eshell-record-args nil t)
|
||||
(local-set-key (kbd "M-.") #'my-eshell-insert-prev-arg)))))
|
||||
(:hook eshell-mode@setup
|
||||
eshell-arg-hist-mode))
|
||||
|
||||
(setup eww
|
||||
(:option eww-search-prefix "https://duckduckgo.com/html?q="
|
||||
|
@ -578,32 +538,6 @@
|
|||
recentf-auto-cleanup 'mode
|
||||
(append recentf-exclude) (acdw/dir))
|
||||
|
||||
;; Magic advice to rename entries in recentf when moving files in
|
||||
;; dired.
|
||||
(defun rjs/recentf-rename-notify (oldname newname &rest args)
|
||||
(if (file-directory-p newname)
|
||||
(rjs/recentf-rename-directory oldname newname)
|
||||
(rjs/recentf-rename-file oldname newname)))
|
||||
|
||||
(defun rjs/recentf-rename-file (oldname newname)
|
||||
(setq recentf-list
|
||||
(mapcar (lambda (name)
|
||||
(if (string-equal name oldname)
|
||||
newname
|
||||
oldname))
|
||||
recentf-list)))
|
||||
|
||||
(defun rjs/recentf-rename-directory (oldname newname)
|
||||
;; oldname, newname and all entries of recentf-list should already
|
||||
;; be absolute and normalised so I think this can just test whether
|
||||
;; oldname is a prefix of the element.
|
||||
(setq recentf-list
|
||||
(mapcar (lambda (name)
|
||||
(if (string-prefix-p oldname name)
|
||||
(concat newname (substring name (length oldname)))
|
||||
name))
|
||||
recentf-list)))
|
||||
|
||||
(advice-add 'dired-rename-file :after #'rjs/recentf-rename-notify)
|
||||
|
||||
(recentf-mode +1))
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
;;; acdw-eshell.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
||||
|
||||
;; Author: Case Duckworth <acdw@acdw.net>
|
||||
;; Keywords: configuration
|
||||
;; URL: https://tildegit.org/acdw/emacs
|
||||
|
||||
;; This file is NOT part of GNU Emacs.
|
||||
|
||||
;;; License:
|
||||
;; Everyone is permitted to do whatever with this software, without
|
||||
;; limitation. This software comes without any warranty whatsoever,
|
||||
;; but with two pieces of advice:
|
||||
;; - Don't hurt yourself.
|
||||
;; - Make good choices.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cl-lib)
|
||||
|
||||
|
||||
;;; Eshell starting and quitting
|
||||
|
||||
;;;###autoload
|
||||
(defun eshell-quit-or-delete-char (arg)
|
||||
"Delete the character to the right, or quit eshell on an empty line."
|
||||
(interactive "p")
|
||||
(if (and (eolp) (looking-back eshell-prompt-regexp))
|
||||
(eshell-life-is-too-much)
|
||||
(delete-forward-char arg)))
|
||||
|
||||
;;;###autoload
|
||||
(defun eshell-pop-or-quit (&optional buffer-name)
|
||||
"Pop open an eshell buffer, or if in an eshell buffer, bury it."
|
||||
(interactive)
|
||||
(if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*")))
|
||||
(eshell-life-is-too-much)
|
||||
(with-message "Starting eshell"
|
||||
(eshell))))
|
||||
|
||||
|
||||
;;; Insert previous arguments
|
||||
;; Record arguments
|
||||
|
||||
(defvar eshell-arg-history nil)
|
||||
(defvar eshell-arg-history-index nil)
|
||||
(add-to-list 'savehist-additional-variables 'eshell-arg-history)
|
||||
|
||||
(defun eshell-record-args (&rest _)
|
||||
"Record unique arguments onto the front of `eshell-arg-history'."
|
||||
(setq eshell-arg-history
|
||||
(cl-loop with history = eshell-arg-history
|
||||
for arg in (reverse eshell-last-arguments)
|
||||
do (setq history (cons arg (remove arg history)))
|
||||
finally return history)))
|
||||
|
||||
(defun eshell-insert-prev-arg ()
|
||||
"Insert an argument from `eshell-arg-history' at point."
|
||||
(interactive)
|
||||
(if (eq last-command 'eshell-insert-prev-arg)
|
||||
(progn
|
||||
(let ((pos (point)))
|
||||
(eshell-backward-argument 1)
|
||||
(delete-region (point) pos))
|
||||
(if-let ((text (nth eshell-arg-history-index
|
||||
eshell-arg-history)))
|
||||
(progn
|
||||
(insert text)
|
||||
(cl-incf eshell-arg-history-index))
|
||||
(insert (cl-first eshell-arg-history))
|
||||
(setq eshell-arg-history-index 1)))
|
||||
(insert (cl-first eshell-arg-history))
|
||||
(setq eshell-arg-history-index 1)))
|
||||
|
||||
(add-hook 'eshell-mode-hook
|
||||
(lambda ()
|
||||
(add-hook 'eshell-post-command-hook
|
||||
#'eshell-record-args nil t)
|
||||
(local-set-key (kbd "M-.") #'eshell-insert-prev-arg)))
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode eshell-arg-hist-mode
|
||||
"Minor mode to enable argument history, like bash/zsh with M-."
|
||||
:lighter "$."
|
||||
:keymap (let ((map (make-sparse-keymap)))
|
||||
(define-key map (kbd "M-.") #'eshell-insert-prev-arg)
|
||||
map)
|
||||
(if eshell-arg-hist-mode
|
||||
(add-hook 'eshell-post-command-hook #'eshell-record-args nil t)
|
||||
(remove-hook 'eshell-post-command-hook #'eshell-record-args t)))
|
||||
|
||||
(provide 'acdw-eshell)
|
||||
;;; acdw-eshell.el ends here
|
31
lisp/acdw.el
31
lisp/acdw.el
|
@ -474,6 +474,37 @@ Then, build `browse-url-button-regexp' with the new protocol."
|
|||
(add-to-list 'acdw/button-protocols proto)
|
||||
(setq-default browse-url-button-regexp (acdw/build-button-url-regexp)))
|
||||
|
||||
|
||||
;;; Recentf renaming with dired
|
||||
;; from ... somewhere. 'rjs', apparently?
|
||||
;; I'm throwing these here because they look better here than in init.el.
|
||||
;; Comments are "rjs"'s.
|
||||
|
||||
;; Magic advice to rename entries in recentf when moving files in
|
||||
;; dired.
|
||||
(defun rjs/recentf-rename-notify (oldname newname &rest args)
|
||||
(if (file-directory-p newname)
|
||||
(rjs/recentf-rename-directory oldname newname)
|
||||
(rjs/recentf-rename-file oldname newname)))
|
||||
|
||||
(defun rjs/recentf-rename-file (oldname newname)
|
||||
(setq recentf-list
|
||||
(mapcar (lambda (name)
|
||||
(if (string-equal name oldname)
|
||||
newname
|
||||
oldname))
|
||||
recentf-list)))
|
||||
|
||||
(defun rjs/recentf-rename-directory (oldname newname)
|
||||
;; oldname, newname and all entries of recentf-list should already
|
||||
;; be absolute and normalised so I think this can just test whether
|
||||
;; oldname is a prefix of the element.
|
||||
(setq recentf-list
|
||||
(mapcar (lambda (name)
|
||||
(if (string-prefix-p oldname name)
|
||||
(concat newname (substring name (length oldname)))
|
||||
name))
|
||||
recentf-list)))
|
||||
|
||||
|
||||
;;; Minor modes
|
||||
|
|
Loading…
Reference in New Issue