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?

5
  • See the manual re: key-bindings.
    – Dan
    Commented Jan 9, 2016 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
    Commented Jan 10, 2016 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
    Commented Jan 10, 2016 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 Commented Jan 10, 2016 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
    Commented Jan 10, 2016 at 17:18

1 Answer 1

8

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 "b") '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.

2
  • 1
    did you mean to write "b" instead of "d" in the source block? Commented Feb 8, 2022 at 9:13
  • Yes. Thanks. Fixed. Commented Feb 8, 2022 at 10:15

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.