emacs-orgmode
[Top][All Lists]
Advanced

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

[BUG] (org-element-context) caused (re-search-forward <regexp>) + (match


From: Christopher M. Miles
Subject: [BUG] (org-element-context) caused (re-search-forward <regexp>) + (match-string-no-properties 1) returned matched data wrong
Date: Mon, 01 Apr 2024 20:38:59 +0800
User-agent: mu4e 1.12.2; emacs 30.0.50


Here is a simple test:

#+begin_src org :file "test.org"
,#+NAME: hello1
,#+BEGIN_SRC sh :var name=""
  echo "hello, $name"
,#+END_SRC

,#+BEGIN_SRC sh :noweb yes
<<hello1(name="chris")>>
,#+END_SRC

,#+NAME: hello2
,#+BEGIN_SRC emacs-lisp :var name="" :results output
(prin1 name)
,#+END_SRC

,#+BEGIN_SRC emacs-lisp :noweb yes :results output
<<hello2(name="chris")>>
,#+END_SRC

,#+BEGIN_SRC emacs-lisp :results output
(prin1 "hi")
,#+END_SRC

,#+RESULTS:
: "hi"

#+end_src

#+begin_src emacs-lisp :results output
(defvar org-simple-ref-label-re
  (rx-to-string
   '(group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~"))))
  "Regexp for labels.")

(defvar org-simple-ref-ref-label-regexps
  (list
   (concat ":ID:\\s-+" org-simple-ref-label-re "\\_>")
   ;; CUSTOM_ID in a heading
   (concat ":CUSTOM_ID:\\s-+" org-simple-ref-label-re "\\_>")
   ;; #+name
   (concat "^\\s-*#\\+name:\\s-+" org-simple-ref-label-re)
   ;; labels in latex
   (concat "\\\\label{" org-simple-ref-label-re "}")
   ;; A target, code copied from org-target-regexp and group 1 numbered.
   (let ((border "[^<>\n\r \t]"))
     (format "<<\\(?1:%s\\|%s[^<>\n\r]*%s\\)>>" border border border))
   ;; A label link
   (concat "label:" org-simple-ref-label-re "\\_>")
   ;; code ref
   "[   ]*(\\(?2:ref\\):\\(?1:[-a-zA-Z0-9_][-a-zA-Z0-9_ ]*\\))[         ]*$"
   ;; noweb ref
   ":noweb-ref\\s-+\\(?1:.*?\\)\\s-"
   "\\\\lstset{.*label=\\(?1:.*?\\),.*}")
  "List of regular expressions to labels.
The label should always be in group 1.")

(with-current-buffer (get-buffer "test.org")
  (org-with-wide-buffer
   (goto-char (point-min))
   (while (re-search-forward (string-join org-simple-ref-ref-label-regexps 
"\\|") nil t)
     (save-match-data
       (print (format "%s -> %s" (match-string-no-properties 0) 
(match-string-no-properties 1)))

       (org-element-context) ; <----- REASON!! cause 
`match-string-no-properties' result wrong.

       (print (propertize (match-string-no-properties 1)
                          'org-simple-ref--location
                          (match-beginning 1)))))))
#+end_src

#+RESULTS[(2024-04-01 20:16:21) dc738972b5676dea6e0821cb02b2767219f4fd77]:
#+begin_example

"
,#+NAME: hello1 -> hello1"

#("NAME" 0 4 (org-simple-ref--location 46))

"<<hello1(name=\"chris\")>> -> hello1(name=\"chris\")"

#("hello1(name=\"chris\")" 0 20 (org-simple-ref--location 148))

"
,#+NAME: hello2 -> hello2"

#("NAME" 0 4 (org-simple-ref--location 184))

"<<hello2(name=\"chris\")>> -> hello2(name=\"chris\")"

#("hello2(name=\"chris\")" 0 20 (org-simple-ref--location 325))
#+end_example

Found reason, check out the marker in the screenshot:

PNG image

Get more background details from this link: 
https://github.com/Elilif/Elilif.github.io/discussions/8#discussioncomment-8971127

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

Attachment: signature.asc
Description: PGP signature


reply via email to

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