Browse Source

org-exp-blocks: use markers instead of points to remember code block locations

* lisp/org-exp-blocks.el (org-marker-from-point): Helper function to
  create markers at specific points in source buffers.
  (org-export-blocks-preprocess): Use markers instead of points to
  delimit code blocks.
Eric Schulte 13 năm trước cách đây
mục cha
commit
f51e540c4c
1 tập tin đã thay đổi với 7 bổ sung3 xóa
  1. 7 3
      lisp/org-exp-blocks.el

+ 7 - 3
lisp/org-exp-blocks.el

@@ -158,6 +158,10 @@ The optional OPEN and CLOSE tags will be inserted around BODY."
    (or close "")
    "#+END_LaTeX\n"))
 
+(defun org-marker-from-point (point)
+  "Return a marker located at POINT."
+  (save-excursion (goto-char point) (point-marker)))
+
 (defun org-export-blocks-preprocess ()
   "Export all blocks according to the `org-export-blocks' block export alist.
 Does not export block types specified in specified in BLOCKS
@@ -175,8 +179,8 @@ which defaults to the value of `org-export-blocks-witheld'."
 	(setq start (point))
 	(let ((beg-re "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]"))
 	  (while (re-search-forward beg-re nil t)
-	    (let* ((match-start (match-beginning 0))
-		   (body-start (match-end 0))
+	    (let* ((match-start (org-marker-from-point (match-beginning 0)))
+		   (body-start (org-marker-from-point (match-end 0)))
 		   (indentation (length (match-string 1)))
 		   (inner-re (format "[\r\n]*[ \t]*#\\+\\(begin\\|end\\)_%s"
 				     (regexp-quote (downcase (match-string 2)))))
@@ -195,7 +199,7 @@ which defaults to the value of `org-export-blocks-witheld'."
 	      (when (not (zerop balanced))
 		(error "unbalanced begin/end_%s blocks with %S"
 		       type (buffer-substring match-start (point))))
-	      (setq match-end (match-end 0))
+	      (setq match-end (org-marker-from-point (match-end 0)))
 	      (unless preserve-indent
 		(setq body (save-match-data (org-remove-indentation
 					     (buffer-substring