From 669bb68aae3da16d0336bb7e6e1950bb716c8719 Mon Sep 17 00:00:00 2001 From: Mikhail Skorzhinskii Date: Thu, 8 Sep 2022 21:29:23 +0200 Subject: [PATCH 1/3] org-clock.el: Rename org-clock-get-file-title * lisp/org.el (org-get-title): A new function to collect a document title from an org-mode buffer, based on a `org-clock-get-file-title' implementation. * lisp/org-clock.el (org-clock-get-file-title): Removed --- etc/ORG-NEWS | 4 ++++ lisp/org-clock.el | 13 ++----------- lisp/org.el | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index c18c03725..e96aa482b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -361,6 +361,10 @@ event time when the alarm time is set to 0. The default value is nil -- do not create alarms at the event time. ** New functions and changes in function arguments +*** New function ~org-get-title~ to get =#+TITLE:= property from buffers + +A function to collect the document title from the org-mode buffer. + *** ~org-fold-show-entry~ does not fold drawers by default anymore ~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS. diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 6332399bb..e98a34f0d 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2484,16 +2484,6 @@ the currently selected interval size." (org-update-dblock) t))))) -(defun org-clock-get-file-title (file-name) - "Get the file title from FILE-NAME as a string. -Return short FILE-NAME if #+title keyword is not found." - (with-current-buffer (find-file-noselect file-name) - (org-macro-initialize-templates) - (let ((title (assoc-default "title" org-macro-templates))) - (if (null title) - (file-name-nondirectory file-name) - title)))) - ;;;###autoload (defun org-dblock-write:clocktable (params) "Write the standard clocktable." @@ -2750,7 +2740,8 @@ from the dynamic block definition." "\n") (if filetitle - (org-clock-get-file-title file-name) + (or (org-get-title file-name) + (file-name-nondirectory file-name)) (file-name-nondirectory file-name)) (if level? "| " "") ;level column, maybe (if timestamp "| " "") ;timestamp column, maybe diff --git a/lisp/org.el b/lisp/org.el index 8191f0860..f51e6d6d9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7423,6 +7423,20 @@ the default is \"/\"." (setf (substring fpath (- width 2)) ".."))) fpath)) +(defun org-get-title (&optional buffer-or-file) + "Collect title from the provided `org-mode' BUFFER-OR-FILE. + +Returns nil if there are no #+TITLE property." + (let ((buffer (cond ((bufferp buffer-or-file) buffer-or-file) + ((stringp buffer-or-file) (find-file-noselect + buffer-or-file)) + (t (current-buffer))))) + (with-current-buffer buffer + (org-macro-initialize-templates) + (let ((title (assoc-default "title" org-macro-templates))) + (unless (string= "" title) + title))))) + (defun org-display-outline-path (&optional file current separator just-return-string) "Display the current outline path in the echo area. -- 2.35.1