| 1 | This library makes it possible to reliably use the Emacsclient as |
| 2 | the `$EDITOR' of child processes. It makes sure that they know how |
| 3 | to call home. For remote processes a substitute is provided, which |
| 4 | communicates with Emacs on standard output/input instead of using a |
| 5 | socket as the Emacsclient does. |
| 6 | |
| 7 | It provides the commands `with-editor-async-shell-command' and |
| 8 | `with-editor-shell-command', which are intended as replacements |
| 9 | for `async-shell-command' and `shell-command'. They automatically |
| 10 | export `$EDITOR' making sure the executed command uses the current |
| 11 | Emacs instance as "the editor". With a prefix argument these |
| 12 | commands prompt for an alternative environment variable such as |
| 13 | `$GIT_EDITOR'. To always use these variants add this to your init |
| 14 | file: |
| 15 | |
| 16 | (keymap-global-set "<remap> <async-shell-command>" |
| 17 | #'with-editor-async-shell-command) |
| 18 | (keymap-global-set "<remap> <shell-command>" |
| 19 | #'with-editor-shell-command) |
| 20 | |
| 21 | Alternatively use the global `shell-command-with-editor-mode', |
| 22 | which always sets `$EDITOR' for all Emacs commands which ultimately |
| 23 | use `shell-command' to asynchronously run some shell command. |
| 24 | |
| 25 | The command `with-editor-export-editor' exports `$EDITOR' or another |
| 26 | such environment variable in `shell-mode', `eshell-mode', `term-mode', |
| 27 | `vterm-mode', `eat-mode' and `ghostel-mode' buffers. Use this Emacs |
| 28 | command before executing a shell command which needs the editor set, |
| 29 | or always arrange for the current Emacs instance to be used as editor |
| 30 | by adding it to the appropriate mode hooks: |
| 31 | |
| 32 | (add-hook 'shell-mode-hook #'with-editor-export-editor) |
| 33 | (add-hook 'eshell-mode-hook #'with-editor-export-editor) |
| 34 | (add-hook 'term-exec-hook #'with-editor-export-editor) |
| 35 | (add-hook 'vterm-mode-hook #'with-editor-export-editor) |
| 36 | (add-hook 'eat-exec-hook #'with-editor-export-editor) |
| 37 | (add-hook 'ghostel-pre-spawn-hook #'with-editor-export-editor) |
| 38 | |
| 39 | Some variants of this function exist, these two forms are |
| 40 | equivalent: |
| 41 | |
| 42 | (add-hook 'shell-mode-hook |
| 43 | (apply-partially #'with-editor-export-editor "GIT_EDITOR")) |
| 44 | (add-hook 'shell-mode-hook #'with-editor-export-git-editor) |
| 45 | |
| 46 | This library can also be used by other packages which need to use |
| 47 | the current Emacs instance as editor. In fact this library was |
| 48 | written for Magit and its `git-commit-mode' and `git-rebase-mode'. |
| 49 | Consult `git-rebase.el' and the related code in `magit-sequence.el' |
| 50 | for a simple example. |