Browse Source

lisp/org-clock.el: Show file title in org-clock clocktable

* lisp/org-clock.el (org-clocktable-defaults): Add default value for
new clock table option `:filetitle'.
(org-clock-get-file-title): Add new function to extract title of org file.
(org-clocktable-write-default): Print org file name in clock table if
`:filetitle' is set to `t'.

* doc/org-manual.org (The clock table): Include new `:filetitle'
option in manual for clock table.

* etc/ORG-NEWS (New =:filetitle= option for clock table): Include new
`:filetitle' option for clock table.

Allow user to show org file title instead of file name in the
clock table.  If the file does not have a title defined, the file name
will be shown in the clock table.

TINYCHANGE
Duy Nguyen 2 years ago
parent
commit
2cc2d8f1f6
3 changed files with 32 additions and 1 deletions
  1. 4 0
      doc/org-manual.org
  2. 13 0
      etc/ORG-NEWS
  3. 15 1
      lisp/org-clock.el

+ 4 - 0
doc/org-manual.org

@@ -6800,6 +6800,10 @@ using the =:formatter= parameter.
 
   Indent each headline field according to its level.
 
+- =:filetitle= ::
+
+  Show title in the file column if the file has a =#+title=.
+ 
 - =:hidefiles= ::
 
   Hide the file column when multiple files are used to produce the

+ 13 - 0
etc/ORG-NEWS

@@ -270,6 +270,19 @@ example,
 
 prints a sub-bibliography containing the book entries with =ai= among
 their keywords.
+*** New =:filetitle= option for clock table
+
+The =:filetitle= option for clock tables can be set to ~t~ to show org
+file title (set by =#+title:=) in the File column instead of the
+file name.  For example:
+
+#+begin_src org
+,#+BEGIN: clocktable :scope agenda :maxlevel 2 :block thisweek :filetitle t
+#+end_src
+
+If a file does not have a title, the table will show the file name
+instead.
+
 ** New options
 *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers
 

+ 15 - 1
lisp/org-clock.el

@@ -324,6 +324,7 @@ string as argument."
    :link nil
    :narrow '40!
    :indent t
+   :filetitle nil
    :hidefiles nil
    :formula nil
    :timestamp nil
@@ -2469,6 +2470,16 @@ 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."
@@ -2584,6 +2595,7 @@ from the dynamic block definition."
 	 (emph (plist-get params :emphasize))
 	 (compact? (plist-get params :compact))
 	 (narrow (or (plist-get params :narrow) (and compact? '40!)))
+	 (filetitle (plist-get params :filetitle))
 	 (level? (and (not compact?) (plist-get params :level)))
 	 (timestamp (plist-get params :timestamp))
 	 (tags (plist-get params :tags))
@@ -2723,7 +2735,9 @@ from the dynamic block definition."
 			     (if (eq formula '%) " %s |" "")
 			     "\n")
 
-		     (file-name-nondirectory file-name)
+                     (if filetitle
+                         (org-clock-get-file-title file-name)
+                       (file-name-nondirectory file-name))
 		     (if level?    "| " "") ;level column, maybe
 		     (if timestamp "| " "") ;timestamp column, maybe
 		     (if tags      "| " "") ;tags column, maybe