I'm using recentf-mode, part of Emacs. I'd like to open a file from the Open Recent buffer read-only, like if I had opened it via C-x C-r. Maybe if you type C-u in the Open Recent buffer before clicking on the file or typing its number.

Thank you!

  • 1
    Isn't it just as easy to use C-x C-q to make the visited buffer read-only as it is to use C-u before choosing it from the recent-buffers list?
    – Drew
    Commented Feb 5, 2016 at 15:53
  • @Drew Good idea, did not occur to me.
    – Keks Dose
    Commented Feb 6, 2016 at 8:22

1 Answer 1


You can customize recentf-menu-action, from C-h v recentf-menu-action:

recentf-menu-action is a variable defined in ‘recentf.el’. Its value is ‘find-file’

Documentation: Function to invoke with a filename item of the recentf menu. The default is to call ‘find-file’ to edit the selected file.

the default value is find-file, so if you always want read-only, you can just change it to find-file-read-only, if you only want read-only when with C-u, you can write a new function as its value, for example,

(defun find-file-maybe-read-only (f)
  (if current-prefix-arg
      (find-file-read-only f)
    (find-file f)))

(setq recentf-menu-action 'find-file-maybe-read-only)

Notes: prefix arguments doesn't work for number, e.g., C-u 2 doesn't work, though both C-u RET and C-u Clicking work.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.