From 76806632058d31b9e031b5e8f5af14d48c360c68 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Wed, 29 Apr 2020 12:42:55 +0800 Subject: [PATCH] (feat): optionally use headline as title (#538) Optionally pulls title from the first headline in Org file. Closes #506. --- CHANGELOG.md | 3 +++ org-roam.el | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb60a44..af404b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ * [#509](https://github.com/jethrokuan/org-roam/pull/509) fix external org files being tracked in database * [#537](https://github.com/jethrokuan/org-roam/pull/537) quote graphviz node and edge configuration options to allow multi-word configurations +### Features +* [#538](https://github.com/jethrokuan/org-roam/pull/538) Optionally use text in first headline as title + ## 1.1.0 (21-04-2020) To the average user, this release is mainly a bugfix release with additional options to customize. However, the changes made to the source is significant. Most notably, in this release: diff --git a/org-roam.el b/org-roam.el index bd8fd67..cd8bc3f 100644 --- a/org-roam.el +++ b/org-roam.el @@ -246,11 +246,19 @@ it as FILE-PATH." (defun org-roam--extract-titles () "Extract the titles from current buffer. -Titles are obtained via the #+TITLE property, or aliases -specified via the #+ROAM_ALIAS property." +Titles are obtained via: + +1. The #+TITLE property or the first headline +2. The aliases specified via the #+ROAM_ALIAS property." (let* ((props (org-roam--extract-global-props '("TITLE" "ROAM_ALIAS"))) (aliases (cdr (assoc "ROAM_ALIAS" props))) - (title (cdr (assoc "TITLE" props))) + (title (or (cdr (assoc "TITLE" props)) + (org-element-map + (org-element-parse-buffer) + 'headline + (lambda (h) + (org-no-properties (org-element-property :raw-value h))) + :first-match t))) (alias-list (org-roam--aliases-str-to-list aliases))) (if title (cons title alias-list)