diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2025-03-25 13:53:06 +0100 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2025-03-25 13:53:06 +0100 |
| commit | 0346df19940b5fdab49a9a79681d1f318355c6ae (patch) | |
| tree | fa5f916be443c957c40c66303ec889b95be01070 | |
| parent | f3488d5b60ad9b838d30e0fa6135eba11fd88b1e (diff) | |
| -rw-r--r-- | shell-quasiquote.el | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/shell-quasiquote.el b/shell-quasiquote.el index c854b3a..d610565 100644 --- a/shell-quasiquote.el +++ b/shell-quasiquote.el @@ -1,11 +1,13 @@ +;; -*- lexical-binding: t; -*- + ;;; shell-quasiquote.el --- Turn s-expressions into shell command strings. -;; Copyright (C) 2015 Taylan Ulrich Bayırlı/Kammer +;; Copyright (C) 2015, 2025 Free Software Foundation -;; Author: Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com> -;; Version: 1.0 +;; Author: Taylan Ulrich Kammer <taylan.kammer@gmail.com> +;; Version: 1.1 ;; Keywords: extensions, unix -;; URL: https://github.com/TaylanUB/emacs-shell-quasiquote +;; URL: https://git.tkammer.de/elisp/shell-quasiquote ;; 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 @@ -55,7 +57,6 @@ ;; ;; Neat, eh? - ;;; Code: ;;; Like `shell-quote-argument', but much simpler in implementation. @@ -72,27 +73,6 @@ (defun shqq--quote-atom (atom) (shqq--quote-string (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, every element of PARTS must be one of: @@ -128,19 +108,18 @@ 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)) + (`(,`\, (,`\, ,part)) + part) ;; ,,@foo i.e. (, (,@ foo)) - ((and (pred shqq--match-comma) - (let `,@,form (shqq--match-comma part))) - `(mapconcat #'identity ,form " ")) + (`(,`\, (,`\,@ ,part)) + `(mapconcat #'identity ,part " ")) ;; ,foo ;; Insert redundant 'and x' to work around debbugs#18554. - ((and x (pred shqq--match-comma)) - `(shqq--quote-atom ,(shqq--match-comma part))) + (`(,`\, ,part) + `(shqq--quote-atom ,part)) ;; ,@foo - (`,@,form - `(mapconcat #'shqq--quote-atom ,form " ")) + (`(,`\,@ ,part) + `(mapconcat #'shqq--quote-atom ,part " ")) (_ (error "Bad shqq part: %S" part)))))) parts))) |
