Skip to content

Commit

Permalink
lisp/org-clock.el: Show file title in org-clock clocktable
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Duy Nguyen authored and yantar92 committed Aug 20, 2022
1 parent a1af06d commit 2cc2d8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/org-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions etc/ORG-NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion lisp/org-clock.el
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ string as argument."
:link nil
:narrow '40!
:indent t
:filetitle nil
:hidefiles nil
:formula nil
:timestamp nil
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2cc2d8f

Please sign in to comment.