Redesign dwim RET on org headings
In an effort to make +org/dwim-at-point more useful and intuitive. - Fix latex preview toggling in subtree - Toggle inline images more selectively - Clean up after itself (delete overlays) - Update +org/dwim-at-point docstring - Always update todo statistics, cookies, checkbox counts and ToC.
This commit is contained in:
parent
2441d28ad1
commit
afcf56a610
1 changed files with 54 additions and 21 deletions
|
@ -3,18 +3,24 @@
|
||||||
;;
|
;;
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
|
|
||||||
(defun +org--refresh-inline-images-in-subtree ()
|
(defun +org--toggle-inline-images-in-subtree (&optional beg end refresh)
|
||||||
"Refresh image previews in the current heading/tree."
|
"Refresh inline image previews in the current heading/tree."
|
||||||
(if (> (length org-inline-image-overlays) 0)
|
(let ((beg (or beg
|
||||||
(org-remove-inline-images)
|
(if (org-before-first-heading-p)
|
||||||
(org-display-inline-images
|
(line-beginning-position)
|
||||||
t t
|
(save-excursion (org-back-to-heading) (point)))))
|
||||||
(if (org-before-first-heading-p)
|
(end (or end
|
||||||
(line-beginning-position)
|
(if (org-before-first-heading-p)
|
||||||
(save-excursion (org-back-to-heading) (point)))
|
(line-end-position)
|
||||||
(if (org-before-first-heading-p)
|
(save-excursion (org-end-of-subtree) (point)))))
|
||||||
(line-end-position)
|
(overlays (cl-remove-if-not (lambda (ov) (overlay-get ov 'org-image-overlay))
|
||||||
(save-excursion (org-end-of-subtree) (point))))))
|
(ignore-errors (overlays-in beg end)))))
|
||||||
|
(dolist (ov overlays nil)
|
||||||
|
(delete-overlay ov)
|
||||||
|
(setq org-inline-image-overlays (delete ov org-inline-image-overlays)))
|
||||||
|
(when (or refresh (not overlays))
|
||||||
|
(org-display-inline-images t t beg end)
|
||||||
|
t)))
|
||||||
|
|
||||||
(defun +org--insert-item (direction)
|
(defun +org--insert-item (direction)
|
||||||
(let* ((context
|
(let* ((context
|
||||||
|
@ -147,7 +153,8 @@ current file). Only scans first 2048 bytes of the document."
|
||||||
If on a:
|
If on a:
|
||||||
- checkbox list item or todo heading: toggle it.
|
- checkbox list item or todo heading: toggle it.
|
||||||
- clock: update its time.
|
- clock: update its time.
|
||||||
- headline: toggle latex fragments and inline images underneath.
|
- headline: cycle ARCHIVE subtrees, toggle latex fragments and inline images in
|
||||||
|
subtree; update statistics cookies/checkboxes and ToCs.
|
||||||
- footnote reference: jump to the footnote's definition
|
- footnote reference: jump to the footnote's definition
|
||||||
- footnote definition: jump to the first reference of this footnote
|
- footnote definition: jump to the first reference of this footnote
|
||||||
- table-row or a TBLFM: recalculate the table's formulas
|
- table-row or a TBLFM: recalculate the table's formulas
|
||||||
|
@ -167,7 +174,8 @@ If on a:
|
||||||
type (org-element-type context)))
|
type (org-element-type context)))
|
||||||
(pcase type
|
(pcase type
|
||||||
(`headline
|
(`headline
|
||||||
(cond ((memq (bound-and-true-p org-goto-map) (current-active-maps))
|
(cond ((memq (bound-and-true-p org-goto-map)
|
||||||
|
(current-active-maps))
|
||||||
(org-goto-ret))
|
(org-goto-ret))
|
||||||
((and (fboundp 'toc-org-insert-toc)
|
((and (fboundp 'toc-org-insert-toc)
|
||||||
(member "TOC" (org-get-tags)))
|
(member "TOC" (org-get-tags)))
|
||||||
|
@ -181,11 +189,32 @@ If on a:
|
||||||
(if (eq (org-element-property :todo-type context) 'done)
|
(if (eq (org-element-property :todo-type context) 'done)
|
||||||
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
|
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
|
||||||
'todo)
|
'todo)
|
||||||
'done)))
|
'done))))
|
||||||
(t
|
;; Update any metadata or inline previews in this subtree
|
||||||
(+org--refresh-inline-images-in-subtree)
|
(org-update-checkbox-count)
|
||||||
(org-clear-latex-preview)
|
(let (org-hierarchical-todo-statistics)
|
||||||
(org-latex-preview '(4)))))
|
(org-update-parent-todo-statistics))
|
||||||
|
(when (and (fboundp 'toc-org-insert-toc)
|
||||||
|
(member "TOC" (org-get-tags)))
|
||||||
|
(toc-org-insert-toc)
|
||||||
|
(message "Updating table of contents"))
|
||||||
|
(let* ((beg (if (org-before-first-heading-p)
|
||||||
|
(line-beginning-position)
|
||||||
|
(save-excursion (org-back-to-heading) (point))))
|
||||||
|
(end (if (org-before-first-heading-p)
|
||||||
|
(line-end-position)
|
||||||
|
(save-excursion (org-end-of-subtree) (point))))
|
||||||
|
(overlays (ignore-errors (overlays-in beg end)))
|
||||||
|
(latex-overlays
|
||||||
|
(cl-find-if (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
|
||||||
|
overlays))
|
||||||
|
(image-overlays
|
||||||
|
(cl-find-if (lambda (o) (overlay-get o 'org-image-overlay))
|
||||||
|
overlays)))
|
||||||
|
(+org--toggle-inline-images-in-subtree beg end)
|
||||||
|
(if (or image-overlays latex-overlays)
|
||||||
|
(org-clear-latex-preview beg end)
|
||||||
|
(org--latex-preview-region beg end))))
|
||||||
|
|
||||||
(`clock (org-clock-update-time-maybe))
|
(`clock (org-clock-update-time-maybe))
|
||||||
|
|
||||||
|
@ -230,7 +259,9 @@ If on a:
|
||||||
(path (org-element-property :path lineage)))
|
(path (org-element-property :path lineage)))
|
||||||
(if (or (equal (org-element-property :type lineage) "img")
|
(if (or (equal (org-element-property :type lineage) "img")
|
||||||
(and path (image-type-from-file-name path)))
|
(and path (image-type-from-file-name path)))
|
||||||
(+org--refresh-inline-images-in-subtree)
|
(+org--toggle-inline-images-in-subtree
|
||||||
|
(org-element-property :begin lineage)
|
||||||
|
(org-element-property :end lineage))
|
||||||
(org-open-at-point arg))))
|
(org-open-at-point arg))))
|
||||||
|
|
||||||
((guard (org-element-property :checkbox (org-element-lineage context '(item) t)))
|
((guard (org-element-property :checkbox (org-element-lineage context '(item) t)))
|
||||||
|
@ -242,7 +273,9 @@ If on a:
|
||||||
(org-in-regexp org-tsr-regexp-both nil t)
|
(org-in-regexp org-tsr-regexp-both nil t)
|
||||||
(org-in-regexp org-link-any-re nil t))
|
(org-in-regexp org-link-any-re nil t))
|
||||||
(call-interactively #'org-open-at-point)
|
(call-interactively #'org-open-at-point)
|
||||||
(+org--refresh-inline-images-in-subtree))))))
|
(+org--toggle-inline-images-in-subtree
|
||||||
|
(org-element-property :begin context)
|
||||||
|
(org-element-property :end context)))))))
|
||||||
|
|
||||||
|
|
||||||
;; I use this instead of `org-insert-item' or `org-insert-heading' which are too
|
;; I use this instead of `org-insert-item' or `org-insert-heading' which are too
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue