lang/org: call push-button on buttons in org-mode

This commit is contained in:
Henrik Lissner 2021-03-22 01:06:36 -04:00
parent 5e7864838a
commit aafed6d8a0

View file

@ -160,115 +160,117 @@ If on a:
- link: follow it - link: follow it
- otherwise, refresh all inline images in current tree." - otherwise, refresh all inline images in current tree."
(interactive "P") (interactive "P")
(let* ((context (org-element-context)) (if (button-at (point))
(type (org-element-type context))) (call-interactively #'push-button)
;; skip over unimportant contexts (let* ((context (org-element-context))
(while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript))) (type (org-element-type context)))
(setq context (org-element-property :parent context) ;; skip over unimportant contexts
type (org-element-type context))) (while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript)))
(pcase type (setq context (org-element-property :parent context)
(`headline type (org-element-type context)))
(cond ((memq (bound-and-true-p org-goto-map) (pcase type
(current-active-maps)) (`headline
(org-goto-ret)) (cond ((memq (bound-and-true-p org-goto-map)
((and (fboundp 'toc-org-insert-toc) (current-active-maps))
(member "TOC" (org-get-tags))) (org-goto-ret))
(toc-org-insert-toc) ((and (fboundp 'toc-org-insert-toc)
(message "Updating table of contents")) (member "TOC" (org-get-tags)))
((string= "ARCHIVE" (car-safe (org-get-tags))) (toc-org-insert-toc)
(org-force-cycle-archived)) (message "Updating table of contents"))
((or (org-element-property :todo-type context) ((string= "ARCHIVE" (car-safe (org-get-tags)))
(org-element-property :scheduled context)) (org-force-cycle-archived))
(org-todo ((or (org-element-property :todo-type context)
(if (eq (org-element-property :todo-type context) 'done) (org-element-property :scheduled context))
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context))) (org-todo
'todo) (if (eq (org-element-property :todo-type context) 'done)
'done)))) (or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
;; Update any metadata or inline previews in this subtree 'todo)
(org-update-checkbox-count) 'done))))
(org-update-parent-todo-statistics) ;; Update any metadata or inline previews in this subtree
(when (and (fboundp 'toc-org-insert-toc) (org-update-checkbox-count)
(member "TOC" (org-get-tags))) (org-update-parent-todo-statistics)
(toc-org-insert-toc) (when (and (fboundp 'toc-org-insert-toc)
(message "Updating table of contents")) (member "TOC" (org-get-tags)))
(let* ((beg (if (org-before-first-heading-p) (toc-org-insert-toc)
(line-beginning-position) (message "Updating table of contents"))
(save-excursion (org-back-to-heading) (point)))) (let* ((beg (if (org-before-first-heading-p)
(end (if (org-before-first-heading-p) (line-beginning-position)
(line-end-position) (save-excursion (org-back-to-heading) (point))))
(save-excursion (org-end-of-subtree) (point)))) (end (if (org-before-first-heading-p)
(overlays (ignore-errors (overlays-in beg end))) (line-end-position)
(latex-overlays (save-excursion (org-end-of-subtree) (point))))
(cl-find-if (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay)) (overlays (ignore-errors (overlays-in beg end)))
overlays)) (latex-overlays
(image-overlays (cl-find-if (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
(cl-find-if (lambda (o) (overlay-get o 'org-image-overlay)) overlays))
overlays))) (image-overlays
(+org--toggle-inline-images-in-subtree beg end) (cl-find-if (lambda (o) (overlay-get o 'org-image-overlay))
(if (or image-overlays latex-overlays) overlays)))
(org-clear-latex-preview beg end) (+org--toggle-inline-images-in-subtree beg end)
(org--latex-preview-region 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))
(`footnote-reference (`footnote-reference
(org-footnote-goto-definition (org-element-property :label context))) (org-footnote-goto-definition (org-element-property :label context)))
(`footnote-definition (`footnote-definition
(org-footnote-goto-previous-reference (org-element-property :label context))) (org-footnote-goto-previous-reference (org-element-property :label context)))
((or `planning `timestamp) ((or `planning `timestamp)
(org-follow-timestamp-link)) (org-follow-timestamp-link))
((or `table `table-row) ((or `table `table-row)
(if (org-at-TBLFM-p) (if (org-at-TBLFM-p)
(org-table-calc-current-TBLFM) (org-table-calc-current-TBLFM)
(ignore-errors (ignore-errors
(save-excursion (save-excursion
(goto-char (org-element-property :contents-begin context)) (goto-char (org-element-property :contents-begin context))
(org-call-with-arg 'org-table-recalculate (or arg t)))))) (org-call-with-arg 'org-table-recalculate (or arg t))))))
(`table-cell (`table-cell
(org-table-blank-field) (org-table-blank-field)
(org-table-recalculate arg) (org-table-recalculate arg)
(when (and (string-empty-p (string-trim (org-table-get-field))) (when (and (string-empty-p (string-trim (org-table-get-field)))
(bound-and-true-p evil-local-mode)) (bound-and-true-p evil-local-mode))
(evil-change-state 'insert))) (evil-change-state 'insert)))
(`babel-call (`babel-call
(org-babel-lob-execute-maybe)) (org-babel-lob-execute-maybe))
(`statistics-cookie (`statistics-cookie
(save-excursion (org-update-statistics-cookies arg))) (save-excursion (org-update-statistics-cookies arg)))
((or `src-block `inline-src-block) ((or `src-block `inline-src-block)
(org-babel-execute-src-block arg)) (org-babel-execute-src-block arg))
((or `latex-fragment `latex-environment) ((or `latex-fragment `latex-environment)
(org-latex-preview arg)) (org-latex-preview arg))
(`link (`link
(let* ((lineage (org-element-lineage context '(link) t)) (let* ((lineage (org-element-lineage context '(link) t))
(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--toggle-inline-images-in-subtree (+org--toggle-inline-images-in-subtree
(org-element-property :begin lineage) (org-element-property :begin lineage)
(org-element-property :end 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)))
(let ((match (and (org-at-item-checkbox-p) (match-string 1)))) (let ((match (and (org-at-item-checkbox-p) (match-string 1))))
(org-toggle-checkbox (if (equal match "[ ]") '(16))))) (org-toggle-checkbox (if (equal match "[ ]") '(16)))))
(_ (_
(if (or (org-in-regexp org-ts-regexp-both nil t) (if (or (org-in-regexp org-ts-regexp-both nil t)
(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--toggle-inline-images-in-subtree (+org--toggle-inline-images-in-subtree
(org-element-property :begin context) (org-element-property :begin context)
(org-element-property :end context))))))) (org-element-property :end context))))))))
;;;###autoload ;;;###autoload
(defun +org/shift-return (&optional arg) (defun +org/shift-return (&optional arg)