1

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 Feb 5 '16 at 15:53
  • @Drew Good idea, did not occur to me. – Keks Dose Feb 6 '16 at 8:22
2

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, privacy policy and cookie policy

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