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

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

[elpa] externals/shell-quasiquote e314501 3/4: * shell-quasiquote.el (sh


From: Stefan Monnier
Subject: [elpa] externals/shell-quasiquote e314501 3/4: * shell-quasiquote.el (shqq): Make better use of pcase
Date: Tue, 1 Dec 2020 17:11:31 -0500 (EST)

branch: externals/shell-quasiquote
commit e3145019797a3ff8a68d59638cf11782b16d5d7c
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * shell-quasiquote.el (shqq): Make better use of pcase
    
    (shqq--match-comma, shqq--match-comma2): Remove.
---
 shell-quasiquote.el | 36 +++++-------------------------------
 1 file changed, 5 insertions(+), 31 deletions(-)

diff --git a/shell-quasiquote.el b/shell-quasiquote.el
index bdea46a..a0bf7c8 100644
--- a/shell-quasiquote.el
+++ b/shell-quasiquote.el
@@ -4,6 +4,7 @@
 
 ;; Author: Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
 ;; Keywords: extensions, unix
+;; Version: 0
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -67,27 +68,6 @@
 
 (defun shqq--quote-atom (atom)
   (shell-quote-argument (shqq--atom-to-string atom)))
-
-(defun shqq--match-comma (form)
-  "Matches FORM against ,foo i.e. (\, foo) and returns foo.
-Returns nil if FORM didn't match.  You can't disambiguate between
-FORM matching ,nil and not matching."
-  (if (and (consp form)
-           (eq '\, (car form))
-           (consp (cdr form))
-           (null (cddr form)))
-      (cadr form)))
-
-(defun shqq--match-comma2 (form)
-  "Matches FORM against ,,foo i.e. (\, (\, foo)) and returns foo.
-Returns nil if FORM didn't match.  You can't disambiguate between
-FORM matching ,,nil and not matching."
-  (if (and (consp form)
-           (eq '\, (car form))
-           (consp (cdr form))
-           (null (cddr form)))
-      (shqq--match-comma (cadr form))))
-
 
 (defmacro shqq (parts)
   "First, PARTS is turned into a list of strings.  For this,
@@ -124,19 +104,13 @@ separating spaces."
              ;; We use the match-comma helpers because pcase can't match ,foo.
              (t (pcase part
                   ;; ,,foo i.e. (, (, foo))
-                  ((pred shqq--match-comma2)
-                   (shqq--match-comma2 part))
+                  (`(,`\, (,`\, ,form))  form)
                   ;; ,,@foo i.e. (, (,@ foo))
-                  ((and (pred shqq--match-comma)
-                        (let `,@,form (shqq--match-comma part)))
-                   `(mapconcat #'identity ,form " "))
+                  (`(,`\, (,`\,@ ,form)) `(mapconcat #'identity ,form " "))
                   ;; ,foo
-                  ;; Insert redundant 'and x' to work around debbugs#18554.
-                  ((and x (pred shqq--match-comma))
-                   `(shqq--quote-atom ,(shqq--match-comma part)))
+                  (`(,`\, ,form) `(shqq--quote-atom ,form))
                   ;; ,@foo
-                  (`,@,form
-                   `(mapconcat #'shqq--quote-atom ,form " "))
+                  (`,@,form `(mapconcat #'shqq--quote-atom ,form " "))
                   (_
                    (error "Bad shqq part: %S" part))))))
           parts)))



reply via email to

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