Skip to content

Instantly share code, notes, and snippets.

@treyharris
Last active September 20, 2019 18:22
Show Gist options
  • Save treyharris/efd1fe33d7ea8d1a345e3a7d0b1e60b5 to your computer and use it in GitHub Desktop.
Save treyharris/efd1fe33d7ea8d1a345e3a7d0b1e60b5 to your computer and use it in GitHub Desktop.
;; Already defined elsewhere, but including in this Gist for context
(defgroup my-customizations nil
"Custom variables introduces in the user init file."
)
(defcustom my-read-only-file-list '()
"Filenames or patterns that will be opened read-only."
:group 'my-customizations
:type '(repeat string)
)
(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)
))
)
(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