To get to my day page (agenda), currently I have to type in the following keys

  1. C-c a (binded to (org-agenda))
  2. a (Agenda for current week or day)
  3. d (to switch from week-view to day-view)
  4. C-c C-x C-c (to switch to column-view)

It's too much! Can I achieve the same thing by pressing just one key say <f10>, and hopefully without unnecessary evaluations? It's not as easy as normal key bindings I suppose, since one has to deal with the org agenda dispatcher.

EDIT: Answer found

  1. See NickD's answer. The key is (org-agenda-list nil nil 1 nil) and details can be found in the manual of the function (org-agenda-list) by C-h f org-agenda-list <RET>. This way is much faster than the second answer below.
  2. If you accept macro as a solution (which is slower), turn it into an elisp function by using the package elmacro and assign a keybind.

You can define your own function that does all the things you want it to do and bind it to a key:

(defun my-day-page ()
   (org-agenda-list nil nil 1 nil)

(define-key global-map [f10] 'my-day-page)

See the doc for org-agenda-list (C-h f org-agenda-list RET) for the meaning of the arguments: the third argument (the 1 above) is the span (i.e. how many days this list should cover).

  • Super! That's exactly what I'm looking for. It makes the workflow much faster by not evaluating unnecessary functions.
    – Student
    Apr 21 '20 at 19:53

The easiest way to do this would be a macro, more information can be found on the emacswiki, but essentially all you would do is:

  1. C-x (
    • Start Recording a Macro
  2. C-c a a C-c C-x C-c
    • Open the Agenda in column view
  3. C-x )
    • End the Macro
  4. M-x name-last-kbd-macro my-day-page
    • Give the macro a name
  5. M-x insert-kbd-macro
    • Insert the Macro
  6. (global-set-key (kbd "C-c b") 'my-day-page)

That macro function and keybinding can now be added to your ~/emacs.d/init.el file and pressing C-c b should now open up the day-page.

All together it might look like this:

;; Macro for Day View
(global-set-key (kbd "C-c a") 'org-agenda)
(fset 'my-day-page
(kmacro-lambda-form [?\C-c ?a ?a ?\C-c ?\C-x ?\C-c] 0 "%d"))
(global-set-key (kbd "C-c b") 'my-day-page)

-- EDIT by OP --

If you want to see what a macro is really doing, use the package elmacro, which turns your macro into a elisp function. In your case, after installation of elmacro from melpa, run elmacro-mode.

Define the macro as usual <f3>C-c a a d R C-c C-x C-c<f4>, and run the magical M-x elmacro-show-last-macro. It will generate a buffer with the elisp function!

(defun last-macro ()
  (org-agenda-list nil)
  (org-agenda nil)
  (org-agenda-day-view nil)

Please note that this result is not completely satisfactory. You want to get rid of (org-agenda nil) from the function, ending up give you

(defun the-macro-you-like ()
  (org-agenda-list nil)
  (org-agenda-day-view nil)

Finally, put this function in your config file, and bind it to <f10> for example by

(global-set-key (kbd "<f10>") 'the-macro-you-like)

  • Thank you. Still two more things are concerning.. 1. Are there other ways to circumvent org-agenda dispatcher, so it can be more scriptable? 2. A macro runs a risk when I happen to be in some other mode where the key-chords are mapped to other dangerous commands. Are there ways to be make it safer?
    – Student
    Apr 21 '20 at 14:14
  • A1. To make it more scriptable, use elmacro, which turns a macro into an elisp function. It might not be perfect everytime, see my edition to the answer.
    – Student
    Apr 21 '20 at 15:07

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.