forked from slime/slime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slime.el
7659 lines (6620 loc) · 285 KB
/
slime.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; slime.el --- Superior Lisp Interaction Mode for Emacs -*-lexical-binding:t-*-
;; URL: https://github.com/slime/slime
;; Package-Requires: ((cl-lib "0.5") (macrostep "0.9"))
;; Keywords: languages, lisp, slime
;; Version: 2.24
;;;; License and Commentary
;; Copyright (C) 2003 Eric Marsden, Luke Gorrie, Helmut Eller
;; Copyright (C) 2004,2005,2006 Luke Gorrie, Helmut Eller
;; Copyright (C) 2007,2008,2009 Helmut Eller, Tobias C. Rittweiler
;;
;; For a detailed list of contributors, see the manual.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;;; Commentary:
;; SLIME is the ``Superior Lisp Interaction Mode for Emacs.''
;;
;; SLIME extends Emacs with support for interactive programming in
;; Common Lisp. The features are centered around slime-mode, an Emacs
;; minor-mode that complements the standard lisp-mode. While lisp-mode
;; supports editing Lisp source files, slime-mode adds support for
;; interacting with a running Common Lisp process for compilation,
;; debugging, documentation lookup, and so on.
;;
;; The slime-mode programming environment follows the example of
;; Emacs's native Emacs Lisp environment. We have also included good
;; ideas from similar systems (such as ILISP) and some new ideas of
;; our own.
;;
;; SLIME is constructed from two parts: a user-interface written in
;; Emacs Lisp, and a supporting server program written in Common
;; Lisp. The two sides are connected together with a socket and
;; communicate using an RPC-like protocol.
;;
;; The Lisp server is primarily written in portable Common Lisp. The
;; required implementation-specific functionality is specified by a
;; well-defined interface and implemented separately for each Lisp
;; implementation. This makes SLIME readily portable.
;;; Code:
;;;; Dependencies and setup
(eval-and-compile
(require 'cl-lib nil t)
;; For emacs 23, look for bundled version
(require 'cl-lib "lib/cl-lib"))
(eval-when-compile (require 'cl)) ; defsetf, lexical-let
(eval-and-compile
(if (< emacs-major-version 23)
(error "Slime requires an Emacs version of 23, or above")))
(require 'hyperspec "lib/hyperspec")
(require 'thingatpt)
(require 'comint)
(require 'pp)
(require 'easymenu)
(require 'outline)
(require 'arc-mode)
(require 'etags)
(require 'compile)
(eval-when-compile
(require 'apropos)
(require 'gud)
(require 'lisp-mnt))
(declare-function lm-version "lisp-mnt")
(defvar slime-path nil
"Directory containing the Slime package.
This is used to load the supporting Common Lisp library, Swank.
The default value is automatically computed from the location of
the Emacs Lisp package.")
(setq slime-path (file-name-directory load-file-name))
(defvar slime-version nil
"The version of SLIME that you're using.")
(setq slime-version
(eval-when-compile
(lm-version
(cl-find "slime.el"
(remove nil
(list load-file-name
(when (boundp 'byte-compile-current-file)
byte-compile-current-file)))
:key #'file-name-nondirectory
:test #'string-equal))))
(defvar slime-lisp-modes '(lisp-mode))
(defvar slime-contribs nil
"A list of contrib packages to load with SLIME.")
(define-obsolete-variable-alias 'slime-setup-contribs
'slime-contribs "2.3.2")
(defun slime-setup (&optional contribs)
"Setup Emacs so that lisp-mode buffers always use SLIME.
CONTRIBS is a list of contrib packages to load. If `nil', use
`slime-contribs'. "
(interactive)
(when (member 'lisp-mode slime-lisp-modes)
(add-hook 'lisp-mode-hook 'slime-lisp-mode-hook))
(when contribs
(setq slime-contribs contribs))
(slime--setup-contribs))
(defvar slime-required-modules '())
(defun slime--setup-contribs ()
"Load and initialize contribs."
(dolist (c slime-contribs)
(unless (featurep c)
(require c)
(let ((init (intern (format "%s-init" c))))
(when (fboundp init)
(funcall init))))))
(defun slime-lisp-mode-hook ()
(slime-mode 1)
(set (make-local-variable 'lisp-indent-function)
'common-lisp-indent-function))
(defvar slime-protocol-version nil)
(setq slime-protocol-version slime-version)
;;;; Customize groups
;;
;;;;; slime
(defgroup slime nil
"Interaction with the Superior Lisp Environment."
:prefix "slime-"
:group 'applications)
;;;;; slime-ui
(defgroup slime-ui nil
"Interaction with the Superior Lisp Environment."
:prefix "slime-"
:group 'slime)
(defcustom slime-truncate-lines t
"Set `truncate-lines' in popup buffers.
This applies to buffers that present lines as rows of data, such as
debugger backtraces and apropos listings."
:type 'boolean
:group 'slime-ui)
(defcustom slime-kill-without-query-p nil
"If non-nil, kill SLIME processes without query when quitting Emacs.
This applies to the *inferior-lisp* buffer and the network connections."
:type 'boolean
:group 'slime-ui)
;;;;; slime-lisp
(defgroup slime-lisp nil
"Lisp server configuration."
:prefix "slime-"
:group 'slime)
(defcustom slime-backend "swank-loader.lisp"
"The name of the Lisp file that loads the Swank server.
This name is interpreted relative to the directory containing
slime.el, but could also be set to an absolute filename."
:type 'string
:group 'slime-lisp)
(defcustom slime-connected-hook nil
"List of functions to call when SLIME connects to Lisp."
:type 'hook
:group 'slime-lisp)
(defcustom slime-enable-evaluate-in-emacs nil
"*If non-nil, the inferior Lisp can evaluate arbitrary forms in Emacs.
The default is nil, as this feature can be a security risk."
:type '(boolean)
:group 'slime-lisp)
(defcustom slime-lisp-host "localhost"
"The default hostname (or IP address) to connect to."
:type 'string
:group 'slime-lisp)
(defcustom slime-port 4005
"Port to use as the default for `slime-connect'."
:type 'integer
:group 'slime-lisp)
(defvar slime-connect-host-history (list slime-lisp-host))
(defvar slime-connect-port-history (list (prin1-to-string slime-port)))
(defvar slime-net-valid-coding-systems
'((iso-latin-1-unix nil "iso-latin-1-unix")
(iso-8859-1-unix nil "iso-latin-1-unix")
(binary nil "iso-latin-1-unix")
(utf-8-unix t "utf-8-unix")
(emacs-mule-unix t "emacs-mule-unix")
(euc-jp-unix t "euc-jp-unix"))
"A list of valid coding systems.
Each element is of the form: (NAME MULTIBYTEP CL-NAME)")
(defun slime-find-coding-system (name)
"Return the coding system for the symbol NAME.
The result is either an element in `slime-net-valid-coding-systems'
of nil."
(let ((probe (assq name slime-net-valid-coding-systems)))
(when (and probe (if (fboundp 'check-coding-system)
(ignore-errors (check-coding-system (car probe)))
(eq (car probe) 'binary)))
probe)))
(defcustom slime-net-coding-system
(car (cl-find-if 'slime-find-coding-system
slime-net-valid-coding-systems :key 'car))
"Coding system used for network connections.
See also `slime-net-valid-coding-systems'."
:type (cons 'choice
(mapcar (lambda (x)
(list 'const (car x)))
slime-net-valid-coding-systems))
:group 'slime-lisp)
;;;;; slime-mode
(defgroup slime-mode nil
"Settings for slime-mode Lisp source buffers."
:prefix "slime-"
:group 'slime)
(defcustom slime-find-definitions-function 'slime-find-definitions-rpc
"Function to find definitions for a name.
The function is called with the definition name, a string, as its
argument."
:type 'function
:group 'slime-mode
:options '(slime-find-definitions-rpc
slime-etags-definitions
(lambda (name)
(append (slime-find-definitions-rpc name)
(slime-etags-definitions name)))
(lambda (name)
(or (slime-find-definitions-rpc name)
(and tags-table-list
(slime-etags-definitions name))))))
;; FIXME: remove one day
(defcustom slime-complete-symbol-function 'nil
"Obsolete. Use `slime-completion-at-point-functions' instead."
:group 'slime-mode
:type '(choice (const :tag "Compound" slime-complete-symbol*)
(const :tag "Fuzzy" slime-fuzzy-complete-symbol)))
(make-obsolete-variable 'slime-complete-symbol-function
'slime-completion-at-point-functions
"2015-10-18")
(defcustom slime-completion-at-point-functions
'(slime-filename-completion
slime-simple-completion-at-point)
"List of functions to perform completion.
Works like `completion-at-point-functions'.
`slime--completion-at-point' uses this variable."
:group 'slime-mode)
;;;;; slime-mode-faces
(defgroup slime-mode-faces nil
"Faces in slime-mode source code buffers."
:prefix "slime-"
:group 'slime-mode)
(defface slime-error-face
`((((class color) (background light))
(:underline "red"))
(((class color) (background dark))
(:underline "red"))
(t (:underline t)))
"Face for errors from the compiler."
:group 'slime-mode-faces)
(defface slime-warning-face
`((((class color) (background light))
(:underline "orange"))
(((class color) (background dark))
(:underline "coral"))
(t (:underline t)))
"Face for warnings from the compiler."
:group 'slime-mode-faces)
(defface slime-style-warning-face
`((((class color) (background light))
(:underline "brown"))
(((class color) (background dark))
(:underline "gold"))
(t (:underline t)))
"Face for style-warnings from the compiler."
:group 'slime-mode-faces)
(defface slime-note-face
`((((class color) (background light))
(:underline "brown4"))
(((class color) (background dark))
(:underline "light goldenrod"))
(t (:underline t)))
"Face for notes from the compiler."
:group 'slime-mode-faces)
(defface slime-early-deprecation-warning-face
`((((type graphic) (class color) (background light))
(:strike-through "brown"))
(((type graphic) (class color) (background dark))
(:strike-through "gold"))
(((type graphic))
(:strike-through t))
(((class color) (background light))
(:underline "brown"))
(((class color) (background dark))
(:underline "gold"))
(t
(:underline t)))
"Face for early deprecation warnings from the compiler."
:group 'slime-mode-faces)
(defface slime-late-deprecation-warning-face
`((((type graphic) (class color) (background light))
(:strike-through "orange"))
(((type graphic) (class color) (background dark))
(:strike-through "coral"))
(((type graphic))
(:strike-through t))
(((class color) (background light))
(:underline "orange"))
(((class color) (background dark))
(:underline "coral"))
(t
(:underline t)))
"Face for late deprecation warnings from the compiler."
:group 'slime-mode-faces)
(defface slime-final-deprecation-warning-face
`((((type graphic) (class color) (background light))
(:strike-through "red"))
(((type graphic) (class color) (background dark))
(:strike-through "red"))
(((type graphic))
(:strike-through t))
(((class color) (background light))
(:underline "red"))
(((class color) (background dark))
(:underline "red"))
(t
(:strike-through t)))
"Face for final deprecation warnings from the compiler."
:group 'slime-mode-faces)
(defface slime-highlight-face
'((t (:inherit highlight :underline nil)))
"Face for compiler notes while selected."
:group 'slime-mode-faces)
;;;;; sldb
(defgroup slime-debugger nil
"Backtrace options and fontification."
:prefix "sldb-"
:group 'slime)
(defmacro define-sldb-faces (&rest faces)
"Define the set of SLDB faces.
Each face specifiation is (NAME DESCRIPTION &optional PROPERTIES).
NAME is a symbol; the face will be called sldb-NAME-face.
DESCRIPTION is a one-liner for the customization buffer.
PROPERTIES specifies any default face properties."
`(progn ,@(cl-loop for face in faces
collect `(define-sldb-face ,@face))))
(defmacro define-sldb-face (name description &optional default)
(let ((facename (intern (format "sldb-%s-face" (symbol-name name)))))
`(defface ,facename
(list (list t ,default))
,(format "Face for %s." description)
:group 'slime-debugger)))
(define-sldb-faces
(topline "the top line describing the error")
(condition "the condition class"
'(:inherit font-lock-warning-face))
(section "the labels of major sections in the debugger buffer"
'(:inherit header-line))
(frame-label "backtrace frame numbers"
'(:inherit shadow))
(restart-type "restart names."
'(:inherit font-lock-keyword-face))
(restart "restart descriptions")
(restart-number "restart numbers (correspond to keystrokes to invoke)"
'(:bold t))
(frame-line "function names and arguments in the backtrace")
(restartable-frame-line
"frames which are surely restartable"
'(:foreground "lime green"))
(non-restartable-frame-line
"frames which are surely not restartable")
(detailed-frame-line
"function names and arguments in a detailed (expanded) frame")
(local-name "local variable names"
'(:inherit font-lock-variable-name-face))
(local-value "local variable values")
(catch-tag "catch tags"
'(:inherit highlight)))
;;;; Minor modes
;;;;; slime-mode
(defvar slime-mode-indirect-map (make-sparse-keymap)
"Empty keymap which has `slime-mode-map' as it's parent.
This is a hack so that we can reinitilize the real slime-mode-map
more easily. See `slime-init-keymaps'.")
(defvar slime-buffer-connection)
(defvar slime-dispatching-connection)
(defvar slime-current-thread)
(defun slime--on ()
(slime-setup-completion))
(defun slime--off ()
(remove-hook 'completion-at-point-functions #'slime--completion-at-point t))
(define-minor-mode slime-mode
"\\<slime-mode-map>\
SLIME: The Superior Lisp Interaction Mode for Emacs (minor-mode).
Commands to compile the current buffer's source file and visually
highlight any resulting compiler notes and warnings:
\\[slime-compile-and-load-file] - Compile and load the current buffer's file.
\\[slime-compile-file] - Compile (but not load) the current buffer's file.
\\[slime-compile-defun] - Compile the top-level form at point.
Commands for visiting compiler notes:
\\[slime-next-note] - Goto the next form with a compiler note.
\\[slime-previous-note] - Goto the previous form with a compiler note.
\\[slime-remove-notes] - Remove compiler-note annotations in buffer.
Finding definitions:
\\[slime-edit-definition]
- Edit the definition of the function called at point.
\\[slime-pop-find-definition-stack]
- Pop the definition stack to go back from a definition.
Documentation commands:
\\[slime-describe-symbol] - Describe symbol.
\\[slime-apropos] - Apropos search.
\\[slime-disassemble-symbol] - Disassemble a function.
Evaluation commands:
\\[slime-eval-defun] - Evaluate top-level from containing point.
\\[slime-eval-last-expression] - Evaluate sexp before point.
\\[slime-pprint-eval-last-expression] \
- Evaluate sexp before point, pretty-print result.
Full set of commands:
\\{slime-mode-map}"
:keymap slime-mode-indirect-map
:lighter (:eval (slime-modeline-string))
(cond (slime-mode (slime--on))
(t (slime--off))))
;;;;;; Modeline
(defun slime-modeline-string ()
"Return the string to display in the modeline.
\"Slime\" only appears if we aren't connected. If connected,
include package-name, connection-name, and possibly some state
information."
(let ((conn (slime-current-connection)))
;; Bail out early in case there's no connection, so we won't
;; implicitly invoke `slime-connection' which may query the user.
(if (not conn)
(and slime-mode " Slime")
(let ((local (eq conn slime-buffer-connection))
(pkg (slime-current-package)))
(concat " "
(if local "{" "[")
(if pkg (slime-pretty-package-name pkg) "?")
" "
;; ignore errors for closed connections
(ignore-errors (slime-connection-name conn))
(slime-modeline-state-string conn)
(if local "}" "]"))))))
(defun slime-pretty-package-name (name)
"Return a pretty version of a package name NAME."
(cond ((string-match "^#?:\\(.*\\)$" name)
(match-string 1 name))
((string-match "^\"\\(.*\\)\"$" name)
(match-string 1 name))
(t name)))
(defun slime-modeline-state-string (conn)
"Return a string possibly describing CONN's state."
(cond ((not (eq (process-status conn) 'open))
(format " %s" (process-status conn)))
((let ((pending (length (slime-rex-continuations conn)))
(sldbs (length (sldb-buffers conn))))
(cond ((and (zerop sldbs) (zerop pending)) nil)
((zerop sldbs) (format " %s" pending))
(t (format " %s/%s" pending sldbs)))))))
(defun slime--recompute-modelines ()
(force-mode-line-update t))
;;;;; Key bindings
(defvar slime-parent-map nil
"Parent keymap for shared between all Slime related modes.")
(defvar slime-parent-bindings
'(("\M-." slime-edit-definition)
("\M-," slime-pop-find-definition-stack)
("\M-_" slime-edit-uses) ; for German layout
("\M-?" slime-edit-uses) ; for USian layout
("\C-x4." slime-edit-definition-other-window)
("\C-x5." slime-edit-definition-other-frame)
("\C-x\C-e" slime-eval-last-expression)
("\C-\M-x" slime-eval-defun)
;; Include PREFIX keys...
("\C-c" slime-prefix-map)))
(defvar slime-prefix-map nil
"Keymap for commands prefixed with `slime-prefix-key'.")
(defvar slime-prefix-bindings
'(("\C-r" slime-eval-region)
(":" slime-interactive-eval)
("\C-e" slime-interactive-eval)
("E" slime-edit-value)
("\C-l" slime-load-file)
("\C-b" slime-interrupt)
("\M-d" slime-disassemble-symbol)
("\C-t" slime-toggle-trace-fdefinition)
("I" slime-inspect)
("\C-xt" slime-list-threads)
("\C-xn" slime-next-connection)
("\C-xp" slime-prev-connection)
("\C-xc" slime-list-connections)
("<" slime-list-callers)
(">" slime-list-callees)
;; Include DOC keys...
("\C-d" slime-doc-map)
;; Include XREF WHO-FOO keys...
("\C-w" slime-who-map)
))
(defvar slime-editing-map nil
"These keys are useful for buffers where the user can insert and
edit s-exprs, e.g. for source buffers and the REPL.")
(defvar slime-editing-keys
`(;; Arglist display & completion
(" " slime-space)
;; Evaluating
;;("\C-x\M-e" slime-eval-last-expression-display-output :inferior t)
("\C-c\C-p" slime-pprint-eval-last-expression)
;; Macroexpand
("\C-c\C-m" slime-expand-1)
("\C-c\M-m" slime-macroexpand-all)
;; Misc
("\C-c\C-u" slime-undefine-function)
(,(kbd "C-M-.") slime-next-location)
(,(kbd "C-M-,") slime-previous-location)
;; Obsolete, redundant bindings
("\C-c\C-i" completion-at-point)
;;("\M-*" pop-tag-mark) ; almost to clever
))
(defvar slime-mode-map nil
"Keymap for slime-mode.")
(defvar slime-keys
'( ;; Compiler notes
("\M-p" slime-previous-note)
("\M-n" slime-next-note)
("\C-c\M-c" slime-remove-notes)
("\C-c\C-k" slime-compile-and-load-file)
("\C-c\M-k" slime-compile-file)
("\C-c\C-c" slime-compile-defun)))
(defun slime-nop ()
"The null command. Used to shadow currently-unused keybindings."
(interactive)
(call-interactively 'undefined))
(defvar slime-doc-map nil
"Keymap for documentation commands. Bound to a prefix key.")
(defvar slime-doc-bindings
'((?a slime-apropos)
(?z slime-apropos-all)
(?p slime-apropos-package)
(?d slime-describe-symbol)
(?f slime-describe-function)
(?h slime-documentation-lookup)
(?~ common-lisp-hyperspec-format)
(?g common-lisp-hyperspec-glossary-term)
(?# common-lisp-hyperspec-lookup-reader-macro)))
(defvar slime-who-map nil
"Keymap for who-xref commands. Bound to a prefix key.")
(defvar slime-who-bindings
'((?c slime-who-calls)
(?w slime-calls-who)
(?r slime-who-references)
(?b slime-who-binds)
(?s slime-who-sets)
(?m slime-who-macroexpands)
(?a slime-who-specializes)))
(defun slime-init-keymaps ()
"(Re)initialize the keymaps for `slime-mode'."
(interactive)
(slime-init-keymap 'slime-doc-map t t slime-doc-bindings)
(slime-init-keymap 'slime-who-map t t slime-who-bindings)
(slime-init-keymap 'slime-prefix-map t nil slime-prefix-bindings)
(slime-init-keymap 'slime-parent-map nil nil slime-parent-bindings)
(slime-init-keymap 'slime-editing-map nil nil slime-editing-keys)
(set-keymap-parent slime-editing-map slime-parent-map)
(slime-init-keymap 'slime-mode-map nil nil slime-keys)
(set-keymap-parent slime-mode-map slime-editing-map)
(set-keymap-parent slime-mode-indirect-map slime-mode-map))
(defun slime-init-keymap (keymap-name prefixp bothp bindings)
(set keymap-name (make-sparse-keymap))
(when prefixp (define-prefix-command keymap-name))
(slime-bind-keys (eval keymap-name) bothp bindings))
(defun slime-bind-keys (keymap bothp bindings)
"Add BINDINGS to KEYMAP.
If BOTHP is true also add bindings with control modifier."
(cl-loop for (key command) in bindings do
(cond (bothp
(define-key keymap `[,key] command)
(unless (equal key ?h) ; But don't bind C-h
(define-key keymap `[(control ,key)] command)))
(t (define-key keymap key command)))))
(slime-init-keymaps)
(define-minor-mode slime-editing-mode
"Minor mode which makes slime-editing-map available.
\\{slime-editing-map}"
nil
nil
slime-editing-map)
;;;; Framework'ey bits
;;;
;;; This section contains some standard SLIME idioms: basic macros,
;;; ways of showing messages to the user, etc. All the code in this
;;; file should use these functions when applicable.
;;;
;;;;; Syntactic sugar
(defmacro slime-dcase (value &rest patterns)
(declare (indent 1))
"Dispatch VALUE to one of PATTERNS.
A cross between `case' and `destructuring-bind'.
The pattern syntax is:
((HEAD . ARGS) . BODY)
The list of patterns is searched for a HEAD `eq' to the car of
VALUE. If one is found, the BODY is executed with ARGS bound to the
corresponding values in the CDR of VALUE."
(let ((operator (cl-gensym "op-"))
(operands (cl-gensym "rand-"))
(tmp (cl-gensym "tmp-")))
`(let* ((,tmp ,value)
(,operator (car ,tmp))
(,operands (cdr ,tmp)))
(cl-case ,operator
,@(mapcar (lambda (clause)
(if (eq (car clause) t)
`(t ,@(cdr clause))
(cl-destructuring-bind ((op &rest rands) &rest body)
clause
`(,op (cl-destructuring-bind ,rands ,operands
. ,(or body
'((ignore)) ; suppress some warnings
))))))
patterns)
,@(if (eq (caar (last patterns)) t)
'()
`((t (error "slime-dcase failed: %S" ,tmp))))))))
(defmacro slime-define-keys (keymap &rest key-command)
"Define keys in KEYMAP. Each KEY-COMMAND is a list of (KEY COMMAND)."
(declare (indent 1))
`(progn . ,(mapcar (lambda (k-c) `(define-key ,keymap . ,k-c))
key-command)))
(cl-defmacro with-struct ((conc-name &rest slots) struct &body body)
"Like with-slots but works only for structs.
\(fn (CONC-NAME &rest SLOTS) STRUCT &body BODY)"
(declare (indent 2))
(let ((struct-var (cl-gensym "struct"))
(reader (lambda (slot)
(intern (concat (symbol-name conc-name)
(symbol-name slot))))))
`(let ((,struct-var ,struct))
(cl-symbol-macrolet
,(mapcar (lambda (slot)
(cl-etypecase slot
(symbol `(,slot (,(funcall reader slot) ,struct-var)))
(cons `(,(cl-first slot)
(,(funcall reader (cl-second slot))
,struct-var)))))
slots)
. ,body))))
;;;;; Very-commonly-used functions
(defvar slime-message-function 'message)
;; Interface
(defun slime-buffer-name (type &optional hidden)
(cl-assert (keywordp type))
(concat (if hidden " " "")
(format "*slime-%s*" (substring (symbol-name type) 1))))
;; Interface
(defun slime-message (format &rest args)
"Like `message' but with special support for multi-line messages.
Single-line messages use the echo area."
(apply slime-message-function format args))
(defun slime-display-warning (message &rest args)
(display-warning '(slime warning) (apply #'format message args)))
(defvar slime-background-message-function 'slime-display-oneliner)
;; Interface
(defun slime-background-message (format-string &rest format-args)
"Display a message in passing.
This is like `slime-message', but less distracting because it
will never pop up a buffer or display multi-line messages.
It should be used for \"background\" messages such as argument lists."
(apply slime-background-message-function format-string format-args))
(defun slime-display-oneliner (format-string &rest format-args)
(let* ((msg (apply #'format format-string format-args)))
(unless (minibuffer-window-active-p (minibuffer-window))
(message "%s" (slime-oneliner msg)))))
(defun slime-oneliner (string)
"Return STRING truncated to fit in a single echo-area line."
(substring string 0 (min (length string)
(or (cl-position ?\n string) most-positive-fixnum)
(1- (window-width (minibuffer-window))))))
;; Interface
(defun slime-set-truncate-lines ()
"Apply `slime-truncate-lines' to the current buffer."
(when slime-truncate-lines
(set (make-local-variable 'truncate-lines) t)))
;; Interface
(defun slime-read-package-name (prompt &optional initial-value)
"Read a package name from the minibuffer, prompting with PROMPT."
(let ((completion-ignore-case t))
(completing-read prompt (slime-bogus-completion-alist
(slime-eval
`(swank:list-all-package-names t)))
nil t initial-value)))
;; Interface
(defun slime-read-symbol-name (prompt &optional query)
"Either read a symbol name or choose the one at point.
The user is prompted if a prefix argument is in effect, if there is no
symbol at point, or if QUERY is non-nil."
(cond ((or current-prefix-arg query (not (slime-symbol-at-point)))
(slime-read-from-minibuffer prompt (slime-symbol-at-point)))
(t (slime-symbol-at-point))))
;; Interface
(defmacro slime-propertize-region (props &rest body)
"Execute BODY and add PROPS to all the text it inserts.
More precisely, PROPS are added to the region between the point's
positions before and after executing BODY."
(declare (indent 1) (debug (sexp &rest form)))
(let ((start (cl-gensym)))
`(let ((,start (point)))
(prog1 (progn ,@body)
(add-text-properties ,start (point) ,props)))))
(defun slime-add-face (face string)
(declare (indent 1))
(add-text-properties 0 (length string) (list 'face face) string)
string)
;; Interface
(defsubst slime-insert-propertized (props &rest args)
"Insert all ARGS and then add text-PROPS to the inserted text."
(slime-propertize-region props (apply #'insert args)))
(defmacro slime-with-rigid-indentation (level &rest body)
"Execute BODY and then rigidly indent its text insertions.
Assumes all insertions are made at point."
(declare (indent 1))
(let ((start (cl-gensym)) (l (cl-gensym)))
`(let ((,start (point)) (,l ,(or level '(current-column))))
(prog1 (progn ,@body)
(slime-indent-rigidly ,start (point) ,l)))))
(defun slime-indent-rigidly (start end column)
;; Similar to `indent-rigidly' but doesn't inherit text props.
(let ((indent (make-string column ?\ )))
(save-excursion
(goto-char end)
(beginning-of-line)
(while (and (<= start (point))
(progn
(insert-before-markers indent)
(zerop (forward-line -1))))))))
(defun slime-insert-indented (&rest strings)
"Insert all arguments rigidly indented."
(slime-with-rigid-indentation nil
(apply #'insert strings)))
(defun slime-property-bounds (prop)
"Return two the positions of the previous and next changes to PROP.
PROP is the name of a text property."
(cl-assert (get-text-property (point) prop))
(let ((end (next-single-char-property-change (point) prop)))
(list (previous-single-char-property-change end prop) end)))
(defun slime-curry (fun &rest args)
"Partially apply FUN to ARGS. The result is a new function.
This idiom is preferred over `lexical-let'."
`(lambda (&rest more) (apply ',fun (append ',args more))))
(defun slime-rcurry (fun &rest args)
"Like `slime-curry' but ARGS on the right are applied."
`(lambda (&rest more) (apply ',fun (append more ',args))))
;;;;; Temporary popup buffers
;; keep compiler quiet
(defvar slime-buffer-package)
(defvar slime-buffer-connection)
;; Interface
(cl-defmacro slime-with-popup-buffer ((name &key package connection select
mode)
&body body)
"Similar to `with-output-to-temp-buffer'.
Bind standard-output and initialize some buffer-local variables.
Restore window configuration when closed.
NAME is the name of the buffer to be created.
PACKAGE is the value `slime-buffer-package'.
CONNECTION is the value for `slime-buffer-connection',
if nil, no explicit connection is associated with
the buffer. If t, the current connection is taken.
MODE is the name of a major mode which will be enabled.
"
(declare (indent 1))
(let ((package-sym (cl-gensym "package-"))
(connection-sym (cl-gensym "connection-")))
`(let ((,package-sym ,(if (eq package t)
`(slime-current-package)
package))
(,connection-sym ,(if (eq connection t)
`(slime-current-connection)
connection)))
(with-current-buffer (get-buffer-create ,name)
(let ((inhibit-read-only t)
(standard-output (current-buffer)))
(erase-buffer)
(funcall (or ,mode 'fundamental-mode))
(setq slime-buffer-package ,package-sym
slime-buffer-connection ,connection-sym)
(set-syntax-table lisp-mode-syntax-table)
,@body
(slime-popup-buffer-mode 1)
(funcall (if ,select 'pop-to-buffer 'display-buffer)
(current-buffer))
(current-buffer))))))
(defvar slime-popup-buffer-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "q") 'quit-window)
;;("\C-c\C-z" . slime-switch-to-output-buffer)
(define-key map (kbd "M-.") 'slime-edit-definition)
map))
(define-minor-mode slime-popup-buffer-mode
"Mode for displaying read only stuff"
nil nil nil
(setq buffer-read-only t))
(add-to-list 'minor-mode-alist
`(slime-popup-buffer-mode
(:eval (unless slime-mode
(slime-modeline-string)))))
(set-keymap-parent slime-popup-buffer-mode-map slime-parent-map)
;;;;; Filename translation
;;;
;;; Filenames passed between Emacs and Lisp should be translated using
;;; these functions. This way users who run Emacs and Lisp on separate
;;; machines have a chance to integrate file operations somehow.
(defvar slime-to-lisp-filename-function #'convert-standard-filename
"Function to translate Emacs filenames to CL namestrings.")
(defvar slime-from-lisp-filename-function #'identity
"Function to translate CL namestrings to Emacs filenames.")
(defun slime-to-lisp-filename (filename)
"Translate the string FILENAME to a Lisp filename."
(funcall slime-to-lisp-filename-function filename))
(defun slime-from-lisp-filename (filename)
"Translate the Lisp filename FILENAME to an Emacs filename."
(funcall slime-from-lisp-filename-function filename))
;;;; Starting SLIME
;;;
;;; This section covers starting an inferior-lisp, compiling and
;;; starting the server, initiating a network connection.
;;;;; Entry points
;; We no longer load inf-lisp, but we use this variable for backward
;; compatibility.
(defvar inferior-lisp-program "lisp"
"*Program name for invoking an inferior Lisp with for Inferior Lisp mode.")
(defvar slime-lisp-implementations nil
"*A list of known Lisp implementations.
The list should have the form:
((NAME (PROGRAM PROGRAM-ARGS...) &key KEYWORD-ARGS) ...)
NAME is a symbol for the implementation.
PROGRAM and PROGRAM-ARGS are strings used to start the Lisp process.
For KEYWORD-ARGS see `slime-start'.
Here's an example:
((cmucl (\"/opt/cmucl/bin/lisp\" \"-quiet\") :init slime-init-command)
(acl (\"acl7\") :coding-system emacs-mule))")
(defvar slime-default-lisp nil
"*The name of the default Lisp implementation.
See `slime-lisp-implementations'")
;; dummy definitions for the compiler
(defvar slime-net-processes)
(defvar slime-default-connection)
(defun slime (&optional command coding-system)
"Start an inferior^_superior Lisp and connect to its Swank server."
(interactive)
(slime-setup)
(let ((inferior-lisp-program (or command inferior-lisp-program))
(slime-net-coding-system (or coding-system slime-net-coding-system)))
(slime-start* (cond ((and command (symbolp command))
(slime-lisp-options command))
(t (slime-read-interactive-args))))))
(defvar slime-inferior-lisp-program-history '()
"History list of command strings. Used by `slime'.")