Skip to content

Instantly share code, notes, and snippets.

@farynaio
Last active August 15, 2023 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farynaio/f9d60dab0ad5fbb1cd13a1129c862e9b to your computer and use it in GitHub Desktop.
Save farynaio/f9d60dab0ad5fbb1cd13a1129c862e9b to your computer and use it in GitHub Desktop.
Prevent opening native and straight files in editable mode.
(defvar aok/read-only-folders
'("/usr/share/emacs" "~/.emacs.d/straight")
"Files in these folders will be opened in read-only mode.")
(defun aok/file-set-read-only-if-listed ()
"Set current file buffer as `read-only' if it's in `aok/read-only-folders'."
(when (seq-some (lambda (i) (string-prefix-p (expand-file-name i) buffer-file-name)) aok/read-only-folders)
(read-only-mode 1)))
(add-hook 'find-file-hook 'aok/file-set-read-only-if-listed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment