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