Skip to content

Commit 20df0e0

Browse files
committed
Smarter CL package search
We now search backwards for the first in-package or defpackage (although maybe it should just be in-package?) above the cursor. So you can have many in-pckages in a file and they should all work contextually. We also reuse *package* if we can't find one. I was hoping that would mean it'd be stateful but it looks like it always reverts to the outer user package.
1 parent 0d8ab89 commit 20df0e0

File tree

4 files changed

+115
-43
lines changed

4 files changed

+115
-43
lines changed

dev/common-lisp/collider.lisp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(ql:quickload :cl-collider)
2+
3+
(in-package :sc-user)
4+
(named-readtables:in-readtable :sc)
5+
6+
;; please check *sc-synth-program*, *sc-plugin-paths*, *sc-synthdefs-path*
7+
;; if you have different path then set to
8+
;;
9+
;; (setf *sc-synth-program* "/path/to/scsynth")
10+
;; (setf *sc-plugin-paths* (list "/path/to/plugin_path" "/path/to/extension_plugin_path"))
11+
;; (setf *sc-synthdefs-path* "/path/to/synthdefs_path")
12+
13+
;; `*s*` defines the server for the entire session
14+
;; functions may use it internally.
15+
16+
(setf *s* (make-external-server "localhost" :port 48800))
17+
(server-boot *s*)
18+
19+
;; in Linux, maybe you need to call this function
20+
#+linux
21+
(jack-connect)
22+
23+
;; Hack music
24+
(defvar *synth*)
25+
(setf *synth* (play (sin-osc.ar [320 321] 0 .2)))
26+
27+
;; Stop music
28+
(free *synth*)
29+
30+
;; Quit SuperCollider server
31+
(server-quit *s*)

dev/common-lisp/ros-swank-server.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
ros run --eval '(ql:quickload :swank)' --eval '(swank:create-server :dont-close t)'

fnl/conjure/client/common-lisp/swank.fnl

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99
config conjure.config
1010
client conjure.client
1111
remote conjure.remote.swank
12+
util conjure.util
1213
ts conjure.tree-sitter}})
1314

1415
(def buf-suffix ".lisp")
15-
(def context-pattern "%(%s*defpackage%s+(.-)[%s){]")
1616
(def comment-prefix "; ")
1717
(def form-node? ts.node-surrounded-by-form-pair-chars?)
1818

19+
(defn- iterate-backwards [f lines]
20+
(for [i (length lines) 1 (- 1)] (local line (. lines i))
21+
(let [res (f line)]
22+
(when res
23+
(lua "return res"))))
24+
nil)
25+
26+
(defn context [_code]
27+
(let [[line _col] (vim.api.nvim_win_get_cursor 0)
28+
lines (vim.api.nvim_buf_get_lines 0 0 line false)]
29+
(iterate-backwards
30+
(fn [line]
31+
(or (string.match line "%(%s*defpackage%s+(.-)[%s){]")
32+
(string.match line "%(%s*in%-package%s+(.-)[%s){]")))
33+
lines)))
34+
1935
;; ------------ common lisp client
2036
;; Can parse simple forms
2137
;; and return the result.
@@ -89,7 +105,7 @@
89105
(str.join
90106
["(:emacs-rex (swank:eval-and-grab-output \""
91107
(escape-string msg)
92-
"\") \"" (or context ":common-lisp-user") "\" t " eval-id ")"])
108+
"\") \"" (or context "*package*") "\" t " eval-id ")"])
93109
cb)))))
94110

95111
(defn connect [opts]

lua/conjure/client/common-lisp/swank.lua

+63-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)