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

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".

This works in shell-mode, term-mode, eshell-mode(var)/eshell-mode(fun) and vterm.

Key Bindings

Source Code

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

;;;###autoload
(cl-defun with-editor-export-editor (&optional (envvar "EDITOR"))
  "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\".

This works in `shell-mode', `term-mode', `eshell-mode' and
`vterm'."
  (interactive (list (with-editor-read-envvar)))
  (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))
    ((and (derived-mode-p 'vterm-mode)
          (fboundp 'vterm-send-return)
          (fboundp 'vterm-send-string))
     (if with-editor-emacsclient-executable
         (let ((with-editor--envvar envvar)
               (process-environment process-environment))
           (with-editor--setup)
           (while (accept-process-output vterm--process 1 nil t))
           (when-let ((v (getenv envvar)))
             (vterm-send-string (format " export %s=%S" envvar v))
             (vterm-send-return))
           (when-let ((v (getenv "EMACS_SERVER_FILE")))
             (vterm-send-string (format " export EMACS_SERVER_FILE=%S" v))
             (vterm-send-return))
           (vterm-send-string " clear")
           (vterm-send-return))
       (error "Cannot use sleeping editor in this buffer")))
    (t
     (error "Cannot export environment variables in this buffer")))
  (message "Successfully exported %s" envvar))