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

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

[elpa] externals/org 879ba22ef6 2/2: org-compat.el: `org--flatten-tree'


From: ELPA Syncer
Subject: [elpa] externals/org 879ba22ef6 2/2: org-compat.el: `org--flatten-tree' for Emacs-26 compatibility
Date: Sat, 8 Jul 2023 06:58:21 -0400 (EDT)

branch: externals/org
commit 879ba22ef69cc54d757b02e84d4f8d37dcef866f
Author: Max Nikulin <manikulin@gmail.com>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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 c5ab655d25..bbda04a15b 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -211,6 +211,25 @@ removed."
       `(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 2b07a377e2..d6cc39aa93 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -328,7 +328,7 @@ results of that splitting are returned as a 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 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 @@ Note, that this function will always behave as if
 `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 @@ returned list."
          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 e1f7d50dcf..7edbe0570d 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -208,7 +208,7 @@ but which mess up the display of a snippet in Org exported 
files.")
 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)



reply via email to

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