Skip to content

Instantly share code, notes, and snippets.

@treyharris
Last active February 2, 2020 20:52
Show Gist options
  • Save treyharris/d0880c9b4f2f09ef9cf3a9f868250c43 to your computer and use it in GitHub Desktop.
Save treyharris/d0880c9b4f2f09ef9cf3a9f868250c43 to your computer and use it in GitHub Desktop.
(defcustom my-read-only-file-list '()
"Filenames or patterns that will be opened read-only."
:group 'my-customizations
:type '(repeat string)
)
;; This defun works if called via:
;; M-: (my-read-only-files)<RET>
;; it sets the buffer read-only iff the file is in my-read-only-file-list
;; but as of Emacs 26, it no longer happens after helm-find-file.
(defun my-read-only-files ()
"Check if current buffer is in the set of files we want to be
loaded read-only, and if so, make it read-only."
(dolist (pattern my-read-only-file-list)
(if (string-match (expand-file-name pattern) buffer-file-name)
(read-only-mode)
))
)
;; If I describe-variable find-file-hook, I see this in the results
(add-hook 'find-file-hook 'my-read-only-files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment