diff options
author | Case Duckworth | 2021-05-12 16:41:58 -0500 |
---|---|---|
committer | Case Duckworth | 2021-05-12 16:41:58 -0500 |
commit | 05ea83385ba5478f7463d99e13b615e166c599eb (patch) | |
tree | 82646b166198799e8f517264f42f520eaf1fedad | |
parent | Merge branch 'main' of https://tildegit.org/acdw/emacs (diff) | |
download | emacs-05ea83385ba5478f7463d99e13b615e166c599eb.tar.gz emacs-05ea83385ba5478f7463d99e13b615e166c599eb.zip |
Make recentf dired-aware
-rw-r--r-- | init.el | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/init.el b/init.el index 24d71ed..9d2fa33 100644 --- a/init.el +++ b/init.el | |||
@@ -450,8 +450,37 @@ | |||
450 | (:option recentf-save-file (acdw/dir "recentf.el") | 450 | (:option recentf-save-file (acdw/dir "recentf.el") |
451 | recentf-max-menu-items 100 | 451 | recentf-max-menu-items 100 |
452 | recentf-max-saved-items nil | 452 | recentf-max-saved-items nil |
453 | recentf-auto-cleanup 60 | 453 | recentf-auto-cleanup 'mode |
454 | (append recentf-exclude) (acdw/dir)) | 454 | (append recentf-exclude) (acdw/dir)) |
455 | |||
456 | ;; Magic advice to rename entries in recentf when moving files in | ||
457 | ;; dired. | ||
458 | (defun rjs/recentf-rename-notify (oldname newname &rest args) | ||
459 | (if (file-directory-p newname) | ||
460 | (rjs/recentf-rename-directory oldname newname) | ||
461 | (rjs/recentf-rename-file oldname newname))) | ||
462 | |||
463 | (defun rjs/recentf-rename-file (oldname newname) | ||
464 | (setq recentf-list | ||
465 | (mapcar (lambda (name) | ||
466 | (if (string-equal name oldname) | ||
467 | newname | ||
468 | oldname)) | ||
469 | recentf-list))) | ||
470 | |||
471 | (defun rjs/recentf-rename-directory (oldname newname) | ||
472 | ;; oldname, newname and all entries of recentf-list should already | ||
473 | ;; be absolute and normalised so I think this can just test whether | ||
474 | ;; oldname is a prefix of the element. | ||
475 | (setq recentf-list | ||
476 | (mapcar (lambda (name) | ||
477 | (if (string-prefix-p oldname name) | ||
478 | (concat newname (substring name (length oldname))) | ||
479 | name)) | ||
480 | recentf-list))) | ||
481 | |||
482 | (advice-add 'dired-rename-file :after #'rjs/recentf-rename-notify) | ||
483 | |||
455 | (recentf-mode +1)) | 484 | (recentf-mode +1)) |
456 | 485 | ||
457 | (setup (:require savehist) | 486 | (setup (:require savehist) |