emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH v2] Fix Emacs-26 compatibility (was: Re: [BUG] org-element loading fails with "regexp" argument not "stringp")
Date: Sat, 8 Jul 2023 11:56:59 +0700	[thread overview]
Message-ID: <u8aqat$860$1@ciao.gmane.io> (raw)
In-Reply-To: <87ttuh74bl.fsf@localhost>

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

On 06/07/2023 16:54, Ihor Radchenko wrote:
> You are removing `org-protocol-flatten' function, which is a breaking
> change. We should leave an obsolete alias.

I have added an alias for this function hardly known to anybody else.

> Also, you are defining `flatten-tree' function, which is outside Org's
> namespace. We should better avoid it and use something like
> `org-flatten-tree'.

The idea was to minimize conflicts with your branch for the compat 
package. I hope, it will be merged soon.

[-- Attachment #2: v2-0001-org-element.el-Fix-Emacs-26-compatibility.patch --]
[-- Type: text/x-patch, Size: 2911 bytes --]

From 635710157476239314d7fe5231fbec2163cbe52d Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Wed, 5 Jul 2023 22:44:33 +0700
Subject: [PATCH v2 1/2] org-element.el: Fix Emacs-26 compatibility

* org-element.el (org-element--current-element-re): Use `rx-to-string'
instead of `rx' to expand variables.
(org-element--cache-setup-change-functions): Avoid multiple variables in
`setq-local'.

Reported as: Justin to emacs-orgmode. [BUG] org-element loading fails
with "regexp" argument not "stringp" Tue, 4 Jul 2023 19:51:44 -0400.
https://list.orgmode.org/2ff109c7-b3ec-27ac-e75d-ae5ddac14746@vallon.homeip.net
---
 lisp/org-element.el | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index bfb1d206e..1c9707573 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4278,20 +4278,20 @@ ;;; Parsing Element Starting At Point
 ;; point.
 
 (defconst org-element--current-element-re
-  (rx
-   (or
-    (group-n 1 (regexp org-element--latex-begin-environment-nogroup))
-    (group-n 2 (regexp org-element-drawer-re-nogroup))
-    (group-n 3 (regexp "[ \t]*:\\( \\|$\\)"))
-    (group-n 7 (regexp org-element-dynamic-block-open-re-nogroup))
-    (seq (group-n 4 (regexp "[ \t]*#\\+"))
-         (or
-          (seq "BEGIN_" (group-n 5 (1+ (not space))))
-          (group-n 6 "CALL:")
-          (group-n 8 (1+ (not space)) ":")))
-    (group-n 9 (regexp org-footnote-definition-re))
-    (group-n 10 (regexp "[ \t]*-----+[ \t]*$"))
-    (group-n 11 "%%(")))
+  (rx-to-string
+   `(or
+     (group-n 1 (regexp ,org-element--latex-begin-environment-nogroup))
+     (group-n 2 (regexp ,org-element-drawer-re-nogroup))
+     (group-n 3 (regexp "[ \t]*:\\( \\|$\\)"))
+     (group-n 7 (regexp ,org-element-dynamic-block-open-re-nogroup))
+     (seq (group-n 4 (regexp "[ \t]*#\\+"))
+          (or
+           (seq "BEGIN_" (group-n 5 (1+ (not space))))
+           (group-n 6 "CALL:")
+           (group-n 8 (1+ (not space)) ":")))
+     (group-n 9 (regexp ,org-footnote-definition-re))
+     (group-n 10 (regexp "[ \t]*-----+[ \t]*$"))
+     (group-n 11 "%%(")))
   "Bulk regexp matching multiple elements in a single regexp.
 This is a bit more efficient compared to invoking regexp search
 multiple times.")
@@ -6916,8 +6916,8 @@ (defun org-element--cache-setup-change-functions ()
     ;; Clear copied local cache to avoid extra memory usage.
     ;; We only use cache stored in the base buffer.
     (when (buffer-base-buffer)
-      (setq-local org-element--cache nil
-                  org-element--headline-cache nil))
+      (setq-local org-element--cache nil)
+      (setq-local org-element--headline-cache nil))
     (add-hook 'before-change-functions
 	      #'org-element--cache-before-change nil t)
     ;; Run `org-element--cache-after-change' early to handle cases
-- 
2.25.1


[-- Attachment #3: v2-0002-org-compat.el-org-flatten-tree-for-Emacs-26-compa.patch --]
[-- Type: text/x-patch, Size: 5106 bytes --]

From e85b19dba86bc3a5937376a0001453dbe3a5dc24 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Wed, 5 Jul 2023 22:50:44 +0700
Subject: [PATCH v2 2/2] org-compat.el: `org--flatten-tree' for Emacs-26
 compatibility

* lisp/org-compat.el (org--flatten-tree): New internal compatibility
alias or function based on `flatten-tree' added to Emacs-27.1.
* lisp/org-protocol.el (org-protocol-flatten): Convert to an obsolete
function alias.
(org-protocol-flatten-greedy): Use the `org--flatten-tree' new
compatibility alias or function instead of `org-protocol-flatten'.
* lisp/org-src.el (org-src--get-known-shells): Make the function
compatible with Emacs-26 by using `org--flatten-tree' instead of
`flatten-tree'.

Reported as: Justin to emacs-orgmode. [PATCH] org-src: flatten-tree is
Emacs 27.1; require compat. Tue, 4 Jul 2023 19:21:05 -0400.
https://list.orgmode.org/0288575b-fde8-0e7d-ac74-1f0ac93ce56f@vallon.homeip.net
---
 lisp/org-compat.el   | 19 +++++++++++++++++++
 lisp/org-protocol.el | 24 +++++++++---------------
 lisp/org-src.el      |  2 +-
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index c5ab655d2..bbda04a15 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -211,6 +211,25 @@     (defmacro org-combine-change-calls (_beg _end &rest body)
       `(progn ,@body))
   (defalias 'org-combine-change-calls 'combine-change-calls))
 
+;; `flatten-tree' was added in Emacs 27.1.
+(if (fboundp 'flatten-tree)
+    (defalias 'org--flatten-tree #'flatten-tree)
+  ;; The implementation is taken from Emacs subr.el 8664ba18c7c5.
+  (defun org--flatten-tree (tree)
+    "Return a \"flattened\" copy of TREE.
+
+A `flatten-tree' polyfill for compatibility with Emacs versions
+older than 27.1"
+    (let (elems)
+      (while (consp tree)
+        (let ((elem (pop tree)))
+          (while (consp elem)
+            (push (cdr elem) tree)
+            (setq elem (car elem)))
+          (if elem (push elem elems))))
+      (if tree (push tree elems))
+      (nreverse elems))))
+
 (if (version< emacs-version "27.1")
     (defsubst org-replace-buffer-contents (source &optional _max-secs _max-costs)
       (replace-buffer-contents source))
diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el
index 2b07a377e..d6cc39aa9 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -328,7 +328,7 @@ (defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
 Greedy handlers might receive a list like this from emacsclient:
 \((\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\"))
 where \"/dir/\" is the absolute path to emacsclient's working directory.  This
-function transforms it into a flat list using `org-protocol-flatten' and
+function transforms it into a flat list using `flatten-tree' and
 transforms the elements of that list as follows:
 
 If STRIP-PATH is non-nil, remove the \"/dir/\" prefix from all members of
@@ -343,9 +343,9 @@ (defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
 `org-protocol-reverse-list-of-files' was set to t and the returned list will
 reflect that.  emacsclient's first parameter will be the first one in the
 returned list."
-  (let* ((l (org-protocol-flatten (if org-protocol-reverse-list-of-files
-				      param-list
-				    (reverse param-list))))
+  (let* ((l (org--flatten-tree (if org-protocol-reverse-list-of-files
+                              param-list
+                            (reverse param-list))))
 	 (trigger (car l))
 	 (len 0)
 	 dir
@@ -368,21 +368,15 @@ (defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
 	  ret)
       l)))
 
-;; `flatten-tree' was added in Emacs 27.1.
-(defalias 'org-protocol-flatten
-  (if (fboundp 'flatten-tree) 'flatten-tree
-    (lambda (list)
-      "Transform LIST into a flat list.
+(define-obsolete-function-alias 'org-protocol-flatten
+  (if (fboundp 'flatten-tree) 'flatten-tree 'org--flatten-tree)
+  "9.7"
+  "Transform LIST into a flat list.
 
 Greedy handlers might receive a list like this from emacsclient:
 \((\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\"))
 where \"/dir/\" is the absolute path to emacsclients working directory.
-This function transforms it into a flat list."
-      (if list
-	  (if (consp list)
-	      (append (org-protocol-flatten (car list))
-		      (org-protocol-flatten (cdr list)))
-	    (list list))))))
+This function transforms it into a flat list.")
 
 (defun org-protocol-parse-parameters (info &optional new-style default-order)
   "Return a property list of parameters from INFO.
diff --git a/lisp/org-src.el b/lisp/org-src.el
index e1f7d50dc..7edbe0570 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -208,7 +208,7 @@ (defun org-src--get-known-shells ()
 The shells are associated with `sh-mode'."
   (mapcar
    (lambda (shell) (cons (symbol-name shell) 'sh))
-   (delete-dups (flatten-tree sh-ancestor-alist))))
+   (delete-dups (org--flatten-tree sh-ancestor-alist))))
 
 (defcustom org-src-lang-modes
   `(("C" . c)
-- 
2.25.1


  reply	other threads:[~2023-07-08  4:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 23:51 [BUG] org-element loading fails with "regexp" argument not "stringp" Justin
2023-07-05 10:35 ` Ihor Radchenko
2023-07-05 16:00   ` [PATCH] Fix Emacs-26 compatibility (was: Re: [BUG] org-element loading fails with "regexp" argument not "stringp") Max Nikulin
2023-07-06  9:54     ` Ihor Radchenko
2023-07-08  4:56       ` Max Nikulin [this message]
2023-07-08  9:18         ` [PATCH v2] " 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='u8aqat$860$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).