Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing list to &rest args [duplicate]

Tags:

emacs

elisp

How can I pass a list of parameters to start-process's 4th argument (PROGRAMS-ARGS):

(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)

for example:

(start-process "program-name" nil "program-name" "-p1" "-p2" "-p3" "program-name")

I want to do the same thing by collecting parameters in a list and passing the list variable to functions argument, but it doesn't work:

(setq program-args (list "-p1" "-p2" "-p3"))

(start-process "program-name" nil "program-name" program-args "program-name")
like image 619
lkjhfhfj Avatar asked Jun 12 '13 21:06

lkjhfhfj


1 Answers

You should use apply in this case:

apply calls function with arguments, just like funcall but with one difference: the last of arguments is a list of objects, which are passed to function as separate arguments, rather than a single list.

I.e., in your case the correct code is:

(apply 'start-process
  (append (list "program-name" nil "program-name")
          program-args
          (list "program-name")))
like image 91
NikitaBaksalyar Avatar answered Oct 12 '22 07:10

NikitaBaksalyar