emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Christopher M. Miles" <numbchild@gmail.com>
To: Org mode (mailing-list) <emacs-orgmode@gnu.org>
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	[thread overview]
Message-ID: <660aaaf5.050a0220.f6c37.3e7c@mx.google.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2644 bytes --]



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:


[-- Attachment #1.2: Screenshot 2024-04-01 at 20.25.43.png --]
[-- Type: image/png, Size: 1012242 bytes --]

[-- Attachment #1.3: Type: text/plain, Size: 397 bytes --]


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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

             reply	other threads:[~2024-04-01 12:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 12:38 Christopher M. Miles [this message]
2024-04-01 12:47 ` [BUG] (org-element-context) caused (re-search-forward <regexp>) + (match-string-no-properties 1) returned matched data wrong Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=660aaaf5.050a0220.f6c37.3e7c@mx.google.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).