2018-06-13 20:10:20 +02:00
|
|
|
;;; lang/common-lisp/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2018-12-05 19:01:17 -05:00
|
|
|
;; `lisp-mode' is loaded at startup. In order to lazy load its config we need to
|
|
|
|
;; pretend it isn't loaded
|
|
|
|
(defer-feature! lisp-mode)
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; packages
|
|
|
|
|
2020-02-23 15:41:49 -05:00
|
|
|
;;;###package lisp-mode
|
2018-10-16 02:15:25 -04:00
|
|
|
(defvar inferior-lisp-program "sbcl")
|
2020-02-23 15:41:49 -05:00
|
|
|
(add-hook 'lisp-mode-hook #'rainbow-delimiters-mode)
|
2018-12-05 19:01:17 -05:00
|
|
|
|
|
|
|
|
2020-02-23 15:41:49 -05:00
|
|
|
(use-package! sly
|
2020-07-22 18:49:05 -04:00
|
|
|
:hook (lisp-mode-local-vars . sly-editing-mode)
|
2020-02-23 15:41:49 -05:00
|
|
|
:init
|
2021-07-05 13:03:03 -04:00
|
|
|
;; I moved this hook to `lisp-mode-local-vars', so it only affects
|
|
|
|
;; `lisp-mode', and not every other derived lisp mode (like `fennel-mode').
|
|
|
|
;; We run it twice because the hook is both autoloaded and evaluated at
|
|
|
|
;; load-time, so it must be removed twice.
|
|
|
|
(after! (:or emacs sly)
|
|
|
|
(remove-hook 'lisp-mode-hook #'sly-editing-mode))
|
|
|
|
|
2020-02-23 15:41:49 -05:00
|
|
|
(after! lisp-mode
|
2023-02-26 15:57:35 +09:00
|
|
|
(set-repl-handler! 'lisp-mode #'+lisp/open-repl)
|
2020-02-23 15:41:49 -05:00
|
|
|
(set-eval-handler! 'lisp-mode #'sly-eval-region)
|
2022-08-15 06:34:12 +01:00
|
|
|
(set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(lisp-mode))
|
2020-02-23 15:41:49 -05:00
|
|
|
(set-lookup-handlers! 'lisp-mode
|
|
|
|
:definition #'sly-edit-definition
|
|
|
|
:documentation #'sly-describe-symbol))
|
|
|
|
|
2022-08-15 06:34:12 +01:00
|
|
|
(add-hook! 'lisp-mode
|
|
|
|
(after! sly (sly-lisp-indent-compatibility-mode)))
|
|
|
|
|
2020-02-24 20:37:46 -05:00
|
|
|
;; HACK Ensures that sly's contrib modules are loaded as soon as possible, but
|
|
|
|
;; also as late as possible, so users have an opportunity to override
|
|
|
|
;; `sly-contrib' in an `after!' block.
|
2022-09-14 14:48:21 +02:00
|
|
|
(add-hook! 'after-init-hook (after! sly (sly-setup)))
|
2020-02-24 20:37:46 -05:00
|
|
|
|
2020-02-23 15:41:49 -05:00
|
|
|
:config
|
2018-10-16 02:15:25 -04:00
|
|
|
(setq sly-mrepl-history-file-name (concat doom-cache-dir "sly-mrepl-history")
|
|
|
|
sly-kill-without-query-p t
|
2018-10-17 15:01:03 -04:00
|
|
|
sly-net-coding-system 'utf-8-unix
|
2020-02-28 16:29:49 -05:00
|
|
|
;; Doom defaults to non-fuzzy search, because it is faster and more
|
|
|
|
;; precise (but requires more keystrokes). Change this to
|
|
|
|
;; `sly-flex-completions' for fuzzy completion
|
2018-10-17 15:01:03 -04:00
|
|
|
sly-complete-symbol-function 'sly-simple-completions)
|
2018-06-13 20:10:20 +02:00
|
|
|
|
2018-09-10 12:50:45 -04:00
|
|
|
(set-popup-rules!
|
2019-10-03 20:41:47 -04:00
|
|
|
'(("^\\*sly-mrepl" :vslot 2 :size 0.3 :quit nil :ttl nil)
|
2018-10-07 21:50:46 -04:00
|
|
|
("^\\*sly-compilation" :vslot 3 :ttl nil)
|
2019-04-14 13:39:57 -04:00
|
|
|
("^\\*sly-traces" :vslot 4 :ttl nil)
|
2020-02-02 02:02:41 -05:00
|
|
|
("^\\*sly-description" :vslot 5 :size 0.3 :ttl 0)
|
2019-04-14 13:39:57 -04:00
|
|
|
;; Do not display debugger or inspector buffers in a popup window. These
|
|
|
|
;; buffers are meant to be displayed with sufficient vertical space.
|
|
|
|
("^\\*sly-\\(?:db\\|inspector\\)" :ignore t)))
|
2018-09-10 12:50:45 -04:00
|
|
|
|
2019-07-25 19:56:20 +02:00
|
|
|
(defun +common-lisp--cleanup-sly-maybe-h ()
|
2018-06-13 22:14:22 +02:00
|
|
|
"Kill processes and leftover buffers when killing the last sly buffer."
|
|
|
|
(unless (cl-loop for buf in (delq (current-buffer) (buffer-list))
|
|
|
|
if (and (buffer-local-value 'sly-mode buf)
|
|
|
|
(get-buffer-window buf))
|
|
|
|
return t)
|
|
|
|
(dolist (conn (sly--purge-connections))
|
|
|
|
(sly-quit-lisp-internal conn 'sly-quit-sentinel t))
|
|
|
|
(let (kill-buffer-hook kill-buffer-query-functions)
|
|
|
|
(mapc #'kill-buffer
|
|
|
|
(cl-loop for buf in (delq (current-buffer) (buffer-list))
|
|
|
|
if (buffer-local-value 'sly-mode buf)
|
|
|
|
collect buf)))))
|
2018-06-13 20:10:20 +02:00
|
|
|
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'sly-mode-hook
|
2019-07-25 19:56:20 +02:00
|
|
|
(defun +common-lisp-init-sly-h ()
|
|
|
|
"Attempt to auto-start sly when opening a lisp buffer."
|
|
|
|
(cond ((or (doom-temp-buffer-p (current-buffer))
|
|
|
|
(sly-connected-p)))
|
2021-09-24 18:42:45 +08:00
|
|
|
((executable-find (car (split-string inferior-lisp-program)))
|
2019-07-25 19:56:20 +02:00
|
|
|
(let ((sly-auto-start 'always))
|
|
|
|
(sly-auto-start)
|
|
|
|
(add-hook 'kill-buffer-hook #'+common-lisp--cleanup-sly-maybe-h nil t)))
|
|
|
|
((message "WARNING: Couldn't find `inferior-lisp-program' (%s)"
|
|
|
|
inferior-lisp-program)))))
|
|
|
|
|
2020-04-30 20:37:19 -04:00
|
|
|
(map! (:map sly-db-mode-map
|
|
|
|
:n "gr" #'sly-db-restart-frame)
|
|
|
|
(:map sly-inspector-mode-map
|
2020-05-08 06:22:21 -04:00
|
|
|
:n "gb" #'sly-inspector-pop
|
2020-04-30 20:37:19 -04:00
|
|
|
:n "gr" #'sly-inspector-reinspect
|
|
|
|
:n "gR" #'sly-inspector-fetch-all
|
|
|
|
:n "K" #'sly-inspector-describe-inspectee)
|
|
|
|
(:map sly-xref-mode-map
|
|
|
|
:n "gr" #'sly-recompile-xref
|
|
|
|
:n "gR" #'sly-recompile-all-xrefs)
|
2020-05-08 06:22:21 -04:00
|
|
|
(:map lisp-mode-map
|
2020-05-09 00:30:21 -04:00
|
|
|
:n "gb" #'sly-pop-find-definition-stack)
|
2020-04-30 20:37:19 -04:00
|
|
|
|
|
|
|
(:localleader
|
|
|
|
:map lisp-mode-map
|
2023-03-17 13:30:04 +09:00
|
|
|
:desc "Sly" "'" #'sly
|
|
|
|
:desc "Sly (ask)" ";" (cmd!! #'sly '-)
|
|
|
|
:desc "Expand macro" "m" #'macrostep-expand
|
|
|
|
:desc "Find local Quicklisp file" "f" #'+lisp/find-file-in-quicklisp
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("c" . "compile")
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Compile file" "c" #'sly-compile-file
|
|
|
|
:desc "Compile/load file" "C" #'sly-compile-and-load-file
|
2019-03-28 19:56:00 -04:00
|
|
|
:desc "Compile toplevel form" "f" #'sly-compile-defun
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Load file" "l" #'sly-load-file
|
|
|
|
:desc "Remove notes" "n" #'sly-remove-notes
|
|
|
|
:desc "Compile region" "r" #'sly-compile-region)
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("e" . "evaluate")
|
2020-05-23 15:38:22 -04:00
|
|
|
:desc "Evaluate buffer" "b" #'sly-eval-buffer
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Evaluate last" "e" #'sly-eval-last-expression
|
2019-03-28 19:56:00 -04:00
|
|
|
:desc "Evaluate/print last" "E" #'sly-eval-print-last-expression
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Evaluate defun" "f" #'sly-eval-defun
|
|
|
|
:desc "Undefine function" "F" #'sly-undefine-function
|
|
|
|
:desc "Evaluate region" "r" #'sly-eval-region)
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("g" . "goto")
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Go back" "b" #'sly-pop-find-definition-stack
|
|
|
|
:desc "Go to" "d" #'sly-edit-definition
|
|
|
|
:desc "Go to (other window)" "D" #'sly-edit-definition-other-window
|
|
|
|
:desc "Next note" "n" #'sly-next-note
|
|
|
|
:desc "Previous note" "N" #'sly-previous-note
|
|
|
|
:desc "Next sticker" "s" #'sly-stickers-next-sticker
|
|
|
|
:desc "Previous sticker" "S" #'sly-stickers-prev-sticker)
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("h" . "help")
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Who calls" "<" #'sly-who-calls
|
|
|
|
:desc "Calls who" ">" #'sly-calls-who
|
|
|
|
:desc "Lookup format directive" "~" #'hyperspec-lookup-format
|
|
|
|
:desc "Lookup reader macro" "#" #'hyperspec-lookup-reader-macro
|
|
|
|
:desc "Apropos" "a" #'sly-apropos
|
|
|
|
:desc "Who binds" "b" #'sly-who-binds
|
|
|
|
:desc "Disassemble symbol" "d" #'sly-disassemble-symbol
|
|
|
|
:desc "Describe symbol" "h" #'sly-describe-symbol
|
|
|
|
:desc "HyperSpec lookup" "H" #'sly-hyperspec-lookup
|
|
|
|
:desc "Who macro-expands" "m" #'sly-who-macroexpands
|
|
|
|
:desc "Apropos package" "p" #'sly-apropos-package
|
|
|
|
:desc "Who references" "r" #'sly-who-references
|
|
|
|
:desc "Who specializes" "s" #'sly-who-specializes
|
|
|
|
:desc "Who sets" "S" #'sly-who-sets)
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("r" . "repl")
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Clear REPL" "c" #'sly-mrepl-clear-repl
|
2023-03-17 13:30:04 +09:00
|
|
|
:desc "Load Project" "l" #'+lisp/load-project-systems
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Quit connection" "q" #'sly-quit-lisp
|
2019-03-28 19:56:00 -04:00
|
|
|
:desc "Restart connection" "r" #'sly-restart-inferior-lisp
|
2023-03-17 13:30:04 +09:00
|
|
|
:desc "Reload Project" "R" #'+lisp/reload-project
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Sync REPL" "s" #'sly-mrepl-sync)
|
2020-04-30 20:37:19 -04:00
|
|
|
(:prefix ("s" . "stickers")
|
2019-03-28 19:56:00 -04:00
|
|
|
:desc "Toggle breaking stickers" "b" #'sly-stickers-toggle-break-on-stickers
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Clear defun stickers" "c" #'sly-stickers-clear-defun-stickers
|
|
|
|
:desc "Clear buffer stickers" "C" #'sly-stickers-clear-buffer-stickers
|
|
|
|
:desc "Fetch stickers" "f" #'sly-stickers-fetch
|
|
|
|
:desc "Replay stickers" "r" #'sly-stickers-replay
|
|
|
|
:desc "Add/remove sticker" "s" #'sly-stickers-dwim)
|
2023-03-17 13:30:04 +09:00
|
|
|
(:prefix ("t" . "test")
|
|
|
|
:desc "Test System" "s" #'+lisp/test-system)
|
|
|
|
(:prefix ("T" . "trace")
|
2019-10-04 17:49:28 -04:00
|
|
|
:desc "Toggle" "t" #'sly-toggle-trace-fdefinition
|
2019-03-28 19:56:00 -04:00
|
|
|
:desc "Toggle (fancy)" "T" #'sly-toggle-fancy-trace
|
2020-04-30 20:37:19 -04:00
|
|
|
:desc "Untrace all" "u" #'sly-untrace-all)))
|
2018-10-03 01:24:29 -04:00
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
(when (modulep! :editor evil +everywhere)
|
2019-10-12 00:41:46 -04:00
|
|
|
(add-hook 'sly-mode-hook #'evil-normalize-keymaps)))
|
2018-12-01 15:26:44 -05:00
|
|
|
|
2019-07-25 19:56:20 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! sly-repl-ansi-color
|
2018-12-05 21:45:22 -05:00
|
|
|
:defer t
|
|
|
|
:init
|
2020-02-23 15:41:49 -05:00
|
|
|
(add-to-list 'sly-contribs 'sly-repl-ansi-color))
|