From 7e6e98e5683f2b0d8d335f53100b6b3623823df3 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 2 Sep 2023 13:45:55 +1000 Subject: A few more org utilities, and small fixes in editing / goto places added my-org-swap-referral-with-headline added my-org-clean-up-entry fixed avy binding org capture todo: contain initial content (if any) in an example block --- emacs/.emacs.d/lisp/my/my-org.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'emacs/.emacs.d/lisp') diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index 334f708..1a44a10 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -1120,6 +1120,39 @@ When BLOCK-REGEXP is non-nil, use this regexp to find blocks." (list "ITEM" "Referral" "Wikipedia-link" "IMDB-link"))) "\t")) +(defun my-org-swap-referral-with-headline () + "Swap Referral property with headline of org node at point. + +Remove the Referral property if empty." + (interactive) + (let ((ref (or (org-entry-get (point) "Referral") "")) + (headline (org-entry-get (point) "ITEM"))) + (if (string-empty-p headline) + (org-delete-property "Referral") + (org-entry-put (point) "Referral" headline)) + (org-edit-headline ref))) + +(defun my-org-clean-up-entry () + "Clean up an org entry. + +Delete empty standard properties. +Sync attachment. +Remove trailing whitespaces. +Flush lines with only some common symbols." + (interactive) + (my-org-delete-empty-properties) + (org-attach-sync) + (save-restriction + (org-narrow-to-subtree) + (flush-lines "^[ \t-]*$") + (delete-trailing-whitespace))) + +(defun my-org-delete-empty-properties () + "Delete empty (standard) properties at point." + (interactive) + (pcase-dolist (`(,name . ,value) (org-entry-properties (point) 'standard)) + (when (string-empty-p value) (org-entry-delete (point) name)))) + (defvar org-entries-tsv-buffer "*org-entries-tsv*") (defun my-org-entries-at-point-to-tsv (beg end) (interactive "r") -- cgit v1.2.3