reddit / emacs

Position the cursor on today's date in org-agenda on startup

revrari100 · 2022-12-23 09:44
When I start `org agenda`, it positions the cursor on the first entry, rather than on today's date. I then press`.` to go to today. One extra step, but cumbersome when opened many times a day. I have `(add-hook 'org-agenda-mode-hook '(lambda () (hl-line-mode 1)))` which currently highlights the line with the cursor. I would like to position the cursor on today's date in org-agenda on startup. 📷
0lMon · 2022-12-23 10:07
Hej Hej, I will give you the answer but I also give you how you could find that out in Emacs by yourself. You already know about hooks so we can skip this. You already found out that `.` gives you the effect you want. Now we only need to find out what `.` is doing. You get the answer by pressing `C-h k` which calls the function `describe-key`. This function asks that you press a button and it will tell you what function will be called by pressing that button. So after pressing `C-h k .` a *Help* Buffer will pop up. In there you will see the following: ". runs the command org-agenda-goto-today". Now we have the function time to add it to the hook. `(add-hook 'org-agenda-mode-hook #'org-agenda-goto-today)` And what do we see after opening the agenda? That is right and Error.... To remove a hook again use: `(remove-hook 'org-agenda-mode-hook #'org-agenda-goto-today)` Why the error occurs is because the buffer is still empty when the mode is activated. So we need an other hook. Searching for the correct hook with `C-h v` you will find `org-agenda-finalize-hook`, that is what we need to use. So the final code is: `(add-hook 'org-agenda-finalize-hook #'org-agenda-goto-today)` Hope this helps more than just gives the answer right away! Cheers and Merry Christmas!
Cletip · 2022-12-23 11:17
More answers should sound like yours :)
revrari100 · 2022-12-23 12:52
What a thoughtful and helpful answer! I am immensely grateful for it.