Add: Bookmark support

This commit is contained in:
Adam Porter 2020-11-02 20:14:43 -06:00
parent 57708e6cc1
commit e5b4cd1065
3 changed files with 59 additions and 19 deletions

View file

@ -407,6 +407,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience
*Added* *Added*
+ View dispatcher using =transient.el= (like Magit), bound to =v= in search/view buffers. + View dispatcher using =transient.el= (like Magit), bound to =v= in search/view buffers.
+ Predicate =link=, which matches descriptions and targets in Org links. + Predicate =link=, which matches descriptions and targets in Org links.
+ Emacs bookmark support: Org QL View buffers can be bookmarked with, e.g. =C-x r m= and shown with, e.g. =C-x r b=. (This also enables view restoration with [[https://github.com/alphapapa/burly.el][Burly]].)
+ Mascot. + Mascot.
*Changed* *Changed*

View file

@ -428,6 +428,7 @@ subsequent refreshing of the buffer: `org-ql-view-buffers-files',
(null (org-ql-view--buffer buffer)) (null (org-ql-view--buffer buffer))
(buffer buffer)))) (buffer buffer))))
(with-current-buffer buffer (with-current-buffer buffer
(setq-local bookmark-make-record-function #'org-ql-view--bookmark-make-record)
(use-local-map org-ql-view-map) (use-local-map org-ql-view-map)
;; Prepare buffer, saving data for refreshing. ;; Prepare buffer, saving data for refreshing.
(cl-loop for symbol in vars (cl-loop for symbol in vars
@ -519,6 +520,40 @@ dates in the past, and negative for dates in the future."
(format "in %sd" (* -1 difference))) (format "in %sd" (* -1 difference)))
(t "today"))) (t "today")))
;;;; Bookmarks
;; Support for Emacs bookmarks.
(eval-when-compile
(require 'bookmark))
(defun org-ql-view--bookmark-make-record ()
"Return a bookmark record for the current Org QL View buffer."
(list (concat "Org QL View: " org-ql-view-title)
(cons 'org-ql-view-plist (org-ql-view--plist (current-buffer)))
(cons 'handler #'org-ql-view--bookmark-handler)
(cons 'position (point))))
;;;###autoload
(defun org-ql-view--bookmark-handler (bookmark)
"Show Org QL View BOOKMARK in current buffer."
(pcase-let* (((map org-ql-view-plist) (bookmark-get-bookmark-record bookmark))
((map :buffers-files :query :super-groups :narrow :sort :title)
org-ql-view-plist)
(super-groups (cl-etypecase super-groups
(symbol (symbol-value super-groups))
(list super-groups))))
(org-ql-search buffers-files query
:super-groups super-groups :narrow narrow :sort sort :title title)
;; HACK: `bookmark--jump-via' expects that, when the handler returns, the current buffer
;; (not merely the selected window's buffer) is the one to be displayed. However,
;; `org-ql-view--display' uses `with-current-buffer', which resets the current buffer to
;; the one that was active when the bookmark was jumped to. So we set the buffer before
;; returning. It might be better to refactor `org-ql-view--display' into a function that
;; returns a buffer which can be displayed by the calling function. But that would be
;; more complicated and might introduce bugs elsewhere, so we'll just do this for now.
(set-buffer (window-buffer (selected-window)))))
;;;; Transient ;;;; Transient
;; This section uses `transient' to allow the user to easily modify ;; This section uses `transient' to allow the user to easily modify

View file

@ -750,6 +750,10 @@ File: README.info, Node: 05-pre, Next: 046, Up: Changelog
search/view buffers. search/view buffers.
• Predicate link, which matches descriptions and targets in Org • Predicate link, which matches descriptions and targets in Org
links. links.
• Emacs bookmark support: Org QL View buffers can be bookmarked with,
e.g. C-x r m and shown with, e.g. C-x r b. (This also enables
view restoration with Burly
(https://github.com/alphapapa/burly.el).)
• Mascot. • Mascot.
*Changed* *Changed*
@ -1187,25 +1191,25 @@ Node: Agenda-like views19768
Node: Listing / acting-on results21173 Node: Listing / acting-on results21173
Node: Changelog25775 Node: Changelog25775
Node: 05-pre26414 Node: 05-pre26414
Node: 04626778 Node: 04627003
Node: 04527181 Node: 04527406
Node: 04427540 Node: 04427765
Node: 04327897 Node: 04328122
Node: 04228092 Node: 04228317
Node: 04128251 Node: 04128476
Node: 0428490 Node: 0428715
Node: 03232421 Node: 03232646
Node: 03132798 Node: 03133023
Node: 0332995 Node: 0333220
Node: 02335970 Node: 02336195
Node: 02236198 Node: 02236423
Node: 02136466 Node: 02136691
Node: 0236665 Node: 0236890
Node: 0140700 Node: 0140925
Node: Notes40801 Node: Notes41026
Node: Comparison with Org Agenda searches40963 Node: Comparison with Org Agenda searches41188
Node: org-sidebar41835 Node: org-sidebar42060
Node: License42114 Node: License42339
 
End Tag Table End Tag Table