Skip to content

Instantly share code, notes, and snippets.

@chebert
Created February 23, 2021 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chebert/b31d52cc041cf8b93af71ffcda3d47f1 to your computer and use it in GitHub Desktop.
Save chebert/b31d52cc041cf8b93af71ffcda3d47f1 to your computer and use it in GitHub Desktop.
my-slime.el
;;; Slime/Swank Setup
(defun multiline? (string)
"True if the string has multiple lines."
(position ?\n string))
(defun multiline-comment (string)
"Return string formatted as a multi-line Lisp comment"
(concat "#||\n" string "\n||#\n"))
;; Note: Redefining to send the error message too.
(defun chebert-eval-async (sexp &optional cont package)
"Evaluate EXPR on the superior Lisp and call CONT with the result."
(declare (indent 1))
(slime-rex (cont (buffer (current-buffer)))
(sexp (or package (slime-current-package)))
((:ok result)
(when cont
(set-buffer buffer)
(funcall cont (cons :ok result))))
((:abort condition)
(message "Evaluation aborted on %s." condition)
(when cont
(set-buffer buffer)
(funcall cont (cons :abort condition)))))
;; Guard against arbitrary return values which once upon a time
;; showed up in the minibuffer spuriously (due to a bug in
;; slime-autodoc.) If this ever happens again, returning the
;; following will make debugging much easier:
:slime-eval-async)
;; Note: Redefining to markup output and value.
(defun chebert-eval-print-last-sexp (string)
"Evaluates the expression before the point in the SLIME Lisp REPL, and prints the value as a comment."
(interactive (list (slime-last-expression)))
(chebert-eval-async
`(swank:eval-and-grab-output ,string)
(lambda (status-and-result)
(let ((status (car status-and-result))
(result (cdr status-and-result)))
(case status
(:ok (cl-destructuring-bind (output value) result
(push-mark)
(let ((valstr (if (multiline? value)
(multiline-comment (concat " =>\n" value "\n"))
(if (zerop (length value))
""
(concat ";; => " value "\n")))))
(insert ?\n)
(if (zerop (length output))
(insert valstr)
(if (multiline? value)
(insert (multiline-comment (concat "Output:\n" output valstr)))
(insert (concat (multiline-comment (concat "Output:\n" output)) valstr)))))))
(:abort
(push-mark)
(insert "\n;; >> Evaluation aborted on " condition "\n")))))))
;; TODO: Make block-comments
;; (ql:quickload :quicklisp-slime-helper)
(load (expand-file-name "~/quicklisp/slime-helper.el"))
;; Replace "sbcl" with the path to your implementation
(setq inferior-lisp-program "sbcl")
;; (ql:quickload :log4slime)
;; (load "~/quicklisp/log4slime-setup.el")
;; (global-log4slime-mode 1)
(add-hook 'slime-mode-hook
(lambda ()
(define-key slime-mode-map (kbd "C-c k") 'slime-eval-buffer)
(define-key slime-mode-map (kbd "C-c j") 'chebert-eval-print-last-sexp)
(define-key slime-mode-map (kbd "C-c J") 'slime-eval-print-last-expression)
(define-key slime-mode-map (kbd "C-c C-f") 'slime-call-defun)
(define-key slime-mode-map (kbd "C-c s") 'slime-selector)))
;; NOTE: Typeout frame.
;; TODO: read-only, disable mini-buffer, pop-up if not existent.
;; TODO: jump to end.
;; Start slime when editing lisp.
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
(defun populate-slime-compiler-notes (notes)
"Populate the current buffer with the slime compiler notes tree."
(erase-buffer)
(when (null notes)
(insert "[no notes]"))
(let ((collapsed-p))
(dolist (tree (slime-compiler-notes-to-tree notes))
(when (slime-tree.collapsed-p tree) (setf collapsed-p t))
(slime-tree-insert tree "")
(insert "\n"))
(goto-char (point-min))))
(defun slime-list-compiler-notes-if-not-null (notes)
"Show the compiler notes NOTES in tree view, if there are
notes to show. Otherwise just update the notes buffer."
(interactive (list (slime-compiler-notes)))
(with-temp-message "Preparing compiler note tree..."
(if (not (null notes))
(slime-with-popup-buffer ((slime-buffer-name :notes)
:mode 'slime-compiler-notes-mode)
(populate-slime-compiler-notes notes))
(with-current-buffer (get-buffer-create (slime-buffer-name :notes))
(let ((inhibit-read-only t))
(populate-slime-compiler-notes notes))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment