Created
March 23, 2020 15:34
-
-
Save codecoll/678a636716404df1c2792454487da881 to your computer and use it in GitHub Desktop.
Expand org search matches into a separate buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun org-expand-search-matches () | |
(interactive) | |
(let (markers) | |
(save-excursion | |
(goto-char (point-min)) | |
(while (not (eobp)) | |
(if (org-get-at-bol 'org-marker) | |
(push (org-get-at-bol 'org-marker) markers)) | |
(forward-line 1))) | |
(switch-to-buffer "*orgnotes*") | |
(erase-buffer) | |
(let ((separator (make-string (window-width) ?―)) | |
start end) | |
(dolist (marker markers) | |
(setq start (point)) | |
(insert (with-current-buffer (marker-buffer marker) | |
(goto-char (marker-position marker)) | |
(setq end (org-entry-end-position)) | |
(font-lock-ensure (point) end) | |
(buffer-substring (point) end)) | |
separator | |
"\n") | |
(put-text-property start (point) | |
'orgnotes-location | |
(list 'buffer (marker-buffer marker) | |
'pos (marker-position marker))))) | |
(goto-char (point-min)) | |
(let ((map (make-sparse-keymap))) | |
(suppress-keymap map) | |
(define-key map (kbd "<RET>") (lambda () | |
(interactive) | |
(let ((prop (get-text-property | |
(point) 'orgnotes-location))) | |
(switch-to-buffer (plist-get prop 'buffer)) | |
(goto-char (plist-get prop 'pos)) | |
(outline-show-entry)))) | |
(use-local-map map)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment