# Start a process in Elisp

How can the following code be made idiomatic in ELisp? Can the temporary f variable be removed?

(global-set-key [f3]
(lambda () (interactive)
(let ((f (ffap-file-at-point)))
(start-process "test" "output" "mpv" f))))


## 1 Answer

You can remove the let, as you only reference f once.

I'd also make it a named function; this makes it easier for you to update the definition, or to bind it to additional keys:

(defun start-mpv--file-at-point ()
(interactive)
(start-process "test" "output" "mpv" (ffap-file-at-point)))

(global-set-key [f3] 'start-mpv--file-at-point)


You might also want to look at the implementation of shell-command for inspiration. Some things it does that might interest you:

• killing any process that's already writing to the output buffer
• erasing the current contents of that buffer
• setting the comint output filter to handle carriage motion
• making the output buffer visible