Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active February 24, 2024 01:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdtsmith/8602d998116b953725218224b77b8766 to your computer and use it in GitHub Desktop.
Save jdtsmith/8602d998116b953725218224b77b8766 to your computer and use it in GitHub Desktop.
Insert link from consult-org-headings with embark
@bram85
Copy link

bram85 commented Nov 2, 2022

Made an extension to also support consult-outline. Although outline != org, most of the outline modes I work in happens to be Org mode anyway.

(cl-defun my/org-link-heading-here (cand)
  (when-let ((marker (or (get-text-property 0 'consult--candidate cand)
                         (car (get-text-property 0 'consult-location cand)))))
    (save-excursion
      (goto-char marker)
      (org-store-link nil t))
    (org-insert-all-links 1 "" " ")))

(embark-define-keymap embark-consult-org-heading-map
  "Keymap for operating on org headings"
  ("l" 'my/org-link-heading-here))
(add-to-list 'embark-keymap-alist '(consult-org-heading embark-consult-org-heading-map))

(embark-define-keymap embark-consult-outline-map
  "Keymap for operating on org headings listed by consult-outline"
  ("l" 'my/org-link-heading-here))
(add-to-list 'embark-keymap-alist '(consult-location embark-consult-outline-map))

;; make sure it quits to restore point
(setf (alist-get 'my/org-link-heading-here embark-quit-after-action) t)

@jdtsmith
Copy link
Author

jdtsmith commented Nov 2, 2022

Good idea. Does org-store-link know how to deal with outline headings (separate from org headings)?

@bram85
Copy link

bram85 commented Nov 2, 2022

No, org-store-link is outline unaware, and outline-mode is unaware of storing links. I just happened to have a shortcut for outline instead of consult-org-heading.

@jdtsmith
Copy link
Author

jdtsmith commented Feb 4, 2023

Recently, embark has removed embark-define-keymap; updated.

@bram85
Copy link

bram85 commented Feb 5, 2023

The parentheses around ("l" 'my/org-link-heading-here) should be removed.

@jdtsmith
Copy link
Author

jdtsmith commented Feb 9, 2023

Yep, thanks.

@jdtsmith
Copy link
Author

jdtsmith commented Feb 9, 2023

BTW, have you tried consult-org-agenda? Basically it's consult-org-heading across all agenda files. A little slow for giant files but pretty good. I updated the function to correctly handle adding an :ID: and linking to other files.

@bram85
Copy link

bram85 commented Feb 9, 2023

No I didn't, mostly because I use a single Org file per context. But good to know nevertheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment