diff --git a/README.org b/README.org index fdc43fc..842a50a 100644 --- a/README.org +++ b/README.org @@ -407,6 +407,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience *Added* + View dispatcher using =transient.el= (like Magit), bound to =v= in search/view buffers. + 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. *Changed* diff --git a/org-ql-view.el b/org-ql-view.el index 15499a3..9e69b62 100644 --- a/org-ql-view.el +++ b/org-ql-view.el @@ -428,6 +428,7 @@ subsequent refreshing of the buffer: `org-ql-view-buffers-files', (null (org-ql-view--buffer buffer)) (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) ;; Prepare buffer, saving data for refreshing. (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))) (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 ;; This section uses `transient' to allow the user to easily modify diff --git a/org-ql.info b/org-ql.info index 1791312..55c0d52 100644 --- a/org-ql.info +++ b/org-ql.info @@ -750,6 +750,10 @@ File: README.info, Node: 05-pre, Next: 046, Up: Changelog search/view buffers. • 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 Burly + (https://github.com/alphapapa/burly.el).) • Mascot. *Changed* @@ -1187,25 +1191,25 @@ Node: Agenda-like views19768 Node: Listing / acting-on results21173 Node: Changelog25775 Node: 05-pre26414 -Node: 04626778 -Node: 04527181 -Node: 04427540 -Node: 04327897 -Node: 04228092 -Node: 04128251 -Node: 0428490 -Node: 03232421 -Node: 03132798 -Node: 0332995 -Node: 02335970 -Node: 02236198 -Node: 02136466 -Node: 0236665 -Node: 0140700 -Node: Notes40801 -Node: Comparison with Org Agenda searches40963 -Node: org-sidebar41835 -Node: License42114 +Node: 04627003 +Node: 04527406 +Node: 04427765 +Node: 04328122 +Node: 04228317 +Node: 04128476 +Node: 0428715 +Node: 03232646 +Node: 03133023 +Node: 0333220 +Node: 02336195 +Node: 02236423 +Node: 02136691 +Node: 0236890 +Node: 0140925 +Node: Notes41026 +Node: Comparison with Org Agenda searches41188 +Node: org-sidebar42060 +Node: License42339  End Tag Table