From ffea78e98b6a9c494c0a52f59e6ad1678a6dc445 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 21 Aug 2023 16:42:27 +1000 Subject: Fixing a few things in emacs, adding xdgdef Emacs: updating the org clock refile so that it refiles all text in the logbook --- emacs/.emacs.d/lisp/my/my-org.el | 58 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'emacs/.emacs.d/lisp/my') diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index f02784d..ae21b37 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -507,14 +507,37 @@ Assuming they are in the logbook drawer" (append-next-kill) (kill-line)))))) -(defun my-org-clock-yank () +(defun my-org-element-at-drawer-p () + "Returns t if point is at a drawer beginning or end." + (not (not + (member (org-element-type (org-element-at-point)) + '(drawer property-drawer))))) + +(defun my-org-kill-logbook-entries () + "Kill all logbook entries of the org node at point." + (interactive) + (let ((beg)) + (save-excursion + (save-restriction + (org-narrow-to-subtree) + (goto-char (point-min)) + (when (and (re-search-forward "^\\ *:LOGBOOK:\\ *$" nil t) + (my-org-element-at-drawer-p)) + (beginning-of-line 2) + (setq beg (point)) + (when (re-search-forward "^\\ *:END:\\ *$" nil t) + (beginning-of-line) + (kill-region beg (point)))))))) + +(defun my-org-logbook-yank () "Yank whatever is in the kill ring into the logbook drawer." (interactive) (let ((end)) (save-restriction (org-narrow-to-subtree) (goto-char (point-min)) - (if (re-search-forward "^\\ *:LOGBOOK:\\ *$" nil t) + (if (and (re-search-forward "^\\ *:LOGBOOK:\\ *$" nil t) + (my-org-element-at-drawer-p)) ;; If there's already a logbook, move to where the clock ;; entries should be inserted (progn @@ -531,12 +554,12 @@ Assuming they are in the logbook drawer" (delete-char 1)) (yank)))) -(defun my-org-clock-refile-clocking () +(defun my-org-refile-logbook () (interactive) - (my-org-clock-kill-entries) + (my-org-kill-logbook-entries) (save-excursion (call-interactively 'org-goto) - (my-org-clock-yank))) + (my-org-logbook-yank))) ;;; to remove (defun my-org-clock-collect-entries (drawer &optional remove) @@ -1223,5 +1246,30 @@ When BLOCK-REGEXP is non-nil, use this regexp to find blocks." ((member type '(nil entry)) (setq txt "* %?")))) (org-capture-put :template txt :type type))) +(defun my-org-entry-sizes () + "Size analysis of all entries in the current org buffer. + +A new org buffer appears, with the whole org tree of the original +buffer preserved, annotated with the size" + (with-current-buffer (get-buffer-create "*org-sizes*") + (erase-buffer) + (org-mode)) + (save-excursion + (save-restriction + (org-content) + (beginning-of-buffer) + (unless (org-at-heading-p) + (org-next-visible-heading 1)) + (let ((beg) (line)) + (while (org-at-heading-p) + (setq beg (point) + line (buffer-substring-no-properties + beg (save-excursion (org-end-of-line) (point)))) + (org-next-visible-heading 1) + (setq line (format "%s (%d)" line (- (point) beg))) + (with-current-buffer "*org-sizes*" + (insert line "\n")))))) + (switch-to-buffer-other-window "*org-sizes*")) + (provide 'my-org) ;;; my-org.el ends here -- cgit v1.2.3