Apropos the bug report here: https://bugs.launchpad.net/slime/+bug/777405
I'd like to propose the following changes to slime.el's macroexpansion functions: `slime-macroexpand-again' `slime-initialize-macroexpansion-buffer' `slime-create-macroexpansion-buffer'
These changes make explicit which buffer should be current during calls to `slime-macroexpand-again' and are IMO in keeping with the intent of the command.
The changes to `slime-initialize-macroexpansion-buffer' are w/r/t its optional arg BUFFER and provide additional checks to prevent `erase-buffer' and setting `buffer-undo-list' to nil when current-buffer is not "*slime-macroexpansion*".
I've included the proposed changes in full below as well as a diff of slime.el from quicklisp 20110320 with slime.el from CVS 1.1364
;;; ==============================
(defun slime-macroexpand-again () "Reperform the last macroexpansion." (interactive) (slime-eval-async slime-eval-macroexpand-expression (slime-rcurry #'slime-initialize-macroexpansion-buffer (slime-buffer-name :macroexpansion))))
(defun slime-initialize-macroexpansion-buffer (expansion &optional buffer) (let ((expansion-buffer (or (and buffer (get-buffer-create buffer)) (slime-create-macroexpansion-buffer)))) (with-current-buffer expansion-buffer (pop-to-buffer (current-buffer)) (let ((inhibit-read-only t)) (if (eq (current-buffer) (get-buffer (slime-buffer-name :macroexpansion))) (progn ;; Get rid of undo information from previous expansions. (setq buffer-undo-list nil) (erase-buffer) (let ((buffer-undo-list t)) ; Make the initial insertion not be undoable. (insert expansion) (font-lock-fontify-buffer))) (let ((point-now (point))) (save-excursion (insert expansion) (font-lock-fontify-region (point-now) (point)))))))))
(defun slime-create-macroexpansion-buffer () (let ((name (slime-buffer-name :macroexpansion))) (slime-with-popup-buffer (name :package t :connection t :mode 'lisp-mode) (slime-mode 1) (slime-macroexpansion-minor-mode 1) (setq font-lock-keywords-case-fold-search t) (get-buffer name))))
;;; ============================== --- slime-cvs-1.1364.el 2011-05-09 14:46:38.000000000 -0400 +++ slime-20110320-cvs.el 2011-05-09 15:28:43.000000000 -0400 @@ -4988,22 +4973,30 @@ #'slime-initialize-macroexpansion-buffer)))
(defun slime-macroexpand-again () - "Reperform the last macroexpansion." - (interactive) - (slime-eval-async slime-eval-macroexpand-expression - (slime-rcurry #'slime-initialize-macroexpansion-buffer - (current-buffer)))) + "Reperform the last macroexpansion." + (interactive) + (slime-eval-async slime-eval-macroexpand-expression + (slime-rcurry #'slime-initialize-macroexpansion-buffer + (slime-buffer-name :macroexpansion))))
(defun slime-initialize-macroexpansion-buffer (expansion &optional buffer) - (pop-to-buffer (or buffer (slime-create-macroexpansion-buffer))) - (setq buffer-undo-list nil) ; Get rid of undo information from - ; previous expansions. - (let ((inhibit-read-only t) - (buffer-undo-list t)) ; Make the initial insertion not be undoable. - (erase-buffer) - (insert expansion) - (goto-char (point-min)) - (font-lock-fontify-buffer))) + (let ((expansion-buffer + (or (and buffer (get-buffer-create buffer)) + (slime-create-macroexpansion-buffer)))) + (with-current-buffer expansion-buffer + (pop-to-buffer (current-buffer)) + (let ((inhibit-read-only t)) + (if (eq (current-buffer) (get-buffer (slime-buffer-name :macroexpansion))) + (progn + ;; Get rid of undo information from previous expansions. + (setq buffer-undo-list nil) + (erase-buffer) + (let ((buffer-undo-list t)) ; Make the initial insertion not be undoable. + (insert expansion) + (font-lock-fontify-buffer))) + (let ((point-now (point))) + (save-excursion (insert expansion) + (font-lock-fontify-region (point-now) (point)))))))))
(defun slime-create-macroexpansion-buffer () (let ((name (slime-buffer-name :macroexpansion))) @@ -5012,7 +5005,7 @@ (slime-mode 1) (slime-macroexpansion-minor-mode 1) (setq font-lock-keywords-case-fold-search t) - (current-buffer)))) + (get-buffer name))))
(defun slime-eval-macroexpand-inplace (expander) "Substitute the sexp at point with its macroexpansion.