https://github.com/magit/with-editor
Use the Emacsclient as the $EDITOR of child processes
https://github.com/magit/with-editor
Last synced: 6 months ago
JSON representation
Use the Emacsclient as the $EDITOR of child processes
- Host: GitHub
- URL: https://github.com/magit/with-editor
- Owner: magit
- License: gpl-3.0
- Created: 2016-01-26T01:37:10.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T15:59:03.000Z (over 1 year ago)
- Last Synced: 2024-05-09T21:05:27.833Z (over 1 year ago)
- Language: Emacs Lisp
- Homepage: http://magit.vc/manual/with-editor
- Size: 265 KB
- Stars: 175
- Watchers: 10
- Forks: 43
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* With-Editor
This library makes it possible to reliably use the Emacsclient as
the ~$EDITOR~ of child processes. It makes sure that they know how
to call home. For remote processes a substitute is provided, which
communicates with Emacs on standard output/input instead of using a
socket as the Emacsclient does.
It provides the commands ~with-editor-async-shell-command~ and
~with-editor-shell-command~, which are intended as replacements
for ~async-shell-command~ and ~shell-command~. They automatically
export ~$EDITOR~ making sure the executed command uses the current
Emacs instance as "the editor". With a prefix argument these
commands prompt for an alternative environment variable such as
~$GIT_EDITOR~. To always use these variants add this to your init
file:
#+begin_src emacs-lisp
(keymap-global-set " "
#'with-editor-async-shell-command)
(keymap-global-set " "
#'with-editor-shell-command)
#+end_src
Alternatively use the global ~shell-command-with-editor-mode~,
which always sets ~$EDITOR~ for all Emacs commands which ultimately
use ~shell-command~ to asynchronously run some shell command.
The command ~with-editor-export-editor~ exports ~$EDITOR~ or
another such environment variable in ~shell-mode~, ~eshell-mode~,
~term-mode~ and ~vterm-mode~ buffers. Use this Emacs command
before executing a shell command which needs the editor set, or
always arrange for the current Emacs instance to be used as editor
by adding it to the appropriate mode hooks:
#+begin_src emacs-lisp
(add-hook 'shell-mode-hook 'with-editor-export-editor)
(add-hook 'eshell-mode-hook 'with-editor-export-editor)
(add-hook 'term-exec-hook 'with-editor-export-editor)
(add-hook 'vterm-mode-hook 'with-editor-export-editor)
#+end_src
Some variants of this function exist, these two forms are
equivalent:
#+begin_src emacs-lisp
(add-hook 'shell-mode-hook
(apply-partially 'with-editor-export-editor "GIT_EDITOR"))
(add-hook 'shell-mode-hook 'with-editor-export-git-editor)
#+end_src
This library can also be used by other packages which need to use
the current Emacs instance as editor. In fact this library was
written for Magit and its ~git-commit-mode~ and ~git-rebase-mode~.
Consult ~git-rebase.el~ and the related code in ~magit-sequence.el~
for a simple example.