diff options
author | Bastien Guerry <bastien.guerry@data.gouv.fr> | 2020-09-04 19:15:15 +0200 |
---|---|---|
committer | Bastien Guerry <bastien.guerry@data.gouv.fr> | 2020-09-04 19:15:15 +0200 |
commit | 39d9eb541fda710be8c43282e47c04c35065bd17 (patch) | |
tree | 666e2e79f2453d444d46059047bd05d0cdcd6d81 | |
parent | de3ffe99d014a7efaf51c6ea9a985b3c2309cd8b (diff) | |
download | org-mode-39d9eb541fda710be8c43282e47c04c35065bd17.tar.gz |
org-agenda.el: Filter category names with a hyphen specially
* lisp/org-agenda.el (org-agenda-filter)
(org-agenda-get-represented-categories): Handle category names
with one hyphen specially.
See <https://orgmode.org/list/87d06ds46s.fsf@fastmail.fm>
-rw-r--r-- | lisp/org-agenda.el | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 8f8fd45..a9b4406 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -7709,6 +7709,11 @@ the variable `org-agenda-auto-exclude-function'." (fe (if keep org-agenda-effort-filter)) (fr (if keep org-agenda-regexp-filter)) pm s) + ;; If the filter contains a double-quoted string, replace a + ;; single hyphen by the arbitrary and temporary string "~~~" + ;; to disambiguate such hyphens from syntactic ones. + (setq f-string (replace-regexp-in-string + "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string)) (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string) (setq pm (if (match-beginning 1) (match-string 1 f-string) "+")) (when negate @@ -7716,12 +7721,15 @@ the variable `org-agenda-auto-exclude-function'." (cond ((match-beginning 3) ;; category or tag - (setq s (match-string 3 f-string)) + (setq s (replace-regexp-in-string ; Remove the temporary special string. + "~~~" "-" (match-string 3 f-string))) (cond ((member s tag-list) (add-to-list 'ft (concat pm s) 'append 'equal)) ((member s category-list) - (add-to-list 'fc (concat pm s) 'append 'equal)) + (add-to-list 'fc (concat pm ; Remove temporary double quotes. + (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s)) + 'append 'equal)) (t (message "`%s%s' filter ignored because tag/category is not represented" pm s)))) @@ -7890,7 +7898,10 @@ also press `-' or `+' to switch between filtering and excluding." pos 'org-category nil (point-max)))) (push (get-text-property pos 'org-category) categories)) (setq org-agenda-represented-categories - (nreverse (org-uniquify (delq nil categories)))))))) + ;; Enclose category names with a hyphen in double + ;; quotes to process them specially in `org-agenda-filter'. + (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s)) + (nreverse (org-uniquify (delq nil categories))))))))) (defun org-agenda-get-represented-tags () "Return a list of all tags used in this agenda buffer. |