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