File: with-editor.el.html

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:

  (keymap-global-set "<remap> <async-shell-command>"
                     #'with-editor-async-shell-command)
  (keymap-global-set "<remap> <shell-command>"
                     #'with-editor-shell-command)

Alternatively use the global shell-command-with-editor-mode(var)/shell-command-with-editor-mode(fun), 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(var)/eshell-mode(fun), 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:

  (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)

Some variants of this function exist, these two forms are equivalent:

  (add-hook 'shell-mode-hook
            (apply-partially #'with-editor-export-editor "GIT_EDITOR"))
  (add-hook 'shell-mode-hook #'with-editor-export-git-editor)

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(var)/git-commit-mode(fun) and git-rebase-mode. Consult git-rebase.el and the related code in magit-sequence.el for a simple example.

Defined variables (15)

shell-command-with-editor-modeNon-nil if Shell-Command-With-Editor mode is enabled.
shell-command-with-editor-mode-hookHook run after entering or leaving ‘shell-command-with-editor-mode’.
with-editor--envvarFor internal use.
with-editor--pidFor internal use.
with-editor-cancel-query-functionsList of functions called to query before canceling session.
with-editor-emacsclient-executableThe Emacsclient executable used by the ‘with-editor’ macro.
with-editor-emacsclient-program-suffixesSuffixes to append to append when looking for a Emacsclient executables.
with-editor-file-name-history-excludeList of regexps for filenames ‘server-visit’ should not remember.
with-editor-finish-query-functionsList of functions called to query before finishing session.
with-editor-modeNon-nil if With-Editor mode is enabled.
with-editor-mode-hookHook run after entering or leaving ‘with-editor-mode’.
with-editor-mode-lighterThe mode-line lighter of the With-Editor mode.
with-editor-server-window-alistAlist of filename patterns vs corresponding ‘server-window’.
with-editor-shell-command-use-emacsclientWhether to use the emacsclient when running shell commands.
with-editor-sleeping-editorThe sleeping editor, used when the Emacsclient cannot be used.

Defined functions (28)

make-process@with-editor-process-filter
server-switch-buffer@with-editor-server-window-alist(FN &optional NEXT-BUFFER &rest ARGS)
server-visit-files@with-editor-file-name-history-exclude(FILES PROC &optional NOWAIT)
shell-command-with-editor-mode(&optional ARG)
shell-command@shell-command-with-editor-mode(FN COMMAND &optional OUTPUT-BUFFER ERROR-BUFFER)
start-file-process@with-editor-process-filter(FN NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
with-editor([ENVVAR] BODY...)
with-editor*(ENVVAR BODY...)
with-editor-async-shell-command(COMMAND &optional OUTPUT-BUFFER ERROR-BUFFER ENVVAR)
with-editor-cancel(FORCE)
with-editor-debug()
with-editor-emacsclient-version(EXEC)
with-editor-emulate-terminal(PROCESS STRING)
with-editor-export-editor(&optional (ENVVAR "EDITOR"))
with-editor-export-git-editor()
with-editor-export-hg-editor()
with-editor-finish(FORCE)
with-editor-locate-emacsclient()
with-editor-locate-emacsclient-1(PATH DEPTH)
with-editor-mode(&optional ARG)
with-editor-output-filter(STRING)
with-editor-process-filter(PROCESS STRING &optional NO-DEFAULT-FILTER)
with-editor-read-envvar(&optional (PROMPT "Set environment variable") (DEFAULT "EDITOR"))
with-editor-return(CANCEL)
with-editor-set-process-filter(PROCESS FILTER)
with-editor-shell-command(COMMAND &optional OUTPUT-BUFFER ERROR-BUFFER ENVVAR)
with-editor-shell-command-read-args(PROMPT &optional ASYNC)
with-editor-sleeping-editor-filter(PROCESS STRING)

Defined faces (0)