/[climacs]/climacs/gui.lisp
ViewVC logotype

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.110 - (hide annotations)
Sat Feb 19 05:45:03 2005 UTC (9 years, 1 month ago) by rstrandh
Branch: MAIN
Changes since 1.109: +19 -13 lines
Used the new *numeric-argument-p* feature to implement Emacs-like
behavior for kill-line.
1 ejohnson 1.27 ;;; -*- Mode: Lisp; Package: CLIMACS-GUI -*-
2    
3 mvilleneuve 1.65 ;;; (c) copyright 2004-2005 by
4 ejohnson 1.27 ;;; Robert Strandh (strandh@labri.fr)
5 mvilleneuve 1.65 ;;; (c) copyright 2004-2005 by
6 ejohnson 1.27 ;;; Elliott Johnson (ejohnson@fasl.info)
7 mvilleneuve 1.65 ;;; (c) copyright 2005 by
8     ;;; Matthieu Villeneuve (matthieu.villeneuve@free.fr)
9 abakic 1.68 ;;; (c) copyright 2005 by
10     ;;; Aleksandar Bakic (a_bakic@yahoo.com)
11 ejohnson 1.27
12     ;;; This library is free software; you can redistribute it and/or
13     ;;; modify it under the terms of the GNU Library General Public
14     ;;; License as published by the Free Software Foundation; either
15     ;;; version 2 of the License, or (at your option) any later version.
16     ;;;
17     ;;; This library is distributed in the hope that it will be useful,
18     ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19     ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20     ;;; Library General Public License for more details.
21     ;;;
22     ;;; You should have received a copy of the GNU Library General Public
23     ;;; License along with this library; if not, write to the
24     ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25     ;;; Boston, MA 02111-1307 USA.
26    
27     ;;; GUI for the Climacs editor.
28    
29     (in-package :climacs-gui)
30    
31 rstrandh 1.70 (defclass extended-pane (climacs-pane)
32     (;; allows a certain number of commands to have some minimal memory
33 rstrandh 1.49 (previous-command :initform nil :accessor previous-command)
34     ;; for next-line and previous-line commands
35     (goal-column :initform nil)
36     ;; for dynamic abbrev expansion
37     (original-prefix :initform nil)
38     (prefix-start-offset :initform nil)
39 abakic 1.68 (dabbrev-expansion-mark :initform nil)
40     (overwrite-mode :initform nil)))
41 ejohnson 1.27
42 rstrandh 1.81 (defclass info-pane (application-pane)
43     ((climacs-pane :initarg :climacs-pane)))
44    
45 rstrandh 1.28 (defclass minibuffer-pane (application-pane) ())
46    
47     (defmethod stream-accept :before ((pane minibuffer-pane) type &rest args)
48     (declare (ignore type args))
49     (window-clear pane))
50    
51 ejohnson 1.27 (define-application-frame climacs ()
52 rstrandh 1.83 ((windows :accessor windows)
53 rstrandh 1.85 (buffers :initform '() :accessor buffers)
54     (recordingp :initform nil :accessor recordingp)
55     (executingp :initform nil :accessor executingp)
56     (recorded-keys :initform '() :accessor recorded-keys)
57     (remaining-keys :initform '() :accessor remaining-keys))
58 ejohnson 1.27 (:panes
59 rstrandh 1.81 (win (let* ((extended-pane
60     (make-pane 'extended-pane
61     :width 900 :height 400
62     :name 'bla
63     :incremental-redisplay t
64     :display-function 'display-win))
65     (info-pane
66     (make-pane 'info-pane
67     :climacs-pane extended-pane
68     :width 900 :height 20 :max-height 20 :min-height 20
69     ::background +gray85+
70     :scroll-bars nil
71     :borders nil
72     :incremental-redisplay t
73     :display-function 'display-info)))
74     (vertically ()
75     (scrolling ()
76     extended-pane)
77     info-pane)))
78 rstrandh 1.62 (int (make-pane 'minibuffer-pane
79     :width 900 :height 20 :max-height 20 :min-height 20
80 rstrandh 1.106 :display-function 'display-minibuffer
81 rstrandh 1.62 :scroll-bars nil)))
82 ejohnson 1.27 (:layouts
83     (default
84     (vertically (:scroll-bars nil)
85 rstrandh 1.77 win
86 rstrandh 1.80 int)))
87 ejohnson 1.27 (:top-level (climacs-top-level)))
88    
89 rstrandh 1.106 (defparameter *message* nil)
90    
91     (defun display-message (format-string &rest format-args)
92     (setf *message*
93     (apply #'format nil format-string format-args)))
94    
95     (defun display-minibuffer (frame pane)
96     (declare (ignore frame))
97     (unless (null *message*)
98     (princ *message* pane)
99     (setf *message* nil)))
100    
101 abakic 1.87 (defmacro current-window () ; shouldn't this be an inlined function? --amb
102 rstrandh 1.83 `(car (windows *application-frame*)))
103 rstrandh 1.80
104 rstrandh 1.98 (defmethod execute-frame-command :around ((frame climacs) command)
105     (declare (ignore command))
106     (with-undo ((buffer (current-window)))
107     (call-next-method)))
108    
109 rstrandh 1.80 (defmethod redisplay-frame-panes :around ((frame climacs) &rest args)
110 rstrandh 1.70 (declare (ignore args))
111 rstrandh 1.83 (let ((buffers (remove-duplicates (mapcar #'buffer (windows frame)))))
112     (loop for buffer in buffers
113     do (update-syntax buffer (syntax buffer)))
114 rstrandh 1.80 (call-next-method)
115 rstrandh 1.83 (loop for buffer in buffers
116     do (clear-modify buffer))))
117 rstrandh 1.28
118 ejohnson 1.27 (defun climacs ()
119     "Starts up a climacs session"
120     (let ((frame (make-application-frame 'climacs)))
121     (run-frame-top-level frame)))
122    
123     (defun display-info (frame pane)
124 rstrandh 1.81 (declare (ignore frame))
125     (with-slots (climacs-pane) pane
126     (let* ((buf (buffer climacs-pane))
127 mvilleneuve 1.96 (name-info (format nil " ~a ~a Syntax: ~a~a~a~a ~a"
128 rstrandh 1.81 (if (needs-saving buf) "**" "--")
129     (name buf)
130     (name (syntax buf))
131     (if (slot-value climacs-pane 'overwrite-mode)
132 mvilleneuve 1.86 " Ovwrt"
133 rstrandh 1.85 "")
134 mvilleneuve 1.92 (if (auto-fill-mode climacs-pane)
135 mvilleneuve 1.86 " Fill"
136     "")
137 mvilleneuve 1.96 (if (isearch-mode climacs-pane)
138     " Isearch"
139     "")
140 rstrandh 1.85 (if (recordingp *application-frame*)
141     "Def"
142 rstrandh 1.81 ""))))
143     (princ name-info pane))))
144 ejohnson 1.27
145     (defun display-win (frame pane)
146     "The display function used by the climacs application frame."
147     (declare (ignore frame))
148 rstrandh 1.83 (redisplay-pane pane (eq pane (car (windows *application-frame*)))))
149 ejohnson 1.27
150     (defun find-gestures (gestures start-table)
151     (loop with table = (find-command-table start-table)
152     for (gesture . rest) on gestures
153     for item = (find-keystroke-item gesture table :errorp nil)
154     while item
155     do (if (eq (command-menu-item-type item) :command)
156     (return (if (null rest) item nil))
157     (setf table (command-menu-item-value item)))
158     finally (return item)))
159    
160 ejohnson 1.50 (defvar *kill-ring* (make-instance 'kill-ring :max-size 7))
161 ejohnson 1.27 (defparameter *current-gesture* nil)
162    
163 rstrandh 1.36 (defun meta-digit (gesture)
164     (position gesture
165     '((#\0 :meta) (#\1 :meta) (#\2 :meta) (#\3 :meta) (#\4 :meta)
166     (#\5 :meta) (#\6 :meta) (#\7 :meta) (#\8 :meta) (#\9 :meta))
167     :test #'event-matches-gesture-name-p))
168    
169 rstrandh 1.47 (defun climacs-read-gesture ()
170 rstrandh 1.85 (unless (null (remaining-keys *application-frame*))
171     (return-from climacs-read-gesture
172     (pop (remaining-keys *application-frame*))))
173 rstrandh 1.47 (loop for gesture = (read-gesture :stream *standard-input*)
174 rstrandh 1.85 when (event-matches-gesture-name-p gesture '(:keyboard #\g 512)) ; FIXME
175 rstrandh 1.47 do (throw 'outer-loop nil)
176     until (or (characterp gesture)
177     (and (typep gesture 'keyboard-event)
178     (or (keyboard-event-character gesture)
179     (not (member (keyboard-event-key-name
180     gesture)
181     '(:control-left :control-right
182     :shift-left :shift-right
183     :meta-left :meta-right
184     :super-left :super-right
185     :hyper-left :hyper-right
186     :shift-lock :caps-lock
187     :alt-left :alt-right))))))
188 rstrandh 1.85 finally (progn (when (recordingp *application-frame*)
189     (push gesture (recorded-keys *application-frame*)))
190     (return gesture))))
191    
192     (defun climacs-unread-gesture (gesture stream)
193     (cond ((recordingp *application-frame*)
194 rstrandh 1.88 (pop (recorded-keys *application-frame*))
195     (unread-gesture gesture :stream stream))
196 rstrandh 1.85 ((executingp *application-frame*)
197 rstrandh 1.88 (push gesture (remaining-keys *application-frame*)))
198     (t
199     (unread-gesture gesture :stream stream))))
200 rstrandh 1.47
201 rstrandh 1.36 (defun read-numeric-argument (&key (stream *standard-input*))
202 rstrandh 1.47 (let ((gesture (climacs-read-gesture)))
203 rstrandh 1.62 (cond ((event-matches-gesture-name-p gesture '(:keyboard #\u 512)) ; FIXME
204 rstrandh 1.36 (let ((numarg 4))
205 rstrandh 1.47 (loop for gesture = (climacs-read-gesture)
206 rstrandh 1.62 while (event-matches-gesture-name-p gesture '(:keyboard #\u 512)) ; FIXME
207 rstrandh 1.36 do (setf numarg (* 4 numarg))
208 rstrandh 1.85 finally (climacs-unread-gesture gesture stream))
209 rstrandh 1.47 (let ((gesture (climacs-read-gesture)))
210 rstrandh 1.36 (cond ((and (characterp gesture)
211     (digit-char-p gesture 10))
212     (setf numarg (- (char-code gesture) (char-code #\0)))
213 rstrandh 1.47 (loop for gesture = (climacs-read-gesture)
214 rstrandh 1.36 while (and (characterp gesture)
215     (digit-char-p gesture 10))
216 rstrandh 1.62 do (setf numarg (+ (* 10 numarg)
217     (- (char-code gesture) (char-code #\0))))
218 rstrandh 1.85 finally (climacs-unread-gesture gesture stream)
219 rstrandh 1.36 (return (values numarg t))))
220     (t
221 rstrandh 1.85 (climacs-unread-gesture gesture stream)
222 rstrandh 1.36 (values numarg t))))))
223     ((meta-digit gesture)
224     (let ((numarg (meta-digit gesture)))
225 rstrandh 1.47 (loop for gesture = (climacs-read-gesture)
226 rstrandh 1.36 while (meta-digit gesture)
227     do (setf numarg (+ (* 10 numarg) (meta-digit gesture)))
228 rstrandh 1.85 finally (climacs-unread-gesture gesture stream)
229 rstrandh 1.36 (return (values numarg t)))))
230 rstrandh 1.85 (t (climacs-unread-gesture gesture stream)
231 rstrandh 1.36 (values 1 nil)))))
232    
233 rstrandh 1.77 ;;; we know the vbox pane has a scroller pane and an info
234     ;;; pane in it. The scroller pane has a viewport in it,
235     ;;; and the viewport contains the climacs-pane as its only child.
236     (defun find-climacs-pane (vbox)
237     (first (sheet-children
238     (find-if-not (lambda (pane) (typep pane 'scroll-bar-pane))
239     (sheet-children
240     (find-if (lambda (pane) (typep pane 'scroller-pane))
241     (sheet-children vbox)))))))
242    
243 rstrandh 1.109 (defvar *numeric-argument-p* (list nil))
244    
245     (defun substitute-numeric-argument-p (command numargp)
246     (substitute numargp *numeric-argument-p* command :test #'eq))
247    
248 ejohnson 1.27 (defun climacs-top-level (frame &key
249     command-parser command-unparser
250     partial-command-parser prompt)
251     (declare (ignore command-parser command-unparser partial-command-parser prompt))
252 rstrandh 1.83 (with-slots (windows) frame
253     (setf windows (list (find-climacs-pane (find-pane-named frame 'win))))
254     (push (buffer (car windows)) (buffers frame))
255     (let ((*standard-output* (car windows))
256 rstrandh 1.77 (*standard-input* (find-pane-named frame 'int))
257     (*print-pretty* nil)
258     (*abort-gestures* nil))
259     (redisplay-frame-panes frame :force-p t)
260     (loop (catch 'outer-loop
261     (loop for gestures = '()
262 rstrandh 1.109 do (multiple-value-bind (numarg numargp)
263     (read-numeric-argument :stream *standard-input*)
264     (loop (setf *current-gesture* (climacs-read-gesture))
265     (setf gestures (nconc gestures (list *current-gesture*)))
266     (let ((item (find-gestures gestures 'global-climacs-table)))
267     (cond ((not item)
268     (beep) (return))
269     ((eq (command-menu-item-type item) :command)
270     (let ((command (command-menu-item-value item)))
271     (unless (consp command)
272     (setf command (list command)))
273     (setf command (substitute-numeric-argument-marker command numarg))
274     (setf command (substitute-numeric-argument-p command numargp))
275     (handler-case
276     (execute-frame-command frame command)
277     (error (condition)
278     (beep)
279     (format *error-output* "~a~%" condition)))
280     (setf (previous-command *standard-output*)
281     (if (consp command)
282     (car command)
283     command))
284     (return)))
285     (t nil))))
286     (let ((buffer (buffer (current-window))))
287     (when (modified-p buffer)
288     (setf (needs-saving buffer) t)))
289     (when (null (remaining-keys *application-frame*))
290     (setf (executingp *application-frame*) nil)
291     (redisplay-frame-panes frame)))))
292 rstrandh 1.77 (beep)
293 rstrandh 1.83 (let ((buffer (buffer (current-window))))
294 rstrandh 1.77 (when (modified-p buffer)
295     (setf (needs-saving buffer) t)))
296 rstrandh 1.85 (when (null (remaining-keys *application-frame*))
297     (setf (executingp *application-frame*) nil)
298     (redisplay-frame-panes frame))))))
299 ejohnson 1.27
300 mvilleneuve 1.100 (defmacro simple-command-loop (command-table loop-condition end-clauses)
301     (let ((gesture (gensym))
302     (item (gensym))
303     (command (gensym))
304     (condition (gensym)))
305     `(progn
306     (redisplay-frame-panes *application-frame*)
307     (loop while ,loop-condition
308     as ,gesture = (climacs-read-gesture)
309     as ,item = (find-gestures (list ,gesture) ,command-table)
310     do (cond ((and ,item (eq (command-menu-item-type ,item) :command))
311     (setf *current-gesture* ,gesture)
312     (let ((,command (command-menu-item-value ,item)))
313     (unless (consp ,command)
314     (setf ,command (list ,command)))
315     (handler-case
316     (execute-frame-command *application-frame*
317     ,command)
318     (error (,condition)
319     (beep)
320     (format *error-output* "~a~%" ,condition)))))
321     (t
322     (unread-gesture ,gesture)
323     ,@end-clauses))
324     (redisplay-frame-panes *application-frame*)))))
325    
326 mvilleneuve 1.64 (defun region-limits (pane)
327 rstrandh 1.70 (if (mark< (mark pane) (point pane))
328     (values (mark pane) (point pane))
329     (values (point pane) (mark pane))))
330 mvilleneuve 1.64
331 abridgewater 1.34 (defmacro define-named-command (command-name args &body body)
332 rstrandh 1.62 `(define-climacs-command ,(if (listp command-name)
333     `(,@command-name :name t)
334     `(,command-name :name t)) ,args ,@body))
335 abridgewater 1.34
336 abakic 1.58 (define-named-command com-toggle-overwrite-mode ()
337 abakic 1.87 (with-slots (overwrite-mode) (current-window)
338     (setf overwrite-mode (not overwrite-mode))))
339 abakic 1.58
340 mvilleneuve 1.89 (defun possibly-fill-line ()
341 mvilleneuve 1.86 (let* ((pane (current-window))
342     (buffer (buffer pane)))
343 mvilleneuve 1.92 (when (auto-fill-mode pane)
344 mvilleneuve 1.95 (let* ((fill-column (auto-fill-column pane))
345 mvilleneuve 1.86 (point (point pane))
346     (offset (offset point))
347     (tab-width (tab-space-count (stream-default-view pane)))
348     (syntax (syntax buffer)))
349     (when (>= (buffer-display-column buffer offset tab-width)
350 mvilleneuve 1.95 (1- fill-column))
351 mvilleneuve 1.86 (fill-line point
352     (lambda (mark)
353     (syntax-line-indentation mark tab-width syntax))
354     fill-column
355 mvilleneuve 1.89 tab-width))))))
356    
357     (defun insert-character (char)
358     (let* ((win (current-window))
359     (point (point win)))
360     (unless (constituentp char)
361     (possibly-expand-abbrev point))
362     (when (whitespacep char)
363     (possibly-fill-line))
364     (if (and (slot-value win 'overwrite-mode) (not (end-of-line-p point)))
365     (progn
366     (delete-range point)
367     (insert-object point char))
368     (insert-object point char))))
369    
370     (define-command com-self-insert ()
371 mvilleneuve 1.86 (insert-character *current-gesture*))
372 ejohnson 1.27
373 abridgewater 1.34 (define-named-command com-beginning-of-line ()
374 rstrandh 1.80 (beginning-of-line (point (current-window))))
375 ejohnson 1.27
376 abridgewater 1.34 (define-named-command com-end-of-line ()
377 rstrandh 1.80 (end-of-line (point (current-window))))
378 ejohnson 1.27
379 rstrandh 1.62 (define-named-command com-delete-object ((count 'integer :prompt "Number of Objects"))
380 rstrandh 1.80 (delete-range (point (current-window)) count))
381 ejohnson 1.27
382 rstrandh 1.62 (define-named-command com-backward-delete-object ((count 'integer :prompt "Number of Objects"))
383 rstrandh 1.80 (delete-range (point (current-window)) (- count)))
384 ejohnson 1.27
385 rstrandh 1.42 (define-named-command com-transpose-objects ()
386 rstrandh 1.80 (let* ((point (point (current-window))))
387 rstrandh 1.42 (unless (beginning-of-buffer-p point)
388     (when (end-of-line-p point)
389 rstrandh 1.43 (backward-object point))
390     (let ((object (object-after point)))
391     (delete-range point)
392     (backward-object point)
393     (insert-object point object)
394     (forward-object point)))))
395    
396 rstrandh 1.62 (define-named-command com-backward-object ((count 'integer :prompt "Number of Objects"))
397 rstrandh 1.80 (backward-object (point (current-window)) count))
398 rstrandh 1.43
399 rstrandh 1.62 (define-named-command com-forward-object ((count 'integer :prompt "Number of Objects"))
400 rstrandh 1.80 (forward-object (point (current-window)) count))
401 rstrandh 1.43
402     (define-named-command com-transpose-words ()
403 rstrandh 1.80 (let* ((point (point (current-window))))
404 rstrandh 1.43 (let (bw1 bw2 ew1 ew2)
405     (backward-word point)
406     (setf bw1 (offset point))
407     (forward-word point)
408     (setf ew1 (offset point))
409     (forward-word point)
410     (when (= (offset point) ew1)
411     ;; this is emacs' message in the minibuffer
412     (error "Don't have two things to transpose"))
413     (setf ew2 (offset point))
414     (backward-word point)
415     (setf bw2 (offset point))
416     (let ((w2 (buffer-sequence (buffer point) bw2 ew2))
417     (w1 (buffer-sequence (buffer point) bw1 ew1)))
418     (delete-word point)
419     (insert-sequence point w1)
420     (backward-word point)
421     (backward-word point)
422     (delete-word point)
423     (insert-sequence point w2)
424     (forward-word point)))))
425 rstrandh 1.42
426 rstrandh 1.45 (define-named-command com-transpose-lines ()
427 rstrandh 1.80 (let ((point (point (current-window))))
428 rstrandh 1.45 (beginning-of-line point)
429     (unless (beginning-of-buffer-p point)
430     (previous-line point))
431     (let* ((bol (offset point))
432     (eol (progn (end-of-line point)
433     (offset point)))
434     (line (buffer-sequence (buffer point) bol eol)))
435     (delete-region bol point)
436     ;; Remove newline at end of line as well.
437     (unless (end-of-buffer-p point)
438     (delete-range point))
439     ;; If the current line is at the end of the buffer, we want to
440     ;; be able to insert past it, so we need to get an extra line
441     ;; at the end.
442 abakic 1.82 (end-of-line point)
443     (when (end-of-buffer-p point)
444 rstrandh 1.45 (insert-object point #\Newline))
445 abakic 1.82 (next-line point 0)
446 rstrandh 1.45 (insert-sequence point line)
447     (insert-object point #\Newline))))
448    
449 abridgewater 1.34 (define-named-command com-previous-line ()
450 rstrandh 1.80 (let* ((win (current-window))
451 rstrandh 1.49 (point (point win)))
452     (unless (or (eq (previous-command win) 'com-previous-line)
453     (eq (previous-command win) 'com-next-line))
454     (setf (slot-value win 'goal-column) (column-number point)))
455     (previous-line point (slot-value win 'goal-column))))
456 ejohnson 1.27
457 abridgewater 1.34 (define-named-command com-next-line ()
458 rstrandh 1.80 (let* ((win (current-window))
459 rstrandh 1.49 (point (point win)))
460     (unless (or (eq (previous-command win) 'com-previous-line)
461     (eq (previous-command win) 'com-next-line))
462     (setf (slot-value win 'goal-column) (column-number point)))
463     (next-line point (slot-value win 'goal-column))))
464 ejohnson 1.27
465 abridgewater 1.34 (define-named-command com-open-line ()
466 rstrandh 1.80 (open-line (point (current-window))))
467 ejohnson 1.27
468 rstrandh 1.110 (define-named-command com-kill-line ((numarg 'integer :prompt "Kill how many lines?")
469     (numargp 'boolean :prompt "Kill entire lines?"))
470 rstrandh 1.80 (let* ((pane (current-window))
471 ejohnson 1.54 (point (point pane))
472     (mark (offset point)))
473 rstrandh 1.110 (cond ((or numargp (> numarg 1))
474     (loop repeat numarg
475     until (end-of-buffer-p point)
476     do (end-of-line point)
477     until (end-of-buffer-p point)
478     do (forward-object point)))
479 ejohnson 1.56 (t
480 rstrandh 1.110 (cond ((end-of-buffer-p point) nil)
481     ((end-of-line-p point)(forward-object point))
482     (t (end-of-line point)))))
483     (unless (mark= point mark)
484     (if (eq (previous-command pane) 'com-kill-line)
485     (kill-ring-concatenating-push *kill-ring*
486     (region-to-sequence mark point))
487     (kill-ring-standard-push *kill-ring*
488     (region-to-sequence mark point)))
489     (delete-region mark point))))
490 ejohnson 1.27
491 rstrandh 1.102 (define-named-command com-forward-word ((count 'integer :prompt "Number of words"))
492     (forward-word (point (current-window)) count))
493 ejohnson 1.27
494 rstrandh 1.102 (define-named-command com-backward-word ((count 'integer :prompt "Number of words"))
495     (backward-word (point (current-window)) count))
496 ejohnson 1.27
497 rstrandh 1.103 (define-named-command com-delete-word ((count 'integer :prompt "Number of words"))
498     (delete-word (point (current-window)) count))
499 rstrandh 1.32
500 rstrandh 1.103 (define-named-command com-backward-delete-word ((count 'integer :prompt "Number of words"))
501     (backward-delete-word (point (current-window)) count))
502 rstrandh 1.32
503 mvilleneuve 1.64 (define-named-command com-upcase-region ()
504 abakic 1.101 (let ((cw (current-window)))
505     (upcase-region (mark cw) (point cw))))
506 mvilleneuve 1.64
507     (define-named-command com-downcase-region ()
508 abakic 1.101 (let ((cw (current-window)))
509     (downcase-region (mark cw) (point cw))))
510 mvilleneuve 1.64
511     (define-named-command com-capitalize-region ()
512 abakic 1.101 (let ((cw (current-window)))
513     (capitalize-region (mark cw) (point cw))))
514 mvilleneuve 1.64
515 rstrandh 1.60 (define-named-command com-upcase-word ()
516 rstrandh 1.80 (upcase-word (point (current-window))))
517 rstrandh 1.60
518     (define-named-command com-downcase-word ()
519 rstrandh 1.80 (downcase-word (point (current-window))))
520 rstrandh 1.60
521     (define-named-command com-capitalize-word ()
522 rstrandh 1.80 (capitalize-word (point (current-window))))
523 rstrandh 1.60
524 mvilleneuve 1.69 (define-named-command com-tabify-region ()
525 rstrandh 1.80 (let ((pane (current-window)))
526 mvilleneuve 1.69 (multiple-value-bind (start end) (region-limits pane)
527 rstrandh 1.70 (tabify-region start end (tab-space-count (stream-default-view pane))))))
528 mvilleneuve 1.69
529     (define-named-command com-untabify-region ()
530 rstrandh 1.80 (let ((pane (current-window)))
531 mvilleneuve 1.69 (multiple-value-bind (start end) (region-limits pane)
532 rstrandh 1.70 (untabify-region start end (tab-space-count (stream-default-view pane))))))
533 mvilleneuve 1.69
534 mvilleneuve 1.79 (defun indent-current-line (pane point)
535     (let* ((buffer (buffer pane))
536     (view (stream-default-view pane))
537     (tab-space-count (tab-space-count view))
538     (indentation (syntax-line-indentation point
539     tab-space-count
540     (syntax buffer))))
541     (indent-line point indentation (and (indent-tabs-mode buffer)
542     tab-space-count))))
543    
544     (define-named-command com-indent-line ()
545 rstrandh 1.80 (let* ((pane (current-window))
546 mvilleneuve 1.79 (point (point pane)))
547     (indent-current-line pane point)))
548    
549     (define-named-command com-newline-and-indent ()
550 rstrandh 1.80 (let* ((pane (current-window))
551 mvilleneuve 1.79 (point (point pane)))
552     (insert-object point #\Newline)
553     (indent-current-line pane point)))
554    
555 mvilleneuve 1.72 (define-named-command com-delete-indentation ()
556 rstrandh 1.80 (delete-indentation (point (current-window))))
557 ejohnson 1.27
558 mvilleneuve 1.86 (define-named-command com-auto-fill-mode ()
559 mvilleneuve 1.92 (let ((pane (current-window)))
560     (setf (auto-fill-mode pane) (not (auto-fill-mode pane)))))
561 mvilleneuve 1.86
562 mvilleneuve 1.90 (define-named-command com-fill-paragraph ()
563     (let* ((pane (current-window))
564     (buffer (buffer pane))
565     (syntax (syntax buffer))
566     (point (point pane))
567     (begin-mark (clone-mark point))
568     (end-mark (clone-mark point)))
569     (unless (eql (object-before begin-mark) #\Newline)
570     (beginning-of-paragraph begin-mark syntax))
571     (unless (eql (object-after end-mark) #\Newline)
572     (end-of-paragraph end-mark syntax))
573     (do-buffer-region (object offset buffer
574     (offset begin-mark) (offset end-mark))
575     (when (eql object #\Newline)
576     (setf object #\Space)))
577     (let ((point-backup (clone-mark point)))
578     (setf (offset point) (offset end-mark))
579     (possibly-fill-line)
580     (setf (offset point) (offset point-backup)))))
581    
582 ejohnson 1.27 (define-command com-extended-command ()
583     (let ((item (accept 'command :prompt "Extended Command")))
584     (execute-frame-command *application-frame* item)))
585    
586 rstrandh 1.41 (eval-when (:compile-toplevel :load-toplevel)
587 ejohnson 1.35 (define-presentation-type completable-pathname ()
588     :inherit-from 'pathname))
589 ejohnson 1.27
590     (defun filename-completer (so-far mode)
591     (flet ((remove-trail (s)
592     (subseq s 0 (let ((pos (position #\/ s :from-end t)))
593     (if pos (1+ pos) 0)))))
594     (let* ((directory-prefix
595     (if (and (plusp (length so-far)) (eql (aref so-far 0) #\/))
596     ""
597 rstrandh 1.78 (namestring #+sbcl *default-pathname-defaults*
598     #+cmu (ext:default-directory)
599     #-(or sbcl cmu) *default-pathname-defaults*)))
600 ejohnson 1.27 (full-so-far (concatenate 'string directory-prefix so-far))
601     (pathnames
602     (loop with length = (length full-so-far)
603     for path in (directory (concatenate 'string
604     (remove-trail so-far)
605     "*.*"))
606     when (let ((mismatch (mismatch (namestring path) full-so-far)))
607     (or (null mismatch) (= mismatch length)))
608     collect path))
609     (strings (mapcar #'namestring pathnames))
610     (first-string (car strings))
611     (length-common-prefix nil)
612     (completed-string nil)
613     (full-completed-string nil))
614     (unless (null pathnames)
615     (setf length-common-prefix
616     (loop with length = (length first-string)
617     for string in (cdr strings)
618     do (setf length (min length (or (mismatch string first-string) length)))
619     finally (return length))))
620     (unless (null pathnames)
621     (setf completed-string
622     (subseq first-string (length directory-prefix)
623     (if (null (cdr pathnames)) nil length-common-prefix)))
624     (setf full-completed-string
625     (concatenate 'string directory-prefix completed-string)))
626     (case mode
627     ((:complete-limited :complete-maximal)
628     (cond ((null pathnames)
629     (values so-far nil nil 0 nil))
630     ((null (cdr pathnames))
631     (values completed-string t (car pathnames) 1 nil))
632     (t
633     (values completed-string nil nil (length pathnames) nil))))
634     (:complete
635     (cond ((null pathnames)
636     (values so-far t so-far 1 nil))
637     ((null (cdr pathnames))
638     (values completed-string t (car pathnames) 1 nil))
639     ((find full-completed-string strings :test #'string-equal)
640     (let ((pos (position full-completed-string strings :test #'string-equal)))
641     (values completed-string
642     t (elt pathnames pos) (length pathnames) nil)))
643     (t
644     (values completed-string nil nil (length pathnames) nil))))
645     (:possibilities
646     (values nil nil nil (length pathnames)
647     (loop with length = (length directory-prefix)
648     for name in pathnames
649     collect (list (subseq (namestring name) length nil)
650     name))))))))
651    
652     (define-presentation-method accept
653     ((type completable-pathname) stream (view textual-view) &key)
654     (multiple-value-bind (pathname success string)
655     (complete-input stream
656     #'filename-completer
657     :partial-completers '(#\Space)
658     :allow-any-input t)
659     (declare (ignore success))
660     (or pathname string)))
661    
662     (defun pathname-filename (pathname)
663     (if (null (pathname-type pathname))
664     (pathname-name pathname)
665     (concatenate 'string (pathname-name pathname)
666     "." (pathname-type pathname))))
667    
668 abridgewater 1.34 (define-named-command com-find-file ()
669 ejohnson 1.27 (let ((filename (accept 'completable-pathname
670 rstrandh 1.70 :prompt "Find File"))
671     (buffer (make-instance 'climacs-buffer))
672 rstrandh 1.80 (pane (current-window)))
673 rstrandh 1.75 (push buffer (buffers *application-frame*))
674 rstrandh 1.80 (setf (buffer (current-window)) buffer)
675 rstrandh 1.106 (setf (syntax buffer) (make-instance 'basic-syntax :buffer buffer))
676 rstrandh 1.84 ;; Don't want to create the file if it doesn't exist.
677     (when (probe-file filename)
678     (with-open-file (stream filename :direction :input)
679     (input-from-stream stream buffer 0)))
680 rstrandh 1.70 (setf (filename buffer) filename
681     (name buffer) (pathname-filename filename)
682     (needs-saving buffer) nil)
683     (beginning-of-buffer (point pane))
684     ;; this one is needed so that the buffer modification protocol
685     ;; resets the low and high marks after redisplay
686     (redisplay-frame-panes *application-frame*)))
687 ejohnson 1.27
688 rstrandh 1.93 (defun save-buffer (buffer)
689     (let ((filename (or (filename buffer)
690     (accept 'completable-pathname
691     :prompt "Save Buffer to File"))))
692     (with-open-file (stream filename :direction :output :if-exists :supersede)
693     (output-to-stream stream buffer 0 (size buffer)))
694     (setf (filename buffer) filename
695     (name buffer) (pathname-filename filename))
696     (display-message "Wrote: ~a" (filename buffer))
697     (setf (needs-saving buffer) nil)))
698    
699 abridgewater 1.34 (define-named-command com-save-buffer ()
700 rstrandh 1.93 (let ((buffer (buffer (current-window))))
701 rstrandh 1.30 (if (or (null (filename buffer))
702     (needs-saving buffer))
703 rstrandh 1.93 (save-buffer buffer)
704     (display-message "No changes need to be saved from ~a" (name buffer)))))
705    
706     (define-named-command (com-quit) ()
707     (loop for buffer in (buffers *application-frame*)
708     when (and (needs-saving buffer)
709     (accept 'boolean
710     :prompt (format nil "Save buffer: ~a ?" (name buffer))))
711     do (save-buffer buffer))
712     (when (or (notany #'needs-saving
713     (buffers *application-frame*))
714     (accept 'boolean :prompt "Modified buffers exist. Quit anyway?"))
715     (frame-exit *application-frame*)))
716 ejohnson 1.27
717 abridgewater 1.34 (define-named-command com-write-buffer ()
718 ejohnson 1.27 (let ((filename (accept 'completable-pathname
719     :prompt "Write Buffer to File"))
720 rstrandh 1.80 (buffer (buffer (current-window))))
721 ejohnson 1.27 (with-open-file (stream filename :direction :output :if-exists :supersede)
722     (output-to-stream stream buffer 0 (size buffer)))
723     (setf (filename buffer) filename
724 rstrandh 1.28 (name buffer) (pathname-filename filename)
725 rstrandh 1.30 (needs-saving buffer) nil)
726     (display-message "Wrote: ~a" (filename buffer))))
727 ejohnson 1.27
728 rstrandh 1.75 (define-presentation-method accept
729     ((type buffer) stream (view textual-view) &key)
730     (multiple-value-bind (object success string)
731     (complete-input stream
732     (lambda (so-far action)
733     (complete-from-possibilities
734     so-far (buffers *application-frame*) '() :action action
735     :name-key #'name
736     :value-key #'identity))
737     :partial-completers '(#\Space)
738     :allow-any-input t)
739 rstrandh 1.76 (declare (ignore success))
740     (or object
741     (car (push (make-instance 'climacs-buffer :name string)
742     (buffers *application-frame*))))))
743 rstrandh 1.75
744     (define-named-command com-switch-to-buffer ()
745     (let ((buffer (accept 'buffer
746     :prompt "Switch to buffer")))
747 rstrandh 1.80 (setf (buffer (current-window)) buffer)
748 rstrandh 1.106 (setf (syntax buffer) (make-instance 'basic-syntax :buffer buffer))
749 rstrandh 1.80 (beginning-of-buffer (point (current-window)))
750     (full-redisplay (current-window))))
751 rstrandh 1.75
752 rstrandh 1.91 (define-named-command com-kill-buffer ()
753     (with-slots (buffers) *application-frame*
754     (let ((buffer (buffer (current-window))))
755     (when (and (needs-saving buffer)
756     (accept 'boolean :prompt "Save buffer first?"))
757     (com-save-buffer))
758     (setf buffers (remove buffer buffers))
759     ;; Always need one buffer.
760     (when (null buffers)
761     (push (make-instance 'climacs-buffer :name "*scratch*")
762     buffers))
763     (setf (buffer (current-window)) (car buffers)))))
764    
765 rstrandh 1.75 (define-named-command com-full-redisplay ()
766 rstrandh 1.80 (full-redisplay (current-window)))
767 rstrandh 1.75
768 rstrandh 1.63 (define-named-command com-load-file ()
769     (let ((filename (accept 'completable-pathname
770     :prompt "Load File")))
771     (load filename)))
772    
773 abridgewater 1.34 (define-named-command com-beginning-of-buffer ()
774 rstrandh 1.80 (beginning-of-buffer (point (current-window))))
775 ejohnson 1.27
776 rstrandh 1.39 (define-named-command com-page-down ()
777 rstrandh 1.80 (let ((pane (current-window)))
778 rstrandh 1.70 (page-down pane)))
779 rstrandh 1.39
780 rstrandh 1.40 (define-named-command com-page-up ()
781 rstrandh 1.80 (let ((pane (current-window)))
782 rstrandh 1.70 (page-up pane)))
783 rstrandh 1.40
784 abridgewater 1.34 (define-named-command com-end-of-buffer ()
785 rstrandh 1.80 (end-of-buffer (point (current-window))))
786 ejohnson 1.27
787 abridgewater 1.34 (define-named-command com-back-to-indentation ()
788 rstrandh 1.80 (let ((point (point (current-window))))
789 rstrandh 1.32 (beginning-of-line point)
790     (loop until (end-of-line-p point)
791     while (whitespacep (object-after point))
792     do (incf (offset point)))))
793    
794 abridgewater 1.34 (define-named-command com-goto-position ()
795 rstrandh 1.80 (setf (offset (point (current-window)))
796 rstrandh 1.32 (accept 'integer :prompt "Goto Position")))
797    
798 abridgewater 1.34 (define-named-command com-goto-line ()
799 abakic 1.99 (loop with mark = (make-instance 'standard-right-sticky-mark ;PB
800 rstrandh 1.80 :buffer (buffer (current-window)))
801 rstrandh 1.32 do (end-of-line mark)
802     until (end-of-buffer-p mark)
803     repeat (accept 'integer :prompt "Goto Line")
804     do (incf (offset mark))
805     (end-of-line mark)
806     finally (beginning-of-line mark)
807 rstrandh 1.80 (setf (offset (point (current-window)))
808 rstrandh 1.32 (offset mark))))
809    
810 abridgewater 1.34 (define-named-command com-browse-url ()
811 ejohnson 1.27 (accept 'url :prompt "Browse URL"))
812    
813 abridgewater 1.34 (define-named-command com-set-mark ()
814 rstrandh 1.80 (let ((pane (current-window)))
815 rstrandh 1.70 (setf (mark pane) (clone-mark (point pane)))))
816 rstrandh 1.45
817     (define-named-command com-exchange-point-and-mark ()
818 rstrandh 1.80 (let ((pane (current-window)))
819 rstrandh 1.70 (psetf (offset (mark pane)) (offset (point pane))
820     (offset (point pane)) (offset (mark pane)))))
821 rstrandh 1.38
822     (define-named-command com-set-syntax ()
823 rstrandh 1.80 (let* ((pane (current-window))
824 rstrandh 1.67 (buffer (buffer pane)))
825 rstrandh 1.70 (setf (syntax buffer)
826 rstrandh 1.106 (make-instance (accept 'syntax :prompt "Set Syntax")
827     :buffer buffer))
828 rstrandh 1.67 (setf (offset (low-mark buffer)) 0
829     (offset (high-mark buffer)) (size buffer))))
830 ejohnson 1.27
831 rstrandh 1.77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
832     ;;;
833 rstrandh 1.85 ;;; Keyboard macros
834    
835     (define-named-command com-start-kbd-macro ()
836     (setf (recordingp *application-frame*) t)
837     (setf (recorded-keys *application-frame*) '()))
838    
839     (define-named-command com-end-kbd-macro ()
840     (setf (recordingp *application-frame*) nil)
841     (setf (recorded-keys *application-frame*)
842     ;; this won't work if the command was invoked in any old way
843     (reverse (cddr (recorded-keys *application-frame*)))))
844    
845     (define-named-command com-call-last-kbd-macro ()
846     (setf (remaining-keys *application-frame*)
847     (recorded-keys *application-frame*))
848     (setf (executingp *application-frame*) t))
849    
850     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
851     ;;;
852 rstrandh 1.77 ;;; Commands for splitting windows
853    
854 rstrandh 1.91 ;;; put this in for real when we find a solution for the problem
855     ;;; it causes for com-delete-window
856     ;; (defun replace-constellation (constellation additional-constellation vertical-p)
857     ;; (let* ((parent (sheet-parent constellation))
858     ;; (children (sheet-children parent))
859     ;; (first (first children))
860     ;; (second (second children))
861     ;; (adjust (make-pane 'clim-extensions:box-adjuster-gadget)))
862     ;; (assert (member constellation children))
863     ;; (cond ((eq constellation first)
864     ;; (sheet-disown-child parent constellation)
865     ;; (let ((new (if vertical-p
866     ;; (vertically ()
867     ;; constellation adjust additional-constellation)
868     ;; (horizontally ()
869     ;; constellation adjust additional-constellation))))
870     ;; (sheet-adopt-child parent new)
871     ;; (reorder-sheets parent (list new second))))
872     ;; (t
873     ;; (sheet-disown-child parent constellation)
874     ;; (let ((new (if vertical-p
875     ;; (vertically ()
876     ;; constellation adjust additional-constellation)
877     ;; (horizontally ()
878     ;; constellation adjust additional-constellation))))
879     ;; (sheet-adopt-child parent new)
880     ;; (reorder-sheets parent (list first new)))))))
881    
882 rstrandh 1.83 (defun replace-constellation (constellation additional-constellation vertical-p)
883     (let* ((parent (sheet-parent constellation))
884     (children (sheet-children parent))
885     (first (first children))
886     (second (second children)))
887     (assert (member constellation children))
888     (cond ((eq constellation first)
889     (sheet-disown-child parent constellation)
890     (let ((new (if vertical-p
891     (vertically () constellation additional-constellation)
892     (horizontally () constellation additional-constellation))))
893     (sheet-adopt-child parent new)
894     (reorder-sheets parent (list new second))))
895     (t
896     (sheet-disown-child parent constellation)
897     (let ((new (if vertical-p
898     (vertically () constellation additional-constellation)
899     (horizontally () constellation additional-constellation))))
900     (sheet-adopt-child parent new)
901     (reorder-sheets parent (list first new)))))))
902    
903     (defun parent3 (sheet)
904     (sheet-parent (sheet-parent (sheet-parent sheet))))
905    
906     (defun make-pane-constellation ()
907     "make a vbox containing a scroller pane as its first child and an
908     info pane as its second child. The scroller pane contains a viewport
909     which contains an extended pane. Return the vbox and the extended pane
910     as two values"
911     (let* ((extended-pane
912     (make-pane 'extended-pane
913     :width 900 :height 400
914     :name 'win
915     :incremental-redisplay t
916     :display-function 'display-win))
917     (vbox
918     (vertically ()
919     (scrolling () extended-pane)
920     (make-pane 'info-pane
921     :climacs-pane extended-pane
922     :width 900 :height 20
923     :max-height 20 :min-height 20
924     ::background +gray85+
925     :scroll-bars nil
926     :borders nil
927     :incremental-redisplay t
928     :display-function 'display-info))))
929     (values vbox extended-pane)))
930    
931 rstrandh 1.77 (define-named-command com-split-window-vertically ()
932     (with-look-and-feel-realization
933     ((frame-manager *application-frame*) *application-frame*)
934 rstrandh 1.83 (multiple-value-bind (vbox new-pane) (make-pane-constellation)
935     (let* ((current-window (current-window))
936     (constellation-root (parent3 current-window)))
937 mvilleneuve 1.95 (setf (buffer new-pane) (buffer current-window)
938     (auto-fill-mode new-pane) (auto-fill-mode current-window)
939     (auto-fill-column new-pane) (auto-fill-column current-window))
940 rstrandh 1.83 (push new-pane (windows *application-frame*))
941     (replace-constellation constellation-root vbox t)
942     (full-redisplay current-window)
943     (full-redisplay new-pane)))))
944    
945     (define-named-command com-split-window-horizontally ()
946     (with-look-and-feel-realization
947     ((frame-manager *application-frame*) *application-frame*)
948     (multiple-value-bind (vbox new-pane) (make-pane-constellation)
949     (let* ((current-window (current-window))
950     (constellation-root (parent3 current-window)))
951 mvilleneuve 1.95 (setf (buffer new-pane) (buffer current-window)
952     (auto-fill-mode new-pane) (auto-fill-mode current-window)
953     (auto-fill-column new-pane) (auto-fill-column current-window))
954 rstrandh 1.83 (push new-pane (windows *application-frame*))
955     (replace-constellation constellation-root vbox nil)
956     (full-redisplay current-window)
957     (full-redisplay new-pane)))))
958    
959     (define-named-command com-other-window ()
960     (setf (windows *application-frame*)
961     (append (cdr (windows *application-frame*))
962     (list (car (windows *application-frame*))))))
963    
964     (define-named-command com-delete-window ()
965     (unless (null (cdr (windows *application-frame*)))
966     (let* ((constellation (parent3 (current-window)))
967     (box (sheet-parent constellation))
968     (box-children (sheet-children box))
969     (other (if (eq constellation (first box-children))
970     (second box-children)
971     (first box-children)))
972     (parent (sheet-parent box))
973     (children (sheet-children parent))
974     (first (first children))
975     (second (second children)))
976     (pop (windows *application-frame*))
977     (sheet-disown-child box other)
978     (cond ((eq box first)
979     (sheet-disown-child parent box)
980     (sheet-adopt-child parent other)
981     (reorder-sheets parent (list other second)))
982     (t
983     (sheet-disown-child parent box)
984     (sheet-adopt-child parent other)
985     (reorder-sheets parent (list first other)))))))
986 rstrandh 1.77
987 ejohnson 1.107
988     (define-named-command com-single-window ()
989     (unless (null (cdr (windows *application-frame*)))
990     (let* ((saver (parent3 (current-window)))
991     (top-level (do
992 ejohnson 1.108 ((n saver (setf n (sheet-parent n))))
993 ejohnson 1.107 ((clim-internals::top-level-sheet-pane-p n) n)))
994     (level1 (car (sheet-children top-level))) ;; should be the only thing on level1
995     (level2 (if (typep (car (sheet-children level1)) 'vrack-pane) ;;don't select raised pane
996     (car (sheet-children level1))
997     (cadr (sheet-children level1))))
998     (level2-children (sheet-children level2))
999     (junker (if (typep (car level2-children) 'vrack-pane) ;;don't select minibuffer
1000     (car level2-children)
1001     (cadr level2-children))))
1002     (sheet-disown-child (sheet-parent saver) saver)
1003     (sheet-disown-child level2 junker)
1004     (sheet-adopt-child level2 saver)
1005     (reorder-sheets level2 (reverse (sheet-children level2))) ;;minibuffer goes on bottom
1006     (setf (windows *application-frame*) (list (car (windows *application-frame*)))))))
1007    
1008    
1009 rstrandh 1.94 ;; (define-named-command com-delete-window ()
1010     ;; (unless (null (cdr (windows *application-frame*)))
1011     ;; (let* ((constellation (parent3 (current-window)))
1012     ;; (box (sheet-parent constellation))
1013     ;; (box-children (sheet-children box))
1014     ;; (other (if (eq constellation (first box-children))
1015     ;; (third box-children)
1016     ;; (first box-children)))
1017     ;; (parent (sheet-parent box))
1018     ;; (children (sheet-children parent))
1019     ;; (first (first children))
1020     ;; (second (second children))
1021     ;; (third (third children)))
1022     ;; (pop (windows *application-frame*))
1023     ;; (sheet-disown-child box other)
1024     ;; (cond ((eq box first)
1025     ;; (sheet-disown-child parent box)
1026     ;; (sheet-adopt-child parent other)
1027     ;; (reorder-sheets parent (list other second third)))
1028     ;; (t
1029     ;; (sheet-disown-child parent box)
1030     ;; (sheet-adopt-child parent other)
1031     ;; (reorder-sheets parent (list first second other)))))))
1032    
1033 ejohnson 1.27 ;;;;;;;;;;;;;;;;;;;;
1034     ;; Kill ring commands
1035    
1036 ejohnson 1.31 ;; Copies an element from a kill-ring to a buffer at the given offset
1037 ejohnson 1.50 (define-named-command com-yank ()
1038 rstrandh 1.80 (insert-sequence (point (current-window)) (kill-ring-yank *kill-ring*)))
1039 ejohnson 1.27
1040 ejohnson 1.31 ;; Destructively cut a given buffer region into the kill-ring
1041 abridgewater 1.34 (define-named-command com-cut-out ()
1042 rstrandh 1.80 (multiple-value-bind (start end) (region-limits (current-window))
1043 mvilleneuve 1.64 (kill-ring-standard-push *kill-ring* (region-to-sequence start end))
1044     (delete-region (offset start) end)))
1045 ejohnson 1.27
1046 ejohnson 1.31 ;; Non destructively copies in buffer region to the kill ring
1047 abridgewater 1.34 (define-named-command com-copy-out ()
1048 rstrandh 1.80 (let ((pane (current-window)))
1049 rstrandh 1.70 (kill-ring-standard-push *kill-ring* (region-to-sequence (point pane) (mark pane)))))
1050 ejohnson 1.27
1051 ejohnson 1.50 (define-named-command com-rotate-yank ()
1052 rstrandh 1.80 (let* ((pane (current-window))
1053 ejohnson 1.54 (point (point pane))
1054 ejohnson 1.50 (last-yank (kill-ring-yank *kill-ring*)))
1055 ejohnson 1.54 (if (eq (previous-command pane)
1056 ejohnson 1.50 'com-rotate-yank)
1057 ejohnson 1.54 (progn
1058     (delete-range point (* -1 (length last-yank)))
1059     (rotate-yank-position *kill-ring*)))
1060     (insert-sequence point (kill-ring-yank *kill-ring*))))
1061 ejohnson 1.27
1062 ejohnson 1.50 (define-named-command com-resize-kill-ring ()
1063 ejohnson 1.46 (let ((size (accept 'integer :prompt "New kill ring size")))
1064 ejohnson 1.50 (setf (kill-ring-max-size *kill-ring*) size)))
1065 rstrandh 1.47
1066 mvilleneuve 1.96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1067     ;;;
1068     ;;; Incremental search
1069    
1070 mvilleneuve 1.97 (defun isearch-command-loop (pane forwardp)
1071     (let ((point (point pane)))
1072 mvilleneuve 1.96 (unless (endp (isearch-states pane))
1073     (setf (isearch-previous-string pane)
1074     (search-string (first (isearch-states pane)))))
1075     (setf (isearch-mode pane) t)
1076     (setf (isearch-states pane)
1077     (list (make-instance 'isearch-state
1078     :search-string ""
1079 mvilleneuve 1.97 :search-mark (clone-mark point)
1080 mvilleneuve 1.105 :search-forward-p forwardp
1081     :search-success-p t)))
1082 mvilleneuve 1.100 (simple-command-loop 'isearch-climacs-table
1083     (isearch-mode pane)
1084     ((setf (isearch-mode pane) nil)))))
1085 mvilleneuve 1.96
1086 mvilleneuve 1.97 (defun isearch-from-mark (pane mark string forwardp)
1087     (flet ((object-equal (x y)
1088     (if (characterp x)
1089     (and (characterp y) (char-equal x y))
1090     (eql x y))))
1091     (let* ((point (point pane))
1092     (mark2 (clone-mark mark))
1093     (success (funcall (if forwardp #'search-forward #'search-backward)
1094     mark2
1095     string
1096     :test #'object-equal)))
1097 mvilleneuve 1.105 (when success
1098     (setf (offset point) (offset mark2)
1099     (offset mark) (if forwardp
1100     (- (offset mark2) (length string))
1101     (+ (offset mark2) (length string)))))
1102     (push (make-instance 'isearch-state
1103     :search-string string
1104     :search-mark mark
1105     :search-forward-p forwardp
1106     :search-success-p success)
1107     (isearch-states pane))
1108     (unless success
1109     (beep)))))
1110 mvilleneuve 1.97
1111     (define-named-command com-isearch-mode-forward ()
1112     (isearch-command-loop (current-window) t))
1113    
1114     (define-named-command com-isearch-mode-backward ()
1115     (isearch-command-loop (current-window) nil))
1116 mvilleneuve 1.96
1117     (define-named-command com-isearch-append-char ()
1118     (let* ((pane (current-window))
1119     (states (isearch-states pane))
1120     (string (concatenate 'string
1121     (search-string (first states))
1122     (string *current-gesture*)))
1123     (mark (clone-mark (search-mark (first states))))
1124 mvilleneuve 1.97 (forwardp (search-forward-p (first states))))
1125     (unless forwardp
1126     (incf (offset mark)))
1127     (isearch-from-mark pane mark string forwardp)))
1128 mvilleneuve 1.96
1129     (define-named-command com-isearch-delete-char ()
1130     (let* ((pane (current-window)))
1131     (cond ((null (second (isearch-states pane)))
1132     (beep))
1133     (t
1134     (pop (isearch-states pane))
1135 mvilleneuve 1.105 (loop until (endp (rest (isearch-states pane)))
1136     until (search-success-p (first (isearch-states pane)))
1137     do (pop (isearch-states pane)))
1138 mvilleneuve 1.96 (let ((state (first (isearch-states pane))))
1139     (setf (offset (point pane))
1140 mvilleneuve 1.97 (if (search-forward-p state)
1141     (+ (offset (search-mark state))
1142     (length (search-string state)))
1143     (- (offset (search-mark state))
1144     (length (search-string state))))))))))
1145 mvilleneuve 1.96
1146     (define-named-command com-isearch-forward ()
1147     (let* ((pane (current-window))
1148     (point (point pane))
1149     (states (isearch-states pane))
1150     (string (if (null (second states))
1151     (isearch-previous-string pane)
1152     (search-string (first states))))
1153 mvilleneuve 1.97 (mark (clone-mark point)))
1154     (isearch-from-mark pane mark string t)))
1155    
1156     (define-named-command com-isearch-backward ()
1157     (let* ((pane (current-window))
1158     (point (point pane))
1159     (states (isearch-states pane))
1160     (string (if (null (second states))
1161     (isearch-previous-string pane)
1162     (search-string (first states))))
1163     (mark (clone-mark point)))
1164     (isearch-from-mark pane mark string nil)))
1165 mvilleneuve 1.96
1166     (define-named-command com-isearch-exit ()
1167     (setf (isearch-mode (current-window)) nil))
1168    
1169 mvilleneuve 1.100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1170     ;;;
1171     ;;; Query replace
1172    
1173     (defun query-replace-find-next-match (mark string)
1174 mvilleneuve 1.104 (flet ((object-equal (x y)
1175     (and (characterp x)
1176     (characterp y)
1177     (char-equal x y))))
1178     (let ((offset-before (offset mark)))
1179     (search-forward mark string :test #'object-equal)
1180     (/= (offset mark) offset-before))))
1181 mvilleneuve 1.100
1182     (define-named-command com-query-replace ()
1183     (let* ((string1 (accept 'string :prompt "Query replace"))
1184     (string2 (accept 'string
1185     :prompt (format nil "Query replace ~A with"
1186     string1)))
1187     (pane (current-window))
1188     (point (point pane)))
1189     (when (query-replace-find-next-match point string1)
1190     (setf (query-replace-state pane) (make-instance 'query-replace-state
1191     :string1 string1
1192     :string2 string2)
1193     (query-replace-mode pane) t)
1194     (simple-command-loop 'query-replace-climacs-table
1195     (query-replace-mode pane)
1196     ((setf (query-replace-mode pane) nil))))))
1197    
1198     (define-named-command com-query-replace-replace ()
1199     (let* ((pane (current-window))
1200     (point (point pane))
1201 mvilleneuve 1.104 (buffer (buffer pane))
1202 mvilleneuve 1.100 (state (query-replace-state pane))
1203     (string1-length (length (string1 state))))
1204     (backward-object point string1-length)
1205 mvilleneuve 1.104 (let* ((offset1 (offset point))
1206     (offset2 (+ offset1 string1-length))
1207     (region-case (buffer-region-case buffer offset1 offset2)))
1208     (delete-range point string1-length)
1209     (insert-sequence point (string2 state))
1210     (setf offset2 (+ offset1 (length (string2 state))))
1211     (finish-output *error-output*)
1212     (case region-case
1213     (:upper-case (upcase-buffer-region buffer offset1 offset2))
1214     (:lower-case (downcase-buffer-region buffer offset1 offset2))
1215     (:capitalized (capitalize-buffer-region buffer offset1 offset2))))
1216 mvilleneuve 1.100 (unless (query-replace-find-next-match point (string1 state))
1217     (setf (query-replace-mode pane) nil))))
1218    
1219     (define-named-command com-query-replace-skip ()
1220     (let* ((pane (current-window))
1221     (point (point pane))
1222     (state (query-replace-state pane)))
1223     (unless (query-replace-find-next-match point (string1 state))
1224     (setf (query-replace-mode pane) nil))))
1225    
1226     (define-named-command com-query-replace-exit ()
1227     (setf (query-replace-mode (current-window)) nil))
1228    
1229     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1230     ;;;
1231     ;;; Undo/redo
1232    
1233 rstrandh 1.98 (define-named-command com-undo ()
1234     (undo (undo-tree (buffer (current-window)))))
1235    
1236     (define-named-command com-redo ()
1237     (redo (undo-tree (buffer (current-window)))))
1238    
1239 mvilleneuve 1.96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1240     ;;;
1241     ;;; Dynamic abbrevs
1242 ejohnson 1.27
1243 rstrandh 1.49 (define-named-command com-dabbrev-expand ()
1244 rstrandh 1.80 (let* ((win (current-window))
1245 rstrandh 1.49 (point (point win)))
1246     (with-slots (original-prefix prefix-start-offset dabbrev-expansion-mark) win
1247     (flet ((move () (cond ((beginning-of-buffer-p dabbrev-expansion-mark)
1248     (setf (offset dabbrev-expansion-mark)
1249     (offset point))
1250     (forward-word dabbrev-expansion-mark))
1251     ((mark< dabbrev-expansion-mark point)
1252     (backward-object dabbrev-expansion-mark))
1253     (t (forward-object dabbrev-expansion-mark)))))
1254     (unless (or (beginning-of-buffer-p point)
1255     (not (constituentp (object-before point))))
1256     (unless (and (eq (previous-command win) 'com-dabbrev-expand)
1257     (not (null prefix-start-offset)))
1258     (setf dabbrev-expansion-mark (clone-mark point))
1259     (backward-word dabbrev-expansion-mark)
1260     (setf prefix-start-offset (offset dabbrev-expansion-mark))
1261     (setf original-prefix (region-to-sequence prefix-start-offset point))
1262     (move))
1263     (loop until (or (end-of-buffer-p dabbrev-expansion-mark)
1264     (and (or (beginning-of-buffer-p dabbrev-expansion-mark)
1265     (not (constituentp (object-before dabbrev-expansion-mark))))
1266     (looking-at dabbrev-expansion-mark original-prefix)))
1267     do (move))
1268     (if (end-of-buffer-p dabbrev-expansion-mark)
1269     (progn (delete-region prefix-start-offset point)
1270     (insert-sequence point original-prefix)
1271     (setf prefix-start-offset nil))
1272     (progn (delete-region prefix-start-offset point)
1273     (insert-sequence point
1274     (let ((offset (offset dabbrev-expansion-mark)))
1275     (prog2 (forward-word dabbrev-expansion-mark)
1276     (region-to-sequence offset dabbrev-expansion-mark)
1277     (setf (offset dabbrev-expansion-mark) offset))))
1278     (move))))))))
1279    
1280 rstrandh 1.71 (define-named-command com-beginning-of-paragraph ()
1281 rstrandh 1.80 (let* ((pane (current-window))
1282 rstrandh 1.71 (point (point pane))
1283     (syntax (syntax (buffer pane))))
1284     (beginning-of-paragraph point syntax)))
1285    
1286     (define-named-command com-end-of-paragraph ()
1287 rstrandh 1.80 (let* ((pane (current-window))
1288 rstrandh 1.71 (point (point pane))
1289     (syntax (syntax (buffer pane))))
1290     (end-of-paragraph point syntax)))
1291 rstrandh 1.106
1292     (define-named-command com-backward-to-error ()
1293     (let* ((pane (current-window))
1294     (point (point pane))
1295     (syntax (syntax (buffer pane))))
1296     (display-message "~a" (backward-to-error point syntax))))
1297    
1298     (define-named-command com-forward-to-error ()
1299     (let* ((pane (current-window))
1300     (point (point pane))
1301     (syntax (syntax (buffer pane))))
1302     (display-message "~a" (forward-to-error point syntax))))
1303 rstrandh 1.71
1304 rstrandh 1.109 (define-named-command com-eval-expression ((insertp 'boolean :prompt "Insert?"))
1305     (let* ((*package* (find-package :climacs-gui))
1306     (string (accept 'string :prompt "Eval"))
1307     (result (format nil "~a" (eval (read-from-string string)))))
1308     (if insertp
1309     (insert-sequence (point (current-window)) result)
1310     (display-message result))))
1311    
1312 ejohnson 1.27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1313     ;;;
1314 rstrandh 1.80 ;;; Global and dead-escape command tables
1315 ejohnson 1.27
1316     (make-command-table 'global-climacs-table :errorp nil)
1317    
1318 rstrandh 1.80 (make-command-table 'dead-escape-climacs-table :errorp nil)
1319    
1320     (add-menu-item-to-command-table 'global-climacs-table "dead-escape"
1321     :menu 'dead-escape-climacs-table
1322     :keystroke '(:escape))
1323    
1324     (defun dead-escape-set-key (gesture command)
1325     (add-command-to-command-table command 'dead-escape-climacs-table
1326     :keystroke gesture :errorp nil))
1327    
1328 ejohnson 1.27 (defun global-set-key (gesture command)
1329     (add-command-to-command-table command 'global-climacs-table
1330 rstrandh 1.80 :keystroke gesture :errorp nil)
1331     (when (and
1332     (listp gesture)
1333     (find :meta gesture))
1334     (dead-escape-set-key (remove :meta gesture) command)))
1335 ejohnson 1.27
1336 mvilleneuve 1.89 (loop for code from (char-code #\Space) to (char-code #\~)
1337 ejohnson 1.27 do (global-set-key (code-char code) 'com-self-insert))
1338    
1339 mvilleneuve 1.89 (global-set-key #\Newline 'com-self-insert)
1340 mvilleneuve 1.86 (global-set-key #\Tab 'com-indent-line)
1341 rstrandh 1.109 (global-set-key '(#\: :shift :meta) `(com-eval-expression ,*numeric-argument-p*))
1342 mvilleneuve 1.79 (global-set-key '(#\j :control) 'com-newline-and-indent)
1343 rstrandh 1.62 (global-set-key '(#\f :control) `(com-forward-object ,*numeric-argument-marker*))
1344     (global-set-key '(#\b :control) `(com-backward-object ,*numeric-argument-marker*))
1345 ejohnson 1.27 (global-set-key '(#\a :control) 'com-beginning-of-line)
1346     (global-set-key '(#\e :control) 'com-end-of-line)
1347 rstrandh 1.62 (global-set-key '(#\d :control) `(com-delete-object ,*numeric-argument-marker*))
1348 ejohnson 1.27 (global-set-key '(#\p :control) 'com-previous-line)
1349 rstrandh 1.75 (global-set-key '(#\l :control) 'com-full-redisplay)
1350 ejohnson 1.27 (global-set-key '(#\n :control) 'com-next-line)
1351     (global-set-key '(#\o :control) 'com-open-line)
1352 rstrandh 1.110 (global-set-key '(#\k :control) `(com-kill-line ,*numeric-argument-marker* ,*numeric-argument-p*))
1353 rstrandh 1.42 (global-set-key '(#\t :control) 'com-transpose-objects)
1354 ejohnson 1.27 (global-set-key '(#\Space :control) 'com-set-mark)
1355 ejohnson 1.50 (global-set-key '(#\y :control) 'com-yank)
1356 ejohnson 1.27 (global-set-key '(#\w :control) 'com-cut-out)
1357 rstrandh 1.102 (global-set-key '(#\f :meta) `(com-forward-word ,*numeric-argument-marker*))
1358     (global-set-key '(#\b :meta) `(com-backward-word ,*numeric-argument-marker*))
1359 rstrandh 1.43 (global-set-key '(#\t :meta) 'com-transpose-words)
1360 rstrandh 1.60 (global-set-key '(#\u :meta) 'com-upcase-word)
1361     (global-set-key '(#\l :meta) 'com-downcase-word)
1362     (global-set-key '(#\c :meta) 'com-capitalize-word)
1363 ejohnson 1.27 (global-set-key '(#\x :meta) 'com-extended-command)
1364 ejohnson 1.50 (global-set-key '(#\y :meta) 'com-rotate-yank)
1365 ejohnson 1.27 (global-set-key '(#\w :meta) 'com-copy-out)
1366 rstrandh 1.39 (global-set-key '(#\v :control) 'com-page-down)
1367 rstrandh 1.40 (global-set-key '(#\v :meta) 'com-page-up)
1368 ejohnson 1.27 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
1369     (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
1370 rstrandh 1.32 (global-set-key '(#\m :meta) 'com-back-to-indentation)
1371 mvilleneuve 1.74 (global-set-key '(#\^ :shift :meta) 'com-delete-indentation)
1372 mvilleneuve 1.90 (global-set-key '(#\q :meta) 'com-fill-paragraph)
1373 rstrandh 1.103 (global-set-key '(#\d :meta) `(com-delete-word ,*numeric-argument-marker*))
1374     (global-set-key '(#\Backspace :meta) `(com-backward-delete-word ,*numeric-argument-marker*))
1375 rstrandh 1.49 (global-set-key '(#\/ :meta) 'com-dabbrev-expand)
1376 rstrandh 1.71 (global-set-key '(#\a :control :meta) 'com-beginning-of-paragraph)
1377     (global-set-key '(#\e :control :meta) 'com-end-of-paragraph)
1378 mvilleneuve 1.97 (global-set-key '(#\s :control) 'com-isearch-mode-forward)
1379     (global-set-key '(#\r :control) 'com-isearch-mode-backward)
1380 mvilleneuve 1.100 (global-set-key '(#\% :shift :meta) 'com-query-replace)
1381 ejohnson 1.27
1382     (global-set-key '(:up) 'com-previous-line)
1383     (global-set-key '(:down) 'com-next-line)
1384 rstrandh 1.62 (global-set-key '(:left) `(com-backward-object ,*numeric-argument-marker*))
1385 ejohnson 1.66 (global-set-key '(:right) `(com-forward-object ,*numeric-argument-marker*))
1386 rstrandh 1.102 (global-set-key '(:left :control) `(com-backward-word ,*numeric-argument-marker*))
1387     (global-set-key '(:right :control) `(com-forward-word ,*numeric-argument-marker*))
1388 ejohnson 1.27 (global-set-key '(:home) 'com-beginning-of-line)
1389     (global-set-key '(:end) 'com-end-of-line)
1390 abridgewater 1.57 (global-set-key '(:prior) 'com-page-up)
1391     (global-set-key '(:next) 'com-page-down)
1392 ejohnson 1.27 (global-set-key '(:home :control) 'com-beginning-of-buffer)
1393     (global-set-key '(:end :control) 'com-end-of-buffer)
1394 rstrandh 1.62 (global-set-key #\Rubout `(com-delete-object ,*numeric-argument-marker*))
1395     (global-set-key #\Backspace `(com-backward-delete-object ,*numeric-argument-marker*))
1396 abakic 1.58
1397     (global-set-key '(:insert) 'com-toggle-overwrite-mode)
1398 ejohnson 1.27
1399     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1400     ;;;
1401     ;;; C-x command table
1402    
1403     (make-command-table 'c-x-climacs-table :errorp nil)
1404    
1405     (add-menu-item-to-command-table 'global-climacs-table "C-x"
1406     :menu 'c-x-climacs-table
1407     :keystroke '(#\x :control))
1408    
1409     (defun c-x-set-key (gesture command)
1410     (add-command-to-command-table command 'c-x-climacs-table
1411     :keystroke gesture :errorp nil))
1412    
1413 rstrandh 1.83 (c-x-set-key '(#\0) 'com-delete-window)
1414 ejohnson 1.107 (c-x-set-key '(#\1) 'com-single-window)
1415 rstrandh 1.77 (c-x-set-key '(#\2) 'com-split-window-vertically)
1416 rstrandh 1.83 (c-x-set-key '(#\3) 'com-split-window-horizontally)
1417 rstrandh 1.85 (c-x-set-key '(#\() 'com-start-kbd-macro)
1418     (c-x-set-key '(#\)) 'com-end-kbd-macro)
1419 rstrandh 1.75 (c-x-set-key '(#\b) 'com-switch-to-buffer)
1420 rstrandh 1.85 (c-x-set-key '(#\e) 'com-call-last-kbd-macro)
1421 ejohnson 1.27 (c-x-set-key '(#\c :control) 'com-quit)
1422     (c-x-set-key '(#\f :control) 'com-find-file)
1423 rstrandh 1.91 (c-x-set-key '(#\k) 'com-kill-buffer)
1424 rstrandh 1.63 (c-x-set-key '(#\l :control) 'com-load-file)
1425 rstrandh 1.83 (c-x-set-key '(#\o) 'com-other-window)
1426 rstrandh 1.98 (c-x-set-key '(#\r) 'com-redo)
1427     (c-x-set-key '(#\u) 'com-undo)
1428 ejohnson 1.27 (c-x-set-key '(#\s :control) 'com-save-buffer)
1429 rstrandh 1.45 (c-x-set-key '(#\t :control) 'com-transpose-lines)
1430 ejohnson 1.27 (c-x-set-key '(#\w :control) 'com-write-buffer)
1431 rstrandh 1.45 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
1432 rstrandh 1.44
1433     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1434     ;;;
1435     ;;; Some Unicode stuff
1436    
1437     (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
1438 rstrandh 1.80 (insert-object (point (current-window)) (code-char code)))
1439 rstrandh 1.44
1440     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1441     ;;;
1442     ;;; Dead-acute command table
1443    
1444     (make-command-table 'dead-acute-climacs-table :errorp nil)
1445    
1446     (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
1447     :menu 'dead-acute-climacs-table
1448     :keystroke '(:dead--acute))
1449    
1450     (defun dead-acute-set-key (gesture command)
1451     (add-command-to-command-table command 'dead-acute-climacs-table
1452     :keystroke gesture :errorp nil))
1453    
1454     (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
1455     (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
1456     (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
1457     (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
1458     (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
1459     (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
1460     (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
1461     (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
1462     (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
1463     (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
1464     (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
1465     (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
1466     (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
1467     (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
1468     (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
1469     (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
1470     (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
1471     (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
1472     (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
1473     (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
1474    
1475 rstrandh 1.45 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
1476    
1477     (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
1478     :menu 'dead-acute-dead-accute-climacs-table
1479     :keystroke '(:dead--acute))
1480    
1481     (defun dead-acute-dead-accute-set-key (gesture command)
1482     (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
1483     :keystroke gesture :errorp nil))
1484    
1485     (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
1486     (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
1487 rstrandh 1.44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1488     ;;;
1489     ;;; Dead-grave command table
1490    
1491     (make-command-table 'dead-grave-climacs-table :errorp nil)
1492    
1493     (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
1494     :menu 'dead-grave-climacs-table
1495     :keystroke '(:dead--grave))
1496    
1497     (defun dead-grave-set-key (gesture command)
1498     (add-command-to-command-table command 'dead-grave-climacs-table
1499     :keystroke gesture :errorp nil))
1500    
1501     (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
1502     (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
1503     (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
1504     (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
1505     (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
1506     (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
1507     (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
1508     (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
1509     (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
1510     (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
1511     (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
1512    
1513     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1514     ;;;
1515     ;;; Dead-diaeresis command table
1516    
1517     (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
1518    
1519     (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
1520     :menu 'dead-diaeresis-climacs-table
1521     :keystroke '(:dead--diaeresis :shift))
1522    
1523     (defun dead-diaeresis-set-key (gesture command)
1524     (add-command-to-command-table command 'dead-diaeresis-climacs-table
1525     :keystroke gesture :errorp nil))
1526    
1527     (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
1528     (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
1529     (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
1530     (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
1531     (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
1532     (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
1533     (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
1534     (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
1535     (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
1536     (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
1537     (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
1538     (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
1539    
1540     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1541     ;;;
1542     ;;; Dead-tilde command table
1543    
1544     (make-command-table 'dead-tilde-climacs-table :errorp nil)
1545    
1546     (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
1547     :menu 'dead-tilde-climacs-table
1548     :keystroke '(:dead--tilde :shift))
1549    
1550     (defun dead-tilde-set-key (gesture command)
1551     (add-command-to-command-table command 'dead-tilde-climacs-table
1552     :keystroke gesture :errorp nil))
1553    
1554     (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
1555     (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
1556     (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
1557     (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
1558     (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
1559     (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
1560     (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
1561     (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
1562     (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
1563     (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
1564     (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
1565    
1566     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1567     ;;;
1568     ;;; Dead-circumflex command table
1569    
1570     (make-command-table 'dead-circumflex-climacs-table :errorp nil)
1571    
1572     (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
1573     :menu 'dead-circumflex-climacs-table
1574     :keystroke '(:dead--circumflex :shift))
1575    
1576     (defun dead-circumflex-set-key (gesture command)
1577     (add-command-to-command-table command 'dead-circumflex-climacs-table
1578     :keystroke gesture :errorp nil))
1579    
1580     (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
1581     (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
1582     (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
1583     (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
1584     (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
1585     (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
1586     (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
1587     (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
1588     (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
1589     (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
1590     (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))
1591 mvilleneuve 1.96
1592     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1593     ;;;
1594     ;;; Isearch command table
1595    
1596     (make-command-table 'isearch-climacs-table :errorp nil)
1597    
1598     (defun isearch-set-key (gesture command)
1599     (add-command-to-command-table command 'isearch-climacs-table
1600     :keystroke gesture :errorp nil))
1601    
1602     (loop for code from (char-code #\Space) to (char-code #\~)
1603     do (isearch-set-key (code-char code) 'com-isearch-append-char))
1604    
1605     (isearch-set-key '(#\Newline) 'com-isearch-exit)
1606     (isearch-set-key '(#\Backspace) 'com-isearch-delete-char)
1607     (isearch-set-key '(#\s :control) 'com-isearch-forward)
1608 mvilleneuve 1.97 (isearch-set-key '(#\r :control) 'com-isearch-backward)
1609 mvilleneuve 1.100
1610     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1611     ;;;
1612     ;;; Query replace command table
1613    
1614     (make-command-table 'query-replace-climacs-table :errorp nil)
1615    
1616     (defun query-replace-set-key (gesture command)
1617     (add-command-to-command-table command 'query-replace-climacs-table
1618     :keystroke gesture :errorp nil))
1619    
1620     (query-replace-set-key '(#\Newline) 'com-query-replace-exit)
1621     (query-replace-set-key '(#\Space) 'com-query-replace-replace)
1622     (query-replace-set-key '(#\Backspace) 'com-query-replace-skip)
1623     (query-replace-set-key '(#\Rubout) 'com-query-replace-skip)
1624     (query-replace-set-key '(#\q) 'com-query-replace-exit)
1625     (query-replace-set-key '(#\y) 'com-query-replace-replace)
1626     (query-replace-set-key '(#\n) 'com-query-replace-skip)

  ViewVC Help
Powered by ViewVC 1.1.5