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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.52 - (show annotations)
Fri Jan 7 14:59:15 2005 UTC (9 years, 3 months ago) by ejohnson
Branch: MAIN
Changes since 1.51: +2 -1 lines
Now C-k dosn't kill newlines be default and does kill newlines if kills are performed at the end of line.  Good stuff :)
1 ;;; -*- Mode: Lisp; Package: CLIMACS-GUI -*-
2
3 ;;; (c) copyright 2004 by
4 ;;; Robert Strandh (strandh@labri.fr)
5 ;;; (c) copyright 2004 by
6 ;;; Elliott Johnson (ejohnson@fasl.info)
7
8 ;;; This library is free software; you can redistribute it and/or
9 ;;; modify it under the terms of the GNU Library General Public
10 ;;; License as published by the Free Software Foundation; either
11 ;;; version 2 of the License, or (at your option) any later version.
12 ;;;
13 ;;; This library is distributed in the hope that it will be useful,
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;;; Library General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU Library General Public
19 ;;; License along with this library; if not, write to the
20 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;;; Boston, MA 02111-1307 USA.
22
23 ;;; GUI for the Climacs editor.
24
25 (in-package :climacs-gui)
26
27 (defclass filename-mixin ()
28 ((filename :initform nil :accessor filename)))
29
30 (defclass climacs-buffer (standard-buffer abbrev-mixin filename-mixin name-mixin)
31 ((needs-saving :initform nil :accessor needs-saving))
32 (:default-initargs :name "*scratch*"))
33
34
35 (defclass climacs-pane (application-pane)
36 ((buffer :initform (make-instance 'climacs-buffer) :accessor buffer)
37 (point :initform nil :initarg :point :reader point)
38 (syntax :initarg :syntax :accessor syntax)
39 (mark :initform nil :initarg :mark :reader mark)
40 ;; allows a certain number of commands to have some minimal memory
41 (previous-command :initform nil :accessor previous-command)
42 ;; for next-line and previous-line commands
43 (goal-column :initform nil)
44 ;; for dynamic abbrev expansion
45 (original-prefix :initform nil)
46 (prefix-start-offset :initform nil)
47 (dabbrev-expansion-mark :initform nil)))
48
49 (defmethod initialize-instance :after ((pane climacs-pane) &rest args)
50 (declare (ignore args))
51 (with-slots (buffer point syntax mark) pane
52 (when (null point)
53 (setf point (make-instance 'standard-right-sticky-mark
54 :buffer buffer)))
55 (when (null mark)
56 (setf mark (make-instance 'standard-right-sticky-mark
57 :buffer buffer)))
58 (setf syntax (make-instance 'texinfo-syntax :pane pane))))
59
60 (defclass minibuffer-pane (application-pane) ())
61
62 (defmethod stream-accept :before ((pane minibuffer-pane) type &rest args)
63 (declare (ignore type args))
64 (window-clear pane))
65
66 (define-application-frame climacs ()
67 ((win :reader win))
68 (:panes
69 (win (make-pane 'climacs-pane
70 :width 900 :height 400
71 :name 'win
72 :incremental-redisplay t
73 :display-function 'display-win))
74 (info :application
75 :width 900 :height 20 :max-height 20
76 :name 'info :background +light-gray+
77 :scroll-bars nil
78 :incremental-redisplay t
79 :display-function 'display-info)
80 (int (make-pane 'minibuffer-pane
81 :width 900 :height 20 :max-height 20 :min-height 20
82 :scroll-bars nil)))
83 (:layouts
84 (default
85 (vertically (:scroll-bars nil)
86 (scrolling (:width 900 :height 400) win)
87 info
88 int))
89 (without-interactor
90 (vertically (:scroll-bars nil)
91 (scrolling (:width 900 :height 400) win)
92 info)))
93 (:top-level (climacs-top-level)))
94
95 (defmethod redisplay-frame-panes :after ((frame climacs) &rest args)
96 (declare (ignore args))
97 (clear-modify (buffer (win frame))))
98
99 (defun climacs ()
100 "Starts up a climacs session"
101 (let ((frame (make-application-frame 'climacs)))
102 (run-frame-top-level frame)))
103
104 (defun display-message (format-string &rest format-args)
105 (apply #'format *standard-input* format-string format-args))
106
107 (defun display-info (frame pane)
108 (let* ((win (win frame))
109 (buf (buffer win))
110 (name-info (format nil " ~a ~a Syntax: ~a"
111 (if (needs-saving buf) "**" "--")
112 (name buf)
113 (name (syntax win)))))
114 (princ name-info pane)))
115
116 (defun display-win (frame pane)
117 "The display function used by the climacs application frame."
118 (declare (ignore frame))
119 (redisplay-pane pane))
120
121 (defun find-gestures (gestures start-table)
122 (loop with table = (find-command-table start-table)
123 for (gesture . rest) on gestures
124 for item = (find-keystroke-item gesture table :errorp nil)
125 while item
126 do (if (eq (command-menu-item-type item) :command)
127 (return (if (null rest) item nil))
128 (setf table (command-menu-item-value item)))
129 finally (return item)))
130
131 (defvar *kill-ring* (make-instance 'kill-ring :max-size 7))
132 (defparameter *current-gesture* nil)
133
134 (defun meta-digit (gesture)
135 (position gesture
136 '((#\0 :meta) (#\1 :meta) (#\2 :meta) (#\3 :meta) (#\4 :meta)
137 (#\5 :meta) (#\6 :meta) (#\7 :meta) (#\8 :meta) (#\9 :meta))
138 :test #'event-matches-gesture-name-p))
139
140 (defun climacs-read-gesture ()
141 (loop for gesture = (read-gesture :stream *standard-input*)
142 when (event-matches-gesture-name-p gesture '(#\g :control))
143 do (throw 'outer-loop nil)
144 until (or (characterp gesture)
145 (and (typep gesture 'keyboard-event)
146 (or (keyboard-event-character gesture)
147 (not (member (keyboard-event-key-name
148 gesture)
149 '(:control-left :control-right
150 :shift-left :shift-right
151 :meta-left :meta-right
152 :super-left :super-right
153 :hyper-left :hyper-right
154 :shift-lock :caps-lock
155 :alt-left :alt-right))))))
156 finally (return gesture)))
157
158 (defun read-numeric-argument (&key (stream *standard-input*))
159 (let ((gesture (climacs-read-gesture)))
160 (cond ((event-matches-gesture-name-p gesture '(#\u :control))
161 (let ((numarg 4))
162 (loop for gesture = (climacs-read-gesture)
163 while (event-matches-gesture-name-p gesture '(#\u :control))
164 do (setf numarg (* 4 numarg))
165 finally (unread-gesture gesture :stream stream))
166 (let ((gesture (climacs-read-gesture)))
167 (cond ((and (characterp gesture)
168 (digit-char-p gesture 10))
169 (setf numarg (- (char-code gesture) (char-code #\0)))
170 (loop for gesture = (climacs-read-gesture)
171 while (and (characterp gesture)
172 (digit-char-p gesture 10))
173 do (setf gesture (+ (* 10 numarg)
174 (- (char-code gesture) (char-code #\0))))
175 finally (unread-gesture gesture :stream stream)
176 (return (values numarg t))))
177 (t
178 (values numarg t))))))
179 ((meta-digit gesture)
180 (let ((numarg (meta-digit gesture)))
181 (loop for gesture = (climacs-read-gesture)
182 while (meta-digit gesture)
183 do (setf numarg (+ (* 10 numarg) (meta-digit gesture)))
184 finally (unread-gesture gesture :stream stream)
185 (return (values numarg t)))))
186 (t (unread-gesture gesture :stream stream)
187 (values 1 nil)))))
188
189 (defun climacs-top-level (frame &key
190 command-parser command-unparser
191 partial-command-parser prompt)
192 (declare (ignore command-parser command-unparser partial-command-parser prompt))
193 (setf (slot-value frame 'win) (find-pane-named frame 'win))
194 (let ((*standard-output* (find-pane-named frame 'win))
195 (*standard-input* (find-pane-named frame 'int))
196 (*print-pretty* nil)
197 (*abort-gestures* nil))
198 (redisplay-frame-panes frame :force-p t)
199 (loop (catch 'outer-loop
200 (loop with gestures = '()
201 with numarg = 1 ; FIXME (read-numeric-argument :stream *standard-input*)
202 do (setf *current-gesture* (climacs-read-gesture))
203 (setf gestures (nconc gestures (list *current-gesture*)))
204 (let ((item (find-gestures gestures 'global-climacs-table)))
205 (cond ((not item)
206 (beep) (setf gestures '()))
207 ((eq (command-menu-item-type item) :command)
208 (let ((command (command-menu-item-value item)))
209 (unless (consp command)
210 (setf command (list command)))
211 (setf command (substitute-numeric-argument-marker command numarg))
212 (handler-case
213 (execute-frame-command frame command)
214 (error (condition)
215 (beep)
216 (format *error-output* "~a~%" condition)))
217 (setf gestures '())
218 (setf (previous-command *standard-output*)
219 (if (consp command)
220 (car command)
221 command))))
222 (t nil)))
223 (let ((buffer (buffer (win frame))))
224 (when (modified-p buffer)
225 (setf (needs-saving buffer) t)))
226 (redisplay-frame-panes frame)))
227 (beep)
228 (let ((buffer (buffer (win frame))))
229 (when (modified-p buffer)
230 (setf (needs-saving buffer) t)))
231 (redisplay-frame-panes frame))))
232
233 (defmacro define-named-command (command-name args &body body)
234 `(define-climacs-command ,(if (listp command-name) `(,@command-name :name t) `(,command-name :name t)) ,args ,@body))
235
236 (define-named-command (com-quit) ()
237 (frame-exit *application-frame*))
238
239 (define-command com-self-insert ()
240 (unless (constituentp *current-gesture*)
241 (possibly-expand-abbrev (point (win *application-frame*))))
242 (insert-object (point (win *application-frame*)) *current-gesture*))
243
244 (define-named-command com-beginning-of-line ()
245 (beginning-of-line (point (win *application-frame*))))
246
247 (define-named-command com-end-of-line ()
248 (end-of-line (point (win *application-frame*))))
249
250 (define-named-command com-delete-object ()
251 (delete-range (point (win *application-frame*))))
252
253 (define-named-command com-backward-delete-object ()
254 (delete-range (point (win *application-frame*)) -1))
255
256 (define-named-command com-transpose-objects ()
257 (let* ((point (point (win *application-frame*))))
258 (unless (beginning-of-buffer-p point)
259 (when (end-of-line-p point)
260 (backward-object point))
261 (let ((object (object-after point)))
262 (delete-range point)
263 (backward-object point)
264 (insert-object point object)
265 (forward-object point)))))
266
267 (defgeneric backward-object (mark &optional count))
268 (defmethod backward-object ((mark climacs-buffer::mark-mixin)
269 &optional (count 1))
270 (decf (offset mark) count))
271
272 (defgeneric forward-object (mark &optional count))
273 (defmethod forward-object ((mark climacs-buffer::mark-mixin)
274 &optional (count 1))
275 (incf (offset mark) count))
276
277 (define-named-command com-backward-object ()
278 (backward-object (point (win *application-frame*))))
279
280 (define-named-command com-forward-object ()
281 (forward-object (point (win *application-frame*))))
282
283 (define-named-command com-transpose-words ()
284 (let* ((point (point (win *application-frame*))))
285 (let (bw1 bw2 ew1 ew2)
286 (backward-word point)
287 (setf bw1 (offset point))
288 (forward-word point)
289 (setf ew1 (offset point))
290 (forward-word point)
291 (when (= (offset point) ew1)
292 ;; this is emacs' message in the minibuffer
293 (error "Don't have two things to transpose"))
294 (setf ew2 (offset point))
295 (backward-word point)
296 (setf bw2 (offset point))
297 (let ((w2 (buffer-sequence (buffer point) bw2 ew2))
298 (w1 (buffer-sequence (buffer point) bw1 ew1)))
299 (delete-word point)
300 (insert-sequence point w1)
301 (backward-word point)
302 (backward-word point)
303 (delete-word point)
304 (insert-sequence point w2)
305 (forward-word point)))))
306
307 (define-named-command com-transpose-lines ()
308 (let ((point (point (win *application-frame*))))
309 (beginning-of-line point)
310 (unless (beginning-of-buffer-p point)
311 (previous-line point))
312 (let* ((bol (offset point))
313 (eol (progn (end-of-line point)
314 (offset point)))
315 (line (buffer-sequence (buffer point) bol eol)))
316 (delete-region bol point)
317 ;; Remove newline at end of line as well.
318 (unless (end-of-buffer-p point)
319 (delete-range point))
320 ;; If the current line is at the end of the buffer, we want to
321 ;; be able to insert past it, so we need to get an extra line
322 ;; at the end.
323 (when (progn (end-of-line point)
324 (end-of-buffer-p point))
325 (insert-object point #\Newline))
326 (next-line point)
327 (insert-sequence point line)
328 (insert-object point #\Newline))))
329
330 (define-named-command com-previous-line ()
331 (let* ((win (win *application-frame*))
332 (point (point win)))
333 (unless (or (eq (previous-command win) 'com-previous-line)
334 (eq (previous-command win) 'com-next-line))
335 (setf (slot-value win 'goal-column) (column-number point)))
336 (previous-line point (slot-value win 'goal-column))))
337
338 (define-named-command com-next-line ()
339 (let* ((win (win *application-frame*))
340 (point (point win)))
341 (unless (or (eq (previous-command win) 'com-previous-line)
342 (eq (previous-command win) 'com-next-line))
343 (setf (slot-value win 'goal-column) (column-number point)))
344 (next-line point (slot-value win 'goal-column))))
345
346 (define-named-command com-open-line ()
347 (open-line (point (win *application-frame*))))
348
349 (define-named-command com-kill-line ()
350 (let* ((payne (win *application-frame*))
351 (pnt (point payne))
352 (mrk (offset pnt)))
353 (end-of-line pnt)
354 (cond ((or (beginning-of-buffer-p pnt)
355 (end-of-buffer-p pnt)) nil)
356 ((and (beginning-of-line-p pnt)
357 (end-of-line-p pnt))(forward-object pnt)))
358 (if (eq (previous-command payne) 'com-kill-line)
359 (kill-ring-concatenating-push *kill-ring*
360 (region-to-sequence mrk pnt))
361 (kill-ring-standard-push *kill-ring*
362 (region-to-sequence mrk pnt)))
363 (delete-region mrk pnt)))
364
365 (define-named-command com-forward-word ()
366 (forward-word (point (win *application-frame*))))
367
368 (define-named-command com-backward-word ()
369 (backward-word (point (win *application-frame*))))
370
371 (define-named-command com-delete-word ()
372 (delete-word (point (win *application-frame*))))
373
374 (define-named-command com-backward-delete-word ()
375 (backward-delete-word (point (win *application-frame*))))
376
377 (define-named-command com-toggle-layout ()
378 (setf (frame-current-layout *application-frame*)
379 (if (eq (frame-current-layout *application-frame*) 'default)
380 'without-interactor
381 'default)))
382
383 (define-command com-extended-command ()
384 (let ((item (accept 'command :prompt "Extended Command")))
385 (execute-frame-command *application-frame* item)))
386
387 (eval-when (:compile-toplevel :load-toplevel)
388 (define-presentation-type completable-pathname ()
389 :inherit-from 'pathname))
390
391 (defun filename-completer (so-far mode)
392 (flet ((remove-trail (s)
393 (subseq s 0 (let ((pos (position #\/ s :from-end t)))
394 (if pos (1+ pos) 0)))))
395 (let* ((directory-prefix
396 (if (and (plusp (length so-far)) (eql (aref so-far 0) #\/))
397 ""
398 (namestring #+sbcl (car (directory ".")) #+cmu (ext:default-directory))))
399 (full-so-far (concatenate 'string directory-prefix so-far))
400 (pathnames
401 (loop with length = (length full-so-far)
402 for path in (directory (concatenate 'string
403 (remove-trail so-far)
404 "*.*"))
405 when (let ((mismatch (mismatch (namestring path) full-so-far)))
406 (or (null mismatch) (= mismatch length)))
407 collect path))
408 (strings (mapcar #'namestring pathnames))
409 (first-string (car strings))
410 (length-common-prefix nil)
411 (completed-string nil)
412 (full-completed-string nil))
413 (unless (null pathnames)
414 (setf length-common-prefix
415 (loop with length = (length first-string)
416 for string in (cdr strings)
417 do (setf length (min length (or (mismatch string first-string) length)))
418 finally (return length))))
419 (unless (null pathnames)
420 (setf completed-string
421 (subseq first-string (length directory-prefix)
422 (if (null (cdr pathnames)) nil length-common-prefix)))
423 (setf full-completed-string
424 (concatenate 'string directory-prefix completed-string)))
425 (case mode
426 ((:complete-limited :complete-maximal)
427 (cond ((null pathnames)
428 (values so-far nil nil 0 nil))
429 ((null (cdr pathnames))
430 (values completed-string t (car pathnames) 1 nil))
431 (t
432 (values completed-string nil nil (length pathnames) nil))))
433 (:complete
434 (cond ((null pathnames)
435 (values so-far t so-far 1 nil))
436 ((null (cdr pathnames))
437 (values completed-string t (car pathnames) 1 nil))
438 ((find full-completed-string strings :test #'string-equal)
439 (let ((pos (position full-completed-string strings :test #'string-equal)))
440 (values completed-string
441 t (elt pathnames pos) (length pathnames) nil)))
442 (t
443 (values completed-string nil nil (length pathnames) nil))))
444 (:possibilities
445 (values nil nil nil (length pathnames)
446 (loop with length = (length directory-prefix)
447 for name in pathnames
448 collect (list (subseq (namestring name) length nil)
449 name))))))))
450
451 (define-presentation-method accept
452 ((type completable-pathname) stream (view textual-view) &key)
453 (multiple-value-bind (pathname success string)
454 (complete-input stream
455 #'filename-completer
456 :partial-completers '(#\Space)
457 :allow-any-input t)
458 (declare (ignore success))
459 (or pathname string)))
460
461 (defun pathname-filename (pathname)
462 (if (null (pathname-type pathname))
463 (pathname-name pathname)
464 (concatenate 'string (pathname-name pathname)
465 "." (pathname-type pathname))))
466
467 (define-named-command com-find-file ()
468 (let ((filename (accept 'completable-pathname
469 :prompt "Find File")))
470 (with-slots (buffer point syntax) (win *application-frame*)
471 (setf buffer (make-instance 'climacs-buffer)
472 point (make-instance 'standard-right-sticky-mark :buffer buffer)
473 syntax (make-instance 'texinfo-syntax :pane (win *application-frame*)))
474 (with-open-file (stream filename :direction :input :if-does-not-exist :create)
475 (input-from-stream stream buffer 0))
476 (setf (filename buffer) filename
477 (name buffer) (pathname-filename filename)
478 (needs-saving buffer) nil)
479 (beginning-of-buffer point)
480 ;; this one is needed so that the buffer modification protocol
481 ;; resets the low and high marks after redisplay
482 (redisplay-frame-panes *application-frame*))))
483
484 (define-named-command com-save-buffer ()
485 (let* ((buffer (buffer (win *application-frame*)))
486 (filename (or (filename buffer)
487 (accept 'completable-pathname
488 :prompt "Save Buffer to File"))))
489 (if (or (null (filename buffer))
490 (needs-saving buffer))
491 (progn (with-open-file (stream filename :direction :output :if-exists :supersede)
492 (output-to-stream stream buffer 0 (size buffer)))
493 (setf (filename buffer) filename
494 (name buffer) (pathname-filename filename))
495 (display-message "Wrote: ~a" (filename buffer)))
496 (display-message "No changes need to be saved from ~a" (name buffer)))
497 (setf (needs-saving buffer) nil)))
498
499 (define-named-command com-write-buffer ()
500 (let ((filename (accept 'completable-pathname
501 :prompt "Write Buffer to File"))
502 (buffer (buffer (win *application-frame*))))
503 (with-open-file (stream filename :direction :output :if-exists :supersede)
504 (output-to-stream stream buffer 0 (size buffer)))
505 (setf (filename buffer) filename
506 (name buffer) (pathname-filename filename)
507 (needs-saving buffer) nil)
508 (display-message "Wrote: ~a" (filename buffer))))
509
510 (define-named-command com-beginning-of-buffer ()
511 (beginning-of-buffer (point (win *application-frame*))))
512
513 (define-named-command com-page-down ()
514 (let ((pane (win *application-frame*)))
515 (page-down pane (syntax pane))))
516
517 (define-named-command com-page-up ()
518 (let ((pane (win *application-frame*)))
519 (page-up pane (syntax pane))))
520
521 (define-named-command com-end-of-buffer ()
522 (end-of-buffer (point (win *application-frame*))))
523
524 (define-named-command com-back-to-indentation ()
525 (let ((point (point (win *application-frame*))))
526 (beginning-of-line point)
527 (loop until (end-of-line-p point)
528 while (whitespacep (object-after point))
529 do (incf (offset point)))))
530
531 (define-named-command com-goto-position ()
532 (setf (offset (point (win *application-frame*)))
533 (accept 'integer :prompt "Goto Position")))
534
535 (define-named-command com-goto-line ()
536 (loop with mark = (make-instance 'standard-right-sticky-mark
537 :buffer (buffer (win *application-frame*)))
538 do (end-of-line mark)
539 until (end-of-buffer-p mark)
540 repeat (accept 'integer :prompt "Goto Line")
541 do (incf (offset mark))
542 (end-of-line mark)
543 finally (beginning-of-line mark)
544 (setf (offset (point (win *application-frame*)))
545 (offset mark))))
546
547 (define-named-command com-browse-url ()
548 (accept 'url :prompt "Browse URL"))
549
550 (define-named-command com-set-mark ()
551 (with-slots (point mark) (win *application-frame*)
552 (setf mark (clone-mark point))))
553
554 (define-named-command com-exchange-point-and-mark ()
555 (with-slots (point mark) (win *application-frame*)
556 (psetf (offset mark) (offset point)
557 (offset point) (offset mark))))
558
559 (define-named-command com-set-syntax ()
560 (setf (syntax (win *application-frame*))
561 (make-instance (accept 'syntax :prompt "Set Syntax")
562 :pane (win *application-frame*))))
563
564 ;;;;;;;;;;;;;;;;;;;;
565 ;; Kill ring commands
566
567 ;; Copies an element from a kill-ring to a buffer at the given offset
568 (define-named-command com-yank ()
569 (insert-sequence (point (win *application-frame*)) (kill-ring-yank *kill-ring*)))
570
571 ;; Destructively cut a given buffer region into the kill-ring
572 (define-named-command com-cut-out ()
573 (with-slots (buffer point mark)(win *application-frame*)
574 (let ((offp (offset point))
575 (offm (offset mark)))
576 (if (< offp offm)
577 ((lambda (b o1 o2)
578 (kill-ring-standard-push *kill-ring* (buffer-sequence b o1 o2))
579 (delete-buffer-range b o1 (- o2 o1)))
580 buffer offp offm)
581 ((lambda (b o1 o2)
582 (kill-ring-standard-push *kill-ring* (buffer-sequence b o2 o1))
583 (delete-buffer-range b o1 (- o2 o1)))
584 buffer offm offp)))))
585
586
587 ;; Non destructively copies in buffer region to the kill ring
588 (define-named-command com-copy-out ()
589 (with-slots (buffer point mark)(win *application-frame*)
590 (let ((off1 (offset point))
591 (off2 (offset mark)))
592 (if (< off1 off2)
593 (kill-ring-standard-push *kill-ring* (buffer-sequence buffer off1 off2))
594 (kill-ring-standard-push *kill-ring* (buffer-sequence buffer off2 off1))))))
595
596
597 (define-named-command com-rotate-yank ()
598 (let* ((payne (win *application-frame*))
599 (pnt (point payne))
600 (last-yank (kill-ring-yank *kill-ring*)))
601 (if (eq (previous-command payne)
602 'com-rotate-yank)
603 ((lambda (p ly)
604 (delete-range p (* -1 (length ly)))
605 (rotate-yank-position *kill-ring*))
606 pnt last-yank))
607 (insert-sequence pnt (kill-ring-yank *kill-ring*))))
608
609 (define-named-command com-resize-kill-ring ()
610 (let ((size (accept 'integer :prompt "New kill ring size")))
611 (setf (kill-ring-max-size *kill-ring*) size)))
612
613 (define-named-command com-search-forward ()
614 (search-forward (point (win *application-frame*))
615 (accept 'string :prompt "Search Forward")
616 :test (lambda (a b)
617 (and (characterp b) (char-equal a b)))))
618
619 (define-named-command com-search-backward ()
620 (search-backward (point (win *application-frame*))
621 (accept 'string :prompt "Search Backward")
622 :test (lambda (a b)
623 (and (characterp b) (char-equal a b)))))
624
625 (define-named-command com-dabbrev-expand ()
626 (let* ((win (win *application-frame*))
627 (point (point win)))
628 (with-slots (original-prefix prefix-start-offset dabbrev-expansion-mark) win
629 (flet ((move () (cond ((beginning-of-buffer-p dabbrev-expansion-mark)
630 (setf (offset dabbrev-expansion-mark)
631 (offset point))
632 (forward-word dabbrev-expansion-mark))
633 ((mark< dabbrev-expansion-mark point)
634 (backward-object dabbrev-expansion-mark))
635 (t (forward-object dabbrev-expansion-mark)))))
636 (unless (or (beginning-of-buffer-p point)
637 (not (constituentp (object-before point))))
638 (unless (and (eq (previous-command win) 'com-dabbrev-expand)
639 (not (null prefix-start-offset)))
640 (setf dabbrev-expansion-mark (clone-mark point))
641 (backward-word dabbrev-expansion-mark)
642 (setf prefix-start-offset (offset dabbrev-expansion-mark))
643 (setf original-prefix (region-to-sequence prefix-start-offset point))
644 (move))
645 (loop until (or (end-of-buffer-p dabbrev-expansion-mark)
646 (and (or (beginning-of-buffer-p dabbrev-expansion-mark)
647 (not (constituentp (object-before dabbrev-expansion-mark))))
648 (looking-at dabbrev-expansion-mark original-prefix)))
649 do (move))
650 (if (end-of-buffer-p dabbrev-expansion-mark)
651 (progn (delete-region prefix-start-offset point)
652 (insert-sequence point original-prefix)
653 (setf prefix-start-offset nil))
654 (progn (delete-region prefix-start-offset point)
655 (insert-sequence point
656 (let ((offset (offset dabbrev-expansion-mark)))
657 (prog2 (forward-word dabbrev-expansion-mark)
658 (region-to-sequence offset dabbrev-expansion-mark)
659 (setf (offset dabbrev-expansion-mark) offset))))
660 (move))))))))
661
662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663 ;;;
664 ;;; Global command table
665
666 (make-command-table 'global-climacs-table :errorp nil)
667
668 (defun global-set-key (gesture command)
669 (add-command-to-command-table command 'global-climacs-table
670 :keystroke gesture :errorp nil))
671
672 (loop for code from (char-code #\space) to (char-code #\~)
673 do (global-set-key (code-char code) 'com-self-insert))
674
675 (global-set-key #\newline 'com-self-insert)
676 (global-set-key #\tab 'com-self-insert)
677 (global-set-key '(#\f :control) 'com-forward-object)
678 (global-set-key '(#\b :control) 'com-backward-object)
679 (global-set-key '(#\a :control) 'com-beginning-of-line)
680 (global-set-key '(#\e :control) 'com-end-of-line)
681 (global-set-key '(#\d :control) 'com-delete-object)
682 (global-set-key '(#\p :control) 'com-previous-line)
683 (global-set-key '(#\n :control) 'com-next-line)
684 (global-set-key '(#\o :control) 'com-open-line)
685 (global-set-key '(#\k :control) 'com-kill-line)
686 (global-set-key '(#\t :control) 'com-transpose-objects)
687 (global-set-key '(#\Space :control) 'com-set-mark)
688 (global-set-key '(#\y :control) 'com-yank)
689 (global-set-key '(#\w :control) 'com-cut-out)
690 (global-set-key '(#\f :meta) 'com-forward-word)
691 (global-set-key '(#\b :meta) 'com-backward-word)
692 (global-set-key '(#\t :meta) 'com-transpose-words)
693 (global-set-key '(#\x :meta) 'com-extended-command)
694 (global-set-key '(#\y :meta) 'com-rotate-yank)
695 (global-set-key '(#\w :meta) 'com-copy-out)
696 (global-set-key '(#\v :control) 'com-page-down)
697 (global-set-key '(#\v :meta) 'com-page-up)
698 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
699 (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
700 (global-set-key '(#\u :meta) 'com-browse-url)
701 (global-set-key '(#\m :meta) 'com-back-to-indentation)
702 (global-set-key '(#\d :meta) 'com-delete-word)
703 (global-set-key '(#\Backspace :meta) 'com-backward-delete-word)
704 (global-set-key '(#\/ :meta) 'com-dabbrev-expand)
705
706 (global-set-key '(:up) 'com-previous-line)
707 (global-set-key '(:down) 'com-next-line)
708 (global-set-key '(:left) 'com-backward-object)
709 (global-set-key '(:right) 'com-forward-object)
710 (global-set-key '(:left :control) 'com-backward-word)
711 (global-set-key '(:right :control) 'com-forward-word)
712 (global-set-key '(:home) 'com-beginning-of-line)
713 (global-set-key '(:end) 'com-end-of-line)
714 (global-set-key '(:home :control) 'com-beginning-of-buffer)
715 (global-set-key '(:end :control) 'com-end-of-buffer)
716 (global-set-key #\Rubout 'com-delete-object)
717 (global-set-key #\Backspace 'com-backward-delete-object)
718
719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
720 ;;;
721 ;;; C-x command table
722
723 (make-command-table 'c-x-climacs-table :errorp nil)
724
725 (add-menu-item-to-command-table 'global-climacs-table "C-x"
726 :menu 'c-x-climacs-table
727 :keystroke '(#\x :control))
728
729 (defun c-x-set-key (gesture command)
730 (add-command-to-command-table command 'c-x-climacs-table
731 :keystroke gesture :errorp nil))
732
733 (c-x-set-key '(#\c :control) 'com-quit)
734 (c-x-set-key '(#\f :control) 'com-find-file)
735 (c-x-set-key '(#\s :control) 'com-save-buffer)
736 (c-x-set-key '(#\t :control) 'com-transpose-lines)
737 (c-x-set-key '(#\w :control) 'com-write-buffer)
738 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
739
740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
741 ;;;
742 ;;; Some Unicode stuff
743
744 (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
745 (insert-object (point (win *application-frame*)) (code-char code)))
746
747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
748 ;;;
749 ;;; Dead-acute command table
750
751 (make-command-table 'dead-acute-climacs-table :errorp nil)
752
753 (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
754 :menu 'dead-acute-climacs-table
755 :keystroke '(:dead--acute))
756
757 (defun dead-acute-set-key (gesture command)
758 (add-command-to-command-table command 'dead-acute-climacs-table
759 :keystroke gesture :errorp nil))
760
761 (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
762 (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
763 (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
764 (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
765 (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
766 (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
767 (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
768 (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
769 (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
770 (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
771 (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
772 (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
773 (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
774 (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
775 (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
776 (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
777 (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
778 (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
779 (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
780 (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
781
782 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
783
784 (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
785 :menu 'dead-acute-dead-accute-climacs-table
786 :keystroke '(:dead--acute))
787
788 (defun dead-acute-dead-accute-set-key (gesture command)
789 (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
790 :keystroke gesture :errorp nil))
791
792 (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
793 (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
795 ;;;
796 ;;; Dead-grave command table
797
798 (make-command-table 'dead-grave-climacs-table :errorp nil)
799
800 (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
801 :menu 'dead-grave-climacs-table
802 :keystroke '(:dead--grave))
803
804 (defun dead-grave-set-key (gesture command)
805 (add-command-to-command-table command 'dead-grave-climacs-table
806 :keystroke gesture :errorp nil))
807
808 (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
809 (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
810 (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
811 (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
812 (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
813 (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
814 (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
815 (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
816 (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
817 (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
818 (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
819
820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
821 ;;;
822 ;;; Dead-diaeresis command table
823
824 (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
825
826 (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
827 :menu 'dead-diaeresis-climacs-table
828 :keystroke '(:dead--diaeresis :shift))
829
830 (defun dead-diaeresis-set-key (gesture command)
831 (add-command-to-command-table command 'dead-diaeresis-climacs-table
832 :keystroke gesture :errorp nil))
833
834 (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
835 (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
836 (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
837 (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
838 (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
839 (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
840 (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
841 (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
842 (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
843 (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
844 (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
845 (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
846
847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
848 ;;;
849 ;;; Dead-tilde command table
850
851 (make-command-table 'dead-tilde-climacs-table :errorp nil)
852
853 (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
854 :menu 'dead-tilde-climacs-table
855 :keystroke '(:dead--tilde :shift))
856
857 (defun dead-tilde-set-key (gesture command)
858 (add-command-to-command-table command 'dead-tilde-climacs-table
859 :keystroke gesture :errorp nil))
860
861 (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
862 (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
863 (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
864 (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
865 (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
866 (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
867 (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
868 (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
869 (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
870 (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
871 (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
872
873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
874 ;;;
875 ;;; Dead-circumflex command table
876
877 (make-command-table 'dead-circumflex-climacs-table :errorp nil)
878
879 (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
880 :menu 'dead-circumflex-climacs-table
881 :keystroke '(:dead--circumflex :shift))
882
883 (defun dead-circumflex-set-key (gesture command)
884 (add-command-to-command-table command 'dead-circumflex-climacs-table
885 :keystroke gesture :errorp nil))
886
887 (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
888 (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
889 (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
890 (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
891 (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
892 (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
893 (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
894 (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
895 (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
896 (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
897 (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))

  ViewVC Help
Powered by ViewVC 1.1.5