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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.56 - (show annotations)
Sat Jan 8 07:46:33 2005 UTC (9 years, 3 months ago) by ejohnson
Branch: MAIN
Changes since 1.55: +6 -7 lines
Fixed the beeping from C-k at end-of-buffer, thanks Robert
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* ((pane (win *application-frame*))
351 (point (point pane))
352 (mark (offset point)))
353 (cond ((end-of-buffer-p point) nil)
354 ((end-of-line-p point)(forward-object point))
355 (t
356 (end-of-line point)
357 (cond ((beginning-of-buffer-p point) nil)
358 ((beginning-of-line-p point)(forward-object point)))))
359 (if (eq (previous-command pane) 'com-kill-line)
360 (kill-ring-concatenating-push *kill-ring*
361 (region-to-sequence mark point))
362 (kill-ring-standard-push *kill-ring*
363 (region-to-sequence mark point)))
364 (delete-region mark point)))
365
366 (define-named-command com-forward-word ()
367 (forward-word (point (win *application-frame*))))
368
369 (define-named-command com-backward-word ()
370 (backward-word (point (win *application-frame*))))
371
372 (define-named-command com-delete-word ()
373 (delete-word (point (win *application-frame*))))
374
375 (define-named-command com-backward-delete-word ()
376 (backward-delete-word (point (win *application-frame*))))
377
378 (define-named-command com-toggle-layout ()
379 (setf (frame-current-layout *application-frame*)
380 (if (eq (frame-current-layout *application-frame*) 'default)
381 'without-interactor
382 'default)))
383
384 (define-command com-extended-command ()
385 (let ((item (accept 'command :prompt "Extended Command")))
386 (execute-frame-command *application-frame* item)))
387
388 (eval-when (:compile-toplevel :load-toplevel)
389 (define-presentation-type completable-pathname ()
390 :inherit-from 'pathname))
391
392 (defun filename-completer (so-far mode)
393 (flet ((remove-trail (s)
394 (subseq s 0 (let ((pos (position #\/ s :from-end t)))
395 (if pos (1+ pos) 0)))))
396 (let* ((directory-prefix
397 (if (and (plusp (length so-far)) (eql (aref so-far 0) #\/))
398 ""
399 (namestring #+sbcl (car (directory ".")) #+cmu (ext:default-directory))))
400 (full-so-far (concatenate 'string directory-prefix so-far))
401 (pathnames
402 (loop with length = (length full-so-far)
403 for path in (directory (concatenate 'string
404 (remove-trail so-far)
405 "*.*"))
406 when (let ((mismatch (mismatch (namestring path) full-so-far)))
407 (or (null mismatch) (= mismatch length)))
408 collect path))
409 (strings (mapcar #'namestring pathnames))
410 (first-string (car strings))
411 (length-common-prefix nil)
412 (completed-string nil)
413 (full-completed-string nil))
414 (unless (null pathnames)
415 (setf length-common-prefix
416 (loop with length = (length first-string)
417 for string in (cdr strings)
418 do (setf length (min length (or (mismatch string first-string) length)))
419 finally (return length))))
420 (unless (null pathnames)
421 (setf completed-string
422 (subseq first-string (length directory-prefix)
423 (if (null (cdr pathnames)) nil length-common-prefix)))
424 (setf full-completed-string
425 (concatenate 'string directory-prefix completed-string)))
426 (case mode
427 ((:complete-limited :complete-maximal)
428 (cond ((null pathnames)
429 (values so-far nil nil 0 nil))
430 ((null (cdr pathnames))
431 (values completed-string t (car pathnames) 1 nil))
432 (t
433 (values completed-string nil nil (length pathnames) nil))))
434 (:complete
435 (cond ((null pathnames)
436 (values so-far t so-far 1 nil))
437 ((null (cdr pathnames))
438 (values completed-string t (car pathnames) 1 nil))
439 ((find full-completed-string strings :test #'string-equal)
440 (let ((pos (position full-completed-string strings :test #'string-equal)))
441 (values completed-string
442 t (elt pathnames pos) (length pathnames) nil)))
443 (t
444 (values completed-string nil nil (length pathnames) nil))))
445 (:possibilities
446 (values nil nil nil (length pathnames)
447 (loop with length = (length directory-prefix)
448 for name in pathnames
449 collect (list (subseq (namestring name) length nil)
450 name))))))))
451
452 (define-presentation-method accept
453 ((type completable-pathname) stream (view textual-view) &key)
454 (multiple-value-bind (pathname success string)
455 (complete-input stream
456 #'filename-completer
457 :partial-completers '(#\Space)
458 :allow-any-input t)
459 (declare (ignore success))
460 (or pathname string)))
461
462 (defun pathname-filename (pathname)
463 (if (null (pathname-type pathname))
464 (pathname-name pathname)
465 (concatenate 'string (pathname-name pathname)
466 "." (pathname-type pathname))))
467
468 (define-named-command com-find-file ()
469 (let ((filename (accept 'completable-pathname
470 :prompt "Find File")))
471 (with-slots (buffer point syntax) (win *application-frame*)
472 (setf buffer (make-instance 'climacs-buffer)
473 point (make-instance 'standard-right-sticky-mark :buffer buffer)
474 syntax (make-instance 'texinfo-syntax :pane (win *application-frame*)))
475 (with-open-file (stream filename :direction :input :if-does-not-exist :create)
476 (input-from-stream stream buffer 0))
477 (setf (filename buffer) filename
478 (name buffer) (pathname-filename filename)
479 (needs-saving buffer) nil)
480 (beginning-of-buffer point)
481 ;; this one is needed so that the buffer modification protocol
482 ;; resets the low and high marks after redisplay
483 (redisplay-frame-panes *application-frame*))))
484
485 (define-named-command com-save-buffer ()
486 (let* ((buffer (buffer (win *application-frame*)))
487 (filename (or (filename buffer)
488 (accept 'completable-pathname
489 :prompt "Save Buffer to File"))))
490 (if (or (null (filename buffer))
491 (needs-saving buffer))
492 (progn (with-open-file (stream filename :direction :output :if-exists :supersede)
493 (output-to-stream stream buffer 0 (size buffer)))
494 (setf (filename buffer) filename
495 (name buffer) (pathname-filename filename))
496 (display-message "Wrote: ~a" (filename buffer)))
497 (display-message "No changes need to be saved from ~a" (name buffer)))
498 (setf (needs-saving buffer) nil)))
499
500 (define-named-command com-write-buffer ()
501 (let ((filename (accept 'completable-pathname
502 :prompt "Write Buffer to File"))
503 (buffer (buffer (win *application-frame*))))
504 (with-open-file (stream filename :direction :output :if-exists :supersede)
505 (output-to-stream stream buffer 0 (size buffer)))
506 (setf (filename buffer) filename
507 (name buffer) (pathname-filename filename)
508 (needs-saving buffer) nil)
509 (display-message "Wrote: ~a" (filename buffer))))
510
511 (define-named-command com-beginning-of-buffer ()
512 (beginning-of-buffer (point (win *application-frame*))))
513
514 (define-named-command com-page-down ()
515 (let ((pane (win *application-frame*)))
516 (page-down pane (syntax pane))))
517
518 (define-named-command com-page-up ()
519 (let ((pane (win *application-frame*)))
520 (page-up pane (syntax pane))))
521
522 (define-named-command com-end-of-buffer ()
523 (end-of-buffer (point (win *application-frame*))))
524
525 (define-named-command com-back-to-indentation ()
526 (let ((point (point (win *application-frame*))))
527 (beginning-of-line point)
528 (loop until (end-of-line-p point)
529 while (whitespacep (object-after point))
530 do (incf (offset point)))))
531
532 (define-named-command com-goto-position ()
533 (setf (offset (point (win *application-frame*)))
534 (accept 'integer :prompt "Goto Position")))
535
536 (define-named-command com-goto-line ()
537 (loop with mark = (make-instance 'standard-right-sticky-mark
538 :buffer (buffer (win *application-frame*)))
539 do (end-of-line mark)
540 until (end-of-buffer-p mark)
541 repeat (accept 'integer :prompt "Goto Line")
542 do (incf (offset mark))
543 (end-of-line mark)
544 finally (beginning-of-line mark)
545 (setf (offset (point (win *application-frame*)))
546 (offset mark))))
547
548 (define-named-command com-browse-url ()
549 (accept 'url :prompt "Browse URL"))
550
551 (define-named-command com-set-mark ()
552 (with-slots (point mark) (win *application-frame*)
553 (setf mark (clone-mark point))))
554
555 (define-named-command com-exchange-point-and-mark ()
556 (with-slots (point mark) (win *application-frame*)
557 (psetf (offset mark) (offset point)
558 (offset point) (offset mark))))
559
560 (define-named-command com-set-syntax ()
561 (setf (syntax (win *application-frame*))
562 (make-instance (accept 'syntax :prompt "Set Syntax")
563 :pane (win *application-frame*))))
564
565 ;;;;;;;;;;;;;;;;;;;;
566 ;; Kill ring commands
567
568 ;; Copies an element from a kill-ring to a buffer at the given offset
569 (define-named-command com-yank ()
570 (insert-sequence (point (win *application-frame*)) (kill-ring-yank *kill-ring*)))
571
572 ;; Destructively cut a given buffer region into the kill-ring
573 (define-named-command com-cut-out ()
574 (with-slots (point mark)(win *application-frame*)
575 (cond ((< (offset mark)(offset point))
576 (kill-ring-standard-push *kill-ring* (region-to-sequence mark point))
577 (delete-region (offset mark) point))
578 (t
579 (kill-ring-standard-push *kill-ring* (region-to-sequence point mark))
580 (delete-region (offset point) mark)))))
581
582 ;; Non destructively copies in buffer region to the kill ring
583 (define-named-command com-copy-out ()
584 (with-slots (point mark)(win *application-frame*)
585 (kill-ring-standard-push *kill-ring* (region-to-sequence point mark))))
586
587
588 (define-named-command com-rotate-yank ()
589 (let* ((pane (win *application-frame*))
590 (point (point pane))
591 (last-yank (kill-ring-yank *kill-ring*)))
592 (if (eq (previous-command pane)
593 'com-rotate-yank)
594 (progn
595 (delete-range point (* -1 (length last-yank)))
596 (rotate-yank-position *kill-ring*)))
597 (insert-sequence point (kill-ring-yank *kill-ring*))))
598
599 (define-named-command com-resize-kill-ring ()
600 (let ((size (accept 'integer :prompt "New kill ring size")))
601 (setf (kill-ring-max-size *kill-ring*) size)))
602
603 (define-named-command com-search-forward ()
604 (search-forward (point (win *application-frame*))
605 (accept 'string :prompt "Search Forward")
606 :test (lambda (a b)
607 (and (characterp b) (char-equal a b)))))
608
609 (define-named-command com-search-backward ()
610 (search-backward (point (win *application-frame*))
611 (accept 'string :prompt "Search Backward")
612 :test (lambda (a b)
613 (and (characterp b) (char-equal a b)))))
614
615 (define-named-command com-dabbrev-expand ()
616 (let* ((win (win *application-frame*))
617 (point (point win)))
618 (with-slots (original-prefix prefix-start-offset dabbrev-expansion-mark) win
619 (flet ((move () (cond ((beginning-of-buffer-p dabbrev-expansion-mark)
620 (setf (offset dabbrev-expansion-mark)
621 (offset point))
622 (forward-word dabbrev-expansion-mark))
623 ((mark< dabbrev-expansion-mark point)
624 (backward-object dabbrev-expansion-mark))
625 (t (forward-object dabbrev-expansion-mark)))))
626 (unless (or (beginning-of-buffer-p point)
627 (not (constituentp (object-before point))))
628 (unless (and (eq (previous-command win) 'com-dabbrev-expand)
629 (not (null prefix-start-offset)))
630 (setf dabbrev-expansion-mark (clone-mark point))
631 (backward-word dabbrev-expansion-mark)
632 (setf prefix-start-offset (offset dabbrev-expansion-mark))
633 (setf original-prefix (region-to-sequence prefix-start-offset point))
634 (move))
635 (loop until (or (end-of-buffer-p dabbrev-expansion-mark)
636 (and (or (beginning-of-buffer-p dabbrev-expansion-mark)
637 (not (constituentp (object-before dabbrev-expansion-mark))))
638 (looking-at dabbrev-expansion-mark original-prefix)))
639 do (move))
640 (if (end-of-buffer-p dabbrev-expansion-mark)
641 (progn (delete-region prefix-start-offset point)
642 (insert-sequence point original-prefix)
643 (setf prefix-start-offset nil))
644 (progn (delete-region prefix-start-offset point)
645 (insert-sequence point
646 (let ((offset (offset dabbrev-expansion-mark)))
647 (prog2 (forward-word dabbrev-expansion-mark)
648 (region-to-sequence offset dabbrev-expansion-mark)
649 (setf (offset dabbrev-expansion-mark) offset))))
650 (move))))))))
651
652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
653 ;;;
654 ;;; Global command table
655
656 (make-command-table 'global-climacs-table :errorp nil)
657
658 (defun global-set-key (gesture command)
659 (add-command-to-command-table command 'global-climacs-table
660 :keystroke gesture :errorp nil))
661
662 (loop for code from (char-code #\space) to (char-code #\~)
663 do (global-set-key (code-char code) 'com-self-insert))
664
665 (global-set-key #\newline 'com-self-insert)
666 (global-set-key #\tab 'com-self-insert)
667 (global-set-key '(#\f :control) 'com-forward-object)
668 (global-set-key '(#\b :control) 'com-backward-object)
669 (global-set-key '(#\a :control) 'com-beginning-of-line)
670 (global-set-key '(#\e :control) 'com-end-of-line)
671 (global-set-key '(#\d :control) 'com-delete-object)
672 (global-set-key '(#\p :control) 'com-previous-line)
673 (global-set-key '(#\n :control) 'com-next-line)
674 (global-set-key '(#\o :control) 'com-open-line)
675 (global-set-key '(#\k :control) 'com-kill-line)
676 (global-set-key '(#\t :control) 'com-transpose-objects)
677 (global-set-key '(#\Space :control) 'com-set-mark)
678 (global-set-key '(#\y :control) 'com-yank)
679 (global-set-key '(#\w :control) 'com-cut-out)
680 (global-set-key '(#\f :meta) 'com-forward-word)
681 (global-set-key '(#\b :meta) 'com-backward-word)
682 (global-set-key '(#\t :meta) 'com-transpose-words)
683 (global-set-key '(#\x :meta) 'com-extended-command)
684 (global-set-key '(#\y :meta) 'com-rotate-yank)
685 (global-set-key '(#\w :meta) 'com-copy-out)
686 (global-set-key '(#\v :control) 'com-page-down)
687 (global-set-key '(#\v :meta) 'com-page-up)
688 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
689 (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
690 (global-set-key '(#\u :meta) 'com-browse-url)
691 (global-set-key '(#\m :meta) 'com-back-to-indentation)
692 (global-set-key '(#\d :meta) 'com-delete-word)
693 (global-set-key '(#\Backspace :meta) 'com-backward-delete-word)
694 (global-set-key '(#\/ :meta) 'com-dabbrev-expand)
695
696 (global-set-key '(:up) 'com-previous-line)
697 (global-set-key '(:down) 'com-next-line)
698 (global-set-key '(:left) 'com-backward-object)
699 (global-set-key '(:right) 'com-forward-object)
700 (global-set-key '(:left :control) 'com-backward-word)
701 (global-set-key '(:right :control) 'com-forward-word)
702 (global-set-key '(:home) 'com-beginning-of-line)
703 (global-set-key '(:end) 'com-end-of-line)
704 (global-set-key '(:home :control) 'com-beginning-of-buffer)
705 (global-set-key '(:end :control) 'com-end-of-buffer)
706 (global-set-key #\Rubout 'com-delete-object)
707 (global-set-key #\Backspace 'com-backward-delete-object)
708
709 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
710 ;;;
711 ;;; C-x command table
712
713 (make-command-table 'c-x-climacs-table :errorp nil)
714
715 (add-menu-item-to-command-table 'global-climacs-table "C-x"
716 :menu 'c-x-climacs-table
717 :keystroke '(#\x :control))
718
719 (defun c-x-set-key (gesture command)
720 (add-command-to-command-table command 'c-x-climacs-table
721 :keystroke gesture :errorp nil))
722
723 (c-x-set-key '(#\c :control) 'com-quit)
724 (c-x-set-key '(#\f :control) 'com-find-file)
725 (c-x-set-key '(#\s :control) 'com-save-buffer)
726 (c-x-set-key '(#\t :control) 'com-transpose-lines)
727 (c-x-set-key '(#\w :control) 'com-write-buffer)
728 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
729
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
731 ;;;
732 ;;; Some Unicode stuff
733
734 (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
735 (insert-object (point (win *application-frame*)) (code-char code)))
736
737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
738 ;;;
739 ;;; Dead-acute command table
740
741 (make-command-table 'dead-acute-climacs-table :errorp nil)
742
743 (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
744 :menu 'dead-acute-climacs-table
745 :keystroke '(:dead--acute))
746
747 (defun dead-acute-set-key (gesture command)
748 (add-command-to-command-table command 'dead-acute-climacs-table
749 :keystroke gesture :errorp nil))
750
751 (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
752 (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
753 (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
754 (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
755 (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
756 (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
757 (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
758 (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
759 (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
760 (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
761 (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
762 (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
763 (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
764 (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
765 (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
766 (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
767 (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
768 (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
769 (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
770 (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
771
772 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
773
774 (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
775 :menu 'dead-acute-dead-accute-climacs-table
776 :keystroke '(:dead--acute))
777
778 (defun dead-acute-dead-accute-set-key (gesture command)
779 (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
780 :keystroke gesture :errorp nil))
781
782 (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
783 (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
785 ;;;
786 ;;; Dead-grave command table
787
788 (make-command-table 'dead-grave-climacs-table :errorp nil)
789
790 (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
791 :menu 'dead-grave-climacs-table
792 :keystroke '(:dead--grave))
793
794 (defun dead-grave-set-key (gesture command)
795 (add-command-to-command-table command 'dead-grave-climacs-table
796 :keystroke gesture :errorp nil))
797
798 (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
799 (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
800 (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
801 (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
802 (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
803 (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
804 (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
805 (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
806 (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
807 (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
808 (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
809
810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
811 ;;;
812 ;;; Dead-diaeresis command table
813
814 (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
815
816 (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
817 :menu 'dead-diaeresis-climacs-table
818 :keystroke '(:dead--diaeresis :shift))
819
820 (defun dead-diaeresis-set-key (gesture command)
821 (add-command-to-command-table command 'dead-diaeresis-climacs-table
822 :keystroke gesture :errorp nil))
823
824 (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
825 (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
826 (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
827 (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
828 (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
829 (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
830 (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
831 (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
832 (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
833 (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
834 (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
835 (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
836
837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
838 ;;;
839 ;;; Dead-tilde command table
840
841 (make-command-table 'dead-tilde-climacs-table :errorp nil)
842
843 (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
844 :menu 'dead-tilde-climacs-table
845 :keystroke '(:dead--tilde :shift))
846
847 (defun dead-tilde-set-key (gesture command)
848 (add-command-to-command-table command 'dead-tilde-climacs-table
849 :keystroke gesture :errorp nil))
850
851 (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
852 (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
853 (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
854 (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
855 (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
856 (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
857 (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
858 (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
859 (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
860 (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
861 (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
862
863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
864 ;;;
865 ;;; Dead-circumflex command table
866
867 (make-command-table 'dead-circumflex-climacs-table :errorp nil)
868
869 (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
870 :menu 'dead-circumflex-climacs-table
871 :keystroke '(:dead--circumflex :shift))
872
873 (defun dead-circumflex-set-key (gesture command)
874 (add-command-to-command-table command 'dead-circumflex-climacs-table
875 :keystroke gesture :errorp nil))
876
877 (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
878 (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
879 (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
880 (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
881 (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
882 (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
883 (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
884 (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
885 (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
886 (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
887 (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))

  ViewVC Help
Powered by ViewVC 1.1.5