1
\$\begingroup\$

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))))
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.