emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals-release/org 34b0d95327 1/3: org-in-src-block-p: Do not


From: ELPA Syncer
Subject: [elpa] externals-release/org 34b0d95327 1/3: org-in-src-block-p: Do not rely on fontification
Date: Wed, 12 Jan 2022 08:57:39 -0500 (EST)

branch: externals-release/org
commit 34b0d95327288196f41a1a61fc6af4d906149c34
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>

    org-in-src-block-p: Do not rely on fontification
    
    * lisp/org.el (org-in-src-block-p): New optional argument ELEMENT.
    The code now relies on org-element API to check if we are inside
    src-block.
    
    Partially fixes 
https://list.orgmode.org/20220101200103.GB29829@itccanarias.org/T/#t
---
 lisp/org.el | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8c09a057cc..7ea8d65f3b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18731,17 +18731,19 @@ With prefix arg UNCOMPILED, load the uncompiled 
versions."
   "Is S an ID created by UUIDGEN?"
   (string-match 
"\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'"
 (downcase s)))
 
-(defun org-in-src-block-p (&optional inside)
+(defun org-in-src-block-p (&optional inside element)
   "Whether point is in a code source block.
 When INSIDE is non-nil, don't consider we are within a source
-block when point is at #+BEGIN_SRC or #+END_SRC."
-  (let ((case-fold-search t))
-    (or (and (eq (get-char-property (point) 'src-block) t))
-       (and (not inside)
-            (save-match-data
-              (save-excursion
-                (beginning-of-line)
-                (looking-at ".*#\\+\\(begin\\|end\\)_src")))))))
+block when point is at #+BEGIN_SRC or #+END_SRC.
+When ELEMENT is provided, it is considered to be element at point."
+  (save-match-data (setq element (or element (org-element-at-point))))
+  (when (eq 'src-block (org-element-type element))
+    (or (not inside)
+        (not (or (= (line-beginning-position)
+                  (org-element-property :post-affiliated element))
+               (= (1+ (line-end-position))
+                  (- (org-element-property :end element)
+                     (org-element-property :post-blank element))))))))
 
 (defun org-context ()
   "Return a list of contexts of the current cursor position.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]