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))))
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: