5

org-mode agenda view has a bunch of commands accessible with a single key press.

E.g. typing b moves backward in time to display earlier dates, and typing t brings up a dialog to change the TODO state of the item.

I would like to redefine t to toggle between TODO and DONE without any dialog, and also redefine b to reschedule a task at focus to the next week.

How can those built-in commands be redefined?

  • See the manual re: key-bindings. – Dan Jan 9 '16 at 23:58
  • 2
    (require 'org-agenda) (define-key org-agenda-mode-map "t" 'butterfly) You only need the require statement one time at the outset before redefining the bindings. – lawlist Jan 10 '16 at 1:02
  • This question seems like a duplicate, but I don't have the time to look it up. (This question also seems to be a bit confused. Is it about changing key bindings (per the title) or about redefining commands (per the last line)?) – Drew Jan 10 '16 at 1:35
  • Thanks guys, I've read in the docs about adding new keys to the C-c a <key> scheme, but found nothing about the org-agenda-mode-map – Alexander Shcheblikin Jan 10 '16 at 10:46
  • 2
    Consider revising the question to ask just one question, instead of three different questions. The butterfly example above is sufficient to teach you how to redefine keys for the org-agenda view. The other two questions should each be a separate thread -- i.e., thread number one is the butterfly question/answer; thread number two is creating a simple toggle between todo/done; thread number three is how to reschedule a task for next week. Please be certain to Google a bit and see if there are already threads that answer your question -- because that is what we will do before answering. – lawlist Jan 10 '16 at 17:18
3

You can do that in two steps:

  1. define a function to change the state
  2. map the function to b in org-agenda-mode

Define a function to change the state

(defun my/org-agenda-todo-done ()
  (interactive)
  (org-agenda-todo 'done))

org-todo and org-agenda-todo takes arguments. Of which, you can define the state.

Map the function to b in org-agenda-mode

(add-hook 'org-agenda-mode-hook
          (lambda ()
                  (local-set-key (kbd "d") 'my/org-agenda-todo-done)))

Bind the function to the key of your choice. Make sure to add your key to the org-agenda-mode-map. local-set-key on the hook will do.

Note that b is mapped to org-agenda-earlier in default. If you don't want to lose it, remap to another key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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