emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: citations: rx problems with emacs-26.3
Date: Tue, 10 Aug 2021 00:10:25 +0700	[thread overview]
Message-ID: <sernjh$15dk$1@ciao.gmane.io> (raw)
In-Reply-To: <87sfzlc850.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]

On 08/08/2021 03:27, Nicolas Goaziou wrote:
> 
> Maxim Nikulin writes:
> 
>> It seems, rx e.g. in emacs-26.3 does not support all features used in
>> oc.el and oc-csl.el. Loading an org file using git master, I get
>> a warning
>>
>>> Eager macro-expansion failure: (error "rx form ‘regexp’ requires args satisfying ‘stringp’")
> 
> Thanks. Could you send the patch again with a proper commit message,
> using git format-patch?

With the attached patches I do not see warnings any more while org is 
loading. On the other hand I am not an org-cite user, so I am not sure 
that nothing is broken by these patches.



[-- Attachment #2: 0001-oc-rx-compatibility-with-Emacs-27.1.patch --]
[-- Type: text/x-patch, Size: 5207 bytes --]

From 151191d0283cb55e719c9c01459de02dfb584e02 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Mon, 9 Aug 2021 23:59:41 +0700
Subject: [PATCH 1/2] oc: rx compatibility with Emacs < 27.1

* lisp/oc.el (org-cite-adjust-note):
* lisp/oc-basic.el (org-cite-basic-goto):
* lisp/oc-biblatex.el (org-cite-biblatex-prepare-preamble):
* lisp/oc-csl.el (org-cite-csl--label-regexp): Avoid `rx' forms
introduced in Emacs-27.1 to keep compatibility with older versions.

Use `rx-to-string' instead of `rx' due to lack of support of  `regexp'
and `literal' forms with a variable as an argument.
---
 lisp/oc-basic.el    |  4 +++-
 lisp/oc-biblatex.el |  2 +-
 lisp/oc-csl.el      | 11 +++++++----
 lisp/oc.el          | 21 ++++++++++++++-------
 4 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index c46e7a715..6d625e4a5 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -667,7 +667,9 @@ present in the citation."
     (org-open-file file '(4))
     (pcase (file-name-extension file)
       ("json"
-       (let ((regexp (rx "\"id\":" (0+ (any "[ \t]")) "\"" (literal key) "\"")))
+       ;; `rx' can not be used with Emacs <27.1 since `literal' form
+       ;; is not supported.
+       (let ((regexp (rx-to-string `(seq "\"id\":" (0+ (any "[ \t]")) "\"" ,key "\"") t)))
          (goto-char (point-min))
          (re-search-forward regexp)
          (search-backward "{")))
diff --git a/lisp/oc-biblatex.el b/lisp/oc-biblatex.el
index 5a9c304a3..c82a77046 100644
--- a/lisp/oc-biblatex.el
+++ b/lisp/oc-biblatex.el
@@ -260,7 +260,7 @@ to the document, and set styles."
       ;; Then set options.
       (goto-char (match-beginning 0))
       (let ((re (rx "\\usepackage"
-                    (opt (group "[" (*? anychar) "]"))
+                    (opt (group "[" (*? anything) "]"))
                     "{biblatex}")))
         (cond
          ;; No "biblatex" package loaded.  Insert "usepackage" command
diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index 5e0e27211..c08adc430 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -253,10 +253,13 @@ If nil then the Chicago author-date style is used as a fallback.")
   "Alist mapping locator names to locators.")
 
 (defconst org-cite-csl--label-regexp
-  (rx word-start
-      (regexp (regexp-opt (mapcar #'car org-cite-csl--label-alist) t))
-      (0+ digit)
-      (or word-start line-end (any ?\s ?\t)))
+  ;; Prior to Emacs-27.1 argument of `regexp' form must be a string literal.
+  ;; It is the reason why `rx' is avoided here.
+  (rx-to-string `(seq word-start
+                  (regexp ,(regexp-opt (mapcar #'car org-cite-csl--label-alist) t))
+                  (0+ digit)
+                  (or word-start line-end (any ?\s ?\t)))
+                t)
   "Regexp matching a label in a citation reference suffix.
 Label is in match group 1.")
 
diff --git a/lisp/oc.el b/lisp/oc.el
index 338348116..53eafb3bd 100644
--- a/lisp/oc.el
+++ b/lisp/oc.el
@@ -878,14 +878,19 @@ the same object, call `org-cite-adjust-punctuation' first."
   (when org-cite-adjust-note-numbers
     (pcase-let* ((rule (or rule (org-cite--get-note-rule info)))
                  (punct-re (regexp-opt (or punct org-cite-punctuation-marks)))
+                 ;; with Emacs <27.1. Argument of `regexp' form (PUNCT-RE this case)
+                 ;; must be a string literal.
                  (previous-punct-re
-                  (rx (opt (group (0+ (any blank ?\n)) (regexp punct-re)))
-                      (opt (0+ (any blank ?\n)) (group ?\"))
-                      (opt (group (1+ (any blank ?\n))))
-                      string-end))
+                  (rx-to-string `(seq (opt (group (regexp ,(rx (0+ (any blank ?\n))))
+                                                  (regexp ,punct-re)))
+                                      (regexp ,(rx (opt (0+ (any blank ?\n)) (group ?\"))
+                                                   (opt (group (1+ (any blank ?\n))))
+                                                   string-end)))
+                                t))
                  (next-punct-re
-                  (rx string-start
-                      (group (0+ (any blank ?\n)) (regexp punct-re))))
+                  (rx-to-string `(seq string-start
+                                      (group (0+ (any blank ?\n)) (regexp ,punct-re)))
+                                t))
                  (next (org-export-get-next-element citation info))
                  (final-punct
                   (and (stringp next)
@@ -928,7 +933,9 @@ the same object, call `org-cite-adjust-punctuation' first."
                      (concat final-punct "\"") previous nil nil 2))
                    (new-next
                     (replace-regexp-in-string
-                     (rx string-start (literal final-punct))
+                     ;; Before Emacs-27.1 `literal' `rx' form with a variable
+                     ;; as an argument is not available.
+                     (rx-to-string `(seq string-start ,final-punct) t)
                      "" next)))
                (org-element-set-element previous new-prev)
                (org-element-set-element next new-next)
-- 
2.25.1


[-- Attachment #3: 0002-oc-Add-missing-require.patch --]
[-- Type: text/x-patch, Size: 1015 bytes --]

From 19261fcf089deba09250117fc1beb6a8aef69450 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Tue, 10 Aug 2021 00:03:25 +0700
Subject: [PATCH 2/2] oc: Add missing `require'

* lisp/oc.el:
* lisp/oc-basic.el: Add some `require' to avoid compile warnings.
---
 lisp/oc-basic.el | 3 +++
 lisp/oc.el       | 1 +
 2 files changed, 4 insertions(+)

diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index 6d625e4a5..66f8c069f 100644
--- a/lisp/oc-basic.el
+++ b/lisp/oc-basic.el
@@ -65,7 +65,10 @@
 ;;; Code:
 
 (require 'bibtex)
+(require 'json)
 (require 'oc)
+(require 'org)
+(require 'seq)
 
 (declare-function org-open-at-point "org" (&optional arg))
 
diff --git a/lisp/oc.el b/lisp/oc.el
index 53eafb3bd..f8cc7829c 100644
--- a/lisp/oc.el
+++ b/lisp/oc.el
@@ -57,6 +57,7 @@
 
 (require 'org-compat)
 (require 'org-macs)
+(require 'seq)
 
 (declare-function org-at-heading-p "org" (&optional _))
 (declare-function org-collect-keywords "org" (keywords &optional unique directory))
-- 
2.25.1


  parent reply	other threads:[~2021-08-09 17:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-11 10:36 citations: rx problems with emacs-26.3 Maxim Nikulin
2021-08-07 20:27 ` Nicolas Goaziou
2021-08-08 13:34   ` Maxim Nikulin
2021-08-08 14:14     ` Nicolas Goaziou
2021-08-09 17:18       ` Maxim Nikulin
2021-08-11  5:37         ` Axel Kielhorn
2021-08-11  9:33         ` Nicolas Goaziou
2021-08-11 16:24           ` Maxim Nikulin
2021-08-09 17:10   ` Maxim Nikulin [this message]
2021-08-11  9:18     ` Nicolas Goaziou

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='sernjh$15dk$1@ciao.gmane.io' \
    --to=manikulin@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).