9

I like using recentf mode in Emacs which produces a list of files I have recently opened. This list is persistent between sessions, so I can get to files I used a fairly long time ago.

However, I recently started using Emacsclient to connect to an Emacs server which is automatically turned on when I log it. Overall, this was a big improvement. However, recentf mode started missing most of the files I opened whenever I restarted my computer. It remembers some of them, and I cannot see a pattern in which files get recorded.

How can I fix this behavior? How can I get it to record all the files I visit and remember them between sessions?

4
  • 3
    I have the same problem, would be great to see a solution!
    – student
    Commented Jul 6, 2012 at 19:45
  • I tried this using emacs -nw, loading server and recentf, then running recentf-mode 1 and server-start in that order and was not able to reproduce your problem. Can you post your .emacs file somewhere (such as a pastebin) along with an example of how you're starting emacs and emacsclient?
    – jlp
    Commented Jul 9, 2012 at 9:41
  • Here is my .emacs file. I'm using Fedora and I installed Emacs with Yum; it created a launcher for Emacs Client and that's what I use. The launcher just runs emacsclient -c --alternate-editor="" %f. The problem might be with my not closing Emacs before turning my computer off, but I'm not sure. Manually killing Emacs before shutting off seems to help, but that's not a great solution. Commented Jul 9, 2012 at 20:40
  • Hmmm, I didn't see server-start in your .emacs, I assume it's getting started with --daemon when you log in. I'm suspecting some kind of ordering issue with enabling recentf and starting the server.
    – jlp
    Commented Jul 12, 2012 at 22:02

1 Answer 1

9

I was having this exact same problem, and I solved it by making two changes. First following this post, I created a function to automatically invoke recentf-save-list on a timer. Thus every few minutes, we automatically re-write the ~/.recentf file:

(run-at-time nil (* 5 60) 'recentf-save-list)

The other thing I did was to add a shutdown script to my display manager (lightdm) that gracefully closed the emacs server every time I logout or shutdown. The way you do this will depend on your display manager, but my script simply looks like

#!/bin/bash
emacsclient -e "(save-buffers-kill-emacs)"

It would also be nice to have a hook that automatically re-ran recentf-save-list every time a client "disconnected" from the server, but I couldn't figure out the proper hooks.

1
  • 2
    It's server-done-hook. Personally I use server-visit-hook
    – tungd
    Commented Dec 18, 2012 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .