Browse Source

Fix "Args out of range" when demarcating blocks

* lisp/ob-core.el (org-babel-demarcate-block): Return value from
  `org-babel-where-is-src-block-head' may be nil.

Reported-by: Sébastien Vauban
<http://permalink.gmane.org/gmane.emacs.orgmode/93978>
Nicolas Goaziou 10 years ago
parent
commit
b5072890c3
1 changed files with 6 additions and 5 deletions
  1. 6 5
      lisp/ob-core.el

+ 6 - 5
lisp/ob-core.el

@@ -1860,12 +1860,13 @@ 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."
   (interactive "P")
   (interactive "P")
   (let* ((info (org-babel-get-src-block-info 'light))
   (let* ((info (org-babel-get-src-block-info 'light))
-	 (block (progn (org-babel-where-is-src-block-head) (match-string 0)))
-	 (headers (progn (org-babel-where-is-src-block-head) (match-string 4)))
+	 (start (org-babel-where-is-src-block-head))
+	 (block (and start (match-string 0)))
+	 (headers (and start (match-string 4)))
 	 (stars (concat (make-string (or (org-current-level) 1) ?*) " "))
 	 (stars (concat (make-string (or (org-current-level) 1) ?*) " "))
-	 lower-case-p)
-    (if (let (case-fold-search) (string-match "#\\+begin_src" block))
-	(setq lower-case-p t))
+	 (lower-case-p (and block
+			    (let (case-fold-search)
+			      (org-string-match-p "#\\+begin_src" block)))))
     (if info
     (if info
         (mapc
         (mapc
          (lambda (place)
          (lambda (place)