* RFC: interactive tag query adjustment
@ 2007-12-08 14:00 Christopher League
2007-12-08 18:29 ` Adam Spiers
2008-01-12 22:45 ` Christopher League
0 siblings, 2 replies; 5+ messages in thread
From: Christopher League @ 2007-12-08 14:00 UTC (permalink / raw)
To: emacs-orgmode
Hi, I've been using org-mode for about a year, and recently updated to
the latest release. I was happy to discover the enhanced tag query
features ("phone|email/NEXT|SOMEDAY", etc) and started rethinking my
configuration a little.
I'd like to have an interface for interactive query adjustment. For
example, in a tags match (C-c a m, org-tags-view), I could begin with
the query "phone/NEXT" and type the keys "/h" to quickly turn it into
"phone+home/NEXT" and then ";s" to get "phone+home/NEXT|SOMEDAY", then
"=[" to clear all the tags to "/NEXT|SOMEDAY", and so on. Then, one
more keystroke to save the current query into org-agenda-custom-
commands would be icing on the cake.
I'm new to the mailing list, so maybe some functionality like this was
discussed before. Closest I found was a thread begun by John W in
October, wherein "interactive" and "query" were mentioned together a
few times... http://thread.gmane.org/gmane.emacs.orgmode/3628 but I
don't think it's the same idea.
Below is a first crack at this kind of functionality. It's very
rough.. I've hacked elisp before, but I'm new to the org.el code.
Load this after org, then "C-c a m", enter any match query, then try
some of the commands with your tag shortcut keys. It assumes you have
some settings in org-tag-alist. Currently, todo shortcut keys may not
work because org-todo-key-alist is still nil; it's not clear to me how
this should get initialized from agenda-mode.
Let me know what you think! Thanks Carsten and community for all the
hard work and great ideas surrounding org-mode!
Chris
;; Currently, it seems the query string is kept only as part of the
;; org-agenda-redo-command, which is a Lisp form. A distinct global
;; would be cleaner, but that entails modifications to org-mode."
;; org-agenda-redo-command: (org-tags-view 'nil (if current-prefix-arg
nil ""))
;; The "" will contain the current query string
(defun cl-agenda-twiddle-query ()
(cl-agenda-twiddle-iter org-agenda-redo-command))
(defun cl-agenda-twiddle-iter (sexp)
"Find query string in SEXP and replace it."
(if (consp sexp)
(if (and (stringp (car sexp)) (null (cdr sexp)))
(setcar sexp (cl-agenda-apply-changes (car sexp)))
(cl-agenda-twiddle-iter (car sexp))
(cl-agenda-twiddle-iter (cdr sexp)))))
(defun cl-agenda-apply-changes (str)
(cl-agenda-apply-iter cl-agenda-op str cl-agenda-args))
(defun cl-agenda-apply-iter (op str args)
(if (null args) str
(funcall op (cl-agenda-apply-iter op str (cdr args))
(caar args) (cdar args))))
(defun cl-agenda-tag-clear (query kind str)
(if (string-match (concat "[-\\+&|]?\\b" (regexp-quote str) "\\b")
query)
(replace-match "" t t query)
query))
(defun cl-agenda-tag-set (query kind str)
(let* ((q (cl-agenda-tag-clear query kind str))
(r (string-match "\\([^/]*\\)/?\\(.*\\)" q))
(q1 (match-string 1 q))
(q2 (match-string 2 q)))
(cond
((eq kind 'tag)
(concat q1 cl-agenda-sep str "/" q2))
((equal cl-agenda-sep "+")
(concat q1 "/+" str))
(t
(concat q1 "/" q2 cl-agenda-sep str)))))
;;; ALMOST THERE: IT'S JUST THAT org-todo-key-alist IS NIL.
(defun cl-agenda-all (kind alist)
(cond
((null alist) nil)
((stringp (caar alist))
(cons (cons kind (caar alist)) (cl-agenda-all kind (cdr alist))))
(t
(cl-agenda-all kind (cdr alist)))))
(defun cl-agenda-interp-key (k)
(let ((v1 (rassoc k org-tag-alist))
(v2 (rassoc k org-todo-key-alist)))
(cond
((eq k ? ) (append (cl-agenda-all 'tag org-tag-alist)
(cl-agenda-all 'todo org-todo-key-alist)))
((eq k ?[) (cl-agenda-all 'tag org-tag-alist))
((eq k ?]) (cl-agenda-all 'todo org-todo-key-alist))
(v1 (list (cons 'tag (car v1))))
(v2 (list (cons 'todo (car v2))))
(t nil))))
(defun cl-agenda-tag-cmd (op sep)
(let ((cl-agenda-op op)
(cl-agenda-sep sep)
(cl-agenda-args (cl-agenda-interp-key (read-char))))
(cl-agenda-twiddle-query))
(org-agenda-redo))
(defun cl-agenda-tag-clear-cmd ()
(interactive)
(cl-agenda-tag-cmd 'cl-agenda-tag-clear ""))
(defun cl-agenda-tag-and-cmd ()
(interactive)
(cl-agenda-tag-cmd 'cl-agenda-tag-set "+"))
(defun cl-agenda-tag-or-cmd ()
(interactive)
(cl-agenda-tag-cmd 'cl-agenda-tag-set "|"))
(defun cl-agenda-tag-not-cmd ()
(interactive)
(cl-agenda-tag-cmd 'cl-agenda-tag-set "-"))
(org-defkey org-agenda-mode-map "=" 'cl-agenda-tag-clear-cmd)
(org-defkey org-agenda-mode-map "/" 'cl-agenda-tag-and-cmd)
(org-defkey org-agenda-mode-map ";" 'cl-agenda-tag-or-cmd)
(org-defkey org-agenda-mode-map "\\" 'cl-agenda-tag-not-cmd)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFC: interactive tag query adjustment
2007-12-08 14:00 RFC: interactive tag query adjustment Christopher League
@ 2007-12-08 18:29 ` Adam Spiers
2007-12-08 22:45 ` Christopher League
2008-01-12 22:45 ` Christopher League
1 sibling, 1 reply; 5+ messages in thread
From: Adam Spiers @ 2007-12-08 18:29 UTC (permalink / raw)
To: emacs-orgmode
On Sat, Dec 08, 2007 at 09:00:01AM -0500, Christopher League wrote:
> Hi, I've been using org-mode for about a year, and recently updated to
> the latest release. I was happy to discover the enhanced tag query
> features ("phone|email/NEXT|SOMEDAY", etc) and started rethinking my
> configuration a little.
>
> I'd like to have an interface for interactive query adjustment. For
> example, in a tags match (C-c a m, org-tags-view), I could begin with
> the query "phone/NEXT" and type the keys "/h" to quickly turn it into
> "phone+home/NEXT" and then ";s" to get "phone+home/NEXT|SOMEDAY", then
> "=[" to clear all the tags to "/NEXT|SOMEDAY", and so on. Then, one
> more keystroke to save the current query into org-agenda-custom-
> commands would be icing on the cake.
[snipped]
> Let me know what you think! Thanks Carsten and community for all the
> hard work and great ideas surrounding org-mode!
The idea sounds great! though I copied your code into a buffer, did
M-x eval-buffer, typed C-c a m and couldn't get any of the "electric"
keys to behave any differently to normal. Not sure if I did something
wrong.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFC: interactive tag query adjustment
2007-12-08 18:29 ` Adam Spiers
@ 2007-12-08 22:45 ` Christopher League
2007-12-11 10:51 ` Bastien
0 siblings, 1 reply; 5+ messages in thread
From: Christopher League @ 2007-12-08 22:45 UTC (permalink / raw)
To: Adam Spiers; +Cc: emacs-orgmode
On Dec 8, 2007, at 1:29 PM, Adam Spiers wrote:
> The idea sounds great! though I copied your code into a buffer, did
> M-x eval-buffer, typed C-c a m and couldn't get any of the "electric"
> keys to behave any differently to normal. Not sure if I did something
> wrong.
Huh, okay. Maybe the code is rougher than I thought. :)
The first step is, from the *Org Agenda* buffer, try C-h c / to make
sure it is bound to cl-agenda-tag-and-cmd. If not, then maybe the org-
defkey failed. Also, org-tag-alist must be set up with shortcut keys
for each tag. If this is the case, then typing "/h" should add
"+home" to the current query, assuming you have ("home" . ?h) in org-
tag-alist. It will NOT prompt for anything after typing just the "/".
I'll paste the rest of my current org config below, in case there's
some other relevant assumption I'm making about how things are set
up. My org-version is 5.16a. If this needs further troubleshooting,
maybe we can take it off-list until it gets resolved.
Thanks,
Chris
;; current org configuration
(setq org-agenda-files "~/v/plan/orgfiles.txt")
(setq org-startup-folded nil)
(setq org-hide-leading-stars t)
(setq org-todo-keywords
;; task states
'((type "NEXT(N)" "|" "WAIT(W)" "DONE(D)")
;; project states
(sequence "|" "ONEDAY(O)" "ACTIVE(A)" "CLOSED(C)")))
(setq org-todo-keyword-faces
'(("NEXT" . (:foreground "green3" :weight bold))
("WAIT" . (:foreground "orange2" :weight bold))
("DONE" . (:foreground "red4" :weight bold))
("ONEDAY" . (:foreground "orange2" :inverse-video t))
("ACTIVE" . (:foreground "green3" :inverse-video t))
("CLOSED" . (:foreground "red4" :inverse-video t))))
(setq org-fast-tag-selection-include-todo t)
(setq org-tag-alist
'(("ARCHIVE" . ?-)
(:startgroup)
("focus" . ?f)
("tired" . ?t)
(:endgroup)
(:startgroup)
("inet" . ?i)
("comp" . ?c)
(:endgroup)
(:startgroup)
("email" . ?m)
("phone" . ?p)
(:endgroup)
(:startgroup)
("home" . ?h)
("office" . ?o)
("errand" . ?e)
(:endgroup)))
(setq org-log-done nil)
(setq org-use-tag-inheritance nil)
(setq org-agenda-ndays 10)
(setq org-stuck-projects
'("/ACTIVE" ("NEXT" "WAIT")
nil ""))
(setq org-agenda-sorting-strategy
'((agenda time-up priority-down category-keep)
(todo priority-down tag-up category-keep)
(tags priority-down tag-up category-keep)))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFC: interactive tag query adjustment
2007-12-08 22:45 ` Christopher League
@ 2007-12-11 10:51 ` Bastien
0 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2007-12-11 10:51 UTC (permalink / raw)
To: Christopher League; +Cc: emacs-orgmode
Hi Christopher,
Christopher League <league@contrapunctus.net> writes:
> On Dec 8, 2007, at 1:29 PM, Adam Spiers wrote:
>> The idea sounds great! though I copied your code into a buffer, did
>> M-x eval-buffer, typed C-c a m and couldn't get any of the "electric"
>> keys to behave any differently to normal. Not sure if I did something
>> wrong.
>
> Huh, okay. Maybe the code is rougher than I thought. :)
The code is quite okay, it worked for me. I think it's just a matter of
having a good interface that could tell you how to add a tag or a to-do
keyword.
Anyway, I really love the idea and I think this is a promising feature
for Org!
--
Bastien
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFC: interactive tag query adjustment
2007-12-08 14:00 RFC: interactive tag query adjustment Christopher League
2007-12-08 18:29 ` Adam Spiers
@ 2008-01-12 22:45 ` Christopher League
1 sibling, 0 replies; 5+ messages in thread
From: Christopher League @ 2008-01-12 22:45 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1.1: Type: text/plain, Size: 1065 bytes --]
Hi again, last month I proposed an idea for interactively manipulating
the current query in a tags agenda match (C-c a m, org-tags-view).
Attached here is a patch against 5.18a that implements this idea.
It's pretty slick, if I may be so bold!
In a tags match buffer, the prompt will now say, for example:
Headlines with TAGS match: office
Press `C-u r' to enter new search string; use `/;\=' to adjust
interactively
The extra keys are / (and), ; (or), \ (not), = (clear). Any one of
them will bring up another window, much like fast tag selection. You
can press one key to select the tag or TODO keyword, and that will be
added to or removed from the query string accordingly.
So, starting with the query "office", I can hit the keys ";p/N-f" to
transform it to "office|phone-focus/NEXT", assuming my tags and TODO
keywords are assigned those keys already. Like fast tag selection, it
supports single-key (the default), multi-key (waits for RET), and
expert (no separate window) modes.
Enjoy.. comments & critiques welcome.
Chris
[-- Attachment #1.1.2: org-interactive-query.patch.txt --]
[-- Type: text/plain, Size: 12923 bytes --]
--- org-vendor/org.el 2008-01-06 10:30:26.000000000 -0500
+++ org/org.el 2008-01-12 17:19:15.000000000 -0500
@@ -15078,7 +15078,8 @@
(let ((org-last-tags-completion-table
(org-global-tags-completion-table)))
(setq match (completing-read
- "Match: " 'org-tags-completion-function nil nil nil
+ "Match: " 'org-tags-completion-function nil nil
+ org-agenda-query-string
'org-tags-history))))
;; Parse the string and create a lisp form
@@ -18812,6 +18813,7 @@
(defvar org-agenda-follow-mode nil)
(defvar org-agenda-show-log nil)
(defvar org-agenda-redo-command nil)
+(defvar org-agenda-query-string nil)
(defvar org-agenda-mode-hook nil)
(defvar org-agenda-type nil)
(defvar org-agenda-force-single-file nil)
@@ -18947,6 +18949,10 @@
(org-defkey org-agenda-mode-map [(right)] 'org-agenda-later)
(org-defkey org-agenda-mode-map [(left)] 'org-agenda-earlier)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
+(org-defkey org-agenda-mode-map "=" 'org-agenda-query-clear-cmd)
+(org-defkey org-agenda-mode-map "/" 'org-agenda-query-and-cmd)
+(org-defkey org-agenda-mode-map ";" 'org-agenda-query-or-cmd)
+(org-defkey org-agenda-mode-map "\\" 'org-agenda-query-not-cmd)
(defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
"Local keymap for agenda entries from Org-mode.")
@@ -20423,9 +20429,10 @@
(setq matcher (org-make-tags-matcher match)
match (car matcher) matcher (cdr matcher))
(org-prepare-agenda (concat "TAGS " match))
+ (setq org-agenda-query-string match)
(setq org-agenda-redo-command
(list 'org-tags-view (list 'quote todo-only)
- (list 'if 'current-prefix-arg nil match)))
+ (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
(setq files (org-agenda-files)
rtnall nil)
(while (setq file (pop files))
@@ -20461,7 +20468,7 @@
(add-text-properties pos (1- (point)) (list 'face 'org-warning))
(setq pos (point))
(unless org-agenda-multi
- (insert "Press `C-u r' to search again with new search string\n"))
+ (insert "Press `C-u r' to enter new search string; use `/;\\=' to adjust interactively\n"))
(add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
(when rtnall
(insert (org-finalize-agenda-entries rtnall) "\n"))
@@ -20471,6 +20478,275 @@
(org-finalize-agenda)
(setq buffer-read-only t)))
+;;; Agenda interactive query manipulation
+
+(defcustom org-agenda-query-selection-single-key t
+ "Non-nil means, query manipulation exits after first change.
+When nil, you have to press RET to exit it.
+During query selection, you can toggle this flag with `C-c'.
+This variable can also have the value `expert'. In this case, the window
+displaying the tags menu is not even shown, until you press C-c again."
+ :group 'org-agenda
+ :type '(choice
+ (const :tag "No" nil)
+ (const :tag "Yes" t)
+ (const :tag "Expert" expert)))
+
+(defun org-agenda-query-selection (current op table &optional todo-table)
+ "Fast query manipulation with single keys.
+CURRENT is the current query string, OP is the initial
+operator (one of \"+|-=\"), TABLE is an alist of tags and
+corresponding keys, possibly with grouping information.
+TODO-TABLE is a similar table with TODO keywords, should these
+have keys assigned to them. If the keys are nil, a-z are
+automatically assigned. Returns the new query string, or nil to
+not change the current one."
+ (let* ((fulltable (append table todo-table))
+ (maxlen (apply 'max (mapcar
+ (lambda (x)
+ (if (stringp (car x)) (string-width (car x)) 0))
+ fulltable)))
+ (fwidth (+ maxlen 3 1 3))
+ (ncol (/ (- (window-width) 4) fwidth))
+ (expert (eq org-agenda-query-selection-single-key 'expert))
+ (exit-after-next org-agenda-query-selection-single-key)
+ (done-keywords org-done-keywords)
+ tbl char cnt e groups ingroup
+ tg c2 c c1 ntable rtn)
+ (save-window-excursion
+ (if expert
+ (set-buffer (get-buffer-create " *Org tags*"))
+ (delete-other-windows)
+ (split-window-vertically)
+ (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
+ (erase-buffer)
+ (org-set-local 'org-done-keywords done-keywords)
+ (insert "Query: " current "\n")
+ (org-agenda-query-op-line op)
+ (insert "\n\n")
+ (org-fast-tag-show-exit exit-after-next)
+ (setq tbl fulltable char ?a cnt 0)
+ (while (setq e (pop tbl))
+ (cond
+ ((equal e '(:startgroup))
+ (push '() groups) (setq ingroup t)
+ (when (not (= cnt 0))
+ (setq cnt 0)
+ (insert "\n"))
+ (insert "{ "))
+ ((equal e '(:endgroup))
+ (setq ingroup nil cnt 0)
+ (insert "}\n"))
+ (t
+ (setq tg (car e) c2 nil)
+ (if (cdr e)
+ (setq c (cdr e))
+ ;; automatically assign a character.
+ (setq c1 (string-to-char
+ (downcase (substring
+ tg (if (= (string-to-char tg) ?@) 1 0)))))
+ (if (or (rassoc c1 ntable) (rassoc c1 table))
+ (while (or (rassoc char ntable) (rassoc char table))
+ (setq char (1+ char)))
+ (setq c2 c1))
+ (setq c (or c2 char)))
+ (if ingroup (push tg (car groups)))
+ (setq tg (org-add-props tg nil 'face
+ (cond
+ ((not (assoc tg table))
+ (org-get-todo-face tg))
+ (t nil))))
+ (if (and (= cnt 0) (not ingroup)) (insert " "))
+ (insert "[" c "] " tg (make-string
+ (- fwidth 4 (length tg)) ?\ ))
+ (push (cons tg c) ntable)
+ (when (= (setq cnt (1+ cnt)) ncol)
+ (insert "\n")
+ (if ingroup (insert " "))
+ (setq cnt 0)))))
+ (setq ntable (nreverse ntable))
+ (insert "\n")
+ (goto-char (point-min))
+ (if (and (not expert) (fboundp 'fit-window-to-buffer))
+ (fit-window-to-buffer))
+ (setq rtn
+ (catch 'exit
+ (while t
+ (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free%s%s"
+ (if groups " [!] no groups" " [!]groups")
+ (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
+ (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
+ (cond
+ ((= c ?\r) (throw 'exit t))
+ ((= c ?!)
+ (setq groups (not groups))
+ (goto-char (point-min))
+ (while (re-search-forward "[{}]" nil t) (replace-match " ")))
+ ((= c ?\C-c)
+ (if (not expert)
+ (org-fast-tag-show-exit
+ (setq exit-after-next (not exit-after-next)))
+ (setq expert nil)
+ (delete-other-windows)
+ (split-window-vertically)
+ (org-switch-to-buffer-other-window " *Org tags*")
+ (and (fboundp 'fit-window-to-buffer)
+ (fit-window-to-buffer))))
+ ((or (= c ?\C-g)
+ (and (= c ?q) (not (rassoc c ntable))))
+ (setq quit-flag t))
+ ((= c ?\ )
+ (setq current "")
+ (if exit-after-next (setq exit-after-next 'now)))
+ ((= c ?\[) ; clear left
+ (org-agenda-query-decompose current)
+ (setq current (concat "/" (match-string 2 current)))
+ (if exit-after-next (setq exit-after-next 'now)))
+ ((= c ?\]) ; clear right
+ (org-agenda-query-decompose current)
+ (setq current (match-string 1 current))
+ (if exit-after-next (setq exit-after-next 'now)))
+ ((= c ?\t)
+ (condition-case nil
+ (setq current (read-string "Query: " current))
+ (quit))
+ (if exit-after-next (setq exit-after-next 'now)))
+ ;; operators
+ ((or (= c ?/) (= c ?+)) (setq op "+"))
+ ((or (= c ?\;) (= c ?|)) (setq op "|"))
+ ((or (= c ?\\) (= c ?-)) (setq op "-"))
+ ((= c ?=) (setq op "="))
+ ;; todos
+ ((setq e (rassoc c todo-table) tg (car e))
+ (setq current (org-agenda-query-manip
+ current op groups 'todo tg))
+ (if exit-after-next (setq exit-after-next 'now)))
+ ;; tags
+ ((setq e (rassoc c ntable) tg (car e))
+ (setq current (org-agenda-query-manip
+ current op groups 'tag tg))
+ (if exit-after-next (setq exit-after-next 'now))))
+ (if (eq exit-after-next 'now) (throw 'exit t))
+ (goto-char (point-min))
+ (beginning-of-line 1)
+ (delete-region (point) (point-at-eol))
+ (insert "Query: " current)
+ (beginning-of-line 2)
+ (delete-region (point) (point-at-eol))
+ (org-agenda-query-op-line op)
+ (goto-char (point-min)))))
+ (if rtn current nil))))
+
+(defun org-agenda-query-op-line (op)
+ (insert "Operator: "
+ (org-agenda-query-op-entry (equal op "+") "/+" "and")
+ (org-agenda-query-op-entry (equal op "|") ";|" "or")
+ (org-agenda-query-op-entry (equal op "-") "\\-" "not")
+ (org-agenda-query-op-entry (equal op "=") "=" "clear")))
+
+(defun org-agenda-query-op-entry (matchp chars str)
+ (if matchp
+ (org-add-props (format "[%s %s] " chars (upcase str))
+ nil 'face 'org-todo)
+ (format "[%s]%s " chars str)))
+
+(defun org-agenda-query-decompose (current)
+ (string-match "\\([^/]*\\)/?\\(.*\\)" current))
+
+(defun org-agenda-query-clear (current prefix tag)
+ (if (string-match (concat prefix "\\b" (regexp-quote tag) "\\b") current)
+ (replace-match "" t t current)
+ current))
+
+(defun org-agenda-query-manip (current op groups kind tag)
+ "Apply an operator to a query string and a tag.
+CURRENT is the current query string, OP is the operator, GROUPS is a
+list of lists of tags that are mutually exclusive. KIND is 'tag for a
+regular tag, or 'todo for a TODO keyword, and TAG is the tag or
+keyword string."
+ ;; If this tag is already in query string, remove it.
+ (setq current (org-agenda-query-clear current "[-\\+&|]?" tag))
+ (if (equal op "=") current
+ ;; When using AND, also remove mutually exclusive tags.
+ (if (equal op "+")
+ (loop for g in groups do
+ (if (member tag g)
+ (mapc (lambda (x)
+ (setq current
+ (org-agenda-query-clear current "\\+" x)))
+ g))))
+ ;; Decompose current query into q1 (tags) and q2 (TODOs).
+ (org-agenda-query-decompose current)
+ (let* ((q1 (match-string 1 current))
+ (q2 (match-string 2 current)))
+ (cond
+ ((eq kind 'tag)
+ (concat q1 op tag "/" q2))
+ ;; It's a TODO; when using AND, drop all other TODOs.
+ ((equal op "+")
+ (concat q1 "/+" tag))
+ (t
+ (concat q1 "/" q2 op tag))))))
+
+(defun org-agenda-query-global-todo-keys (&optional files)
+ "Return alist of all TODO keywords and their fast keys, in all FILES."
+ (let (alist)
+ (unless (and files (car files))
+ (setq files (org-agenda-files)))
+ (save-excursion
+ (loop for f in files do
+ (set-buffer (find-file-noselect f))
+ (loop for k in org-todo-key-alist do
+ (setq alist (org-agenda-query-merge-todo-key
+ alist k)))))
+ alist))
+
+(defun org-agenda-query-merge-todo-key (alist entry)
+ (let (e)
+ (cond
+ ;; if this is not a keyword (:startgroup, etc), ignore it
+ ((not (stringp (car entry))))
+ ;; if keyword already exists, replace char if it's null
+ ((setq e (assoc (car entry) alist))
+ (when (null (cdr e)) (setcdr e (cdr entry))))
+ ;; if char already exists, prepend keyword but drop char
+ ((rassoc (cdr entry) alist)
+ (error "TRACE POSITION 2")
+ (setq alist (cons (cons (car entry) nil) alist)))
+ ;; else, prepend COPY of entry
+ (t
+ (setq alist (cons (cons (car entry) (cdr entry)) alist)))))
+ alist)
+
+(defun org-agenda-query-generic-cmd (op)
+ "Activate query manipulation with OP as initial operator."
+ (let ((q (org-agenda-query-selection org-agenda-query-string op
+ org-tag-alist
+ (org-agenda-query-global-todo-keys))))
+ (when q
+ (setq org-agenda-query-string q)
+ (org-agenda-redo))))
+
+(defun org-agenda-query-clear-cmd ()
+ "Activate query manipulation, to clear a tag from the string."
+ (interactive)
+ (org-agenda-query-generic-cmd "="))
+
+(defun org-agenda-query-and-cmd ()
+ "Activate query manipulation, initially using the AND (+) operator."
+ (interactive)
+ (org-agenda-query-generic-cmd "+"))
+
+(defun org-agenda-query-or-cmd ()
+ "Activate query manipulation, initially using the OR (|) operator."
+ (interactive)
+ (org-agenda-query-generic-cmd "|"))
+
+(defun org-agenda-query-not-cmd ()
+ "Activate query manipulation, initially using the NOT (-) operator."
+ (interactive)
+ (org-agenda-query-generic-cmd "-"))
+
;;; Agenda Finding stuck projects
(defvar org-agenda-skip-regexp nil
[-- Attachment #1.1.3: Type: text/plain, Size: 2037 bytes --]
CAVEATS:
1. Carsten, my signed papers are on their way back to FSF; I'll let
you know when I have a copy with their signature too.
2. Keys (even auto-assigned ones) can conflict between the tags and
todo-keywords; in this case, the todo takes precedence. This is
disappointing if you have a key assigned to tag "focus(f)" and
meanwhile have a "#+TYP_TODO: Fred" in some buffer. Fred will get
assigned the key "f" and make "focus" inaccessible. Same thing
happens with fast-tag-selection if include-todo is on, so it's not
unique to my patch, and maybe needs a more general solution.
3. The main function `org-agenda-query-selection' started as a copy of
`org-fast-tag-selection' and there are possibly some parts that could
be reasonably factored out of both and shared. (Mostly the code that
lays out the tag names and keys in the buffer.)
4. ...? Let me know if you find anything else strange.
On Dec 8, 2007, at 9:00 AM, Christopher League wrote:
> Hi, I've been using org-mode for about a year, and recently updated
> to the latest release. I was happy to discover the enhanced tag
> query features ("phone|email/NEXT|SOMEDAY", etc) and started
> rethinking my configuration a little.
>
> I'd like to have an interface for interactive query adjustment. For
> example, in a tags match (C-c a m, org-tags-view), I could begin
> with the query "phone/NEXT" and type the keys "/h" to quickly turn
> it into "phone+home/NEXT" and then ";s" to get "phone+home/NEXT|
> SOMEDAY", then "=[" to clear all the tags to "/NEXT|SOMEDAY", and so
> on. Then, one more keystroke to save the current query into org-
> agenda-custom-commands would be icing on the cake.
>
> I'm new to the mailing list, so maybe some functionality like this
> was discussed before. Closest I found was a thread begun by John W
> in October, wherein "interactive" and "query" were mentioned
> together a few times... http://thread.gmane.org/gmane.emacs.orgmode/3628
> but I don't think it's the same idea.
[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2476 bytes --]
[-- Attachment #2: Type: text/plain, Size: 204 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-01-12 22:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-08 14:00 RFC: interactive tag query adjustment Christopher League
2007-12-08 18:29 ` Adam Spiers
2007-12-08 22:45 ` Christopher League
2007-12-11 10:51 ` Bastien
2008-01-12 22:45 ` Christopher League
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.