11

I renamed few files using Dired. I noticed helm shows old names in the list of recent files (helm-recentf).

How do I remove the files that do not exist from recent files list?

Drew
  • 75,699
  • 9
  • 109
  • 225
Andrew-Dufresne
  • 293
  • 4
  • 12
  • Not sure it helps, however, just to be sure, did you try to type the 'g' letter? This is the usual key you must type to update stuff like 'dired', 'magit' etc... – Picaud Vincent Nov 30 '17 at 13:13
  • Where do I type it? – Andrew-Dufresne Nov 30 '17 at 13:23
  • 1
    Thank you Picaud but this does not work with `helm-recentf`. Because it only shows a text field that is used to filter the list of recent files. As soon as I type `g` it is evaluated as the search pattern. – Andrew-Dufresne Nov 30 '17 at 13:58

1 Answers1

21

How do I remove the files that do not exist from recent files list?

M-xrecentf-cleanupRET

recentf-cleanup is an interactive compiled Lisp function in
‘recentf.el’.

(recentf-cleanup)

Cleanup the recent list.
That is, remove duplicates, non-kept, and excluded files.

See also the user options recentf-auto-cleanup:

recentf-auto-cleanup is a variable defined in ‘recentf.el’.
Its value is ‘mode’

Documentation:
Define when to automatically cleanup the recent list.
The following values can be set:

- ‘mode’
Cleanup when turning the mode on (default).
- ‘never’
Never cleanup the list automatically.
- A number
Cleanup each time Emacs has been idle that number of seconds.
- A time string
Cleanup at specified time string, for example at "11:00pm".

Setting this variable directly does not take effect;
use M-x customize.

See also the command ‘recentf-cleanup’, that can be used to manually
cleanup the list.

You can customize this variable.

as well as recentf-keep and recentf-exclude for more granular control over what is allowed into recentf-list. The default value of recentf-keep ensures non-readable files are removed from the list.


See also M-xrecentf-edit-listRET:

recentf-edit-list is an interactive compiled Lisp function in `recentf.el'.

(recentf-edit-list)

Show a dialog to delete selected files from the recent list.
Basil
  • 12,019
  • 43
  • 69
  • Wouldn't make more sense to set a maximum length for the history? – rph Jun 20 '19 at 17:24
  • @rph Sorry, I fail to see what history length has to do with either the question in the OP or my answer. The question is clearly about removing non-existent files from the cached recent file list. – Basil Jun 20 '19 at 23:31
  • I keep cleaning my list but whenevet I reopen my emacs daemon everyhing shows up again @Basil – alper May 03 '20 at 12:49
  • 1
    @alper `recentf-cleanup` does not empty `recentf-list`. Try setting `recentf-list` to the empty list, either directly or by calling `recentf-edit-list`, followed by `recentf-save-list`. – Basil May 03 '20 at 13:04
  • I have also done that but I think emacs-daemon keeps its own copy samewhere and keep overwriting into the empty `recentf` file – alper May 03 '20 at 14:16
  • @alper Sorry, I can't help you without more information. Try reproducing the issue starting with `emacs -Q`. If you can't, then your configuration or one of the packages you've installed could be at fault. If you can, then please report it as a bug via `M-x report-emacs-bug`. – Basil May 03 '20 at 18:31
  • @alper That's still not enough information for me to be able to help you. Please try narrowing down which part of your configuration gives rise to the issue, ideally by starting Emacs as `emacs -Q`. – Basil Jul 13 '20 at 17:42
  • @alper This Emacs Stack Exchange comments section is not the best place to get help with Emacs issues. For that, there is the [`help-gnu-emacs`](https://lists.gnu.org/mailman/listinfo/help-gnu-emacs) mailing list and `M-x report-emacs-bug RET`. Alternatively, you can ask a new question on the Emacs SE. – Basil Jul 13 '20 at 17:43
  • Ok sorry for asking here – alper Jul 13 '20 at 17:44
  • What should I use to set recentf-auto-cleanup? Is `(customize-set-value recentf-auto-cleanup 3600)` good enough? – HappyFace Jul 30 '20 at 09:44
  • 1
    @HappyFace `customize-set-value` is only useful for interactive use, or for setting a `variable-comment` property; otherwise you can just use `setq` or `setq-default`. If you want the function `recentf-auto-cleanup` to be called after you set the user option `recentf-auto-cleanup`, then you should use `customize-set-variable` instead, as this makes sure to call the user option's custom `:set` function. – Basil Aug 10 '20 at 09:07
  • "The default value of recentf-keep ensures non-readable files are removed from the list." I have a different experience - I executed `recentf-cleanup` and it removed 0 files from the list, even though it contains lots of deleted and moved files... – xeruf Nov 27 '20 at 11:21
  • @Xerus Precisely what is kept and isn't depends on the user options `recentf-exclude` and `recentf-keep`, which in turn defaults to the function `recentf-keep-default-predicate`, which returns `nil` for unreadable files. I can't comment further on your setup without more information, based only on a comment such as "it doesn't work". If you think something isn't working correctly, try debugging it or report it upstream via `M-x report-emacs-bug RET`. – Basil Nov 27 '20 at 15:45