11

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,

Drew
  • 75,699
  • 9
  • 109
  • 225
Adam
  • 1,857
  • 11
  • 32

1 Answers1

9

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.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41
  • 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 '17 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. – John Kitchin May 26 '17 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 '17 at 13:20
  • What does a remote file path look like? You can probably match it with a regexp in a conditional expression. – John Kitchin May 31 '17 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 '17 at 21:31