mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-07-16 13:46:27 +00:00
org-babel-demarcate-block: Fix when within blank after src block
* lisp/ob-core.el (org-babel-where-is-src-block-head): Clarify that return value is nil within blank after src block. (org-babel-demarcate-block): Insert new block inheriting language when within blank lines after existing src block. Document the behavior. Reported-by: dalanicolai <dalanicolai@gmail.com> Link: https://orgmode.org/list/CACJP=3nCekgX4RuYBWf=R_2t05-s4ikx-L9qP7W0cSicNG55BA@mail.gmail.com
This commit is contained in:
parent
c3aa6a6d43
commit
cd835dcad8
|
@ -1813,7 +1813,8 @@ its current beginning instead.
|
||||||
Return the point at the beginning of the current source block.
|
Return the point at the beginning of the current source block.
|
||||||
Specifically at the beginning of the #+BEGIN_SRC line. Also set
|
Specifically at the beginning of the #+BEGIN_SRC line. Also set
|
||||||
match-data relatively to `org-babel-src-block-regexp', which see.
|
match-data relatively to `org-babel-src-block-regexp', which see.
|
||||||
If the point is not on a source block then return nil."
|
If the point is not on a source block or within blank lines after an
|
||||||
|
src block, then return nil."
|
||||||
(let ((element (or src-block (org-element-at-point))))
|
(let ((element (or src-block (org-element-at-point))))
|
||||||
(when (eq (org-element-type element) 'src-block)
|
(when (eq (org-element-type element) 'src-block)
|
||||||
(let ((end (org-element-property :end element)))
|
(let ((end (org-element-property :end element)))
|
||||||
|
@ -1965,17 +1966,21 @@ With optional prefix argument ARG, jump backward ARG many source blocks."
|
||||||
When called from inside of a code block the current block is
|
When called from inside of a code block the current block is
|
||||||
split. When called from outside of a code block a new code block
|
split. When called from outside of a code block a new code block
|
||||||
is created. In both cases if the region is demarcated and if the
|
is created. In both cases if the region is demarcated and if the
|
||||||
region is not active then the point is demarcated."
|
region is not active then the point is demarcated.
|
||||||
|
|
||||||
|
When called within blank lines after a code block, create a new code
|
||||||
|
block of the same language with the previous."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((info (org-babel-get-src-block-info 'no-eval))
|
(let* ((info (org-babel-get-src-block-info 'no-eval))
|
||||||
(start (org-babel-where-is-src-block-head))
|
(start (org-babel-where-is-src-block-head))
|
||||||
|
;; `start' will be nil when within space lines after src block.
|
||||||
(block (and start (match-string 0)))
|
(block (and start (match-string 0)))
|
||||||
(headers (and start (match-string 4)))
|
(headers (and start (match-string 4)))
|
||||||
(stars (concat (make-string (or (org-current-level) 1) ?*) " "))
|
(stars (concat (make-string (or (org-current-level) 1) ?*) " "))
|
||||||
(upper-case-p (and block
|
(upper-case-p (and block
|
||||||
(let (case-fold-search)
|
(let (case-fold-search)
|
||||||
(string-match-p "#\\+BEGIN_SRC" block)))))
|
(string-match-p "#\\+BEGIN_SRC" block)))))
|
||||||
(if info
|
(if (and info start) ;; At src block, but not within blank lines after it.
|
||||||
(mapc
|
(mapc
|
||||||
(lambda (place)
|
(lambda (place)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
@ -2000,13 +2005,14 @@ region is not active then the point is demarcated."
|
||||||
(move-end-of-line 2))
|
(move-end-of-line 2))
|
||||||
(sort (if (org-region-active-p) (list (mark) (point)) (list (point))) #'>))
|
(sort (if (org-region-active-p) (list (mark) (point)) (list (point))) #'>))
|
||||||
(let ((start (point))
|
(let ((start (point))
|
||||||
(lang (completing-read
|
(lang (or (car info) ; Reuse language from previous block.
|
||||||
|
(completing-read
|
||||||
"Lang: "
|
"Lang: "
|
||||||
(mapcar #'symbol-name
|
(mapcar #'symbol-name
|
||||||
(delete-dups
|
(delete-dups
|
||||||
(append (mapcar #'car org-babel-load-languages)
|
(append (mapcar #'car org-babel-load-languages)
|
||||||
(mapcar (lambda (el) (intern (car el)))
|
(mapcar (lambda (el) (intern (car el)))
|
||||||
org-src-lang-modes))))))
|
org-src-lang-modes)))))))
|
||||||
(body (delete-and-extract-region
|
(body (delete-and-extract-region
|
||||||
(if (org-region-active-p) (mark) (point)) (point))))
|
(if (org-region-active-p) (mark) (point)) (point))))
|
||||||
(insert (concat (if (looking-at "^") "" "\n")
|
(insert (concat (if (looking-at "^") "" "\n")
|
||||||
|
|
Loading…
Reference in a new issue