reddit / emacs

org-store-link overrides the default org-mode behavior

Constant_Try_2065 · 2022-12-22 21:06
organic-bookworm · 2022-12-24 12:20
[Doom sets `org-id-link-to-org-use-id`](https://github.com/doomemacs/doomemacs/blob/d5ccac5d71c819035fa251f01d023b3f94b4fba4/modules/lang/org/contrib/roam2.el#L103-L104) in `org-roam` files, which makes `org-store-link` to use `org-id-store-link`, which doesn't store element context. [Doom extends `id` links to support `id:<id>::<search>` format](https://github.com/doomemacs/doomemacs/blob/d5ccac5d71c819035fa251f01d023b3f94b4fba4/modules/lang/org/config.el#L639-L659), but it doesn't provide means to capture such links. Here's a *simplistic* snippet to extend `org-id-store-link` to capture element names in Doom's `id` format: (defun my/org-id-store-link-a (fn &rest args) (when-let ((link (apply fn args))) (when-let ((name (org-element-property :name (org-element-at-point)))) (setq link (format "%s::%s" link name) org-store-link-plist (plist-put org-store-link-plist :link link))) link)) (advice-add #'org-id-store-link :around #'my/org-id-store-link-a)
Constant_Try_2065 · 2022-12-25 13:54
>(defun my/org-id-store-link-a (fn &rest args) (when-let ((link (apply fn args))) (when-let ((name (org-element-property :name (org-element-at-point)))) (setq link (format "%s::%s" link name) org-store-link-plist (plist-put org-store-link-plist :link link))) link)) (advice-add #'org-id-store-link :around #'my/org-id-store-link-a) Thank you for your suggestion. I am sorry that I tried, but could not utilize it. `org-id-store-link` and `org-store-link` both creates `ID` in the nearest heading and store that link. Note: I tried the cursor is in the `#+name`, and inside the source block.
organic-bookworm · 2022-12-25 15:36
> creates `ID` in the nearest heading and store that link. When the point is at a named element, the `id:` link should now also include the `#+name:` value. Following a link would jump directly to that element. To disable `ID`'s altogether, forget my previous snippet and just do `(setq +org-roam-link-to-org-use-id nil)`.
Constant_Try_2065 · 2022-12-25 17:43
Thank you. Now I get it. It works fine. Great solution.