[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to pass a evaluated list as argument of macro?
From: |
stardiviner |
Subject: |
How to pass a evaluated list as argument of macro? |
Date: |
Mon, 06 Jul 2020 21:02:08 +0800 |
User-agent: |
mu4e 1.4; emacs 28.0.50 |
I have a prototype of bellowing elisp code. I try to write a macro for construct
ffmpeg commands. But found the passed in arglist is not evaluated or literal
"arglist" in some ways. I marked the problem in source code. Can somebody help
me on this problem? Thanks in advance. :)
#+begin_src emacs-lisp
(defmacro ffmpeg--command-macro (name arglist &rest body)
"Construct ffmpeg command with ARGS and BODY."
;; (declare (debug t))
`(defun ,(intern (format "ffmpeg-%s" name)) ()
(interactive)
(make-process
:name "ffmpeg"
;; FIXME `arglist' is not evaluated
:command ,(apply 'append '("ffmpeg") (eval arglist)) ; <-------------
problem here
:buffer "*ffmpeg*"
:sentinel (lambda (_ __)
(message "FFmpeg process finished.")))
,@body))
;;; NOTE Because ffmpeg command option "-t" accept seconds like 57 as value.
(defun ffmpeg--subtract-timestamps (start-timestamp end-timestamp)
"Subtract END-TIMESTAMP with START-TIMESTAMP."
(time-subtract
(encode-time (parse-time-string
(concat "2020-01-01T" end-timestamp)))
(encode-time (parse-time-string
(concat "2020-01-01T" start-timestamp)))))
;; (ffmpeg--subtract-timestamps "00:11:25" "00:12:12")
(defun ffmpeg-cut-clip (input-filename start-timestamp end-timestamp
output-filename)
"Cut clip of media INPUT-FILENAME between START-TIMESTAMP END-TIMESTAMP and
output to OUTPUT-FILENAME."
(interactive (list
(read-file-name "FFmpeg input filename: ")
(read-string "FFmpeg start timestamp: ")
(read-string "FFmpeg end timestamp: ")
(read-file-name "FFmpeg output filename: ")))
;; "ffmpeg -i input-filename -ss start-timestamp -t time-timestamp -codec
copy output-filename"
(let ((arglist `("-i" ,input-filename
"-ss" ,start-timestamp
"-t" ,(ffmpeg--subtract-timestamps start-timestamp
end-timestamp)
"-codec" "copy"
,output-filename)))
(ffmpeg--command-macro "cut-clip" arglist)))
#+end_src
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
- How to pass a evaluated list as argument of macro?,
stardiviner <=