9

I have the following problem with recentf. If I open a file from commandline like emacs myfile the file myfile doesn't appear in the list of recently opened files (I also checked directly the file .recentf). It doesn't matter if I change and save it or not.

Same problem if I kill emacs (kill $(pgrep emacs)). Even if the file was opened via emacs find-files.

If I open a file via find-files and close emacs properly it works also if I just visit the file without changing or saving anything.

Any ideas how to fix both issues?

To make sure that the problem is not an interference effect with other packages I reduced my .emacs file for test purposes to the follwing:

;; -*-Emacs-Lisp-*-
;; -*- coding:utf-8 -*-

(require 'package)

(package-initialize)

(require 'recentf)
(recentf-mode 1)


;; Usually I use it via helm
;; From http://emacs.stackexchange.com/questions/14282/replace-splash-screen-with-list-of-recentf
;; (require 'helm)
;; (require 'helm-config)

;; (if (< (length command-line-args) 2) 
;; (setq initial-buffer-choice (car (helm-recentf)))
;; )

My emacs version is 24.4.1. The OS is ubuntu vivid. As commandline I use zsh (with urxvt).

student
  • 1,007
  • 9
  • 29
  • Are you sure that files opened from the command-line are not saved to the recentf list when they are modified and written to disk? – François Févotte Aug 27 '15 at 21:09
  • Do you have some sort of alias to start emacs in a special way? Using your reduced `.emacs` file with a standard (debian) emacs, I find that everything works fine for files visited from the command-line. – François Févotte Aug 27 '15 at 21:23

1 Answers1

15

When you open emacs, open several files and exit emacs using C-x C-c (graceful exit), it will call the recentf-save-list function which saves recently opened files to a file specified by recentf-save-file.

On the other hand if you kill emacs using kill, it is NOT a graceful exit and there is no chance for emacs to save the files. So they will not be there in recentf list.

If you want to save files at any point, you can call recentf-save-list

M-x recentf-save-list RET

which saves recent files.

If you don't want to do this manually, you can add a timer which will do that for you every 5 minutes.

(run-at-time (current-time) 300 'recentf-save-list)

Add this to your config. So whenever you open emacs, it will call the function and every 5 minutes (or 300 seconds) it will go on calling that function.

Glorfindel
  • 234
  • 1
  • 5
  • 13
Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • 1
    If I run this on boot in my init.el, it deletes all my recentf files. Maybe I need to add a delay or tell it to run after the first 500 seconds. Is there a way to put a delay? – J Spen Jan 12 '19 at 08:30
  • 1
    @JSpen `(run-at-time "5 min" 300 'recentf-save-list)` -- see the help for `run-at-time`. – Mark Sep 09 '19 at 18:40