Strona domowa

Witam na mojej prywatnej stronie internetowej!

[If this is all Polish to you, click here: English]

Uwaga: z oczywistych powodów nie mogę zagwarantować swojej nieomylności, choć staram się o zgodność tego, co piszę, z Prawdą. Jest również oczywiste, że nie gwarantuję takiej zgodności w przypadku komentarzy. Umieszczenie linku do strony spoza niniejszego serwisu nie musi oznaczać, że podzielam poglądy autora tej strony, a jedynie, że uważam ją za wartościową z takich czy innych powodów.

Marcin ‘mbork’ Borkowski

2024-12-16 Changing the TODO state of an Org entry when refiling

One of the things I do quite often is refiling Org entries to my “archive” file and marking them as DONE or CANCELED. (For some reason I can’t even remember now, I don’t use the archiving feature of Org.) It occurred to me that having Emacs change the todo state automatically would be very convenient.

Of course, I don’t want to do that every time I refile anything – just when I refile a headline to my archive.org file. Guess what? Emacs and Org mode have me covered!

(defun org-todo-when-archive ()
  "Run `org-todo' but only when in `archive.org'.
This is suitable for putting in `org-after-refile-insert-hook' so that
I can easily mark stuff refiled there as `DONE' or `CANCELED'."
  (when (string= (file-name-nondirectory (buffer-file-name)) "archive.org")
    (org-todo)))

(add-hook #'org-after-refile-insert-hook #'org-todo-when-archive)

From now on, items I refile to my personal archive will get a chance of having their state changed with just one more keypress. And the best thing is, I needed less than 10 minutes to code this!

Of course, I have to make an obligatory shoutout to the wonderful Introduction to programming in Emacs Lisp by the late Robert J. Chassell, which will teach you the basics of Emacs Lisp so that you’ll be able to extend your Emacs, too. And if you want to learn more, but studying the Emacs Lisp reference manual seems too daunting, check out my ebook Hacking your way around in Emacs.

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

More...