emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Agenda todo states autocompletion: suggestion for improvement
@ 2019-02-21 18:47 Carlos Pita
  2019-02-21 18:54 ` Carlos Pita
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos Pita @ 2019-02-21 18:47 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

M-x org-agenda T prompts for a todo keyword. But it builds the
completion list while preparing the agenda buffers and this is done
*after* prompting. So the first time no completion is presented, the
second time completions from previous invocation of
org-agenda-prepare-buffers are presented, etc.

This has some drawbacks:

1. The first time one has to explicitly type the state.

2. I'm not sure about this but: aren't completions potentially
outdated, since the last time the list was built was for a previous
agenda?

To prepare the buffers before showing the prompt will fix both issues
but maybe at a high computational cost, I've not investigated the code
in any depth yet. Otherwise, at least the default list of state
keywords could be shown when org-todo-keywords-for-agenda is nil,
couldn't it?

Best regards
--
Carlos

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Agenda todo states autocompletion: suggestion for improvement
  2019-02-21 18:47 Agenda todo states autocompletion: suggestion for improvement Carlos Pita
@ 2019-02-21 18:54 ` Carlos Pita
  2019-02-21 19:12   ` Carlos Pita
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos Pita @ 2019-02-21 18:54 UTC (permalink / raw)
  To: emacs-orgmode

It doesn't seem to be any relevant computational penalty:

    (when (equal arg '(4))
      (setq org-select-this-todo-keyword
        (completing-read "Keyword (or KWD1|K2D2|...): "
                 (mapcar #'list kwds) nil nil)))
<------------ (1)
    (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
    (catch 'exit
      (when org-agenda-sticky
    (setq org-agenda-buffer-name
          (if (stringp org-select-this-todo-keyword)
          (format "*Org Agenda(%s:%s)*" (or org-keys "t")
              org-select-this-todo-keyword)
        (format "*Org Agenda(%s)*" (or org-keys "t")))))
      (org-agenda-prepare "TODO")                        <------------ (2)

It's true that the user might abort the prompt (1) without executing
(2) but that's an exceptional use case.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Agenda todo states autocompletion: suggestion for improvement
  2019-02-21 18:54 ` Carlos Pita
@ 2019-02-21 19:12   ` Carlos Pita
  2019-02-22 18:59     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos Pita @ 2019-02-21 19:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

Here is a patch inverting (1) and (2) above.

[-- Attachment #2: 0001-org-agenda-improve-todo-states-completion.patch --]
[-- Type: text/x-patch, Size: 2287 bytes --]

From 9c97eebb6c26332415fb03c65e872d304576fe07 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Thu, 21 Feb 2019 16:09:58 -0300
Subject: [PATCH] org-agenda: improve todo states completion

* lisp/org-agenda.el (org-todo-list): prepare agenda buffers before
  prompting for state.
---
 lisp/org-agenda.el | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 2765718ac..ff98cd65d 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -4673,18 +4673,8 @@ for a keyword.  A numeric prefix directly selects the Nth keyword in
   (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
   (let* ((today (org-today))
 	 (date (calendar-gregorian-from-absolute today))
-	 (kwds org-todo-keywords-for-agenda)
 	 (completion-ignore-case t)
-	 (org-select-this-todo-keyword
-	  (if (stringp arg) arg
-	    (and arg (integerp arg) (> arg 0)
-                 (nth (1- arg) kwds))))
-	 rtn rtnall files file pos)
-    (when (equal arg '(4))
-      (setq org-select-this-todo-keyword
-	    (completing-read "Keyword (or KWD1|K2D2|...): "
-			     (mapcar #'list kwds) nil nil)))
-    (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
+         kwds org-select-this-todo-keyword rtn rtnall files file pos)
     (catch 'exit
       (when org-agenda-sticky
 	(setq org-agenda-buffer-name
@@ -4693,6 +4683,15 @@ for a keyword.  A numeric prefix directly selects the Nth keyword in
 			  org-select-this-todo-keyword)
 		(format "*Org Agenda(%s)*" (or org-keys "t")))))
       (org-agenda-prepare "TODO")
+      (setq kwds org-todo-keywords-for-agenda
+            org-select-this-todo-keyword (if (stringp arg) arg
+                                           (and arg (integerp arg) (> arg 0)
+                                                (nth (1- arg) kwds))))
+      (when (equal arg '(4))
+        (setq org-select-this-todo-keyword
+              (completing-read "Keyword (or KWD1|K2D2|...): "
+                               (mapcar #'list kwds) nil nil)))
+      (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
       (org-compile-prefix-format 'todo)
       (org-set-sorting-strategy 'todo)
       (setq org-agenda-redo-command
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Agenda todo states autocompletion: suggestion for improvement
  2019-02-21 19:12   ` Carlos Pita
@ 2019-02-22 18:59     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2019-02-22 18:59 UTC (permalink / raw)
  To: Carlos Pita; +Cc: emacs-orgmode

Hello,

Carlos Pita <carlosjosepita@gmail.com> writes:

> Here is a patch inverting (1) and (2) above.
>
> From 9c97eebb6c26332415fb03c65e872d304576fe07 Mon Sep 17 00:00:00 2001
> From: memeplex <carlosjosepita@gmail.com>
> Date: Thu, 21 Feb 2019 16:09:58 -0300
> Subject: [PATCH] org-agenda: improve todo states completion
>
> * lisp/org-agenda.el (org-todo-list): prepare agenda buffers before
>   prompting for state.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-22 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 18:47 Agenda todo states autocompletion: suggestion for improvement Carlos Pita
2019-02-21 18:54 ` Carlos Pita
2019-02-21 19:12   ` Carlos Pita
2019-02-22 18:59     ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).