This commit is contained in:
ry
2022-01-11 18:05:13 -08:00
parent 2046befee2
commit 8e7b654716
846 changed files with 71287 additions and 4 deletions

View File

@@ -0,0 +1,71 @@
#+TITLE: lang/common-lisp
#+DATE: June 13, 2018
#+SINCE: v2.0
#+STARTUP: inlineimages nofold
* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#maintainers][Maintainers]]
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#features][Features]]
- [[#sly][Sly]]
- [[#org-mode][org-mode]]
- [[#configuration][Configuration]]
* Description
This module provides support for [[https://lisp-lang.org/][Common Lisp]] and the [[https://github.com/joaotavora/sly][Sly]] development
environment. Common Lisp is not a single language but a specification, with many
competing compiler implementations. By default, [[http://www.sbcl.org/][Steel Bank Common Lisp]] (SBCL) is
assumed to be installed, but this can be configured.
Common Lisp benefits from a mature specification and rich standard library.
Thanks to its powerful REPL and debugger, it boasts an "interactive programming"
style often unseen in other languages. Compiled Common Lisp programs are trusted
to run unmodified for a long time.
** Maintainers
This module has no dedicated maintainers.
** Module Flags
This module provides no flags.
** Plugins
+ [[https://github.com/joaotavora/sly][sly]]
+ [[https://github.com/joaotavora/sly-macrostep][sly-macrostep]]
+ [[https://github.com/PuercoPop/sly-repl-ansi-color][sly-repl-ansi-color]]
* Prerequisites
This module requires the [[http://www.sbcl.org/][SBCL]] compiler to be installed.
* Features
This module does not integrate with the =lsp= module. Sly (and SLIME before it) is
considered the defacto development environment for Common Lisp and provides much
of what is normally expected of an LSP, plus tight integration with the REPL and
Emacs.
** Sly
Using this module is mostly a matter of using Sly. Please consider reading
through [[http://joaotavora.github.io/sly/#A-SLY-tour-for-SLIME-users][the Sly Tour]].
A Sly session will be started when you open a =.lisp= file. Use =SPC m '= to switch
to the REPL minibuffer.
** org-mode
This module also enables the evaluation of =lisp= source blocks in Org Mode.
However, you will need a running Sly session for this to work. =M-x sly= starts
such a session if you didn't have one open already.
* Configuration
If you don't want Sly to use SBCL, you can configure the variable
~inferior-lisp-program~ to some other binary on your PATH.

View File

@@ -0,0 +1,5 @@
;;; lang/common-lisp/autoload/common-lisp.el -*- lexical-binding: t; -*-
;; HACK Fix #1772: void-variable sly-contribs errors due to sly packages (like
;; `sly-macrostep') trying to add to `sly-contribs' before it is defined.
;;;###autoload (defvar sly-contribs '(sly-fancy))

View File

@@ -0,0 +1,162 @@
;;; lang/common-lisp/config.el -*- lexical-binding: t; -*-
;; `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
;;;###package lisp-mode
(defvar inferior-lisp-program "sbcl")
(add-hook 'lisp-mode-hook #'rainbow-delimiters-mode)
(use-package! sly
:hook (lisp-mode-local-vars . sly-editing-mode)
:init
;; 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))
(after! lisp-mode
(set-repl-handler! 'lisp-mode #'sly-mrepl)
(set-eval-handler! 'lisp-mode #'sly-eval-region)
(set-lookup-handlers! 'lisp-mode
:definition #'sly-edit-definition
:documentation #'sly-describe-symbol))
;; 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.
(add-hook! 'doom-after-init-modules-hook
(after! sly (sly-setup)))
:config
(setq sly-mrepl-history-file-name (concat doom-cache-dir "sly-mrepl-history")
sly-kill-without-query-p t
sly-net-coding-system 'utf-8-unix
;; 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
sly-complete-symbol-function 'sly-simple-completions)
(set-popup-rules!
'(("^\\*sly-mrepl" :vslot 2 :size 0.3 :quit nil :ttl nil)
("^\\*sly-compilation" :vslot 3 :ttl nil)
("^\\*sly-traces" :vslot 4 :ttl nil)
("^\\*sly-description" :vslot 5 :size 0.3 :ttl 0)
;; 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)))
(defun +common-lisp--cleanup-sly-maybe-h ()
"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)))))
(add-hook! 'sly-mode-hook
(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)))
((executable-find (car (split-string inferior-lisp-program)))
(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)))))
(map! (:map sly-db-mode-map
:n "gr" #'sly-db-restart-frame)
(:map sly-inspector-mode-map
:n "gb" #'sly-inspector-pop
: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)
(:map lisp-mode-map
:n "gb" #'sly-pop-find-definition-stack)
(:localleader
:map lisp-mode-map
:desc "Sly" "'" #'sly
:desc "Sly (ask)" ";" (cmd!! #'sly '-)
:desc "Expand macro" "m" #'macrostep-expand
(:prefix ("c" . "compile")
:desc "Compile file" "c" #'sly-compile-file
:desc "Compile/load file" "C" #'sly-compile-and-load-file
:desc "Compile toplevel form" "f" #'sly-compile-defun
:desc "Load file" "l" #'sly-load-file
:desc "Remove notes" "n" #'sly-remove-notes
:desc "Compile region" "r" #'sly-compile-region)
(:prefix ("e" . "evaluate")
:desc "Evaluate buffer" "b" #'sly-eval-buffer
:desc "Evaluate last" "e" #'sly-eval-last-expression
:desc "Evaluate/print last" "E" #'sly-eval-print-last-expression
:desc "Evaluate defun" "f" #'sly-eval-defun
:desc "Undefine function" "F" #'sly-undefine-function
:desc "Evaluate region" "r" #'sly-eval-region)
(:prefix ("g" . "goto")
: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)
(:prefix ("h" . "help")
: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)
(:prefix ("r" . "repl")
:desc "Clear REPL" "c" #'sly-mrepl-clear-repl
:desc "Quit connection" "q" #'sly-quit-lisp
:desc "Restart connection" "r" #'sly-restart-inferior-lisp
:desc "Sync REPL" "s" #'sly-mrepl-sync)
(:prefix ("s" . "stickers")
:desc "Toggle breaking stickers" "b" #'sly-stickers-toggle-break-on-stickers
: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)
(:prefix ("t" . "trace")
:desc "Toggle" "t" #'sly-toggle-trace-fdefinition
:desc "Toggle (fancy)" "T" #'sly-toggle-fancy-trace
:desc "Untrace all" "u" #'sly-untrace-all)))
(when (featurep! :editor evil +everywhere)
(add-hook 'sly-mode-hook #'evil-normalize-keymaps)))
(use-package! sly-repl-ansi-color
:defer t
:init
(add-to-list 'sly-contribs 'sly-repl-ansi-color))

View File

@@ -0,0 +1,7 @@
;;; lang/common-lisp/doctor.el -*- lexical-binding: t; -*-
(when (require 'sly nil t)
(let ((prog-name (car (split-string inferior-lisp-program))))
(unless (executable-find prog-name)
(warn! "Couldn't find your `inferior-lisp-program' (%s). Is it installed?"
inferior-lisp-program))))

View File

@@ -0,0 +1,6 @@
;; -*- no-byte-compile: t; -*-
;;; lang/common-lisp/packages.el
(when (package! sly :pin "540a8c5b9a04af0a6907e07cb070f1fed8a76f48")
(package! sly-macrostep :pin "5113e4e926cd752b1d0bcc1508b3ebad5def5fad")
(package! sly-repl-ansi-color :pin "b9cd52d1cf927bf7e08582d46ab0bcf1d4fb5048"))