Add: (org-ql-block) Respect Org Agenda restrictions

Fixes #84.  Thanks to Ihor Radchenko (@yantar92) for reporting.
This commit is contained in:
Adam Porter 2020-01-18 22:20:52 -06:00
parent 0a7e4f349f
commit b3601cf0ae
3 changed files with 47 additions and 30 deletions

View file

@ -398,6 +398,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience
+ Info manual. + Info manual.
+ Function ~helm-org-ql-source~, which returns a Helm source that searches given buffers/files with ~helm-org-ql~. It can be used for custom Helm commands that search certain files. + Function ~helm-org-ql-source~, which returns a Helm source that searches given buffers/files with ~helm-org-ql~. It can be used for custom Helm commands that search certain files.
+ Display a message when views are refreshed. (Thanks to [[https://github.com/xeijin][xeijin]].) + Display a message when views are refreshed. (Thanks to [[https://github.com/xeijin][xeijin]].)
+ Respect Org Agenda restriction in =org-ql-block=. (Thanks to [[https://github.com/yantar92][Ihor Radchenko]] for reporting.)
*Fixed* *Fixed*
+ Inherit file tags when =org-tag-inheritance= is enabled. (Fixes [[https://github.com/alphapapa/org-ql/issues/55][#55]]. Thanks to [[https://github.com/mskorzhinskiy][Mikhail Skorzhinskiy]].) + Inherit file tags when =org-tag-inheritance= is enabled. (Fixes [[https://github.com/alphapapa/org-ql/issues/55][#55]]. Thanks to [[https://github.com/mskorzhinskiy][Mikhail Skorzhinskiy]].)

View file

@ -231,9 +231,23 @@ function `org-agenda-files'. Inserts a newline after the block.
If `org-ql-block-header' is non-nil, it is used as the header If `org-ql-block-header' is non-nil, it is used as the header
string for the block, otherwise a the header is formed string for the block, otherwise a the header is formed
automatically from the query." automatically from the query."
(when-let* ((from (org-agenda-files nil 'ifmode)) (let (narrow-p old-beg old-end)
(when-let* ((from (pcase org-agenda-overriding-restriction
('nil (org-agenda-files nil 'ifmode))
('file (get 'org-agenda-files 'org-restrict))
('subtree (prog1 org-agenda-restrict
(with-current-buffer org-agenda-restrict
;; Narrow the buffer; remember to widen it later.
(setf old-beg (point-min) old-end (point-max)
narrow-p t)
(narrow-to-region org-agenda-restrict-begin org-agenda-restrict-end))))))
(items (org-ql-select from query (items (org-ql-select from query
:action 'element-with-markers))) :action 'element-with-markers
:narrow narrow-p)))
(when narrow-p
;; Restore buffer's previous restrictions.
(with-current-buffer from
(narrow-to-region old-beg old-end)))
;; Not sure if calling the prepare function is necessary, but let's follow the pattern. ;; Not sure if calling the prepare function is necessary, but let's follow the pattern.
(org-agenda-prepare) (org-agenda-prepare)
;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than ;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than
@ -248,7 +262,7 @@ automatically from the query."
(-map #'org-ql-view--format-element) (-map #'org-ql-view--format-element)
org-agenda-finalize-entries org-agenda-finalize-entries
insert) insert)
(insert "\n"))) (insert "\n"))))
;;;###autoload ;;;###autoload
(defalias 'org-ql-block 'org-ql-search-block) (defalias 'org-ql-block 'org-ql-search-block)

View file

@ -723,6 +723,8 @@ File: README.info, Node: 04-pre, Next: 032, Up: Changelog
for custom Helm commands that search certain files. for custom Helm commands that search certain files.
• Display a message when views are refreshed. (Thanks to xeijin • Display a message when views are refreshed. (Thanks to xeijin
(https://github.com/xeijin).) (https://github.com/xeijin).)
• Respect Org Agenda restriction in org-ql-block. (Thanks to Ihor
Radchenko (https://github.com/yantar92) for reporting.)
*Fixed* *Fixed*
• Inherit file tags when org-tag-inheritance is enabled. (Fixes #55 • Inherit file tags when org-tag-inheritance is enabled. (Fixes #55
@ -1028,18 +1030,18 @@ Node: Agenda-like views18025
Node: Listing / acting-on results19430 Node: Listing / acting-on results19430
Node: Changelog24032 Node: Changelog24032
Node: 04-pre24569 Node: 04-pre24569
Node: 03226689 Node: 03226822
Node: 03127070 Node: 03127203
Node: 0327265 Node: 0327398
Node: 02330238 Node: 02330371
Node: 02230464 Node: 02230597
Node: 02130730 Node: 02130863
Node: 0230927 Node: 0231060
Node: 0134960 Node: 0135093
Node: Notes35059 Node: Notes35192
Node: Comparison with Org Agenda searches35221 Node: Comparison with Org Agenda searches35354
Node: org-sidebar36092 Node: org-sidebar36225
Node: License36371 Node: License36504
 
End Tag Table End Tag Table