Fix org-ql-select-tags-local-count

This commit is contained in:
Phil Bajsicki 2025-04-25 21:04:16 +02:00
parent d6332967c8
commit a4b1d094f4
2 changed files with 23 additions and 21 deletions

View file

@ -248,10 +248,11 @@ The rationale behind using ~list-buffers~ is the same as with dired. They both d
Seems to be one of the most reliable tools in the basket... mostly because Seems to be one of the most reliable tools in the basket... mostly because
#+begin_src elisp #+begin_src elisp
(defun gptel-org-tool--list-buffers () (defun gptel-org-tool--list-buffers (&optional arg)
(list-buffers-noselect) (list-buffers-noselect)
(with-temp-buffer "*Buffer List*" (with-temp-buffer "*Buffer List*"
(buffer-string))) (let ((content (buffer-string)))
content)))
(add-to-list 'gptel-org-tools (add-to-list 'gptel-org-tools
(gptel-make-tool (gptel-make-tool
@ -502,7 +503,7 @@ Currently *not* tangled, as I'm testing breaking out each type of query into its
:description "Run org-ql-select against buffer with query. Using filename fails." :description "Run org-ql-select against buffer with query. Using filename fails."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. Can be multiple buffers. See the NAME column in `emacs-list-buffers`.") :description "The name of the buffer. Can be multiple buffers. See the NAME column in `list-buffers`.")
'(:name "query" '(:name "query"
:type string :type string
:description "The query to pass into org-ql-select. See org-ql documentation for syntax. Usually `(tags \"tag1\" \"tag2\")` is sufficient. Possible predicates: `tags` (finds both local and inherited tags), `tags-local` (finds only local tags), `rifle` (matches against both heading and body text). This is a sexp, not a string.")) :description "The query to pass into org-ql-select. See org-ql documentation for syntax. Usually `(tags \"tag1\" \"tag2\")` is sufficient. Possible predicates: `tags` (finds both local and inherited tags), `tags-local` (finds only local tags), `rifle` (matches against both heading and body text). This is a sexp, not a string."))
@ -628,7 +629,7 @@ Retrieve the headings where the heading matches query..
:description "Retreive matching headings from buffer. Matches only a single string. Using filename fails." :description "Retreive matching headings from buffer. Matches only a single string. Using filename fails."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in ~emacs-list-buffers~.") :description "The name of the buffer. See the NAME column in ~list-buffers~.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -652,7 +653,7 @@ Retrieve all the headings where either heading or content matches query.
:description "Retreive headings from buffer using org-ql-select. Matches against both heading and content. Using filename fails." :description "Retreive headings from buffer using org-ql-select. Matches against both heading and content. Using filename fails."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in ~emacs-list-buffers~.") :description "The name of the buffer. See the NAME column in ~list-buffers~.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -676,7 +677,7 @@ This pulls all the headings (and their contents) when they match tags (without i
:description "Run org-ql-select-tags-local against buffer with query. No tag inheritance." :description "Run org-ql-select-tags-local against buffer with query. No tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string match entry tags against.")) :description "The string match entry tags against."))
@ -686,7 +687,7 @@ This pulls all the headings (and their contents) when they match tags (without i
***** org-ql-select-tags-local-count ***** org-ql-select-tags-local-count
This pulls all the local tags (without inheritance) from buffer, and returns the number of these tagged headings. This pulls all the local tags (without inheritance) from buffer, and returns the number of these tagged headings.
#+begin_src elisp #+begin_src elisp
(defun gptel-org-tools--org-ql-select-tags-local (buf query) (defun gptel-org-tools--org-ql-select-tags-local-count (buf query)
(length (org-ql-select (length (org-ql-select
(get-buffer buf) (get-buffer buf)
`(tags-local ,query) `(tags-local ,query)
@ -695,12 +696,12 @@ This pulls all the local tags (without inheritance) from buffer, and returns the
(add-to-list 'gptel-org-tools (add-to-list 'gptel-org-tools
(gptel-make-tool (gptel-make-tool
:function #'gptel-org-tools--org-ql-select-tags-local :function #'gptel-org-tools--org-ql-select-tags-local-count
:name "gptel-org-tools--org-ql-select-tags-local" :name "gptel-org-tools--org-ql-select-tags-local"
:description "Get count of matching tags from buffer. No tag inheritance." :description "Get count of matching tags from buffer. No tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string match entry tags against.")) :description "The string match entry tags against."))
@ -723,7 +724,7 @@ This pulls all the headings (and their contents) when they match tags (with inhe
:description "Run org-ql-select-tags against buffer with query. Supports tag inheritance." :description "Run org-ql-select-tags against buffer with query. Supports tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -749,7 +750,7 @@ And, the "grab everything that matches" tool.
:description "Run org-ql-select-rifle against buffer with query." :description "Run org-ql-select-rifle against buffer with query."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "A single string to search for.")) :description "A single string to search for."))

View file

@ -61,10 +61,11 @@
(org-end-of-subtree)) (org-end-of-subtree))
"---\n")) "---\n"))
(defun gptel-org-tool--list-buffers () (defun gptel-org-tool--list-buffers (&optional arg)
(list-buffers-noselect) (list-buffers-noselect)
(with-temp-buffer "*Buffer List*" (with-temp-buffer "*Buffer List*"
(buffer-string))) (let ((content (buffer-string)))
content)))
(add-to-list 'gptel-org-tools (add-to-list 'gptel-org-tools
(gptel-make-tool (gptel-make-tool
@ -245,7 +246,7 @@ DATE is the date or date range to match."
:description "Retreive matching headings from buffer. Matches only a single string. Using filename fails." :description "Retreive matching headings from buffer. Matches only a single string. Using filename fails."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in ~emacs-list-buffers~.") :description "The name of the buffer. See the NAME column in ~list-buffers~.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -265,7 +266,7 @@ DATE is the date or date range to match."
:description "Retreive headings from buffer using org-ql-select. Matches against both heading and content. Using filename fails." :description "Retreive headings from buffer using org-ql-select. Matches against both heading and content. Using filename fails."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in ~emacs-list-buffers~.") :description "The name of the buffer. See the NAME column in ~list-buffers~.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -285,13 +286,13 @@ DATE is the date or date range to match."
:description "Run org-ql-select-tags-local against buffer with query. No tag inheritance." :description "Run org-ql-select-tags-local against buffer with query. No tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string match entry tags against.")) :description "The string match entry tags against."))
:category "org-ql")) :category "org-ql"))
(defun gptel-org-tools--org-ql-select-tags-local (buf query) (defun gptel-org-tools--org-ql-select-tags-local-count (buf query)
(length (org-ql-select (length (org-ql-select
(get-buffer buf) (get-buffer buf)
`(tags-local ,query) `(tags-local ,query)
@ -300,12 +301,12 @@ DATE is the date or date range to match."
(add-to-list 'gptel-org-tools (add-to-list 'gptel-org-tools
(gptel-make-tool (gptel-make-tool
:function #'gptel-org-tools--org-ql-select-tags-local :function #'gptel-org-tools--org-ql-select-tags-local-count
:name "gptel-org-tools--org-ql-select-tags-local" :name "gptel-org-tools--org-ql-select-tags-local"
:description "Get count of matching tags from buffer. No tag inheritance." :description "Get count of matching tags from buffer. No tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string match entry tags against.")) :description "The string match entry tags against."))
@ -324,7 +325,7 @@ DATE is the date or date range to match."
:description "Run org-ql-select-tags against buffer with query. Supports tag inheritance." :description "Run org-ql-select-tags against buffer with query. Supports tag inheritance."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "The string to match entry headings against.")) :description "The string to match entry headings against."))
@ -346,7 +347,7 @@ DATE is the date or date range to match."
:description "Run org-ql-select-rifle against buffer with query." :description "Run org-ql-select-rifle against buffer with query."
:args (list '(:name "buffer" :args (list '(:name "buffer"
:type string :type string
:description "The name of the buffer. See the NAME column in `emacs-list-buffers`. Using filename fails.") :description "The name of the buffer. See the NAME column in `list-buffers`. Using filename fails.")
'(:name "query" '(:name "query"
:type string :type string
:description "A single string to search for.")) :description "A single string to search for."))