From: Duy Nguyen <ddnguyen2101@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: Emacs-orgmode@gnu.org
Subject: Re: [Patch] Show org file title in org-clock clocktable
Date: Sat, 13 Aug 2022 12:55:37 +0200 [thread overview]
Message-ID: <CAM=3T07tcQ4MrC3BDbp_eV-zHy4-3MA5DX0xmeP3-msbgOXXBQ@mail.gmail.com> (raw)
In-Reply-To: <87edxk7etq.fsf@localhost>
[-- Attachment #1.1: Type: text/plain, Size: 511 bytes --]
>
> Please use the built-in org-collect-keywords instead.
>
Thanks for the pointer, I changed the function in the attached patch.
This is a user-facing change and should be documented in etc/ORG-NEWS file.
Updated both the etc/ORG-NEWS and the doc/org-manual.org files.
Not sure how you normally go about updates to submitted patches. For this
time, I just updated the patch by amending the commit of the previous patch
I sent. Please let me know another approach is preferable going forward.
Thanks,
Duy
[-- Attachment #1.2: Type: text/html, Size: 955 bytes --]
[-- Attachment #2: 0001-lisp-org-clock.el-Show-file-title-in-org-clock-clock.patch --]
[-- Type: application/octet-stream, Size: 3999 bytes --]
From 45882f233d961aadbcbc88ee28ba3aac8599296a Mon Sep 17 00:00:00 2001
From: Duy Nguyen <duynguyen@Duys-MBP.home>
Date: Fri, 12 Aug 2022 18:40:10 +0200
Subject: [PATCH] lisp/org-clock.el: Show file title in org-clock clocktable
* lisp/org-clock.el (org-clocktable-defaults): Add default value for
new clocktable 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 clocktable 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
clocktable. If the file does not have a title defined, the file name
will be shown in the clocktable.
TINYCHANGE
---
doc/org-manual.org | 4 ++++
etc/ORG-NEWS | 13 +++++++++++++
lisp/org-clock.el | 16 +++++++++++++++-
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 466718e6e..046da3790 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -6797,6 +6797,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
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 00fe101dc..e9585617e 100644
--- a/etc/ORG-NEWS
+++ b/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
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 362abe358..5baa730f8 100644
--- a/lisp/org-clock.el
+++ b/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)))))
+;;;###autoload
+(defun org-clock-get-file-title (file-name)
+ "Get the file title from FILE-NAME as a string. Returns short
+FILE-NAME if title is not found."
+ (with-current-buffer (find-file-noselect file-name)
+ (let ((title (org-collect-keywords '("title"))))
+ (if (null title)
+ (file-name-nondirectory file-name)
+ (nth 1 (assoc "TITLE" 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
--
2.32.1 (Apple Git-133)
next prev parent reply other threads:[~2022-08-13 10:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 21:54 [Patch] Show org file title in org-clock clocktable Duy Nguyen
2022-08-13 8:00 ` Ihor Radchenko
2022-08-13 10:55 ` Duy Nguyen [this message]
2022-08-13 11:35 ` Ihor Radchenko
2022-08-15 6:40 ` [PATCH v2] " Duy Nguyen
2022-08-17 9:34 ` Ihor Radchenko
2022-08-17 18:53 ` [PATCH v3] " Duy Nguyen
2022-08-20 6:14 ` Ihor Radchenko
2022-08-21 12:06 ` Duy Nguyen
2022-08-28 8:11 ` Duy Nguyen
2022-08-28 8:33 ` Duy Nguyen
2022-08-28 11:30 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAM=3T07tcQ4MrC3BDbp_eV-zHy4-3MA5DX0xmeP3-msbgOXXBQ@mail.gmail.com' \
--to=ddnguyen2101@gmail.com \
--cc=Emacs-orgmode@gnu.org \
--cc=yantar92@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).