Skip to content

Instantly share code, notes, and snippets.

@kings2u
Created June 13, 2024 03:54
Show Gist options
  • Save kings2u/5a8acbf0986f0848be66169d2dba7260 to your computer and use it in GitHub Desktop.
Save kings2u/5a8acbf0986f0848be66169d2dba7260 to your computer and use it in GitHub Desktop.
(defun counsel--outline-free-markers (outlines)
"Point all markers in OUTLINES to nil. OUTLINES is an alist as per `counsel-outline-candidates'."
(dolist (outline outlines)
(set-marker (cdr outline) nil)))
;; NOTE revised functions:
(defun counsel-org-goto-all ()
"Go to a different location in any org file."
(interactive)
(let (entries)
(dolist (b (buffer-list))
(with-current-buffer b
(when (derived-mode-p 'org-mode)
(setq entries
(nconc entries
(counsel-outline-candidates
(cdr (assq 'org-mode counsel-outline-settings))
(counsel-org-goto-all--outline-path-prefix)))))))
(ivy-read "Goto: " entries
:history 'counsel-org-goto-history
:action #'counsel-org-goto-action
:caller 'counsel-org-goto-all)
(counsel--outline-free-markers entries)))
(defun counsel-outline ()
"Jump to an outline heading with completion."
(interactive)
(let* ((settings (cdr (assq major-mode counsel-outline-settings)))
(outlines (counsel-outline-candidates settings)))
(ivy-read "Outline: " outlines
:action (or (plist-get settings :action)
#'counsel-outline-action)
:history (or (plist-get settings :history)
'counsel-outline-history)
:preselect (max (1- counsel-outline--preselect) 0)
:caller (or (plist-get settings :caller)
'counsel-outline))
(counsel--outline-free-markers outlines)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment