dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 098d22c5e57fc836eb98774ff097bd3a997a334d
parent ad21c21005eb1ceb77b8bc339fa25cdcb858e6a4
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Fri, 11 Nov 2022 11:56:24 +0100

emacs: org timestamp overlay styling & prefix toggle

Diffstat:
Memacs/config.org | 103++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 63 insertions(+), 40 deletions(-)

diff --git a/emacs/config.org b/emacs/config.org @@ -1830,46 +1830,69 @@ Fix column alignment in agenda. Also a method to add overlays with that timestamp: #+begin_src emacs-lisp - (defvar-local za/org-timestamp-overlays--list nil "Buffer-local list of overlays with timestamps") - (defvar-local za/org-timestamp-overlays--show nil "Buffer-local boolean to show overlays.") - (defun za/org-timestamp-overlays-clear () - "Clear all overlays with timestamps in current buffer." - (dolist (ov za/org-timestamp-overlays--list) - (delete-overlay ov)) - (setq-local za/org-timestamp-overlays--list nil)) - - (defun za/org-timestamp-overlays-add () - "Add overlays for active timestamps in current buffer. - TODO this should be more easily distinguishable, like with a background." - (save-excursion - (let* ((beg (point-min)) - (end (point-max))) - (goto-char beg) - (while (re-search-forward (org-re-timestamp 'active) end t) - (let ((ov (make-overlay (point) (point)))) - (overlay-put ov 'before-string (format "{%s}" (za/org-time-since))) - (add-to-list 'za/org-timestamp-overlays--list ov)))))) - - (defun za/org-timestamp-overlays-redraw () - "Redraw all overlays for active timestamps." - (za/org-timestamp-overlays-clear) - (za/org-timestamp-overlays-add)) - - (defun za/org-timestamp-hook-fn (&rest _) - (za/org-timestamp-overlays-redraw)) - - (defun za/org-timestamp-overlays-toggle () - (interactive) - (cond (za/org-timestamp-overlays--show - (za/org-timestamp-overlays-clear) - (remove-hook 'org-cycle-hook #'za/org-timestamp-hook-fn) - (setq za/org-timestamp-overlays--show nil) - (message "Overlays hidden.")) - (t - (za/org-timestamp-overlays-redraw) - (add-hook 'org-cycle-hook #'za/org-timestamp-hook-fn) - (setq za/org-timestamp-overlays--show t) - (message "Overlays showing.")))) + (defvar-local za/org-timestamp-overlays--list nil "Buffer-local list of overlays with timestamps") + (defvar-local za/org-timestamp-overlays--show nil "Buffer-local boolean to show overlays.") + (defun za/org-timestamp-overlays-clear () + "Clear all overlays with timestamps in current buffer." + (dolist (ov za/org-timestamp-overlays--list) + (delete-overlay ov)) + (setq-local za/org-timestamp-overlays--list nil)) + + (defun za/org-timestamp-overlays-add () + "Add overlays for active timestamps in current buffer." + (let ((markup-string (lambda (s) (propertize (format "{%s}" s) + 'face 'org-habit-ready-future-face)))) + (save-excursion + (let* ((beg (point-min)) + (end (point-max))) + (goto-char beg) + (while (re-search-forward (org-re-timestamp 'active) end t) + (let ((ov (make-overlay (point) (point)))) + (overlay-put ov 'before-string (funcall markup-string (za/org-time-since))) + (add-to-list 'za/org-timestamp-overlays--list ov))))))) + + (defun za/org-timestamp-overlays-redraw () + "Redraw all overlays for active timestamps." + (za/org-timestamp-overlays-clear) + (za/org-timestamp-overlays-add)) + + (defun za/org-timestamp-hook-fn (&rest _) + (za/org-timestamp-overlays-redraw)) + + (bind-key "C-c q p" #'tmp/p) + (defun za/org-timestamp-overlays-toggle (&optional prefix) + "With no prefix, toggle showing timestamp overlay. + With PREFIX = 0, redraw overlays. + With PREFIX > 0, show overlays. + With PREFIX < 0, hide overlays." + (interactive "P") + (let ((overlays-hide (lambda () + (za/org-timestamp-overlays-clear) + (remove-hook 'org-cycle-hook #'za/org-timestamp-hook-fn) + (setq za/org-timestamp-overlays--show nil) + (message "Overlays hidden."))) + (overlays-show (lambda () + (za/org-timestamp-overlays-redraw) + (add-hook 'org-cycle-hook #'za/org-timestamp-hook-fn) + (setq za/org-timestamp-overlays--show t) + (message "Overlays showing."))) + (overlays-redraw-maybe (lambda () + (when za/org-timestamp-overlays--show + (za/org-timestamp-overlays-redraw) + (message "Redrawing overlays.")))) + (prefix-num (prefix-numeric-value prefix))) + (cond ((not prefix) + (cond (za/org-timestamp-overlays--show + (funcall overlays-hide)) + (t + (funcall overlays-show)))) + ((zerop prefix-num) + ) + ((> prefix-num 0) + (funcall overlays-show)) + ((< prefix-num 0) + (funcall overlays-hide))))) + #+end_src Bind a key: