summaryrefslogtreecommitdiff
path: root/elpa/with-editor-3.4.3/README.org
blob: aea30cc4a437cb87de8cfff157754866b81bd0e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
* 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 "<remap> <async-shell-command>"
                     #'with-editor-async-shell-command)
  (keymap-global-set "<remap> <shell-command>"
                     #'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.

#+html: <br><br>
#+html: <a href="https://github.com/magit/with-editor/actions/workflows/compile.yml"><img alt="Compile" src="https://github.com/magit/with-editor/actions/workflows/compile.yml/badge.svg"/></a>
#+html: <a href="https://github.com/magit/with-editor/actions/workflows/manual.yml"><img alt="Manual" src="https://github.com/magit/with-editor/actions/workflows/manual.yml/badge.svg"/></a>
#+html: <a href="https://elpa.nongnu.org/nongnu/with-editor.html"><img alt="NonGNU ELPA" src="https://emacsair.me/assets/badges/nongnu-elpa.svg"/></a>
#+html: <a href="https://stable.melpa.org/#/with-editor"><img alt="MELPA Stable" src="https://stable.melpa.org/packages/with-editor-badge.svg"/></a>
#+html: <a href="https://melpa.org/#/with-editor"><img alt="MELPA" src="https://melpa.org/packages/with-editor-badge.svg"/></a>