Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 298 lines (249 sloc) 11.404 kb
9e7ffcf Committed Drei.
Troels Henriksen authored
1 ;;; -*- Mode: Lisp; Package: DREI-LISP-SYNTAX; -*-
2
3 ;;; (c) copyright 2004-2005 by
4 ;;; Robert Strandh (strandh@labri.fr)
5 ;;; (c) copyright 2004-2005 by
6 ;;; Elliott Johnson (ejohnson@fasl.info)
7 ;;; (c) copyright 2005 by
8 ;;; Matthieu Villeneuve (matthieu.villeneuve@free.fr)
9 ;;; (c) copyright 2005 by
10 ;;; Aleksandar Bakic (a_bakic@yahoo.com)
11 ;;; (c) copyright 2006 by
12 ;;; Troels Henriksen (athas@sigkill.dk)
13 ;;;
14 ;;; This library is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU Library General Public
16 ;;; License as published by the Free Software Foundation; either
17 ;;; version 2 of the License, or (at your option) any later version.
18 ;;;
19 ;;; This library is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;;; Library General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU Library General Public
25 ;;; License along with this library; if not, write to the
26 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;;; Boston, MA 02111-1307 USA.
28
29 ;;; Commands specific to the Lisp syntax for Drei.
30
31 (in-package :drei-lisp-syntax)
32
33 ;;; This command table is used when Drei runs as a pane.
34 (make-command-table 'pane-lisp-table
35 :errorp nil)
36
37 (defmethod additional-command-tables append ((drei drei-pane) (command-table lisp-table))
38 '(pane-lisp-table))
39
40 ;; Movement commands.
41 (drei-commands:define-motion-commands expression lisp-table)
42 (drei-commands:define-motion-commands definition lisp-table)
43 (drei-commands:define-motion-commands up lisp-table
44 :noun "nesting level up"
45 :plural "levels")
46 (drei-commands:define-motion-commands down lisp-table
47 :noun "nesting level down"
48 :plural "levels")
49 (drei-commands:define-motion-commands list lisp-table)
50
51 (drei-commands:define-editing-commands expression lisp-table)
52 (drei-commands:define-deletion-commands expression lisp-table)
53
54 (define-command (com-fill-paragraph :name t :command-table lisp-table)
55 ()
56 "Fill paragraph at point. Will have no effect unless there is a
57 string at point."
c786456 Changed Drei to use a view-based paradigm, didn't make any significant
Troels Henriksen authored
58 (let* ((token (form-around (current-syntax) (offset (point))))
579593e Fixed two more instances where the value of *drei-instance* was
Robert Strandh authored
59 (fill-column (auto-fill-column (current-view))))
9e7ffcf Committed Drei.
Troels Henriksen authored
60 (when (form-string-p token)
61 (with-accessors ((offset1 start-offset)
62 (offset2 end-offset)) token
c786456 Changed Drei to use a view-based paradigm, didn't make any significant
Troels Henriksen authored
63 (fill-region (make-buffer-mark (current-buffer) offset1 :right)
64 (make-buffer-mark (current-buffer) offset2 :right)
9e7ffcf Committed Drei.
Troels Henriksen authored
65 #'(lambda (mark)
c786456 Changed Drei to use a view-based paradigm, didn't make any significant
Troels Henriksen authored
66 (proper-line-indentation (current-view) mark))
9e7ffcf Committed Drei.
Troels Henriksen authored
67 fill-column
c088abf Changed *drei-instance* to be a function (drei-instance).
Troels Henriksen authored
68 (tab-space-count (current-view))
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
69 (current-syntax)
9e7ffcf Committed Drei.
Troels Henriksen authored
70 t)))))
71
72 (define-command (com-indent-expression :name t :command-table lisp-table)
b4a1d34 Use the default value of the parameter for parameters specified to use
Troels Henriksen authored
73 ((count 'integer :prompt "Number of expressions" :default 1))
24d7747 Fixed Indent Expression.
Troels Henriksen authored
74 (let ((mark (clone-mark (point))))
9e7ffcf Committed Drei.
Troels Henriksen authored
75 (if (plusp count)
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
76 (loop repeat count do (forward-expression mark (current-syntax)))
77 (loop repeat (- count) do (backward-expression mark (current-syntax))))
c786456 Changed Drei to use a view-based paradigm, didn't make any significant
Troels Henriksen authored
78 (indent-region (current-view) (point) mark)))
9e7ffcf Committed Drei.
Troels Henriksen authored
79
80 (define-command (com-lookup-arglist-for-this-symbol :command-table lisp-table)
81 ()
82 "Show argument list for symbol at point."
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
83 (let* ((token (this-form (current-syntax) (point))))
9e7ffcf Committed Drei.
Troels Henriksen authored
84 (if (and token (form-token-p token))
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
85 (com-lookup-arglist (form-to-object (current-syntax) token))
9e7ffcf Committed Drei.
Troels Henriksen authored
86 (display-message "Could not find symbol at point."))))
87
88 (define-command (com-lookup-arglist :name t :command-table lisp-table)
89 ((symbol 'symbol :prompt "Symbol"))
90 "Show argument list for a given symbol."
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
91 (show-arglist (current-syntax) symbol))
9e7ffcf Committed Drei.
Troels Henriksen authored
92
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
93 (define-command (com-self-insert-then-arglist :command-table lisp-table)
9e7ffcf Committed Drei.
Troels Henriksen authored
94 ()
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
95 "Insert the gesture used to invoke this command and display
96 argument hints in the minibuffer."
97 (insert-character *current-gesture*)
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
98 (show-arglist-for-form-at-mark (point) (current-syntax))
51dc43b Revised Lisp syntax module, making a bunch of improvements and added
Troels Henriksen authored
99 (clear-completions))
9e7ffcf Committed Drei.
Troels Henriksen authored
100
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
101 (define-command (com-newline-indent-then-arglist :command-table lisp-table) ()
102 "Inserts a newline, indents the new line, then displays
103 argument hints in the minibuffer."
104 (insert-object (point) #\Newline)
105 (indent-current-line (current-view) (point))
106 (show-arglist-for-form-at-mark (point) (current-syntax)))
107
b39ebc6 Using #\Tab for completing Lisp symbols will no longer potentially
Troels Henriksen authored
108 (define-command (com-complete-symbol :name t :command-table lisp-table)
109 ()
9e7ffcf Committed Drei.
Troels Henriksen authored
110 "Attempt to complete the symbol at mark. If successful, move point
111 to end of symbol.
112
b39ebc6 Using #\Tab for completing Lisp symbols will no longer potentially
Troels Henriksen authored
113 If more than one completion is available, a list of possible
114 completions will be displayed. If there is no symbol at mark, all
115 relevant symbols accessible in the current package will be
116 displayed."
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
117 (complete-symbol-at-mark (current-syntax) (point)))
9e7ffcf Committed Drei.
Troels Henriksen authored
118
b39ebc6 Using #\Tab for completing Lisp symbols will no longer potentially
Troels Henriksen authored
119 (define-command (com-fuzzily-complete-symbol :name t :command-table lisp-table)
120 ()
9e7ffcf Committed Drei.
Troels Henriksen authored
121 "Attempt to fuzzily complete the abbreviation at mark.
122
123 Fuzzy completion tries to guess which symbol is abbreviated. If
124 the abbreviation is ambiguous, a list of possible completions
b39ebc6 Using #\Tab for completing Lisp symbols will no longer potentially
Troels Henriksen authored
125 will be displayed. If there is no symbol at mark, all relevant
126 symbols accessible in the current package will be displayed."
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
127 (fuzzily-complete-symbol-at-mark (current-syntax) (point)))
9e7ffcf Committed Drei.
Troels Henriksen authored
128
129 (define-command (com-indent-line-and-complete-symbol :name t :command-table lisp-table) ()
130 "Indents the current line and performs symbol completion.
131 First indents the line. If the line was already indented,
132 completes the symbol. If there's no symbol at the point, shows
133 the arglist for the most recently enclosed operator."
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
134 (let ((old-offset (offset (point))))
c786456 Changed Drei to use a view-based paradigm, didn't make any significant
Troels Henriksen authored
135 (indent-current-line (current-view) (point))
9e7ffcf Committed Drei.
Troels Henriksen authored
136 (when (= old-offset
c1f10e7 As it turns out, a lot of Drei code still used (current-window), which
Troels Henriksen authored
137 (offset (point)))
138 (or (complete-symbol-at-mark (current-syntax) (point) nil)
139 (show-arglist-for-form-at-mark (point) (current-syntax))))))
9e7ffcf Committed Drei.
Troels Henriksen authored
140
141 (define-presentation-to-command-translator lookup-symbol-arglist
142 (symbol com-lookup-arglist lisp-table
143 :gesture :describe
144 :documentation "Lookup arglist")
145 (object)
146 (list object))
147
148 (define-command (com-eval-region :name t :command-table pane-lisp-table)
149 ()
150 "Evaluate the current region."
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
151 (let ((mark (mark))
152 (point (point)))
9e7ffcf Committed Drei.
Troels Henriksen authored
153 (when (mark> mark point)
154 (rotatef mark point))
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
155 (eval-region mark point (current-syntax))))
9e7ffcf Committed Drei.
Troels Henriksen authored
156
157 (define-command (com-eval-last-expression :name t :command-table pane-lisp-table)
b4a1d34 Use the default value of the parameter for parameters specified to use
Troels Henriksen authored
158 ((insertp 'boolean :prompt "Insert?" :default nil))
9e7ffcf Committed Drei.
Troels Henriksen authored
159 "Evaluate the expression before point in the local Lisp image."
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
160 (let ((token (form-before (current-syntax) (offset (point)))))
9e7ffcf Committed Drei.
Troels Henriksen authored
161 (if token
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
162 (with-syntax-package ((current-syntax) (point))
163 (let ((*read-base* (base (current-syntax))))
9e7ffcf Committed Drei.
Troels Henriksen authored
164 (drei-commands::com-eval-expression
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
165 (form-to-object (current-syntax) token :read t)
9e7ffcf Committed Drei.
Troels Henriksen authored
166 insertp)))
167 (display-message "Nothing to evaluate."))))
168
169 (define-command (com-eval-defun :name t :command-table pane-lisp-table) ()
ea8159f Change the use of global variables in Drei to functions that query a
Troels Henriksen authored
170 (eval-defun (point) (current-syntax)))
9e7ffcf Committed Drei.
Troels Henriksen authored
171
525cc1d Added Remove Definition command to Lisp syntax.
Troels Henriksen authored
172 (define-command (com-remove-definition :name t :command-table lisp-table)
173 ()
174 "Remove the definition point is in.
175
176 The operator of the definition form will be used to determine
177 what kind of definition it is. The user will be asked for
178 confirmation before anything is actually done."
179 (let ((definition-form (definition-at-mark (current-syntax) (point))))
180 (if (or (null definition-form)
181 (mark> (point) (end-offset definition-form))
182 (mark< (point) (start-offset definition-form)))
183 (display-message "No definition found at point.")
184 (handler-case
185 (let* ((definition-type (form-to-object (current-syntax)
186 (form-operator definition-form)))
187 (undefiner (get-undefiner definition-type)))
188 (if (null undefiner)
189 (display-message "Doesn't know how to undefine ~S." definition-type)
190 (handler-case
191 (when (accept 'boolean
192 :prompt (format nil "Undefine the ~A ~S?"
193 (undefiner-type undefiner)
194 (definition-name undefiner (current-syntax) definition-form))
195 :default t :insert-default t)
196 (undefine undefiner (current-syntax) definition-form))
197 (form-conversion-error (e)
198 (display-message "Could not undefine ~S form: ~A" definition-type (problem e))))))
199 (form-conversion-error (e)
200 (display-message "Couldn't turn \"~A\" into valid operator: ~A"
201 (form-string (current-syntax) (form e)) (problem e)))))))
202
9e7ffcf Committed Drei.
Troels Henriksen authored
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 ;;;
205 ;;; Gesture bindings
206
207 (set-key 'com-fill-paragraph
208 'lisp-table
209 '((#\q :meta)))
210
211 (set-key `(com-indent-expression ,*numeric-argument-marker*)
212 'lisp-table
213 '((#\q :meta :control)))
214
215 (set-key `(com-backward-up ,*numeric-argument-marker*)
216 'lisp-table
217 '((#\u :control :meta)))
218
219 (set-key `(com-forward-down ,*numeric-argument-marker*)
220 'lisp-table
221 '((#\d :control :meta)))
222
223 (set-key `(com-backward-expression ,*numeric-argument-marker*)
224 'lisp-table
225 '((#\b :control :meta)))
226
227 (set-key `(com-forward-expression ,*numeric-argument-marker*)
228 'lisp-table
229 '((#\f :control :meta)))
230
231 (set-key `(com-backward-definition ,*numeric-argument-marker*)
232 'lisp-table
233 '((#\a :control :meta)))
234
235 (set-key `(com-forward-definition ,*numeric-argument-marker*)
236 'lisp-table
237 '((#\e :control :meta)))
238
239 (set-key `(com-forward-list ,*numeric-argument-marker*)
240 'lisp-table
241 '((#\n :control :meta)))
242
243 (set-key `(com-backward-list ,*numeric-argument-marker*)
244 'lisp-table
245 '((#\p :control :meta)))
246
247 (set-key `(com-kill-expression ,*numeric-argument-marker*)
248 'lisp-table
249 '((#\k :control :meta)))
250
251 (set-key 'com-lookup-arglist-for-this-symbol
252 'lisp-table
253 '((#\c :control) (#\d :control) (#\a)))
254
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
255 (set-key 'com-self-insert-then-arglist
9e7ffcf Committed Drei.
Troels Henriksen authored
256 'lisp-table
257 '((#\Space)))
258
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
259 (set-key 'com-self-insert-then-arglist
260 'lisp-table
261 '((#\))))
262
9e7ffcf Committed Drei.
Troels Henriksen authored
263 (set-key 'com-complete-symbol
264 'lisp-table
265 '((#\Tab :meta)))
266
267 (set-key 'com-fuzzily-complete-symbol
268 'lisp-table
269 '((#\c :control) (#\i :meta)))
270
271 (set-key 'com-indent-line-and-complete-symbol
272 'lisp-table
273 '((#\Tab)))
274
1ee9cfb Added argument hinting for Lisp when entering newlines and right pare…
Troels Henriksen authored
275 (set-key 'com-newline-indent-then-arglist
9e7ffcf Committed Drei.
Troels Henriksen authored
276 'lisp-table
277 '(#\Newline))
278
279 (set-key 'com-eval-region
280 'pane-lisp-table
281 '((#\c :control) (#\r :control)))
282
b4a1d34 Use the default value of the parameter for parameters specified to use
Troels Henriksen authored
283 (set-key `(com-eval-last-expression ,*numeric-argument-marker*)
9e7ffcf Committed Drei.
Troels Henriksen authored
284 'pane-lisp-table
285 '((#\c :control) (#\e :control)))
38e11b7 Fix insert-pair, add move-past-close-and-reindent, bind M-), C-M-Delete,
Andy Hefner authored
286
287 (set-key `(com-backward-kill-expression ,*numeric-argument-marker*)
288 'lisp-table
289 '((#\Backspace :control :meta)))
290
291 (set-key `(com-kill-expression ,*numeric-argument-marker*)
292 'lisp-table
293 '((#\Delete :control :meta)))
294
525cc1d Added Remove Definition command to Lisp syntax.
Troels Henriksen authored
295 (set-key 'com-remove-definition
296 'lisp-table
297 '((#\c :control) (#\u :control)))
Something went wrong with that request. Please try again.