Since my .emacs.d is a symbolic link of ~/dotfile/dot/.emacs.d, recentf keeps duplicated thing like


because some command/functions the symbolic link path and some use the real one.

How to let recentf not to remember real path when there's a symbolic link of a parent directory ? The real path is so long, I prefer the short one.

I used

(defvar recentf--exclude-remote-regexp "\\/\\w*?:\\w*?@\\w*?:\\/")
 (defun recentf//file-symbolic-link-in-recentf-list (file)
   "Test whether there's a symbolic parent of FILE in `recentf-list'."
   (cl-some (lambda (x)
              (and (string= (file-truename x) file)
                   (not (string= x file))))

 (defun recentf//exclude-symbolic-vc-files (file)
   "Exclude local FILE that has a symbolic parent in `recentf-list'."
   ;; Unless the file is local
   (unless (string-match recentf--exclude-remote-regexp file)
     (recentf//file-symbolic-link-in-recentf-list file)))
 (add-to-list 'recentf-exclude #'recentf//exclude-symbolic-vc-files)

before, but this is a bit slow which take almost 2 second to handle with a recentf-listin length of 500.

Also I find that there's recentf-filename-handlers which may be used to combine with directory-abbrev-alist. But this require manually add all the mappings.

Any suggestions will be appreciated! Thanks!

  • Is the option vc-follow-symlinks sufficient? gnu.org/software/emacs/manual/html_node/emacs/…
    – xuhdev
    Nov 17, 2016 at 9:36
  • @xuhdev Nope, it isn't. I set it to t long before ago. I guess we should handle this in recentf. Nov 17, 2016 at 13:55
  • How about adding a function to recentf-mode-hook to do the cleanup?
    – xuhdev
    Nov 17, 2016 at 20:33
  • The function I listed does the trick, but it takes O(n^2) and a bit slow. I wonder there's a better way to achieve it . Nov 17, 2016 at 23:06
  • 1
    For posterity: I wanted something similar, namely to not include files in folders which are symlinks (meaning file-symlink-p is insufficient as a predicate), and using (add-to-list 'recentf-exclude (lambda (f) (not (string= (file-truename f) f)))) (adapted from this question) works in combination with setting find-file-visit-truename to non-nil to keep only the real paths in recentf. Thanks!
    – Andy
    Oct 15, 2018 at 3:04


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.