Add `org-right-shift-block'

This commit is contained in:
Gerard Vermeulen 2024-01-17 12:23:17 +01:00
parent d3aba70a21
commit 03911e076b

View File

@ -2306,9 +2306,8 @@ list detailing and motivating each listing:
[[info:org#Hyperlinks][hyperlinks (info)]].
5. Listing [[lst:setup-org-mode-map]] extends the =org-mode-map= with useful
key-bindings.
6. Listing [[lst:setup-org-src]] facilitates [[info:org#Editing Source Code][editing Python source code blocks]],
and it provides a function to remove the indentation of all =org-src-mode=
blocks without =-i= switch.
6. Listing [[lst:setup-org-src]] facilitates [[info:org#Editing Source Code][editing source code blocks]], and it
provides functions to change the indentation of all =org-src-mode= blocks.
7. Listing [[lst:setup-ob-python]] allows to pretty-print Python session source
block values with [[https://github.com/psf/black#readme][black]] instead of [[https://docs.python.org/3/library/pprint.html][pprint]]. This snippet may break in the
future, because it sets =org-babel-python--def-format-value= which is a
@ -2504,6 +2503,21 @@ When called twice, replace the previously inserted \\(\\) by one $."
(org-src-preserve-indentation nil))
(org-indent-block))))
(defun org-right-shift-block (&optional arg)
"Right-shift the block at point 4 spaces.
With prefix argument ARG, prompt for the number of spaces."
(interactive "P")
(let ((spaces 4)
(start (org-babel-where-is-src-block-head)))
(if (not start) (message "Not at block")
(when arg
(setq spaces (read-number "Number of spaces: ")))
;; The `SUBEXP' of the block body is 5.
(goto-char (match-end 5))
(forward-line -1)
(string-insert-rectangle
(match-beginning 5) (point) (make-string spaces ?\s)))))
(declare-function org-babel-map-src-blocks "ext:ob-core" (file &rest body))
(declare-function org-do-remove-indentation "ext:org-macs" (n skip-fl))