Function: with-editor-export-editor

with-editor-export-editor is an autoloaded, interactive and byte-compiled function defined in with-editor.el.

Signature

(with-editor-export-editor &optional (ENVVAR "EDITOR") PROCESS INTERACTIVE)

Documentation

Teach subsequent commands to use current Emacs instance as editor.

Set and export the environment variable ENVVAR, by default "EDITOR". The value is automatically generated to teach commands to use the current Emacs instance as "the editor".

PROCESS is only intended for use by eat-exec-hook. When invoked interactively, INTERACTIVE is non-nil, which supresses the call to
"clear" (only relevant in vterm-mode and eat-mode).

This command can be used in shell-mode, term-mode, eshell-mode(var)/eshell-mode(fun), vterm-mode and eat-mode.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/with-editor-20260731.2234/with-editor.el
;;; Augmentations

;;;###autoload
(cl-defun with-editor-export-editor
    (&optional (envvar "EDITOR") process interactive)
  "Teach subsequent commands to use current Emacs instance as editor.

Set and export the environment variable ENVVAR, by default \"EDITOR\".
The value is automatically generated to teach commands to use the
current Emacs instance as \"the editor\".

PROCESS is only intended for use by `eat-exec-hook'.  When invoked
interactively, INTERACTIVE is non-nil, which supresses the call to
\"clear\" (only relevant in `vterm-mode' and `eat-mode').

This command can be used in `shell-mode', `term-mode', `eshell-mode',
`vterm-mode' and `eat-mode'."
  (interactive (list (with-editor-read-envvar) nil t))
  (cond
    ((derived-mode-p 'comint-mode 'term-mode)
     (when-let ((process (get-buffer-process (current-buffer))))
       (goto-char (process-mark process))
       (process-send-string
        process (format " export %s=%s\n" envvar
                        (shell-quote-argument with-editor-sleeping-editor)))
       (while (accept-process-output process 1 nil t))
       (if (derived-mode-p 'term-mode)
           (with-editor-set-process-filter process #'with-editor-emulate-terminal)
         (add-hook 'comint-output-filter-functions #'with-editor-output-filter
                   nil t))))
    ((derived-mode-p 'eshell-mode)
     (add-to-list 'eshell-preoutput-filter-functions
                  #'with-editor-output-filter)
     (setenv envvar with-editor-sleeping-editor))
    ((not with-editor-emacsclient-executable)
     (if (derived-mode-p 'vterm-mode 'eat-mode)
         (error "Cannot use sleeping editor in this buffer")
       (error "Cannot export environment variables in this buffer")))
    ((and (derived-mode-p 'vterm-mode)
          (fboundp 'vterm-send-return)
          (fboundp 'vterm-send-string))
     (let ((process-environment process-environment)
           (with-editor--envvar envvar))
       (with-editor--setup)
       (while (accept-process-output vterm--process 1 nil t))
       (when$ (getenv envvar)
         (vterm-send-string (format " export %s=%S" envvar $))
         (vterm-send-return))
       (when$ (getenv "EMACS_SERVER_FILE")
         (vterm-send-string (format " export EMACS_SERVER_FILE=%S" $))
         (vterm-send-return))
       (unless interactive
         (vterm-send-string " clear")
         (vterm-send-return))))
    ((and (derived-mode-p 'eat-mode)
          (fboundp 'eat-self-input)
          (fboundp 'eat-term-parameter)
          (fboundp 'eat-term-send-string))
     (let* ((process-environment process-environment)
            ;; `eat-exec-hook' calls this function with one argument.  If
            ;; (apply-partially #'with-editor-export-editor "SOMEEDITOR"))
            ;; was added to that hook, we receive that as the PROCESS
            ;; argument.  However, if this function is called via one of
            ;; the commands below, then ENVVAR actually is an envvar, and
            ;; the process has to be determined by other means.
            (process (cond ((processp envvar)
                            (prog1 envvar (setq envvar "EDITOR")))
                           ((processp process) process)
                           ((eat-term-parameter eat-terminal 'eat--process))))
            (with-editor--envvar envvar))
       (with-editor--setup)
       (while (accept-process-output process 1 nil t))
       (when$ (getenv envvar)
         (eat-term-send-string eat-terminal
                               (format " export %s=%S" envvar $))
         (eat-self-input 1 'return))
       (when$ (getenv "EMACS_SERVER_FILE")
         (eat-term-send-string eat-terminal
                               (format " export EMACS_SERVER_FILE=%S" $))
         (eat-self-input 1 'return))
       (unless interactive
         (eat-term-send-string eat-terminal "clear")
         (eat-self-input 1 'return)))))
  (message "Successfully exported %s" envvar))