0

Inspired by John Kitchin's presentation of org-links features in Org-mode 9, I tried to implement a simple functionality for "file" links. Since I am working on several machines, I wanted the link face to show if file exists on disk. So in org-link-set-parameters func for "file" I've put this simple code:

:face '(lambda (path) (if (file-exists-p path)
                          '(:foreground "green")
                        '(:foreground "red")))

It works just fine unless file has Polish characters in its name ("ąęćłóśżź"). Especially after editing the link description with org-insert-link with cursor on the link it's face becomes red (as non existent file), and the path becomes for example like this (assuming the file name is "żółć.org"):

[[file:%C5%BC%C3%B3%C5%82%C4%87.org]]

I was changing the value of file-name-coding-system variable but without any impact for described behaviour.

When I change value of the :follow key to '(lambda (path) (message "%s" (file-exists-p path))) it returns "t". I assume then that it has something to do with filtering file name by different emacs functions but I can't find which would be responsible for wrong behaviour of the ":face" parameter.

I'd appreciate any help to fix that.

  • 1
    Whatever method you're using to create the "file" link has run org-link-escape on the filename, so you should run org-link-unescape to get back the original. – rpluim Jul 27 '18 at 12:21
  • @rpluim I was going to write something similar (referring to url-encode-url instead of org-link-escape). You should consider transforming your comment into an answer. – Tobias Jul 27 '18 at 12:33
  • 2
    You should not play around with file-name-coding-system. If you do so in spite of the warning you can get problems with names of files created and saved with Emacs. – Tobias Jul 27 '18 at 12:39
  • I suspect url-encode-url and org-link-escape are identical except when they're not :-) – rpluim Jul 27 '18 at 12:42
2

Have you tried using org-link-unescape to get back the original filename? Something like:

:face '(lambda (path)
         (if (file-exists-p (org-link-unescape path))
             '(:foreground "green")
           '(:foreground "red"))))
  • BTW, if this works, you might consider filing a bug with org-mode, as the path argument should be the same in both the :follow and :face cases. – rpluim Jul 27 '18 at 13:01
  • Thanks, this is what I was looking for. (I haven't filed any bug before, will have to check this out) – caseneuve Jul 27 '18 at 17:56
0

I just tried, and an Org-mode file with this content works just fine:

[[file:żółć.org]]

C-c o works as expected and visits the file. For some reason C-c o works with the escaped characters as in your example, but I get an error Error during redisplay: (jit-lock-function 33) signaled (error "Not enough arguments for format string") [2 times] in *Messages* with your example.

  • That is not an answer to the question. I think everything essential you wrote is clear to the OP. You should consider to delete this answer. – Tobias Jul 27 '18 at 12: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.