7

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

/Users/user/.emacs.d/init/init-editor.el
/Users/user/dotfile/dot/.emacs.d/init/init-editor.el

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))))
            recentf-list))

 (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!

Drew
  • 75,699
  • 9
  • 109
  • 225
Saddle Point
  • 481
  • 7
  • 23
  • Is the option `vc-follow-symlinks` sufficient? https://www.gnu.org/software/emacs/manual/html_node/emacs/General-VC-Options.html – xuhdev Nov 17 '16 at 09:36
  • @xuhdev Nope, it isn't. I set it to `t` long before ago. I guess we should handle this in `recentf`. – Saddle Point Nov 17 '16 at 13:55
  • How about adding a function to `recentf-mode-hook` to do the cleanup? – xuhdev Nov 17 '16 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 . – Saddle Point Nov 17 '16 at 23:06
  • If you first put all files in the list to a [hash-table](http://ergoemacs.org/emacs/elisp_hash_table.html), you can achieve `O(nlog n)` – xuhdev Nov 18 '16 at 00:19
  • 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 '18 at 03:04
  • keeping only real paths is exactly what I dont want do do ) They are way too long in some instances Hence symlinks. – RichieHH Apr 24 '21 at 12:28

0 Answers0