dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

README.org (3223B)


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