From 2f2d330e90b10a86aa6b3b9ff279bc012b339396 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Wed, 5 Jul 2023 22:50:44 +0700 Subject: [PATCH 2/2] org-compat.el: Define `flatten-tree' for Emacs-26 compatibility * lisp/org-compat.el (flatten-tree): New compatibility function earlier used as `org-protocol-flatten'. * lisp/org-protocol.el (org-protocol-flatten): Remove the definition of the function. (org-protocol-flatten-greedy): Use `flatten-tree' instead of `org-protocol-flatten'. 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 | 15 +++++++++++++++ lisp/org-protocol.el | 24 ++++-------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index c5ab655d2..7017a5859 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -203,6 +203,21 @@ (defun org-format-prompt (prompt default &rest format-args) ;;; Emacs < 27.1 compatibility +;; `flatten-tree' was added in Emacs 27.1. +(unless (fboundp 'flatten-tree) + (defun flatten-tree (list) + "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 (flatten-tree (car list)) + (flatten-tree (cdr list))) + (list list))))) + (if (version< emacs-version "29") ;; A stub when `combine-change-calls' was not yet there or had ;; critical bugs (see Emacs bug#60467). diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index 2b07a377e..a0d003363 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 (flatten-tree (if org-protocol-reverse-list-of-files + param-list + (reverse param-list)))) (trigger (car l)) (len 0) dir @@ -368,22 +368,6 @@ (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. - -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)))))) - (defun org-protocol-parse-parameters (info &optional new-style default-order) "Return a property list of parameters from INFO. If NEW-STYLE is non-nil, treat INFO as a query string (ex: -- 2.25.1