From 5b15f886b22dc542220b48ae9659c4c2d56dea78 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.el (org-get-file-title): Moved from the org-clock.el to the org.el and renamed, preserving the same behaviour and function signature. * lisp/org-clock.el (org-clock-get-file-title): Moved and renamed, see above. --- etc/ORG-NEWS | 8 ++++++++ lisp/org-clock.el | 12 +----------- lisp/org.el | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 3c98e8ba0..44f0024fb 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -332,6 +332,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. @@ -399,6 +403,10 @@ Previously, executing PlantUML src blocks always exported to a file. Now, if exported and an ASCII graph will be inserted below the src block. ** Removed or renamed functions and variables +*** Rename ~org-clock-get-file-title~ to ~org-get-file-title~ + +This function is now part of the =org.el= file. + *** =org-plantump-executable-args= is renamed and applies to jar as well The new variable name is =org-plantuml-args=. It now applies to both diff --git a/lisp/org-clock.el b/lisp/org-clock.el index b432c7df7..ef0ef2021 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2473,16 +2473,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." @@ -2739,7 +2729,7 @@ from the dynamic block definition." "\n") (if filetitle - (org-clock-get-file-title file-name) + (org-get-file-title 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 34560c83f..f3f9c4096 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7409,6 +7409,26 @@ the default is \"/\"." (setf (substring fpath (- width 2)) ".."))) fpath)) +(defun org-get-file-title (file-name) + "Collect title from `org-mode' FILE-NAME. + +Return file name if title does not exist." + (or (org-get-title (find-file-noselect file-name)) + (file-name-nondirectory file-name))) + +(defun org-get-title (&optional buffer) + "Collect title from the provided `org-mode' BUFFER. + +Returns nil if there are no #+TITLE property." + (let ((buffer (or (buffer-base-buffer) + buffer + (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