Skip to content
loading...

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

twitter logo github logo ・1 min read  

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)
                  (read-only-mode)
                ))))
twitter logo DISCUSS
Classic DEV Post from Dec 11 '19

If you work as a dev for a product team, what's it like?

Keisuke URAGO profile image
Programmer, Freelancer in Japan. I often use Python(Django, Scrapy, PyQt, etc.). I interested in web technologies. I am currently recovering from a mild depression. So I trying to work when I can.
Join dev.to