mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(emacs-lisp): add +emacs-lisp/change-working-buffer command
This changes what buffer `+emacs-lisp-eval` evaluates elisp in (useful for the :tool eval module's commands, like `+eval/buffer` and `+eval/region`, or the Evil operators on gr/gR). Creates a scratch buffer/org src block alternative to ielm.
This commit is contained in:
@ -3,29 +3,38 @@
|
|||||||
;;
|
;;
|
||||||
;;; Library
|
;;; Library
|
||||||
|
|
||||||
|
(defvar +emacs-lisp-eval-working-buffer nil)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +emacs-lisp-eval (beg end)
|
(defun +emacs-lisp-eval (beg end)
|
||||||
"Evaluate a region and print it to the echo area (if one line long), otherwise
|
"Evaluate a region and print it to the echo area (if one line long), otherwise
|
||||||
to a pop up buffer."
|
to a pop up buffer.
|
||||||
|
|
||||||
|
Meant as an eval handler for Doom's :tools eval module."
|
||||||
(+eval-display-results
|
(+eval-display-results
|
||||||
(string-trim-right
|
(string-trim-right
|
||||||
(let ((buffer (generate-new-buffer " *+eval-output*"))
|
(let ((buffer (generate-new-buffer " *+eval-output*"))
|
||||||
|
(working-buffer (or +emacs-lisp-eval-working-buffer (current-buffer)))
|
||||||
(debug-on-error t))
|
(debug-on-error t))
|
||||||
(unwind-protect
|
(unless (buffer-live-p working-buffer)
|
||||||
(condition-case-unless-debug e
|
(setq +emacs-lisp-eval-working-buffer nil
|
||||||
(with-doom-module
|
working-buffer (current-buffer)))
|
||||||
(doom-module-from-path
|
(with-current-buffer working-buffer
|
||||||
(or (buffer-file-name (buffer-base-buffer))
|
(unwind-protect
|
||||||
default-directory))
|
(condition-case-unless-debug e
|
||||||
(with-doom-context 'eval
|
(with-doom-module
|
||||||
(eval-region beg end buffer load-read-function))
|
(doom-module-from-path
|
||||||
(with-current-buffer buffer
|
(or (buffer-file-name (buffer-base-buffer))
|
||||||
(let ((pp-max-width nil))
|
default-directory))
|
||||||
(require 'pp)
|
(with-doom-context 'eval
|
||||||
(pp-buffer)
|
(eval-region beg end buffer load-read-function))
|
||||||
(replace-regexp-in-string "\\\\n" "\n" (string-trim-left (buffer-string))))))
|
(with-current-buffer buffer
|
||||||
(error (format "ERROR: %s" e)))
|
(let ((pp-max-width nil))
|
||||||
(kill-buffer buffer))))
|
(require 'pp)
|
||||||
|
(pp-buffer)
|
||||||
|
(replace-regexp-in-string "\\\\n" "\n" (string-trim-left (buffer-string))))))
|
||||||
|
(error (format "ERROR: %s" e)))
|
||||||
|
(kill-buffer buffer)))))
|
||||||
(current-buffer)))
|
(current-buffer)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
@ -147,6 +156,19 @@ if it's callable, `apropos' otherwise."
|
|||||||
;;
|
;;
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +emacs-lisp/change-working-buffer (buffer &optional clear?)
|
||||||
|
"Change what buffer to run `+emacs-lisp-eval' in.
|
||||||
|
|
||||||
|
If given the prefix arg (CLEAR?), clears the current working buffer."
|
||||||
|
(interactive
|
||||||
|
(list (read-buffer "Set working buffer to: ")
|
||||||
|
current-prefix-arg))
|
||||||
|
(let ((buffer (get-buffer buffer)))
|
||||||
|
(if (and buffer (buffer-live-p buffer))
|
||||||
|
(setq +emacs-lisp-eval-working-buffer buffer)
|
||||||
|
(user-error "No such buffer: %S" buf))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +emacs-lisp/open-repl ()
|
(defun +emacs-lisp/open-repl ()
|
||||||
"Open the Emacs Lisp REPL (`ielm').
|
"Open the Emacs Lisp REPL (`ielm').
|
||||||
|
@ -137,6 +137,7 @@ See `+emacs-lisp-non-package-mode' for details.")
|
|||||||
|
|
||||||
(map! :localleader
|
(map! :localleader
|
||||||
:map (emacs-lisp-mode-map lisp-interaction-mode-map)
|
:map (emacs-lisp-mode-map lisp-interaction-mode-map)
|
||||||
|
:desc "Set working buffer" "b" #'+emacs-lisp/change-working-buffer
|
||||||
:desc "Expand macro" "m" #'macrostep-expand
|
:desc "Expand macro" "m" #'macrostep-expand
|
||||||
(:prefix ("d" . "debug")
|
(:prefix ("d" . "debug")
|
||||||
"f" #'+emacs-lisp/edebug-instrument-defun-on
|
"f" #'+emacs-lisp/edebug-instrument-defun-on
|
||||||
|
Reference in New Issue
Block a user