Pages

Thursday, June 4, 2026

exeln: EXEcute LiNe

The following exeln function passes the current line to the system shell, which executes it, thus EXEcuting LiNe.

On Windows x86, my GNU Emacs has shell-file-name set to cmdproxy.exe, which is provided by x86_64-w64-mingw32, with which Emacs was compiled.

shell is invoked synchronously by default; a prefix argument can change this to asynchronous.

(defun exeln (arg)
    "Execute the current line as a shell command.
With prefix arg, operate asynchronously, same as calling
(shell-command COMMAND) where COMMAND ends in '&'.
Otherwise, execute synchronously."
  (interactive "P")
  (let (asynch)
    (if arg
        (setq asynch "&"))
    (shell-command (concat
                    (buffer-substring
                     (line-beginning-position) (line-end-position))
                    asynch))))

No comments:

Post a Comment

Thank you for taking time to comment. Please note that comments may be deleted if they:

* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.

For posts older than 14 days, comments are moderated and require approval.