Posts tagged "org-mode":
Todo items in org-roam, an update
I got an email from Mr Z with a nice modification to the code in my post on keeping todo items in org-roam.
He already had a bunch of agenda files that he wanted to keep using (I had so few of them that I'd simply converted them to roam files). Here's the solution he shared with me:
(defvar roam-extra-original-org-agenda-files nil "Original value of `org-agenda-files'.") (defun roam-extra:update-todo-files (&rest _) "Update the value of `org-agenda-files'." (unless roam-extra-original-org-agenda-files (setq roam-extra-original-org-agenda-files org-agenda-files)) (setq org-agenda-files (append roam-extra-original-org-agenda-files (roam-extra:todo-files))))
It's a rather nice modification I think. Thanks to Mr Z for agreeing to let me share it here.
Keeping todo items in org-roam
A while ago I made an attempt to improve my work habits by keeping a document
with TODO items. It lasted only for a while, and I've since had the intention to
make another attempt. Since then I've started using org-roam and I've managed to
create a habit of writing daily journal notes using org-roam's daily-notes. A
few times I've thought that it might fit me well to put TODO items in the notes,
but that would mean that I'd have to somehow keep track of them. At first I
manually added a tag to each journal fily containing a TODO item. That didn't
work very well at all, which should have been obvious up front. Then I added the
folders where I keep roam files and journals to org-agenda-files
, that worked
a lot better. I'd still be using that, even if I expected it to slow down
considerably as the number of files grow, but then I found a post on dynamic and
fast agenda with org-roam.
I adjusted it slightly to fit my own setup a bit better, i.e. I made a Spacemacs
layer, roam-extra
, I use the tag todo
, and I use a different hook to get the
tag added on opening an org-roam file.
The layer consists of a single file, layers/roam-extra/funcs.el
. In it I
define 4 functions (they are pretty much copies of the functions in the post
linked above):
roam-extra:todo-p
- returns non-nil
if the current current buffer contains a TODO item.roam-extra:update-todo-tag
- updates the tags of the current buffer to reflect the presence of TODO items, i.e. ensure the the tagtodo
is present iff there's a TODO item.roam-extra:todo-files
- uses the org-roam DB to return a list of all files containing the tagtodo
.roam-extra:update-todo-files
- adjusts'org-agenda-files
to contain only the files with TODO items.
I've put the full contents of the file at the end of the post.
To ensure that the todo
tag is correct in all org-mode files I've added
roam-extra:update-todo-tag
to hooks that are invoked on opening an org-ram
file and when saving a file. (I would love to find a more specialise hook than
before-save-hook
, but it works for now.)
(add-hook 'org-roam-file-setup-hook #'roam-extra:update-todo-tag) (add-hook 'before-save-hook #'roam-extra:update-todo-tag)
To ensure that the list of files with TODO items is kept up to date when I open
I also wrap org-agenda
in an advice so roam-extra:update-todo-files
is
called prior to the agenda being opened.
(advice-add 'org-agenda :before #'roam-extra:update-todo-files)
The layer, layers/roam-extra/funcs.el
(defun roam-extra:todo-p () "Return non-nil if current buffer has any TODO entry. TODO entries marked as done are ignored, meaning the this function returns nil if current buffer contains only completed tasks." (org-element-map (org-element-parse-buffer 'headline) 'headline (lambda (h) (eq (org-element-property :todo-type h) 'todo)) nil 'first-match)) (defun roam-extra:update-todo-tag () "Update TODO tag in the current buffer." (when (and (not (active-minibuffer-window)) (org-roam--org-file-p buffer-file-name)) (let* ((file (buffer-file-name (buffer-base-buffer))) (all-tags (org-roam--extract-tags file)) (prop-tags (org-roam--extract-tags-prop file)) (tags prop-tags)) (if (roam-extra:todo-p) (setq tags (seq-uniq (cons "todo" tags))) (setq tags (remove "todo" tags))) (unless (equal prop-tags tags) (org-roam--set-global-prop "roam_tags" (combine-and-quote-strings tags)))))) (defun roam-extra:todo-files () "Return a list of note files containing todo tag." (seq-map #'car (org-roam-db-query [:select file :from tags :where (like tags (quote "%\"todo\"%"))]))) (defun roam-extra:update-todo-files (&rest _) "Update the value of `org-agenda-files'." (setq org-agenda-files (roam-extra:todo-files)))
Ditaa in Org mode
Just found out that Emacs ships with Babel support for ditaa (yes, I'm late to the party).
Sweet! That is yet another argument for converting all our README.md
into
README.org
at work.
\
The changes I made to my Spacemacs config are
(defun dotspacemacs/user-config () ... (with-eval-after-load 'org ... (add-to-list 'org-babel-load-languages '(ditaa . t)) (setq org-ditaa-jar-path "/usr/share/java/ditaa/ditaa-0.11.jar")) ...)
Some OrgMode stuff
The last few days I've watched Rainer König's OrgMode videos. It's resulted in a few new settings that makes Org a little more useful.
Variable | Value | Description |
---|---|---|
calendar-week-start-day |
1 |
Weeks start on Monday! |
org-modules (list) |
org-habit |
Support for tracking habits |
org-modules (list) |
org-id |
Improved support for ID property |
org-agenda-start-on-weekday |
1 |
Weeks start on Monday, again! |
org-log-into-drawer |
t |
Put notes (logs) into a drawer |
org-enforce-todo-checkbox-dependencies |
t |
Checkboxes must be checked before a TODO can become DONE |
org-id-link-to-org-use-id |
t |
Prefer use of ID property for links |
TIL: prompt matters to org-mode
A workmate just embellished some shell code blocks I'd put in a shared org-mode
file with :session s
. When I tried to run the blocks with sessions my emacs
just froze up though. I found a post on the emacs StackExchange that offered a
possible cause for it: the prompt.
I'm using bash-it so my prompt is rather far from the default.
After inspecting the session buffer simply added the following to my ~/.bashrc
if [[ ${TERM} == "dumb" ]]; then export BASH_IT_THEME='standard' else export BASH_IT_THEME='simple' fi
and now I can finally run shell code blocks in sessions.