ahyatt / ekg

The emacs knowledge graph, app for notes and structured data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Links are not formatted properly in ekg-notes

Gleek opened this issue · comments

I've observed an issue within the ekg-notes buffer where links are not being displayed correctly. Unlike the expected behavior of showing only the link description, the ekg-notes buffer displays both the link itself and its description. You can refer to the attached screenshot for clarification.

image

Upon inspecting the link displaying logic within org mode, I noticed that org mode uses a folding mechanism for links. However, I encountered difficulty implementing this behavior in a mode derived from fundamental mode. I'm considering exploring the approach used in org-agenda-mode as a potential source of inspiration for solving this issue.

I'm reaching out to inquire if you are familiar with potential workarounds or if there are specific challenges associated with addressing this problem. Any guidance or insights would be greatly appreciated.

Best regards

Thanks for bringing this up. For the notes that are in org-mode (or whatever mode, really), we set up a temporary buffer, and render things in that mode. Here it seems to result in links not displaying correctly, for the reasons you mention. I wonder if we should perhaps not just get the propertized contents of a buffer, but apply folding as well. I have no idea how to do that. It may not even be a good idea, because there's no way to unfold things in the notes buffer, so we'd have to be pretty sure that anything we're doing is to won't hide information that is potentially useful to the user. As part of that, I should also note that you can't follow links in the notes as you would in org-mode.

I'm not against doing something customized for org-mode, so that it appears as just link text, and we can perhaps allow some interaction in the notes buffer. I'm not quite sure how to do either of those things, though, because I haven't looked into this problem.

Perhaps a slightly upleveled view of this problem is to ask how much we want the user to interact with notes in the notes mode, rather than interacting with them by opening the note. If it's the latter (and I think it is), then we can at least do the link folding and be OK with the fact that the links are inoperable without opening the note.

I got some free time today and was able to implement the formatting of links. It was an easy fix apparently. This also now allows the follow of links by clicking on the link. A keymap in ekg-notes-mode-map can also be added to run org-open-at-point to do the same.

The following is the code:

(defun +ekg-format-notes()
  (let ((inhibit-read-only t))
    (save-excursion
      (goto-char (point-min))
      (while (org-activate-links (point-max))
        (goto-char (match-end 0)))
      ;; Go back and activate the first link again as it gets missed in the  iteration
      (goto-char (point-min))
      (org-activate-links (point-max))))
  (+ekg-format-note))

(defun +ekg-format-note ()
  (org-redisplay-inline-images))

(add-hook 'ekg-notes-mode-hook '+ekg-format-notes)
(add-hook 'ekg-capture-mode-hook '+ekg-format-note)
(add-hook 'ekg-edit-mode-hook '+ekg-format-note)

Here's the updated screenshot after the change:
image

I can raise this as a PR, if you wish to have this as a core functionality or we can leave it here in case you don't wish to have this in the package.

PS: The code also activates the display of images in all buffers.

Regards.

Thanks! This looks good, let's just put it in, not as a hook, but as the default formatting behavior.

I'm still wondering what, if anything, we should be doing to let people open links in notes from the notes list buffer. But I don't think it's all that great now, so this doesn't seem harmful.

Great changes @Gleek @ahyatt . I've been always wanting this. Thank you all.