0

This is a rare occasion when I need it, but I am trying to figure out a way to change colour of font/point based on the path of source file to easily distinguish which file I am editing when I am working on two similar repositories.

(E.g. based on files from /some/path/local_master and /some/path/remote_master).

Any advice?

  • It might be easier to have two separate frames, one for each repo, i.e. use location on the screen rather than color to distinguish them. – NickD Jan 10 at 15:20
0

You could use a directory-local variable. Relevant documentation node.

To use this, you create a file .dir-locals.el in the root of each project dir with contents like:

     ((nil . ((my/is-local . t))))

Then in your config you need to do two things, you need to set the variable as safe so Emacs doesn't prompt you about it whenever it loads a file in that directory, and you need to modify your display however you want based on it. Below is an example:

;; Mark any boolean value as safe.
;; See https://stackoverflow.com/q/19806176/4851078
(put 'my/is-local 'safe-local-variable #'booleanp)

;; Set unfontified text in buffers from the local repo to dark blue
;; See https://www.emacswiki.org/emacs/FacesPerBuffer
(add-hook 'find-file-hook
          #'(lambda ()
              (when (bound-and-true-p my/is-local)
                (buffer-face-set '(:foreground "#003")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.