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.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
You can customize
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.