Strip /sudo:...@ from recent file paths

Also:
+ Refactors recentf config in general, revises/expands its code
  comments, and uses :custom to set file variable (a new convention I'm
  trying out).
+ recentf-auto-cleanup = 300 in daemon sessions, since the old strategy
  of "cleanup on kill-emacs-hook" isn't so great for daemon users.
This commit is contained in:
Henrik Lissner 2021-05-06 15:46:50 -04:00
parent 280bae0331
commit 3b9aee6868

View file

@ -280,26 +280,29 @@ or file path may exist now."
:defer-incrementally easymenu tree-widget timer :defer-incrementally easymenu tree-widget timer
:hook (doom-first-file . recentf-mode) :hook (doom-first-file . recentf-mode)
:commands recentf-open-files :commands recentf-open-files
:custom (recentf-save-file (concat doom-cache-dir "recentf"))
:config :config
(defun doom--recent-file-truename (file) (setq recentf-auto-cleanup nil ; Don't. We'll auto-cleanup on shutdown
(if (or (file-remote-p file nil t) recentf-max-saved-items 200) ; default is 20
(not (file-remote-p file)))
(file-truename file) (defun doom--recentf-file-truename-fn (file)
file)) (if (file-remote-p file)
(setq recentf-filename-handlers (if-let* ((tfile (and (bound-and-true-p tramp-mode)
'(;; Text properties inflate the size of recentf's files, and there is (tramp-tramp-file-p file)
;; no purpose in persisting them, so we strip them out. (tramp-dissect-file-name file)))
substring-no-properties ((string= (tramp-file-name-method tfile) "sudo")))
;; Resolve symlinks of local files. Otherwise we get duplicate (abbreviate-file-name (file-truename (tramp-file-name-localname tfile)))
;; entries opening symlinks. file)
doom--recent-file-truename (abbreviate-file-name (file-truename file))))
;; Replace $HOME with ~, which is more portable, and reduces how much
;; horizontal space the recentf listing uses to list recent files. ;; Resolve symlinks, strip out the /sudo:X@ prefix in local tramp paths, and
abbreviate-file-name) ;; abbreviate $HOME -> ~ in filepaths (more portable, more readable, & saves
recentf-save-file (concat doom-cache-dir "recentf") ;; space)
recentf-auto-cleanup 'never (add-to-list 'recentf-filename-handlers 'doom--recentf-file-truename-fn)
recentf-max-menu-items 0
recentf-max-saved-items 200) ;; Text properties inflate the size of recentf's files, and there is
;; no purpose in persisting them (Must be first in the list!)
(add-to-list 'recentf-filename-handlers 'substring-no-properties)
(add-hook! '(doom-switch-window-hook write-file-functions) (add-hook! '(doom-switch-window-hook write-file-functions)
(defun doom--recentf-touch-buffer-h () (defun doom--recentf-touch-buffer-h ()
@ -311,10 +314,15 @@ or file path may exist now."
(add-hook! 'dired-mode-hook (add-hook! 'dired-mode-hook
(defun doom--recentf-add-dired-directory-h () (defun doom--recentf-add-dired-directory-h ()
"Add dired directory to recentf file list." "Add dired directories to recentf file list."
(recentf-add-file default-directory))) (recentf-add-file default-directory)))
;; The most sensible time to clean up your recent files list is when you quit
;; Emacs (unless this is a long-running daemon session).
(setq recentf-auto-cleanup (if (daemonp) 300))
(add-hook 'kill-emacs-hook #'recentf-cleanup) (add-hook 'kill-emacs-hook #'recentf-cleanup)
;; Otherwise `load-file' calls in `recentf-load-list' pollute *Messages*
(advice-add #'recentf-load-list :around #'doom-shut-up-a)) (advice-add #'recentf-load-list :around #'doom-shut-up-a))