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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.109 - (hide annotations)
Sat Feb 19 05:23:16 2005 UTC (9 years, 2 months ago) by rstrandh
Branch: MAIN
Changes since 1.108: +44 -28 lines
Implemented flag *numeric-argument-p* to detect whether a numeric
argument was given att all.

Implemented eval-expression, M-:, which uses numeric-argument-p to
dentermine whether to show the result in the minibuffer or to insert
it into the buffer itself.
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 abridgewater 1.34 (define-named-command com-kill-line ()
469 rstrandh 1.80 (let* ((pane (current-window))
470 ejohnson 1.54 (point (point pane))
471     (mark (offset point)))
472 ejohnson 1.56 (cond ((end-of-buffer-p point) nil)
473     ((end-of-line-p point)(forward-object point))
474     (t
475     (end-of-line point)
476     (cond ((beginning-of-buffer-p point) nil)
477     ((beginning-of-line-p point)(forward-object point)))))
478 ejohnson 1.54 (if (eq (previous-command pane) 'com-kill-line)
479 ejohnson 1.51 (kill-ring-concatenating-push *kill-ring*
480 ejohnson 1.54 (region-to-sequence mark point))
481 ejohnson 1.51 (kill-ring-standard-push *kill-ring*
482 ejohnson 1.54 (region-to-sequence mark point)))
483     (delete-region mark point)))
484 ejohnson 1.27
485 rstrandh 1.102 (define-named-command com-forward-word ((count 'integer :prompt "Number of words"))
486     (forward-word (point (current-window)) count))
487 ejohnson 1.27
488 rstrandh 1.102 (define-named-command com-backward-word ((count 'integer :prompt "Number of words"))
489     (backward-word (point (current-window)) count))
490 ejohnson 1.27
491 rstrandh 1.103 (define-named-command com-delete-word ((count 'integer :prompt "Number of words"))
492     (delete-word (point (current-window)) count))
493 rstrandh 1.32
494 rstrandh 1.103 (define-named-command com-backward-delete-word ((count 'integer :prompt "Number of words"))
495     (backward-delete-word (point (current-window)) count))
496 rstrandh 1.32
497 mvilleneuve 1.64 (define-named-command com-upcase-region ()
498 abakic 1.101 (let ((cw (current-window)))
499     (upcase-region (mark cw) (point cw))))
500 mvilleneuve 1.64
501     (define-named-command com-downcase-region ()
502 abakic 1.101 (let ((cw (current-window)))
503     (downcase-region (mark cw) (point cw))))
504 mvilleneuve 1.64
505     (define-named-command com-capitalize-region ()
506 abakic 1.101 (let ((cw (current-window)))
507     (capitalize-region (mark cw) (point cw))))
508 mvilleneuve 1.64
509 rstrandh 1.60 (define-named-command com-upcase-word ()
510 rstrandh 1.80 (upcase-word (point (current-window))))
511 rstrandh 1.60
512     (define-named-command com-downcase-word ()
513 rstrandh 1.80 (downcase-word (point (current-window))))
514 rstrandh 1.60
515     (define-named-command com-capitalize-word ()
516 rstrandh 1.80 (capitalize-word (point (current-window))))
517 rstrandh 1.60
518 mvilleneuve 1.69 (define-named-command com-tabify-region ()
519 rstrandh 1.80 (let ((pane (current-window)))
520 mvilleneuve 1.69 (multiple-value-bind (start end) (region-limits pane)
521 rstrandh 1.70 (tabify-region start end (tab-space-count (stream-default-view pane))))))
522 mvilleneuve 1.69
523     (define-named-command com-untabify-region ()
524 rstrandh 1.80 (let ((pane (current-window)))
525 mvilleneuve 1.69 (multiple-value-bind (start end) (region-limits pane)
526 rstrandh 1.70 (untabify-region start end (tab-space-count (stream-default-view pane))))))
527 mvilleneuve 1.69
528 mvilleneuve 1.79 (defun indent-current-line (pane point)
529     (let* ((buffer (buffer pane))
530     (view (stream-default-view pane))
531     (tab-space-count (tab-space-count view))
532     (indentation (syntax-line-indentation point
533     tab-space-count
534     (syntax buffer))))
535     (indent-line point indentation (and (indent-tabs-mode buffer)
536     tab-space-count))))
537    
538     (define-named-command com-indent-line ()
539 rstrandh 1.80 (let* ((pane (current-window))
540 mvilleneuve 1.79 (point (point pane)))
541     (indent-current-line pane point)))
542    
543     (define-named-command com-newline-and-indent ()
544 rstrandh 1.80 (let* ((pane (current-window))
545 mvilleneuve 1.79 (point (point pane)))
546     (insert-object point #\Newline)
547     (indent-current-line pane point)))
548    
549 mvilleneuve 1.72 (define-named-command com-delete-indentation ()
550 rstrandh 1.80 (delete-indentation (point (current-window))))
551 ejohnson 1.27
552 mvilleneuve 1.86 (define-named-command com-auto-fill-mode ()
553 mvilleneuve 1.92 (let ((pane (current-window)))
554     (setf (auto-fill-mode pane) (not (auto-fill-mode pane)))))
555 mvilleneuve 1.86
556 mvilleneuve 1.90 (define-named-command com-fill-paragraph ()
557     (let* ((pane (current-window))
558     (buffer (buffer pane))
559     (syntax (syntax buffer))
560     (point (point pane))
561     (begin-mark (clone-mark point))
562     (end-mark (clone-mark point)))
563     (unless (eql (object-before begin-mark) #\Newline)
564     (beginning-of-paragraph begin-mark syntax))
565     (unless (eql (object-after end-mark) #\Newline)
566     (end-of-paragraph end-mark syntax))
567     (do-buffer-region (object offset buffer
568     (offset begin-mark) (offset end-mark))
569     (when (eql object #\Newline)
570     (setf object #\Space)))
571     (let ((point-backup (clone-mark point)))
572     (setf (offset point) (offset end-mark))
573     (possibly-fill-line)
574     (setf (offset point) (offset point-backup)))))
575    
576 ejohnson 1.27 (define-command com-extended-command ()
577     (let ((item (accept 'command :prompt "Extended Command")))
578     (execute-frame-command *application-frame* item)))
579    
580 rstrandh 1.41 (eval-when (:compile-toplevel :load-toplevel)
581 ejohnson 1.35 (define-presentation-type completable-pathname ()
582     :inherit-from 'pathname))
583 ejohnson 1.27
584     (defun filename-completer (so-far mode)
585     (flet ((remove-trail (s)
586     (subseq s 0 (let ((pos (position #\/ s :from-end t)))
587     (if pos (1+ pos) 0)))))
588     (let* ((directory-prefix
589     (if (and (plusp (length so-far)) (eql (aref so-far 0) #\/))
590     ""
591 rstrandh 1.78 (namestring #+sbcl *default-pathname-defaults*
592     #+cmu (ext:default-directory)
593     #-(or sbcl cmu) *default-pathname-defaults*)))
594 ejohnson 1.27 (full-so-far (concatenate 'string directory-prefix so-far))
595     (pathnames
596     (loop with length = (length full-so-far)
597     for path in (directory (concatenate 'string
598     (remove-trail so-far)
599     "*.*"))
600     when (let ((mismatch (mismatch (namestring path) full-so-far)))
601     (or (null mismatch) (= mismatch length)))
602     collect path))
603     (strings (mapcar #'namestring pathnames))
604     (first-string (car strings))
605     (length-common-prefix nil)
606     (completed-string nil)
607     (full-completed-string nil))
608     (unless (null pathnames)
609     (setf length-common-prefix
610     (loop with length = (length first-string)
611     for string in (cdr strings)
612     do (setf length (min length (or (mismatch string first-string) length)))
613     finally (return length))))
614     (unless (null pathnames)
615     (setf completed-string
616     (subseq first-string (length directory-prefix)
617     (if (null (cdr pathnames)) nil length-common-prefix)))
618     (setf full-completed-string
619     (concatenate 'string directory-prefix completed-string)))
620     (case mode
621     ((:complete-limited :complete-maximal)
622     (cond ((null pathnames)
623     (values so-far nil nil 0 nil))
624     ((null (cdr pathnames))
625     (values completed-string t (car pathnames) 1 nil))
626     (t
627     (values completed-string nil nil (length pathnames) nil))))
628     (:complete
629     (cond ((null pathnames)
630     (values so-far t so-far 1 nil))
631     ((null (cdr pathnames))
632     (values completed-string t (car pathnames) 1 nil))
633     ((find full-completed-string strings :test #'string-equal)
634     (let ((pos (position full-completed-string strings :test #'string-equal)))
635     (values completed-string
636     t (elt pathnames pos) (length pathnames) nil)))
637     (t
638     (values completed-string nil nil (length pathnames) nil))))
639     (:possibilities
640     (values nil nil nil (length pathnames)
641     (loop with length = (length directory-prefix)
642     for name in pathnames
643     collect (list (subseq (namestring name) length nil)
644     name))))))))
645    
646     (define-presentation-method accept
647     ((type completable-pathname) stream (view textual-view) &key)
648     (multiple-value-bind (pathname success string)
649     (complete-input stream
650     #'filename-completer
651     :partial-completers '(#\Space)
652     :allow-any-input t)
653     (declare (ignore success))
654     (or pathname string)))
655    
656     (defun pathname-filename (pathname)
657     (if (null (pathname-type pathname))
658     (pathname-name pathname)
659     (concatenate 'string (pathname-name pathname)
660     "." (pathname-type pathname))))
661    
662 abridgewater 1.34 (define-named-command com-find-file ()
663 ejohnson 1.27 (let ((filename (accept 'completable-pathname
664 rstrandh 1.70 :prompt "Find File"))
665     (buffer (make-instance 'climacs-buffer))
666 rstrandh 1.80 (pane (current-window)))
667 rstrandh 1.75 (push buffer (buffers *application-frame*))
668 rstrandh 1.80 (setf (buffer (current-window)) buffer)
669 rstrandh 1.106 (setf (syntax buffer) (make-instance 'basic-syntax :buffer buffer))
670 rstrandh 1.84 ;; Don't want to create the file if it doesn't exist.
671     (when (probe-file filename)
672     (with-open-file (stream filename :direction :input)
673     (input-from-stream stream buffer 0)))
674 rstrandh 1.70 (setf (filename buffer) filename
675     (name buffer) (pathname-filename filename)
676     (needs-saving buffer) nil)
677     (beginning-of-buffer (point pane))
678     ;; this one is needed so that the buffer modification protocol
679     ;; resets the low and high marks after redisplay
680     (redisplay-frame-panes *application-frame*)))
681 ejohnson 1.27
682 rstrandh 1.93 (defun save-buffer (buffer)
683     (let ((filename (or (filename buffer)
684     (accept 'completable-pathname
685     :prompt "Save Buffer to File"))))
686     (with-open-file (stream filename :direction :output :if-exists :supersede)
687     (output-to-stream stream buffer 0 (size buffer)))
688     (setf (filename buffer) filename
689     (name buffer) (pathname-filename filename))
690     (display-message "Wrote: ~a" (filename buffer))
691     (setf (needs-saving buffer) nil)))
692    
693 abridgewater 1.34 (define-named-command com-save-buffer ()
694 rstrandh 1.93 (let ((buffer (buffer (current-window))))
695 rstrandh 1.30 (if (or (null (filename buffer))
696     (needs-saving buffer))
697 rstrandh 1.93 (save-buffer buffer)
698     (display-message "No changes need to be saved from ~a" (name buffer)))))
699    
700     (define-named-command (com-quit) ()
701     (loop for buffer in (buffers *application-frame*)
702     when (and (needs-saving buffer)
703     (accept 'boolean
704     :prompt (format nil "Save buffer: ~a ?" (name buffer))))
705     do (save-buffer buffer))
706     (when (or (notany #'needs-saving
707     (buffers *application-frame*))
708     (accept 'boolean :prompt "Modified buffers exist. Quit anyway?"))
709     (frame-exit *application-frame*)))
710 ejohnson 1.27
711 abridgewater 1.34 (define-named-command com-write-buffer ()
712 ejohnson 1.27 (let ((filename (accept 'completable-pathname
713     :prompt "Write Buffer to File"))
714 rstrandh 1.80 (buffer (buffer (current-window))))
715 ejohnson 1.27 (with-open-file (stream filename :direction :output :if-exists :supersede)
716     (output-to-stream stream buffer 0 (size buffer)))
717     (setf (filename buffer) filename
718 rstrandh 1.28 (name buffer) (pathname-filename filename)
719 rstrandh 1.30 (needs-saving buffer) nil)
720     (display-message "Wrote: ~a" (filename buffer))))
721 ejohnson 1.27
722 rstrandh 1.75 (define-presentation-method accept
723     ((type buffer) stream (view textual-view) &key)
724     (multiple-value-bind (object success string)
725     (complete-input stream
726     (lambda (so-far action)
727     (complete-from-possibilities
728     so-far (buffers *application-frame*) '() :action action
729     :name-key #'name
730     :value-key #'identity))
731     :partial-completers '(#\Space)
732     :allow-any-input t)
733 rstrandh 1.76 (declare (ignore success))
734     (or object
735     (car (push (make-instance 'climacs-buffer :name string)
736     (buffers *application-frame*))))))
737 rstrandh 1.75
738     (define-named-command com-switch-to-buffer ()
739     (let ((buffer (accept 'buffer
740     :prompt "Switch to buffer")))
741 rstrandh 1.80 (setf (buffer (current-window)) buffer)
742 rstrandh 1.106 (setf (syntax buffer) (make-instance 'basic-syntax :buffer buffer))
743 rstrandh 1.80 (beginning-of-buffer (point (current-window)))
744     (full-redisplay (current-window))))
745 rstrandh 1.75
746 rstrandh 1.91 (define-named-command com-kill-buffer ()
747     (with-slots (buffers) *application-frame*
748     (let ((buffer (buffer (current-window))))
749     (when (and (needs-saving buffer)
750     (accept 'boolean :prompt "Save buffer first?"))
751     (com-save-buffer))
752     (setf buffers (remove buffer buffers))
753     ;; Always need one buffer.
754     (when (null buffers)
755     (push (make-instance 'climacs-buffer :name "*scratch*")
756     buffers))
757     (setf (buffer (current-window)) (car buffers)))))
758    
759 rstrandh 1.75 (define-named-command com-full-redisplay ()
760 rstrandh 1.80 (full-redisplay (current-window)))
761 rstrandh 1.75
762 rstrandh 1.63 (define-named-command com-load-file ()
763     (let ((filename (accept 'completable-pathname
764     :prompt "Load File")))
765     (load filename)))
766    
767 abridgewater 1.34 (define-named-command com-beginning-of-buffer ()
768 rstrandh 1.80 (beginning-of-buffer (point (current-window))))
769 ejohnson 1.27
770 rstrandh 1.39 (define-named-command com-page-down ()
771 rstrandh 1.80 (let ((pane (current-window)))
772 rstrandh 1.70 (page-down pane)))
773 rstrandh 1.39
774 rstrandh 1.40 (define-named-command com-page-up ()
775 rstrandh 1.80 (let ((pane (current-window)))
776 rstrandh 1.70 (page-up pane)))
777 rstrandh 1.40
778 abridgewater 1.34 (define-named-command com-end-of-buffer ()
779 rstrandh 1.80 (end-of-buffer (point (current-window))))
780 ejohnson 1.27
781 abridgewater 1.34 (define-named-command com-back-to-indentation ()
782 rstrandh 1.80 (let ((point (point (current-window))))
783 rstrandh 1.32 (beginning-of-line point)
784     (loop until (end-of-line-p point)
785     while (whitespacep (object-after point))
786     do (incf (offset point)))))
787    
788 abridgewater 1.34 (define-named-command com-goto-position ()
789 rstrandh 1.80 (setf (offset (point (current-window)))
790 rstrandh 1.32 (accept 'integer :prompt "Goto Position")))
791    
792 abridgewater 1.34 (define-named-command com-goto-line ()
793 abakic 1.99 (loop with mark = (make-instance 'standard-right-sticky-mark ;PB
794 rstrandh 1.80 :buffer (buffer (current-window)))
795 rstrandh 1.32 do (end-of-line mark)
796     until (end-of-buffer-p mark)
797     repeat (accept 'integer :prompt "Goto Line")
798     do (incf (offset mark))
799     (end-of-line mark)
800     finally (beginning-of-line mark)
801 rstrandh 1.80 (setf (offset (point (current-window)))
802 rstrandh 1.32 (offset mark))))
803    
804 abridgewater 1.34 (define-named-command com-browse-url ()
805 ejohnson 1.27 (accept 'url :prompt "Browse URL"))
806    
807 abridgewater 1.34 (define-named-command com-set-mark ()
808 rstrandh 1.80 (let ((pane (current-window)))
809 rstrandh 1.70 (setf (mark pane) (clone-mark (point pane)))))
810 rstrandh 1.45
811     (define-named-command com-exchange-point-and-mark ()
812 rstrandh 1.80 (let ((pane (current-window)))
813 rstrandh 1.70 (psetf (offset (mark pane)) (offset (point pane))
814     (offset (point pane)) (offset (mark pane)))))
815 rstrandh 1.38
816     (define-named-command com-set-syntax ()
817 rstrandh 1.80 (let* ((pane (current-window))
818 rstrandh 1.67 (buffer (buffer pane)))
819 rstrandh 1.70 (setf (syntax buffer)
820 rstrandh 1.106 (make-instance (accept 'syntax :prompt "Set Syntax")
821     :buffer buffer))
822 rstrandh 1.67 (setf (offset (low-mark buffer)) 0
823     (offset (high-mark buffer)) (size buffer))))
824 ejohnson 1.27
825 rstrandh 1.77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
826     ;;;
827 rstrandh 1.85 ;;; Keyboard macros
828    
829     (define-named-command com-start-kbd-macro ()
830     (setf (recordingp *application-frame*) t)
831     (setf (recorded-keys *application-frame*) '()))
832    
833     (define-named-command com-end-kbd-macro ()
834     (setf (recordingp *application-frame*) nil)
835     (setf (recorded-keys *application-frame*)
836     ;; this won't work if the command was invoked in any old way
837     (reverse (cddr (recorded-keys *application-frame*)))))
838    
839     (define-named-command com-call-last-kbd-macro ()
840     (setf (remaining-keys *application-frame*)
841     (recorded-keys *application-frame*))
842     (setf (executingp *application-frame*) t))
843    
844     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
845     ;;;
846 rstrandh 1.77 ;;; Commands for splitting windows
847    
848 rstrandh 1.91 ;;; put this in for real when we find a solution for the problem
849     ;;; it causes for com-delete-window
850     ;; (defun replace-constellation (constellation additional-constellation vertical-p)
851     ;; (let* ((parent (sheet-parent constellation))
852     ;; (children (sheet-children parent))
853     ;; (first (first children))
854     ;; (second (second children))
855     ;; (adjust (make-pane 'clim-extensions:box-adjuster-gadget)))
856     ;; (assert (member constellation children))
857     ;; (cond ((eq constellation first)
858     ;; (sheet-disown-child parent constellation)
859     ;; (let ((new (if vertical-p
860     ;; (vertically ()
861     ;; constellation adjust additional-constellation)
862     ;; (horizontally ()
863     ;; constellation adjust additional-constellation))))
864     ;; (sheet-adopt-child parent new)
865     ;; (reorder-sheets parent (list new second))))
866     ;; (t
867     ;; (sheet-disown-child parent constellation)
868     ;; (let ((new (if vertical-p
869     ;; (vertically ()
870     ;; constellation adjust additional-constellation)
871     ;; (horizontally ()
872     ;; constellation adjust additional-constellation))))
873     ;; (sheet-adopt-child parent new)
874     ;; (reorder-sheets parent (list first new)))))))
875    
876 rstrandh 1.83 (defun replace-constellation (constellation additional-constellation vertical-p)
877     (let* ((parent (sheet-parent constellation))
878     (children (sheet-children parent))
879     (first (first children))
880     (second (second children)))
881     (assert (member constellation children))
882     (cond ((eq constellation first)
883     (sheet-disown-child parent constellation)
884     (let ((new (if vertical-p
885     (vertically () constellation additional-constellation)
886     (horizontally () constellation additional-constellation))))
887     (sheet-adopt-child parent new)
888     (reorder-sheets parent (list new second))))
889     (t
890     (sheet-disown-child parent constellation)
891     (let ((new (if vertical-p
892     (vertically () constellation additional-constellation)
893     (horizontally () constellation additional-constellation))))
894     (sheet-adopt-child parent new)
895     (reorder-sheets parent (list first new)))))))
896    
897     (defun parent3 (sheet)
898     (sheet-parent (sheet-parent (sheet-parent sheet))))
899    
900     (defun make-pane-constellation ()
901     "make a vbox containing a scroller pane as its first child and an
902     info pane as its second child. The scroller pane contains a viewport
903     which contains an extended pane. Return the vbox and the extended pane
904     as two values"
905     (let* ((extended-pane
906     (make-pane 'extended-pane
907     :width 900 :height 400
908     :name 'win
909     :incremental-redisplay t
910     :display-function 'display-win))
911     (vbox
912     (vertically ()
913     (scrolling () extended-pane)
914     (make-pane 'info-pane
915     :climacs-pane extended-pane
916     :width 900 :height 20
917     :max-height 20 :min-height 20
918     ::background +gray85+
919     :scroll-bars nil
920     :borders nil
921     :incremental-redisplay t
922     :display-function 'display-info))))
923     (values vbox extended-pane)))
924    
925 rstrandh 1.77 (define-named-command com-split-window-vertically ()
926     (with-look-and-feel-realization
927     ((frame-manager *application-frame*) *application-frame*)
928 rstrandh 1.83 (multiple-value-bind (vbox new-pane) (make-pane-constellation)
929     (let* ((current-window (current-window))
930     (constellation-root (parent3 current-window)))
931 mvilleneuve 1.95 (setf (buffer new-pane) (buffer current-window)
932     (auto-fill-mode new-pane) (auto-fill-mode current-window)
933     (auto-fill-column new-pane) (auto-fill-column current-window))
934 rstrandh 1.83 (push new-pane (windows *application-frame*))
935     (replace-constellation constellation-root vbox t)
936     (full-redisplay current-window)
937     (full-redisplay new-pane)))))
938    
939     (define-named-command com-split-window-horizontally ()
940     (with-look-and-feel-realization
941     ((frame-manager *application-frame*) *application-frame*)
942     (multiple-value-bind (vbox new-pane) (make-pane-constellation)
943     (let* ((current-window (current-window))
944     (constellation-root (parent3 current-window)))
945 mvilleneuve 1.95 (setf (buffer new-pane) (buffer current-window)
946     (auto-fill-mode new-pane) (auto-fill-mode current-window)
947     (auto-fill-column new-pane) (auto-fill-column current-window))
948 rstrandh 1.83 (push new-pane (windows *application-frame*))
949     (replace-constellation constellation-root vbox nil)
950     (full-redisplay current-window)
951     (full-redisplay new-pane)))))
952    
953     (define-named-command com-other-window ()
954     (setf (windows *application-frame*)
955     (append (cdr (windows *application-frame*))
956     (list (car (windows *application-frame*))))))
957    
958     (define-named-command com-delete-window ()
959     (unless (null (cdr (windows *application-frame*)))
960     (let* ((constellation (parent3 (current-window)))
961     (box (sheet-parent constellation))
962     (box-children (sheet-children box))
963     (other (if (eq constellation (first box-children))
964     (second box-children)
965     (first box-children)))
966     (parent (sheet-parent box))
967     (children (sheet-children parent))
968     (first (first children))
969     (second (second children)))
970     (pop (windows *application-frame*))
971     (sheet-disown-child box other)
972     (cond ((eq box first)
973     (sheet-disown-child parent box)
974     (sheet-adopt-child parent other)
975     (reorder-sheets parent (list other second)))
976     (t
977     (sheet-disown-child parent box)
978     (sheet-adopt-child parent other)
979     (reorder-sheets parent (list first other)))))))
980 rstrandh 1.77
981 ejohnson 1.107
982     (define-named-command com-single-window ()
983     (unless (null (cdr (windows *application-frame*)))
984     (let* ((saver (parent3 (current-window)))
985     (top-level (do
986 ejohnson 1.108 ((n saver (setf n (sheet-parent n))))
987 ejohnson 1.107 ((clim-internals::top-level-sheet-pane-p n) n)))
988     (level1 (car (sheet-children top-level))) ;; should be the only thing on level1
989     (level2 (if (typep (car (sheet-children level1)) 'vrack-pane) ;;don't select raised pane
990     (car (sheet-children level1))
991     (cadr (sheet-children level1))))
992     (level2-children (sheet-children level2))
993     (junker (if (typep (car level2-children) 'vrack-pane) ;;don't select minibuffer
994     (car level2-children)
995     (cadr level2-children))))
996     (sheet-disown-child (sheet-parent saver) saver)
997     (sheet-disown-child level2 junker)
998     (sheet-adopt-child level2 saver)
999     (reorder-sheets level2 (reverse (sheet-children level2))) ;;minibuffer goes on bottom
1000     (setf (windows *application-frame*) (list (car (windows *application-frame*)))))))
1001    
1002    
1003 rstrandh 1.94 ;; (define-named-command com-delete-window ()
1004     ;; (unless (null (cdr (windows *application-frame*)))
1005     ;; (let* ((constellation (parent3 (current-window)))
1006     ;; (box (sheet-parent constellation))
1007     ;; (box-children (sheet-children box))
1008     ;; (other (if (eq constellation (first box-children))
1009     ;; (third box-children)
1010     ;; (first box-children)))
1011     ;; (parent (sheet-parent box))
1012     ;; (children (sheet-children parent))
1013     ;; (first (first children))
1014     ;; (second (second children))
1015     ;; (third (third children)))
1016     ;; (pop (windows *application-frame*))
1017     ;; (sheet-disown-child box other)
1018     ;; (cond ((eq box first)
1019     ;; (sheet-disown-child parent box)
1020     ;; (sheet-adopt-child parent other)
1021     ;; (reorder-sheets parent (list other second third)))
1022     ;; (t
1023     ;; (sheet-disown-child parent box)
1024     ;; (sheet-adopt-child parent other)
1025     ;; (reorder-sheets parent (list first second other)))))))
1026    
1027 ejohnson 1.27 ;;;;;;;;;;;;;;;;;;;;
1028     ;; Kill ring commands
1029    
1030 ejohnson 1.31 ;; Copies an element from a kill-ring to a buffer at the given offset
1031 ejohnson 1.50 (define-named-command com-yank ()
1032 rstrandh 1.80 (insert-sequence (point (current-window)) (kill-ring-yank *kill-ring*)))
1033 ejohnson 1.27
1034 ejohnson 1.31 ;; Destructively cut a given buffer region into the kill-ring
1035 abridgewater 1.34 (define-named-command com-cut-out ()
1036 rstrandh 1.80 (multiple-value-bind (start end) (region-limits (current-window))
1037 mvilleneuve 1.64 (kill-ring-standard-push *kill-ring* (region-to-sequence start end))
1038     (delete-region (offset start) end)))
1039 ejohnson 1.27
1040 ejohnson 1.31 ;; Non destructively copies in buffer region to the kill ring
1041 abridgewater 1.34 (define-named-command com-copy-out ()
1042 rstrandh 1.80 (let ((pane (current-window)))
1043 rstrandh 1.70 (kill-ring-standard-push *kill-ring* (region-to-sequence (point pane) (mark pane)))))
1044 ejohnson 1.27
1045 ejohnson 1.50 (define-named-command com-rotate-yank ()
1046 rstrandh 1.80 (let* ((pane (current-window))
1047 ejohnson 1.54 (point (point pane))
1048 ejohnson 1.50 (last-yank (kill-ring-yank *kill-ring*)))
1049 ejohnson 1.54 (if (eq (previous-command pane)
1050 ejohnson 1.50 'com-rotate-yank)
1051 ejohnson 1.54 (progn
1052     (delete-range point (* -1 (length last-yank)))
1053     (rotate-yank-position *kill-ring*)))
1054     (insert-sequence point (kill-ring-yank *kill-ring*))))
1055 ejohnson 1.27
1056 ejohnson 1.50 (define-named-command com-resize-kill-ring ()
1057 ejohnson 1.46 (let ((size (accept 'integer :prompt "New kill ring size")))
1058 ejohnson 1.50 (setf (kill-ring-max-size *kill-ring*) size)))
1059 rstrandh 1.47
1060 mvilleneuve 1.96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1061     ;;;
1062     ;;; Incremental search
1063    
1064 mvilleneuve 1.97 (defun isearch-command-loop (pane forwardp)
1065     (let ((point (point pane)))
1066 mvilleneuve 1.96 (unless (endp (isearch-states pane))
1067     (setf (isearch-previous-string pane)
1068     (search-string (first (isearch-states pane)))))
1069     (setf (isearch-mode pane) t)
1070     (setf (isearch-states pane)
1071     (list (make-instance 'isearch-state
1072     :search-string ""
1073 mvilleneuve 1.97 :search-mark (clone-mark point)
1074 mvilleneuve 1.105 :search-forward-p forwardp
1075     :search-success-p t)))
1076 mvilleneuve 1.100 (simple-command-loop 'isearch-climacs-table
1077     (isearch-mode pane)
1078     ((setf (isearch-mode pane) nil)))))
1079 mvilleneuve 1.96
1080 mvilleneuve 1.97 (defun isearch-from-mark (pane mark string forwardp)
1081     (flet ((object-equal (x y)
1082     (if (characterp x)
1083     (and (characterp y) (char-equal x y))
1084     (eql x y))))
1085     (let* ((point (point pane))
1086     (mark2 (clone-mark mark))
1087     (success (funcall (if forwardp #'search-forward #'search-backward)
1088     mark2
1089     string
1090     :test #'object-equal)))
1091 mvilleneuve 1.105 (when success
1092     (setf (offset point) (offset mark2)
1093     (offset mark) (if forwardp
1094     (- (offset mark2) (length string))
1095     (+ (offset mark2) (length string)))))
1096     (push (make-instance 'isearch-state
1097     :search-string string
1098     :search-mark mark
1099     :search-forward-p forwardp
1100     :search-success-p success)
1101     (isearch-states pane))
1102     (unless success
1103     (beep)))))
1104 mvilleneuve 1.97
1105     (define-named-command com-isearch-mode-forward ()
1106     (isearch-command-loop (current-window) t))
1107    
1108     (define-named-command com-isearch-mode-backward ()
1109     (isearch-command-loop (current-window) nil))
1110 mvilleneuve 1.96
1111     (define-named-command com-isearch-append-char ()
1112     (let* ((pane (current-window))
1113     (states (isearch-states pane))
1114     (string (concatenate 'string
1115     (search-string (first states))
1116     (string *current-gesture*)))
1117     (mark (clone-mark (search-mark (first states))))
1118 mvilleneuve 1.97 (forwardp (search-forward-p (first states))))
1119     (unless forwardp
1120     (incf (offset mark)))
1121     (isearch-from-mark pane mark string forwardp)))
1122 mvilleneuve 1.96
1123     (define-named-command com-isearch-delete-char ()
1124     (let* ((pane (current-window)))
1125     (cond ((null (second (isearch-states pane)))
1126     (beep))
1127     (t
1128     (pop (isearch-states pane))
1129 mvilleneuve 1.105 (loop until (endp (rest (isearch-states pane)))
1130     until (search-success-p (first (isearch-states pane)))
1131     do (pop (isearch-states pane)))
1132 mvilleneuve 1.96 (let ((state (first (isearch-states pane))))
1133     (setf (offset (point pane))
1134 mvilleneuve 1.97 (if (search-forward-p state)
1135     (+ (offset (search-mark state))
1136     (length (search-string state)))
1137     (- (offset (search-mark state))
1138     (length (search-string state))))))))))
1139 mvilleneuve 1.96
1140     (define-named-command com-isearch-forward ()
1141     (let* ((pane (current-window))
1142     (point (point pane))
1143     (states (isearch-states pane))
1144     (string (if (null (second states))
1145     (isearch-previous-string pane)
1146     (search-string (first states))))
1147 mvilleneuve 1.97 (mark (clone-mark point)))
1148     (isearch-from-mark pane mark string t)))
1149    
1150     (define-named-command com-isearch-backward ()
1151     (let* ((pane (current-window))
1152     (point (point pane))
1153     (states (isearch-states pane))
1154     (string (if (null (second states))
1155     (isearch-previous-string pane)
1156     (search-string (first states))))
1157     (mark (clone-mark point)))
1158     (isearch-from-mark pane mark string nil)))
1159 mvilleneuve 1.96
1160     (define-named-command com-isearch-exit ()
1161     (setf (isearch-mode (current-window)) nil))
1162    
1163 mvilleneuve 1.100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1164     ;;;
1165     ;;; Query replace
1166    
1167     (defun query-replace-find-next-match (mark string)
1168 mvilleneuve 1.104 (flet ((object-equal (x y)
1169     (and (characterp x)
1170     (characterp y)
1171     (char-equal x y))))
1172     (let ((offset-before (offset mark)))
1173     (search-forward mark string :test #'object-equal)
1174     (/= (offset mark) offset-before))))
1175 mvilleneuve 1.100
1176     (define-named-command com-query-replace ()
1177     (let* ((string1 (accept 'string :prompt "Query replace"))
1178     (string2 (accept 'string
1179     :prompt (format nil "Query replace ~A with"
1180     string1)))
1181     (pane (current-window))
1182     (point (point pane)))
1183     (when (query-replace-find-next-match point string1)
1184     (setf (query-replace-state pane) (make-instance 'query-replace-state
1185     :string1 string1
1186     :string2 string2)
1187     (query-replace-mode pane) t)
1188     (simple-command-loop 'query-replace-climacs-table
1189     (query-replace-mode pane)
1190     ((setf (query-replace-mode pane) nil))))))
1191    
1192     (define-named-command com-query-replace-replace ()
1193     (let* ((pane (current-window))
1194     (point (point pane))
1195 mvilleneuve 1.104 (buffer (buffer pane))
1196 mvilleneuve 1.100 (state (query-replace-state pane))
1197     (string1-length (length (string1 state))))
1198     (backward-object point string1-length)
1199 mvilleneuve 1.104 (let* ((offset1 (offset point))
1200     (offset2 (+ offset1 string1-length))
1201     (region-case (buffer-region-case buffer offset1 offset2)))
1202     (delete-range point string1-length)
1203     (insert-sequence point (string2 state))
1204     (setf offset2 (+ offset1 (length (string2 state))))
1205     (finish-output *error-output*)
1206     (case region-case
1207     (:upper-case (upcase-buffer-region buffer offset1 offset2))
1208     (:lower-case (downcase-buffer-region buffer offset1 offset2))
1209     (:capitalized (capitalize-buffer-region buffer offset1 offset2))))
1210 mvilleneuve 1.100 (unless (query-replace-find-next-match point (string1 state))
1211     (setf (query-replace-mode pane) nil))))
1212    
1213     (define-named-command com-query-replace-skip ()
1214     (let* ((pane (current-window))
1215     (point (point pane))
1216     (state (query-replace-state pane)))
1217     (unless (query-replace-find-next-match point (string1 state))
1218     (setf (query-replace-mode pane) nil))))
1219    
1220     (define-named-command com-query-replace-exit ()
1221     (setf (query-replace-mode (current-window)) nil))
1222    
1223     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1224     ;;;
1225     ;;; Undo/redo
1226    
1227 rstrandh 1.98 (define-named-command com-undo ()
1228     (undo (undo-tree (buffer (current-window)))))
1229    
1230     (define-named-command com-redo ()
1231     (redo (undo-tree (buffer (current-window)))))
1232    
1233 mvilleneuve 1.96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1234     ;;;
1235     ;;; Dynamic abbrevs
1236 ejohnson 1.27
1237 rstrandh 1.49 (define-named-command com-dabbrev-expand ()
1238 rstrandh 1.80 (let* ((win (current-window))
1239 rstrandh 1.49 (point (point win)))
1240     (with-slots (original-prefix prefix-start-offset dabbrev-expansion-mark) win
1241     (flet ((move () (cond ((beginning-of-buffer-p dabbrev-expansion-mark)
1242     (setf (offset dabbrev-expansion-mark)
1243     (offset point))
1244     (forward-word dabbrev-expansion-mark))
1245     ((mark< dabbrev-expansion-mark point)
1246     (backward-object dabbrev-expansion-mark))
1247     (t (forward-object dabbrev-expansion-mark)))))
1248     (unless (or (beginning-of-buffer-p point)
1249     (not (constituentp (object-before point))))
1250     (unless (and (eq (previous-command win) 'com-dabbrev-expand)
1251     (not (null prefix-start-offset)))
1252     (setf dabbrev-expansion-mark (clone-mark point))
1253     (backward-word dabbrev-expansion-mark)
1254     (setf prefix-start-offset (offset dabbrev-expansion-mark))
1255     (setf original-prefix (region-to-sequence prefix-start-offset point))
1256     (move))
1257     (loop until (or (end-of-buffer-p dabbrev-expansion-mark)
1258     (and (or (beginning-of-buffer-p dabbrev-expansion-mark)
1259     (not (constituentp (object-before dabbrev-expansion-mark))))
1260     (looking-at dabbrev-expansion-mark original-prefix)))
1261     do (move))
1262     (if (end-of-buffer-p dabbrev-expansion-mark)
1263     (progn (delete-region prefix-start-offset point)
1264     (insert-sequence point original-prefix)
1265     (setf prefix-start-offset nil))
1266     (progn (delete-region prefix-start-offset point)
1267     (insert-sequence point
1268     (let ((offset (offset dabbrev-expansion-mark)))
1269     (prog2 (forward-word dabbrev-expansion-mark)
1270     (region-to-sequence offset dabbrev-expansion-mark)
1271     (setf (offset dabbrev-expansion-mark) offset))))
1272     (move))))))))
1273    
1274 rstrandh 1.71 (define-named-command com-beginning-of-paragraph ()
1275 rstrandh 1.80 (let* ((pane (current-window))
1276 rstrandh 1.71 (point (point pane))
1277     (syntax (syntax (buffer pane))))
1278     (beginning-of-paragraph point syntax)))
1279    
1280     (define-named-command com-end-of-paragraph ()
1281 rstrandh 1.80 (let* ((pane (current-window))
1282 rstrandh 1.71 (point (point pane))
1283     (syntax (syntax (buffer pane))))
1284     (end-of-paragraph point syntax)))
1285 rstrandh 1.106
1286     (define-named-command com-backward-to-error ()
1287     (let* ((pane (current-window))
1288     (point (point pane))
1289     (syntax (syntax (buffer pane))))
1290     (display-message "~a" (backward-to-error point syntax))))
1291    
1292     (define-named-command com-forward-to-error ()
1293     (let* ((pane (current-window))
1294     (point (point pane))
1295     (syntax (syntax (buffer pane))))
1296     (display-message "~a" (forward-to-error point syntax))))
1297 rstrandh 1.71
1298 rstrandh 1.109 (define-named-command com-eval-expression ((insertp 'boolean :prompt "Insert?"))
1299     (let* ((*package* (find-package :climacs-gui))
1300     (string (accept 'string :prompt "Eval"))
1301     (result (format nil "~a" (eval (read-from-string string)))))
1302     (if insertp
1303     (insert-sequence (point (current-window)) result)
1304     (display-message result))))
1305    
1306 ejohnson 1.27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1307     ;;;
1308 rstrandh 1.80 ;;; Global and dead-escape command tables
1309 ejohnson 1.27
1310     (make-command-table 'global-climacs-table :errorp nil)
1311    
1312 rstrandh 1.80 (make-command-table 'dead-escape-climacs-table :errorp nil)
1313    
1314     (add-menu-item-to-command-table 'global-climacs-table "dead-escape"
1315     :menu 'dead-escape-climacs-table
1316     :keystroke '(:escape))
1317    
1318     (defun dead-escape-set-key (gesture command)
1319     (add-command-to-command-table command 'dead-escape-climacs-table
1320     :keystroke gesture :errorp nil))
1321    
1322 ejohnson 1.27 (defun global-set-key (gesture command)
1323     (add-command-to-command-table command 'global-climacs-table
1324 rstrandh 1.80 :keystroke gesture :errorp nil)
1325     (when (and
1326     (listp gesture)
1327     (find :meta gesture))
1328     (dead-escape-set-key (remove :meta gesture) command)))
1329 ejohnson 1.27
1330 mvilleneuve 1.89 (loop for code from (char-code #\Space) to (char-code #\~)
1331 ejohnson 1.27 do (global-set-key (code-char code) 'com-self-insert))
1332    
1333 mvilleneuve 1.89 (global-set-key #\Newline 'com-self-insert)
1334 mvilleneuve 1.86 (global-set-key #\Tab 'com-indent-line)
1335 rstrandh 1.109 (global-set-key '(#\: :shift :meta) `(com-eval-expression ,*numeric-argument-p*))
1336 mvilleneuve 1.79 (global-set-key '(#\j :control) 'com-newline-and-indent)
1337 rstrandh 1.62 (global-set-key '(#\f :control) `(com-forward-object ,*numeric-argument-marker*))
1338     (global-set-key '(#\b :control) `(com-backward-object ,*numeric-argument-marker*))
1339 ejohnson 1.27 (global-set-key '(#\a :control) 'com-beginning-of-line)
1340     (global-set-key '(#\e :control) 'com-end-of-line)
1341 rstrandh 1.62 (global-set-key '(#\d :control) `(com-delete-object ,*numeric-argument-marker*))
1342 ejohnson 1.27 (global-set-key '(#\p :control) 'com-previous-line)
1343 rstrandh 1.75 (global-set-key '(#\l :control) 'com-full-redisplay)
1344 ejohnson 1.27 (global-set-key '(#\n :control) 'com-next-line)
1345     (global-set-key '(#\o :control) 'com-open-line)
1346     (global-set-key '(#\k :control) 'com-kill-line)
1347 rstrandh 1.42 (global-set-key '(#\t :control) 'com-transpose-objects)
1348 ejohnson 1.27 (global-set-key '(#\Space :control) 'com-set-mark)
1349 ejohnson 1.50 (global-set-key '(#\y :control) 'com-yank)
1350 ejohnson 1.27 (global-set-key '(#\w :control) 'com-cut-out)
1351 rstrandh 1.102 (global-set-key '(#\f :meta) `(com-forward-word ,*numeric-argument-marker*))
1352     (global-set-key '(#\b :meta) `(com-backward-word ,*numeric-argument-marker*))
1353 rstrandh 1.43 (global-set-key '(#\t :meta) 'com-transpose-words)
1354 rstrandh 1.60 (global-set-key '(#\u :meta) 'com-upcase-word)
1355     (global-set-key '(#\l :meta) 'com-downcase-word)
1356     (global-set-key '(#\c :meta) 'com-capitalize-word)
1357 ejohnson 1.27 (global-set-key '(#\x :meta) 'com-extended-command)
1358 ejohnson 1.50 (global-set-key '(#\y :meta) 'com-rotate-yank)
1359 ejohnson 1.27 (global-set-key '(#\w :meta) 'com-copy-out)
1360 rstrandh 1.39 (global-set-key '(#\v :control) 'com-page-down)
1361 rstrandh 1.40 (global-set-key '(#\v :meta) 'com-page-up)
1362 ejohnson 1.27 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
1363     (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
1364 rstrandh 1.32 (global-set-key '(#\m :meta) 'com-back-to-indentation)
1365 mvilleneuve 1.74 (global-set-key '(#\^ :shift :meta) 'com-delete-indentation)
1366 mvilleneuve 1.90 (global-set-key '(#\q :meta) 'com-fill-paragraph)
1367 rstrandh 1.103 (global-set-key '(#\d :meta) `(com-delete-word ,*numeric-argument-marker*))
1368     (global-set-key '(#\Backspace :meta) `(com-backward-delete-word ,*numeric-argument-marker*))
1369 rstrandh 1.49 (global-set-key '(#\/ :meta) 'com-dabbrev-expand)
1370 rstrandh 1.71 (global-set-key '(#\a :control :meta) 'com-beginning-of-paragraph)
1371     (global-set-key '(#\e :control :meta) 'com-end-of-paragraph)
1372 mvilleneuve 1.97 (global-set-key '(#\s :control) 'com-isearch-mode-forward)
1373     (global-set-key '(#\r :control) 'com-isearch-mode-backward)
1374 mvilleneuve 1.100 (global-set-key '(#\% :shift :meta) 'com-query-replace)
1375 ejohnson 1.27
1376     (global-set-key '(:up) 'com-previous-line)
1377     (global-set-key '(:down) 'com-next-line)
1378 rstrandh 1.62 (global-set-key '(:left) `(com-backward-object ,*numeric-argument-marker*))
1379 ejohnson 1.66 (global-set-key '(:right) `(com-forward-object ,*numeric-argument-marker*))
1380 rstrandh 1.102 (global-set-key '(:left :control) `(com-backward-word ,*numeric-argument-marker*))
1381     (global-set-key '(:right :control) `(com-forward-word ,*numeric-argument-marker*))
1382 ejohnson 1.27 (global-set-key '(:home) 'com-beginning-of-line)
1383     (global-set-key '(:end) 'com-end-of-line)
1384 abridgewater 1.57 (global-set-key '(:prior) 'com-page-up)
1385     (global-set-key '(:next) 'com-page-down)
1386 ejohnson 1.27 (global-set-key '(:home :control) 'com-beginning-of-buffer)
1387     (global-set-key '(:end :control) 'com-end-of-buffer)
1388 rstrandh 1.62 (global-set-key #\Rubout `(com-delete-object ,*numeric-argument-marker*))
1389     (global-set-key #\Backspace `(com-backward-delete-object ,*numeric-argument-marker*))
1390 abakic 1.58
1391     (global-set-key '(:insert) 'com-toggle-overwrite-mode)
1392 ejohnson 1.27
1393     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1394     ;;;
1395     ;;; C-x command table
1396    
1397     (make-command-table 'c-x-climacs-table :errorp nil)
1398    
1399     (add-menu-item-to-command-table 'global-climacs-table "C-x"
1400     :menu 'c-x-climacs-table
1401     :keystroke '(#\x :control))
1402    
1403     (defun c-x-set-key (gesture command)
1404     (add-command-to-command-table command 'c-x-climacs-table
1405     :keystroke gesture :errorp nil))
1406    
1407 rstrandh 1.83 (c-x-set-key '(#\0) 'com-delete-window)
1408 ejohnson 1.107 (c-x-set-key '(#\1) 'com-single-window)
1409 rstrandh 1.77 (c-x-set-key '(#\2) 'com-split-window-vertically)
1410 rstrandh 1.83 (c-x-set-key '(#\3) 'com-split-window-horizontally)
1411 rstrandh 1.85 (c-x-set-key '(#\() 'com-start-kbd-macro)
1412     (c-x-set-key '(#\)) 'com-end-kbd-macro)
1413 rstrandh 1.75 (c-x-set-key '(#\b) 'com-switch-to-buffer)
1414 rstrandh 1.85 (c-x-set-key '(#\e) 'com-call-last-kbd-macro)
1415 ejohnson 1.27 (c-x-set-key '(#\c :control) 'com-quit)
1416     (c-x-set-key '(#\f :control) 'com-find-file)
1417 rstrandh 1.91 (c-x-set-key '(#\k) 'com-kill-buffer)
1418 rstrandh 1.63 (c-x-set-key '(#\l :control) 'com-load-file)
1419 rstrandh 1.83 (c-x-set-key '(#\o) 'com-other-window)
1420 rstrandh 1.98 (c-x-set-key '(#\r) 'com-redo)
1421     (c-x-set-key '(#\u) 'com-undo)
1422 ejohnson 1.27 (c-x-set-key '(#\s :control) 'com-save-buffer)
1423 rstrandh 1.45 (c-x-set-key '(#\t :control) 'com-transpose-lines)
1424 ejohnson 1.27 (c-x-set-key '(#\w :control) 'com-write-buffer)
1425 rstrandh 1.45 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
1426 rstrandh 1.44
1427     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1428     ;;;
1429     ;;; Some Unicode stuff
1430    
1431     (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
1432 rstrandh 1.80 (insert-object (point (current-window)) (code-char code)))
1433 rstrandh 1.44
1434     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1435     ;;;
1436     ;;; Dead-acute command table
1437    
1438     (make-command-table 'dead-acute-climacs-table :errorp nil)
1439    
1440     (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
1441     :menu 'dead-acute-climacs-table
1442     :keystroke '(:dead--acute))
1443    
1444     (defun dead-acute-set-key (gesture command)
1445     (add-command-to-command-table command 'dead-acute-climacs-table
1446     :keystroke gesture :errorp nil))
1447    
1448     (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
1449     (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
1450     (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
1451     (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
1452     (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
1453     (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
1454     (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
1455     (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
1456     (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
1457     (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
1458     (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
1459     (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
1460     (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
1461     (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
1462     (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
1463     (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
1464     (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
1465     (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
1466     (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
1467     (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
1468    
1469 rstrandh 1.45 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
1470    
1471     (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
1472     :menu 'dead-acute-dead-accute-climacs-table
1473     :keystroke '(:dead--acute))
1474    
1475     (defun dead-acute-dead-accute-set-key (gesture command)
1476     (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
1477     :keystroke gesture :errorp nil))
1478    
1479     (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
1480     (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
1481 rstrandh 1.44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1482     ;;;
1483     ;;; Dead-grave command table
1484    
1485     (make-command-table 'dead-grave-climacs-table :errorp nil)
1486    
1487     (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
1488     :menu 'dead-grave-climacs-table
1489     :keystroke '(:dead--grave))
1490    
1491     (defun dead-grave-set-key (gesture command)
1492     (add-command-to-command-table command 'dead-grave-climacs-table
1493     :keystroke gesture :errorp nil))
1494    
1495     (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
1496     (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
1497     (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
1498     (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
1499     (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
1500     (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
1501     (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
1502     (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
1503     (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
1504     (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
1505     (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
1506    
1507     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1508     ;;;
1509     ;;; Dead-diaeresis command table
1510    
1511     (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
1512    
1513     (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
1514     :menu 'dead-diaeresis-climacs-table
1515     :keystroke '(:dead--diaeresis :shift))
1516    
1517     (defun dead-diaeresis-set-key (gesture command)
1518     (add-command-to-command-table command 'dead-diaeresis-climacs-table
1519     :keystroke gesture :errorp nil))
1520    
1521     (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
1522     (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
1523     (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
1524     (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
1525     (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
1526     (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
1527     (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
1528     (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
1529     (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
1530     (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
1531     (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
1532     (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
1533    
1534     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1535     ;;;
1536     ;;; Dead-tilde command table
1537    
1538     (make-command-table 'dead-tilde-climacs-table :errorp nil)
1539    
1540     (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
1541     :menu 'dead-tilde-climacs-table
1542     :keystroke '(:dead--tilde :shift))
1543    
1544     (defun dead-tilde-set-key (gesture command)
1545     (add-command-to-command-table command 'dead-tilde-climacs-table
1546     :keystroke gesture :errorp nil))
1547    
1548     (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
1549     (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
1550     (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
1551     (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
1552     (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
1553     (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
1554     (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
1555     (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
1556     (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
1557     (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
1558     (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
1559    
1560     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1561     ;;;
1562     ;;; Dead-circumflex command table
1563    
1564     (make-command-table 'dead-circumflex-climacs-table :errorp nil)
1565    
1566     (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
1567     :menu 'dead-circumflex-climacs-table
1568     :keystroke '(:dead--circumflex :shift))
1569    
1570     (defun dead-circumflex-set-key (gesture command)
1571     (add-command-to-command-table command 'dead-circumflex-climacs-table
1572     :keystroke gesture :errorp nil))
1573    
1574     (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
1575     (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
1576     (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
1577     (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
1578     (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
1579     (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
1580     (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
1581     (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
1582     (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
1583     (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
1584     (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))
1585 mvilleneuve 1.96
1586     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1587     ;;;
1588     ;;; Isearch command table
1589    
1590     (make-command-table 'isearch-climacs-table :errorp nil)
1591    
1592     (defun isearch-set-key (gesture command)
1593     (add-command-to-command-table command 'isearch-climacs-table
1594     :keystroke gesture :errorp nil))
1595    
1596     (loop for code from (char-code #\Space) to (char-code #\~)
1597     do (isearch-set-key (code-char code) 'com-isearch-append-char))
1598    
1599     (isearch-set-key '(#\Newline) 'com-isearch-exit)
1600     (isearch-set-key '(#\Backspace) 'com-isearch-delete-char)
1601     (isearch-set-key '(#\s :control) 'com-isearch-forward)
1602 mvilleneuve 1.97 (isearch-set-key '(#\r :control) 'com-isearch-backward)
1603 mvilleneuve 1.100
1604     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1605     ;;;
1606     ;;; Query replace command table
1607    
1608     (make-command-table 'query-replace-climacs-table :errorp nil)
1609    
1610     (defun query-replace-set-key (gesture command)
1611     (add-command-to-command-table command 'query-replace-climacs-table
1612     :keystroke gesture :errorp nil))
1613    
1614     (query-replace-set-key '(#\Newline) 'com-query-replace-exit)
1615     (query-replace-set-key '(#\Space) 'com-query-replace-replace)
1616     (query-replace-set-key '(#\Backspace) 'com-query-replace-skip)
1617     (query-replace-set-key '(#\Rubout) 'com-query-replace-skip)
1618     (query-replace-set-key '(#\q) 'com-query-replace-exit)
1619     (query-replace-set-key '(#\y) 'com-query-replace-replace)
1620     (query-replace-set-key '(#\n) 'com-query-replace-skip)

  ViewVC Help
Powered by ViewVC 1.1.5