feat(org): add +org/reformat-at-point command

A DWIM command to reformat a src block, table, or paragraph at point.

Ref: #7685
This commit is contained in:
Henrik Lissner 2024-07-06 19:58:27 -04:00
parent 8072762de8
commit f6e65c4010
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 19 additions and 1 deletions

View file

@ -334,6 +334,24 @@ see how ARG affects this command."
(org-clock-in))
((org-clock-in-last arg))))
;;;###autoload
(defun +org/reformat-at-point ()
"Reformat the element at point.
If in an org src block, invokes `+format/org-block' if the ':editor format'
module is enabled.
If in an org table, realign the cells with `org-table-align'.
Otherwise, falls back to `org-fill-paragraph' to reflow paragraphs."
(interactive)
(let ((element (org-element-at-point)))
(cond ((org-in-src-block-p nil element)
(unless (modulep! :editor format)
(user-error ":editor format module is disabled, ignoring reformat..."))
(call-interactively #'+format/org-block))
((org-at-table-p)
(save-excursion (org-table-align)))
((call-interactively #'org-fill-paragraph)))))
;;; Folds
;;;###autoload

View file

@ -1222,7 +1222,7 @@ between the two."
:m "[l" #'org-previous-link
:m "]c" #'org-babel-next-src-block
:m "[c" #'org-babel-previous-src-block
:n "gQ" #'org-fill-paragraph
:n "gQ" #'+org/reformat-at-point
;; sensible vim-esque folding keybinds
:n "za" #'+org/toggle-fold
:n "zA" #'org-shifttab