licht1stein / obsidian.el

Obsidian Notes for Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`obsidian-follow-link-at-point` wrongly converts ASCII apostrophes to Unicode right single quotation mark

gabriel-francischini opened this issue · comments

This obsidian link behaves differently between Obsidian and obsidian-mode's obsidian-follow-link-at-point:

[[bushnell's law|pequeno número de regras mas ainda assim interessantes]]

In Obsidian, it would open the file bushnell's law.md however obsidian-follow-link-at-point interprets it as a link to bushnell’s law.md.

The only difference is between the apostrophes, vs ':

Printable Hexcode Unicode Point Unicode Character
' 27 U+0027 APOSTROPHE
e2 80 99 U+2019 RIGHT SINGLE QUOTATION MARK

Here's the obsidian note with the link that causes this issue. The linked note was created inside Obsidian by double-clicking on its link and only later the link was opened on emacs through obsidian-follow-link-at-point, which opened a blank buffer. That blank buffer was named bushnell’s law.md (with the U+2019), hinting that it might have been created due to bushnell’s law.md (the U+2019 one) not existing even though bushnell's law.md (the U+0027 one) already existed. I had ran obsidian-update before opening any notes (or my vault) inside emacs.

Both notes were written in Portuguese with Obsidian configured as English, but that shouldn't cause this bug.

Other ASCII characters or Unicode points may also be affected by this bug.

Here are all notes involved, in case you want to inspect their contents:

Filename Role
chess is the drosophila of ai.md Original note
bushnell's law.md Linked note
bushnell’s law.md Blank note

Here's my obsidian-mode configuration if it helps, copied straight out of the README.org:

(use-package obsidian
  :ensure t
  :demand t
  :config
  (obsidian-specify-path "/mnt/p/pCloud-TCC/Obsidian Vault/TCC")
  (global-obsidian-mode t)
  ;; :custom
  ;; ;; This directory will be used for `obsidian-capture' if set.
  ;; (obsidian-inbox-directory "Inbox")
  :bind
  (:map obsidian-mode-map
        ;; Replace C-c C-o with Obsidian.el's implementation. It's ok to use another key binding.
        ("C-c C-o" . obsidian-follow-link-at-point)
        ;; Jump to backlinks
        ("C-c C-b" . obsidian-backlink-jump)
        ;; If you prefer you can use `obsidian-insert-link'
        ("C-c C-l" . obsidian-insert-wikilink)))

Apparently, on both Doom Emacs and vanilla Emacs (emacs-gtk) the message function returns a prettified version of the string passed to it (i.e. it converts U+0027 into U+2019).

message is called by obsidian-follow-wiki-link-at-point which is called by obsidian-follow-link-at-point:

(defun obsidian-follow-wiki-link-at-point ()
  "Find Wiki Link at point."
  (interactive)
  ;; (obsidian-wiki-link-p)
  (thing-at-point-looking-at markdown-regex-wiki-link)
  (let* ((url (->> (match-string-no-properties 3)
                   s-trim)))
    (if (s-contains-p ":" url)
        (browse-url url)
      (-> url
          obsidian-prepare-file-path
          obsidian-wiki->normal
          message
          obsidian-find-file))))

Replacing the call to message with the identity function solves this issue on my machine:

(defun obsidian-follow-wiki-link-at-point ()
  "Find Wiki Link at point."
  (interactive)
  ;; (obsidian-wiki-link-p)
  (thing-at-point-looking-at markdown-regex-wiki-link)
  (let* ((url (->> (match-string-no-properties 3)
                   s-trim)))
    (if (s-contains-p ":" url)
        (browse-url url)
      (-> url
          obsidian-prepare-file-path
          obsidian-wiki->normal
          ((lambda (i) (message i) i)   )
          obsidian-find-file))))

@gabriel-francischini thank you for such extensive issue and a PR to fix it! I'm very grateful that you took the time to do it. Please check the linting and testing errors produced by the CI on your PR. Thank you!