1

I'd like to occasionally use hg split and hg commit --interactive from Emacs, but those commands bring up a GUI. At the moment I either use a separate terminal or ansi-term for those, but would like to do it in more organic way.

Probably the minimal ideal interface would be a function like this:

(defun run-terminal-app cmd args &optional callback)

I have rough ideas how to implement this, e.g.:

  1. put a command with args into a temporary shell file
  2. launch (ansi-term temp-shell-file some-special-buffer-name)
  3. add a term-exec-hook to wait for exit in a some-special-bufer-name, then running a callback, killing a buffer, and removing a hook

But maybe I am just missing something and this is already implemented in some package, or even out of the box?

1 Answer 1

1

Something like this?

(defvar run-terminal-app-history nil)
(defun run-terminal-app (command &optional name)
  "Runs COMMAND in a `term' buffer."
  (interactive
   (list (read-from-minibuffer "$ " nil nil nil 'run-terminal-app-history)))
  (let* ((name (or name command))
         (switches (split-string-and-unquote command))
         (command (pop switches))
         (termbuf (apply 'make-term name command nil switches))
         (proc (get-buffer-process termbuf)))
    (set-process-query-on-exit-flag proc nil)
    (set-process-sentinel
     proc (lambda (process signal)
            (and (memq (process-status process) '(exit signal))
                 (buffer-live-p (process-buffer process))
                 (kill-buffer (process-buffer process)))))
    (set-buffer termbuf)
    (term-mode)
    (term-char-mode)
    (switch-to-buffer termbuf)))
2
  • Fantastic! To make hg commit --interactive without -m switch working I just needed to wrap it with with-editor Commented Feb 13, 2019 at 10:06
  • Ah, nice. I've never done anything custom using with-editor myself, and now I wish I'd previously looked at just how easy and convenient it is. Thanks for mentioning.
    – phils
    Commented Feb 14, 2019 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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