0

When filtering entries in agenda buffer (including C-c m) I only get auto-completion for tags. But the first thing I want to filter by is always the value of the "Project" property. I set up buttons for a few projects in my main org file but they are somewhat cumbersome to use - I'd much rather prefer to open a general agenda buffer and filter from there.

Is it possible to filter agenda by property without typing out the entire name of the property?

For example I have an entry in a form:

* #10045 Do some very important fix
:PROPERTIES:
:Project: My project
:END:

And I want to have the auto-completion for the name of the property itself and then all the "Project" values that Emacs found in the agenda files. I can settle for a solution that suggests projects from the current buffer only.

The input I want to enter inside the agenda buffer to find the headings with property "Project=My project" would be: / P TAB M TAB RET

Right now to get the desired action I need to type letter by letter (including outer quotes): / "Project=\"My project\"" RET in the regex filter.

EDIT:

I found out that in org-mode I can press C-c / p to filter entries by property with auto-completion for property name and property value. I remember now that this was the reason why I set up my org entries in this way. I want to do exactly the same thing but inside agenda buffer. I also found that if I only want to filter by projects (not ideal but it somewhat helps), I can define "Category" property and filter by category in agenda.

5
  • Yes it is possible. You could install the Vertico package, which works well with other packages such as Orderless, Marginalia and Consult.
    – crocefisso
    Mar 26 at 20:11
  • @crocefisso could you elaborate? I tried all those packages and they seem to just be using the autocompletion that is already present in Emacs when pressing tab. I still need to type out an entire regexp when filtering by project. Mar 27 at 20:46
  • I have the mentioned packages installed and active. When I do C-c a m, if I want to filter by the property gnu_linux_arch, I just have to type arc TAB RET. Maybe I didn't get your question. If this is the case, could you add a minimal example?
    – crocefisso
    Mar 27 at 22:18
  • I think you have properties and tags mixed up. I'll add an example in a minute. Mar 28 at 9:15
  • Indeed, after C-c a m, auto completion works for tags but not for properties.
    – crocefisso
    Mar 28 at 12:57

2 Answers 2

1

Here is a solution using org-super-agenda

To get this

M-x org-agenda in org-super-agenda-mode

M-x org-agenda in org-super-agenda-mode

on these agenda files

/tmp/ox-odt.org

* TODO Upgrade "factory styles" of ODT and ODS exporter :odsexport:odtexport:
:PROPERTIES:
:PROJECT:  odt
:URL:      https://github.com/kjambunathan/org-mode-ox-odt/issues/251
:END:


* TODO Review heuristics used for embedding screenshots in a landscape document :odtexport:
:PROPERTIES:
:PROJECT: odt
:URL:      https://github.com/kjambunathan/org-mode-ox-odt/issues/261
:END:

/tmp/ox-ods.org

* TODO Unable to convert a ods file to a tsv file                 :odsexport:
:PROPERTIES:
:PROJECT: ods
:URL:      https://github.com/kjambunathan/org-mode-ox-odt/issues/235
:END:


* Add support for vmax, vmin etc                                  :odsexport:
:PROPERTIES:
:PROJECT: ods
:URL: https://github.com/kjambunathan/org-mode-ox-odt/issues/253
:END:

do this


(require 'org-super-agenda)
(custom-set-variables
 '(vertico-mode t)
 '(org-agenda-files
   '("/tmp/ox-odt.org"
     "/tmp/ox-ods.org"))
 '(org-super-agenda-groups '((:auto-property "PROJECT")))
 '(org-super-agenda-mode t))
2
  • This looks great, I'll try it as soon as I'll have some free time. Mar 28 at 17:54
  • This is perfect, thank you. Is there a way to interactively hide certain groups when I'm already in agenda mode or narrow it to just one? Mar 28 at 20:26
1

If you are averse to using org-super-agenda you can go with the below recipe ...

(Note that there is no harm in using org-super-agenda-mode though)

(Note that this "pollutes" org-tags-history. So, refine the recipe further if this "pollution" confuses you. You may want to periodically do (setq org-tags-history nil) just to be sure that there is ZERO pollution)

To get this

enter image description here

followed by

enter image description here


;; Recipe for `emacs -Q`

(require 'subr-x)
(require 'map)

(setq package-user-dir "~/.emacs.d/elpa/")
(package-initialize)

(global-set-key (kbd "C-c h") 'consult-history)


(custom-set-variables
 '(vertico-mode t)
 '(org-agenda-files
   '("/tmp/ox-odt.org"
     "/tmp/ox-ods.org")))

(require 'org-agenda)
(setq my-org-agenda-prop-filters
      (thread-last
        org-agenda-files
        (seq-mapcat
         (lambda (it)
           (with-current-buffer (find-file-noselect it)
             (thread-last (org-element-map
                              (org-element-parse-buffer)
                              'property-drawer #'identity)
                          (seq-mapcat (lambda (it) (org-element-map it 'node-property #'cadr)))
                          (seq-map (pcase-lambda ((map :key :value)) (cons key value)))
                          (seq-group-by #'car)
                          (seq-map (pcase-lambda (`(,prop . ,prop-and-values))
                                     (cons prop (thread-last prop-and-values
                                                             map-values))))
                          (seq-mapcat
                           (pcase-lambda (`(,prop . ,values))
                             (thread-last values
                                          (seq-map
                                           (lambda (it)
                                             (format "%s=\"%s\"" prop it))))))))))))

;; '("PROJECT=\"odt\""
;;   "PROJECT=\"odt\""
;;   "URL=\"https://github.com/kjambunathan/org-mode-ox-odt/issues/251\""
;;   "URL=\"https://github.com/kjambunathan/org-mode-ox-odt/issues/261\""
;;   "PROJECT=\"ods\""
;;   "PROJECT=\"ods\""
;;   "URL=\"https://github.com/kjambunathan/org-mode-ox-odt/issues/235\""
;;   "URL=\"https://github.com/kjambunathan/org-mode-ox-odt/issues/253\""
;;   )

(setq org-tags-history
      (append my-org-agenda-prop-filters
              org-tags-history))


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.