Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/slime/contrib/inferior-slime.el
990 views
1
;;; inferior-slime.el --- Minor mode with Slime keys for comint buffers
2
;;
3
;; Author: Luke Gorrie <[email protected]>
4
;; License: GNU GPL (same license as Emacs)
5
;;
6
;;; Installation:
7
;;
8
;; Add something like this to your .emacs:
9
;;
10
;; (add-to-list 'load-path "<directory-of-this-file>")
11
;; (add-hook 'slime-load-hook (lambda () (require 'inferior-slime)))
12
;; (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode 1)))
13
14
(define-minor-mode inferior-slime-mode
15
"\\<slime-mode-map>\
16
Inferior SLIME mode: The Inferior Superior Lisp Mode for Emacs.
17
18
This mode is intended for use with `inferior-lisp-mode'. It provides a
19
subset of the bindings from `slime-mode'.
20
21
\\{inferior-slime-mode-map}"
22
nil
23
nil
24
;; Fake binding to coax `define-minor-mode' to create the keymap
25
'((" " 'undefined)))
26
27
(add-to-list 'minor-mode-alist
28
'(inferior-slime-mode
29
(" Inf-Slime" slime-state-name)))
30
31
(defun inferior-slime-return ()
32
"Handle the return key in the inferior-lisp buffer.
33
The current input should only be sent if a whole expression has been
34
entered, i.e. the parenthesis are matched.
35
36
A prefix argument disables this behaviour."
37
(interactive)
38
(if (or current-prefix-arg (inferior-slime-input-complete-p))
39
(comint-send-input)
40
(insert "\n")
41
(inferior-slime-indent-line)))
42
43
(defun inferior-slime-indent-line ()
44
"Indent the current line, ignoring everything before the prompt."
45
(interactive)
46
(save-restriction
47
(let ((indent-start
48
(save-excursion
49
(goto-char (process-mark (get-buffer-process (current-buffer))))
50
(let ((inhibit-field-text-motion t))
51
(beginning-of-line 1))
52
(point))))
53
(narrow-to-region indent-start (point-max)))
54
(lisp-indent-line)))
55
56
(defun inferior-slime-input-complete-p ()
57
"Return true if the input is complete in the inferior lisp buffer."
58
(slime-input-complete-p (process-mark (get-buffer-process (current-buffer)))
59
(point-max)))
60
61
(defun inferior-slime-closing-return ()
62
"Send the current expression to Lisp after closing any open lists."
63
(interactive)
64
(goto-char (point-max))
65
(save-restriction
66
(narrow-to-region (process-mark (get-buffer-process (current-buffer)))
67
(point-max))
68
(while (ignore-errors (save-excursion (backward-up-list 1) t))
69
(insert ")")))
70
(comint-send-input))
71
72
(defun inferior-slime-change-directory (directory)
73
"Set default-directory in the *inferior-lisp* buffer to DIRECTORY."
74
(let* ((proc (slime-process))
75
(buffer (and proc (process-buffer proc))))
76
(when buffer
77
(with-current-buffer buffer
78
(cd-absolute directory)))))
79
80
(defun inferior-slime-init-keymap ()
81
(let ((map inferior-slime-mode-map))
82
(set-keymap-parent map slime-parent-map)
83
(slime-define-keys map
84
([return] 'inferior-slime-return)
85
([(control return)] 'inferior-slime-closing-return)
86
([(meta control ?m)] 'inferior-slime-closing-return)
87
("\t" 'slime-indent-and-complete-symbol)
88
(" " 'slime-space))))
89
90
(inferior-slime-init-keymap)
91
92
(defun inferior-slime-hook-function ()
93
(inferior-slime-mode 1))
94
95
(defun inferior-slime-switch-to-repl-buffer ()
96
(switch-to-buffer (process-buffer (slime-inferior-process))))
97
98
(defun inferior-slime-show-transcript (string)
99
(remove-hook 'comint-output-filter-functions
100
'inferior-slime-show-transcript t)
101
(with-current-buffer (process-buffer (slime-inferior-process))
102
(let ((window (display-buffer (current-buffer) t)))
103
(set-window-point window (point-max)))))
104
105
(defun inferior-slime-start-transcript ()
106
(let ((proc (slime-inferior-process)))
107
(when proc
108
(with-current-buffer (process-buffer proc)
109
(add-hook 'comint-output-filter-functions
110
'inferior-slime-show-transcript
111
nil t)))))
112
113
(defun inferior-slime-stop-transcript ()
114
(let ((proc (slime-inferior-process)))
115
(when proc
116
(with-current-buffer (process-buffer (slime-inferior-process))
117
(run-with-timer 0.2 nil
118
(lambda (buffer)
119
(with-current-buffer buffer
120
(remove-hook 'comint-output-filter-functions
121
'inferior-slime-show-transcript t)))
122
(current-buffer))))))
123
124
(defun inferior-slime-init ()
125
(add-hook 'slime-inferior-process-start-hook 'inferior-slime-hook-function)
126
(add-hook 'slime-change-directory-hooks 'inferior-slime-change-directory)
127
(add-hook 'slime-transcript-start-hook 'inferior-slime-start-transcript)
128
(add-hook 'slime-transcript-stop-hook 'inferior-slime-stop-transcript)
129
(def-slime-selector-method ?r
130
"SLIME Read-Eval-Print-Loop."
131
(process-buffer (slime-inferior-process))))
132
133
(provide 'inferior-slime)
134
135