10

If I create a bad [[file:link]] or an internal [[Link]] that does not exist, I would like to org-mode to fontify this using org-warning face. How can I get this done?

Thanks,

1 Answer 1

8

In org-9 it might be as simple as this for file links:

(org-link-set-parameters
 "file"
 :face (lambda (path) (if (file-exists-p path) 'org-link 'org-warning)))

For internal links I don't know an easy way to do it.

5
  • Thanks John! This works great. Is there any way to auto-update this, so that once the file is created, the color changes?
    – Adam
    May 26, 2017 at 22:38
  • Not really. It will change the next time it is refontify. If you change the line or refontify the buffer it should change color I think. May 26, 2017 at 22:48
  • Thanks! Is there a way to limit the checking to local files? Emacs shouldn't try to connect to remote files because of this.
    – Timm
    May 31, 2017 at 13:20
  • What does a remote file path look like? You can probably match it with a regexp in a conditional expression. May 31, 2017 at 13:38
  • 1
    There is file-remote-p, which seems to do the job. I've modified your code in the following way: (org-link-set-parameters "file" :face (lambda (path) (when (not (file-remote-p path))(if (file-exists-p path) 'org-link 'org-warning))))
    – Timm
    May 31, 2017 at 21:31

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.