mirror of
https://github.com/pestctrl/emacs-config.git
synced 2026-06-14 12:21:20 +00:00
Recursive macros are harder to debug, let's do this instead
This commit is contained in:
parent
a584410654
commit
5a8cde65fa
1 changed files with 36 additions and 24 deletions
|
|
@ -117,30 +117,42 @@
|
||||||
|
|
||||||
(defmacro shell-let* (let-clauses &rest body)
|
(defmacro shell-let* (let-clauses &rest body)
|
||||||
(declare (indent 1))
|
(declare (indent 1))
|
||||||
(let* ((front-clause (car let-clauses))
|
(let* ((shell-let-clauses
|
||||||
(symbol-name (symbol-name (car front-clause)))
|
(mapcar #'(lambda (x)
|
||||||
(shell-name (string-replace "-" "_" (upcase symbol-name)))
|
(let ((symbol (car x)))
|
||||||
(shell-ref-name (format "${%s}" shell-name))
|
`(,symbol
|
||||||
(let-value (cadr front-clause)))
|
,(--> symbol
|
||||||
(if (not front-clause)
|
(symbol-name it)
|
||||||
`(list ,@body)
|
(upcase it)
|
||||||
(when (or
|
(string-replace "-" "_" it)
|
||||||
(not (consp let-value))
|
(format "${%s}" it)))))
|
||||||
(not (member (car let-value)
|
let-clauses))
|
||||||
'(run set))))
|
(shell-commands
|
||||||
(user-error "Each let form should start with run or set"))
|
(mapcar #'(lambda (x)
|
||||||
`(let ((,(car front-clause) ,shell-ref-name))
|
(let ((let-value (cadr x))
|
||||||
(shell-and
|
(shell-name
|
||||||
,(if (and (consp let-value)
|
(--> (car x)
|
||||||
(eq 'set (car let-value)))
|
(symbol-name it)
|
||||||
`(format "%s=\"%s\""
|
(upcase it)
|
||||||
,shell-name
|
(string-replace "-" "_" it))))
|
||||||
,(cadr let-value))
|
(when (or
|
||||||
`(format "%s=$(%s)"
|
(not (consp let-value))
|
||||||
,shell-name
|
(not (member (car let-value)
|
||||||
,(cadr let-value)))
|
'(run set))))
|
||||||
(shell-let* ,(cdr let-clauses)
|
(user-error "Each let form should start with run or set"))
|
||||||
,@body))))))
|
(if (and (consp let-value)
|
||||||
|
(eq 'set (car let-value)))
|
||||||
|
`(format "%s=\"%s\""
|
||||||
|
,shell-name
|
||||||
|
,(cadr let-value))
|
||||||
|
`(format "%s=$(%s)"
|
||||||
|
,shell-name
|
||||||
|
,(cadr let-value)))))
|
||||||
|
let-clauses)))
|
||||||
|
`(let ,shell-let-clauses
|
||||||
|
(shell-and
|
||||||
|
,@shell-commands
|
||||||
|
,@body))))
|
||||||
|
|
||||||
(provide 'tmux-cmd)
|
(provide 'tmux-cmd)
|
||||||
;;; tmux-cmd.el ends here
|
;;; tmux-cmd.el ends here
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue