DEV Community

Keisuke URAGO
Keisuke URAGO

Posted on

How to set up Emacs to open read-only depending on file location

In order to prevent accidental editing of a file when opening a library of virtual environments such as virtualenv, if you change the Emacs setting, you can open it automatically in read-only state without executing C-x C-q.

An example of setting targeting pyenv's directory is as follows.

(add-hook 'find-file-hook
          (lambda ()
            (dolist (pattern '("~/.pyenv/versions/.*"
                               ;; add here
              (if (string-match (expand-file-name pattern) buffer-file-name)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)