Extract all level 1 headlines as title


I want to extract all level one headlines of notes as a title. My plan is to have that only for daily notes, because I use them for meeting notes, where the level one headline names the meeting. For all other notes, the “normal” title extraction is fine. But as a first try, I just try to add for all notes:

(defun org-roam--extract-titles-allheadlines ()
  (org-map-entries (lambda ()
                     (org-element-property :title (org-element-at-point)) )

which works fine, e.g. I eval (M-: (org-roam--extract-titles-allheadlines) on on org file gives me

("A" "B")

which is correct.

After that, I do

(setq org-roam-title-sources '((title allheadlines) alias))

and (org-roam-db-clear) and (org-roam-db-build-cache) which runs fine and prints the status

(org-roam) total: Δ19, files-modified: Δ19, ids: Δ1, links: Δ43, tags: Δ13, titles: Δ19, refs: Δ0, deleted: Δ0

However, no new titles are extracted and shown in org-roam-find-file.

What can still be missing here?

Best Thanks!

I would put a break point with using edebug-defun on the org-roam--extract-titles function and see how your user option behaves in the actual runtime step-by-step.

If this was not something you would opt to do, then I would need to ask someone more knowledgeable to advise.

Ok, I got it. Completely me to blame:

has to be read as (title OR allheadlines) AND alias. Therefore allheadlines was never evaluated as title returned non-nil.

This is what I actually want:

(setq org-roam-title-sources '(title allheadlines alias))
1 Like

My final configuration is

(defun org-roam--extract-titles-allheadlines-for-daillies ()
  (when (string-prefix-p (concat (expand-file-name org-roam-directory) org-roam-dailies-directory) org-roam-file-name)
    (org-map-entries (lambda ()
                        (car (org-roam--extract-titles-title))
                        ": "
                        (org-element-property :title (org-element-at-point))))

(setq org-roam-title-sources '((title headline) alias allheadlines-for-daillies))

which, only for the daillies gives me titles like

(Meeting, someproject) 2021-05-17: Zusammenarbeit Team1 Team2

which is what I want. Still, open for any ideas or optimizations!

1 Like