magit / with-editor

Use the Emacsclient as the $EDITOR of child processes
http://magit.vc/manual/with-editor
GNU General Public License v3.0
185 stars 45 forks source link

with-editor-export-editor: check whether there is a buffer process #87

Closed marsam closed 3 years ago

marsam commented 3 years ago

When with-editor-export-editor is added to the shell-mode-hook, it's also executed by shell-command, because it calls shell-mode, which inherits from comint-mode' Usually, shell-command is used to execute short-lived process, hence there might not be a process associated to the buffer when the hook is executed.

The previous implementation assumed the existence of a process associated to a buffer, which might not be a case on shell-command buffers. This change intends to checks whether there is a process associated before sending the environment variables.

tarsius commented 3 years ago

Thanks!

Please briefly explain in the commit message why the (derived-mode-p 'comint-mode 'term-mode) code-path is relevant for commands that "use shell-mode" and also what previously happened because we didn't do this. And use elisp-style symbol-quoting not markdown code-quoting in commit message. And capitalize "Check".

tarsius commented 3 years ago

Friendly ping!

tarsius commented 3 years ago

Please complete the commit message. Thanks!

marsam commented 3 years ago

I'm so sorry for the late response 🙏 , somehow this got lost in my notifications. I've updated the commit with your suggestions.

I investigated a bit further and seems to happen when shell-command process exits too quickly. I'm not sure what is the best way to reproduce it, but I have the following in my init.el and happened to me a few times:

(dolist (hook '(shell-mode-hook term-exec-hook eshell-mode-hook))
  (dolist (envvar with-editor-envvars)
    (add-hook hook (apply-partially 'with-editor-export-editor envvar))))
tarsius commented 3 years ago

Well, that happens. Np. Thanks!