fix(emacs-lisp): eval forms from within the current buffer

This fix ensures that functions/macros that are evaluated with +eval/*
et co will remember where they were defined (if possible), so you don't
have to see this in their documentation again:

  FUNCTION is a function without a source file.

Ref: https://github.com/doomemacs/doomemacs/pull/6444#issuecomment-1159457888
This commit is contained in:
Henrik Lissner 2022-06-18 18:10:51 +02:00
parent ff7ae66372
commit 6c5537b487
No known key found for this signature in database
GPG Key ID: B60957CA074D39A3

View File

@ -9,20 +9,19 @@
to a pop up buffer."
(+eval-display-results
(string-trim-right
(condition-case-unless-debug e
(let ((result
(let* ((buffer-file-name (buffer-file-name (buffer-base-buffer)))
(buffer-file-truename
(and buffer-file-name (file-truename buffer-file-name)))
(doom--current-module
(ignore-errors (doom-module-from-path buffer-file-name)))
(debug-on-error t))
(eval (read (format "(progn %s)"
(buffer-substring-no-properties beg end)))
lexical-binding))))
(require 'pp)
(replace-regexp-in-string "\\\\n" "\n" (pp-to-string result)))
(error (error-message-string e))))
(let ((buffer (generate-new-buffer " *+eval-output*"))
(debug-on-error t))
(unwind-protect
(condition-case-unless-debug e
(let ((doom--current-module (ignore-errors (doom-module-from-path buffer-file-name))))
(eval-region beg end buffer load-read-function)
(with-current-buffer buffer
(let ((pp-max-width nil))
(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)))