[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to pass a evaluated list as argument of macro?
From: |
stardiviner |
Subject: |
Re: How to pass a evaluated list as argument of macro? |
Date: |
Mon, 06 Jul 2020 22:46:05 +0800 |
User-agent: |
mu4e 1.4; emacs 28.0.50 |
Noam Postavsky <npostavs@gmail.com> writes:
> On Mon, 6 Jul 2020 at 09:02, stardiviner <numbchild@gmail.com> wrote:
>
>> (defmacro ffmpeg--command-macro (name arglist &rest body)
>> "Construct ffmpeg command with ARGS and BODY."
>> ;; (declare (debug t))
>> `(defun ,(intern (format "ffmpeg-%s" name)) ()
>
>> (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."
>
>> (ffmpeg--command-macro "cut-clip" arglist)))
>
> The way you are using your macro doesn't make sense to me. Do you want
> ffmpeg-cut-clip to define a command which runs ffmpeg (in which case,
> maybe it should be a macro), or actually just run the ffmpeg command
> (in which case, maybe ffmpeg--comand-macro should not be a macro, but
> rather a function (and probably called something like
> ffmpeg-run-command instead))?
You're right, recursive (interactive) command definition is nonsense.
I'm trying to abstract out the "make-process" out.
I modified source code to bellowing:
#+begin_src emacs-lisp
(defmacro ffmpeg--run-command (arglist &rest body)
"Construct ffmpeg command with ARGLIST and BODY."
(declare (debug t))
`(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--run-command arglist))) ; <----- error void arglist
#+end_src
In upper "error void arglist" position, If I use:
#+begin_src emacs-lisp
(ffmpeg--run-command '("-i" ,input-filename
"-ss" ,start-timestamp
"-t" ,(ffmpeg--subtract-timestamps start-timestamp
end-timestamp)
"-codec" "copy"
,output-filename))
#+end_src
Still wrong. I wander why, can you give some simple explanation hints? Thanks :)
--
[ 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