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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (hide annotations)
Mon Jan 3 13:36:34 2005 UTC (9 years, 3 months ago) by ejohnson
Branch: MAIN
Changes since 1.45: +1 -1 lines
a very small fix.  Fixnum was a bad choice here.  Integer works much nicer
1 ejohnson 1.27 ;;; -*- 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 rstrandh 1.38 (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 ejohnson 1.27
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    
41     (defmethod initialize-instance :after ((pane climacs-pane) &rest args)
42     (declare (ignore args))
43     (with-slots (buffer point syntax mark) pane
44     (when (null point)
45     (setf point (make-instance 'standard-right-sticky-mark
46     :buffer buffer)))
47     (when (null mark)
48     (setf mark (make-instance 'standard-right-sticky-mark
49     :buffer buffer)))
50     (setf syntax (make-instance 'texinfo-syntax :pane pane))))
51    
52 rstrandh 1.28 (defclass minibuffer-pane (application-pane) ())
53    
54     (defmethod stream-accept :before ((pane minibuffer-pane) type &rest args)
55     (declare (ignore type args))
56     (window-clear pane))
57    
58 ejohnson 1.27 (define-application-frame climacs ()
59     ((win :reader win))
60     (:panes
61     (win (make-pane 'climacs-pane
62     :width 900 :height 400
63     :name 'win
64     :incremental-redisplay t
65     :display-function 'display-win))
66     (info :application
67 rstrandh 1.28 :width 900 :height 20 :max-height 20
68     :name 'info :background +light-gray+
69     :scroll-bars nil
70     :incremental-redisplay t
71     :display-function 'display-info)
72     (int (make-pane 'minibuffer-pane
73     :width 900 :height 20 :max-height 20 :min-height 20
74     :scroll-bars nil)))
75 ejohnson 1.27 (:layouts
76     (default
77     (vertically (:scroll-bars nil)
78     (scrolling (:width 900 :height 400) win)
79     info
80 rstrandh 1.45 int))
81     (without-interactor
82     (vertically (:scroll-bars nil)
83     (scrolling (:width 900 :height 400) win)
84     info)))
85 ejohnson 1.27 (:top-level (climacs-top-level)))
86    
87 rstrandh 1.28 (defmethod redisplay-frame-panes :after ((frame climacs) &rest args)
88     (declare (ignore args))
89     (clear-modify (buffer (win frame))))
90    
91 ejohnson 1.27 (defun climacs ()
92     "Starts up a climacs session"
93     (let ((frame (make-application-frame 'climacs)))
94     (run-frame-top-level frame)))
95    
96 rstrandh 1.30 (defun display-message (format-string &rest format-args)
97     (apply #'format *standard-input* format-string format-args))
98    
99 ejohnson 1.27 (defun display-info (frame pane)
100     (let* ((win (win frame))
101     (buf (buffer win))
102 rstrandh 1.38 (name-info (format nil " ~a ~a Syntax: ~a"
103 rstrandh 1.28 (if (needs-saving buf) "**" "--")
104 rstrandh 1.38 (name buf)
105     (name (syntax win)))))
106 ejohnson 1.27 (princ name-info pane)))
107    
108     (defun display-win (frame pane)
109     "The display function used by the climacs application frame."
110     (declare (ignore frame))
111     (redisplay-pane pane))
112    
113     (defun find-gestures (gestures start-table)
114     (loop with table = (find-command-table start-table)
115     for (gesture . rest) on gestures
116     for item = (find-keystroke-item gesture table :errorp nil)
117     while item
118     do (if (eq (command-menu-item-type item) :command)
119     (return (if (null rest) item nil))
120     (setf table (command-menu-item-value item)))
121     finally (return item)))
122    
123     (defvar *kill-ring* (initialize-kill-ring 7))
124     (defparameter *current-gesture* nil)
125    
126 rstrandh 1.36 (defun meta-digit (gesture)
127     (position gesture
128     '((#\0 :meta) (#\1 :meta) (#\2 :meta) (#\3 :meta) (#\4 :meta)
129     (#\5 :meta) (#\6 :meta) (#\7 :meta) (#\8 :meta) (#\9 :meta))
130     :test #'event-matches-gesture-name-p))
131    
132     (defun read-numeric-argument (&key (stream *standard-input*))
133     (let ((gesture (read-gesture :stream stream)))
134     (cond ((event-matches-gesture-name-p gesture '(#\u :control))
135     (let ((numarg 4))
136     (loop for gesture = (read-gesture :stream stream)
137     while (event-matches-gesture-name-p gesture '(#\u :control))
138     do (setf numarg (* 4 numarg))
139     finally (unread-gesture gesture :stream stream))
140     (let ((gesture (read-gesture :stream stream)))
141     (cond ((and (characterp gesture)
142     (digit-char-p gesture 10))
143     (setf numarg (- (char-code gesture) (char-code #\0)))
144     (loop for gesture = (read-gesture :stream stream)
145     while (and (characterp gesture)
146     (digit-char-p gesture 10))
147     do (setf gesture (+ (* 10 numarg)
148     (- (char-code gesture) (char-code #\0))))
149     finally (unread-gesture gesture :stream stream)
150     (return (values numarg t))))
151     (t
152     (values numarg t))))))
153     ((meta-digit gesture)
154     (let ((numarg (meta-digit gesture)))
155     (loop for gesture = (read-gesture :stream stream)
156     while (meta-digit gesture)
157     do (setf numarg (+ (* 10 numarg) (meta-digit gesture)))
158     finally (unread-gesture gesture :stream stream)
159     (return (values numarg t)))))
160     (t (unread-gesture gesture :stream stream)
161     (values 1 nil)))))
162    
163 ejohnson 1.27 (defun climacs-top-level (frame &key
164     command-parser command-unparser
165     partial-command-parser prompt)
166     (declare (ignore command-parser command-unparser partial-command-parser prompt))
167     (setf (slot-value frame 'win) (find-pane-named frame 'win))
168     (let ((*standard-output* (find-pane-named frame 'win))
169     (*standard-input* (find-pane-named frame 'int))
170     (*print-pretty* nil)
171     (*abort-gestures* nil))
172     (redisplay-frame-panes frame :force-p t)
173     (loop with gestures = '()
174 rstrandh 1.36 with numarg = 1 ; FIXME (read-numeric-argument :stream *standard-input*)
175 ejohnson 1.27 do (setf *current-gesture* (read-gesture :stream *standard-input*))
176     (when (or (characterp *current-gesture*)
177     (and (typep *current-gesture* 'keyboard-event)
178     (or (keyboard-event-character *current-gesture*)
179     (not (member (keyboard-event-key-name
180     *current-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     (setf gestures (nconc gestures (list *current-gesture*)))
188     (let ((item (find-gestures gestures 'global-climacs-table)))
189     (cond ((not item)
190     (beep) (setf gestures '()))
191     ((eq (command-menu-item-type item) :command)
192 rstrandh 1.36 (let ((command (command-menu-item-value item)))
193     (unless (consp command)
194     (setf command (list command)))
195     (setf command (substitute-numeric-argument-marker command numarg))
196     (handler-case
197     (execute-frame-command frame command)
198     (error (condition)
199     (beep)
200     (format *error-output* "~a~%" condition)))
201     (setf gestures '())))
202 ejohnson 1.27 (t nil))))
203 rstrandh 1.28 (let ((buffer (buffer (win frame))))
204     (when (modified-p buffer)
205     (setf (needs-saving buffer) t)))
206 ejohnson 1.27 (redisplay-frame-panes frame))))
207    
208 abridgewater 1.34 (defmacro define-named-command (command-name args &body body)
209     `(define-climacs-command ,(if (listp command-name) `(,@command-name :name t) `(,command-name :name t)) ,args ,@body))
210    
211     (define-named-command (com-quit) ()
212 ejohnson 1.27 (frame-exit *application-frame*))
213    
214     (define-command com-self-insert ()
215     (unless (constituentp *current-gesture*)
216     (possibly-expand-abbrev (point (win *application-frame*))))
217 rstrandh 1.28 (insert-object (point (win *application-frame*)) *current-gesture*))
218 ejohnson 1.27
219 abridgewater 1.34 (define-named-command com-beginning-of-line ()
220 ejohnson 1.27 (beginning-of-line (point (win *application-frame*))))
221    
222 abridgewater 1.34 (define-named-command com-end-of-line ()
223 ejohnson 1.27 (end-of-line (point (win *application-frame*))))
224    
225 abridgewater 1.34 (define-named-command com-delete-object ()
226 rstrandh 1.28 (delete-range (point (win *application-frame*))))
227 ejohnson 1.27
228 abridgewater 1.34 (define-named-command com-backward-delete-object ()
229 rstrandh 1.28 (delete-range (point (win *application-frame*)) -1))
230 ejohnson 1.27
231 rstrandh 1.42 (define-named-command com-transpose-objects ()
232     (let* ((point (point (win *application-frame*))))
233     (unless (beginning-of-buffer-p point)
234     (when (end-of-line-p point)
235 rstrandh 1.43 (backward-object point))
236     (let ((object (object-after point)))
237     (delete-range point)
238     (backward-object point)
239     (insert-object point object)
240     (forward-object point)))))
241    
242     (defgeneric backward-object (mark &optional count))
243     (defmethod backward-object ((mark climacs-buffer::mark-mixin)
244     &optional (count 1))
245     (decf (offset mark) count))
246    
247     (defgeneric forward-object (mark &optional count))
248     (defmethod forward-object ((mark climacs-buffer::mark-mixin)
249     &optional (count 1))
250     (incf (offset mark) count))
251    
252     (define-named-command com-backward-object ()
253     (backward-object (point (win *application-frame*))))
254    
255     (define-named-command com-forward-object ()
256     (forward-object (point (win *application-frame*))))
257    
258     (define-named-command com-transpose-words ()
259     (let* ((point (point (win *application-frame*))))
260     (let (bw1 bw2 ew1 ew2)
261     (backward-word point)
262     (setf bw1 (offset point))
263     (forward-word point)
264     (setf ew1 (offset point))
265     (forward-word point)
266     (when (= (offset point) ew1)
267     ;; this is emacs' message in the minibuffer
268     (error "Don't have two things to transpose"))
269     (setf ew2 (offset point))
270     (backward-word point)
271     (setf bw2 (offset point))
272     (let ((w2 (buffer-sequence (buffer point) bw2 ew2))
273     (w1 (buffer-sequence (buffer point) bw1 ew1)))
274     (delete-word point)
275     (insert-sequence point w1)
276     (backward-word point)
277     (backward-word point)
278     (delete-word point)
279     (insert-sequence point w2)
280     (forward-word point)))))
281 rstrandh 1.42
282 rstrandh 1.45 (define-named-command com-transpose-lines ()
283     (let ((point (point (win *application-frame*))))
284     (beginning-of-line point)
285     (unless (beginning-of-buffer-p point)
286     (previous-line point))
287     (let* ((bol (offset point))
288     (eol (progn (end-of-line point)
289     (offset point)))
290     (line (buffer-sequence (buffer point) bol eol)))
291     (delete-region bol point)
292     ;; Remove newline at end of line as well.
293     (unless (end-of-buffer-p point)
294     (delete-range point))
295     ;; If the current line is at the end of the buffer, we want to
296     ;; be able to insert past it, so we need to get an extra line
297     ;; at the end.
298     (when (progn (end-of-line point)
299     (end-of-buffer-p point))
300     (insert-object point #\Newline))
301     (next-line point)
302     (insert-sequence point line)
303     (insert-object point #\Newline))))
304    
305 abridgewater 1.34 (define-named-command com-previous-line ()
306 ejohnson 1.27 (previous-line (point (win *application-frame*))))
307    
308 abridgewater 1.34 (define-named-command com-next-line ()
309 ejohnson 1.27 (next-line (point (win *application-frame*))))
310    
311 abridgewater 1.34 (define-named-command com-open-line ()
312 rstrandh 1.28 (open-line (point (win *application-frame*))))
313 ejohnson 1.27
314 abridgewater 1.34 (define-named-command com-kill-line ()
315 rstrandh 1.28 (kill-line (point (win *application-frame*))))
316 ejohnson 1.27
317 abridgewater 1.34 (define-named-command com-forward-word ()
318 ejohnson 1.27 (forward-word (point (win *application-frame*))))
319    
320 abridgewater 1.34 (define-named-command com-backward-word ()
321 ejohnson 1.27 (backward-word (point (win *application-frame*))))
322    
323 abridgewater 1.34 (define-named-command com-delete-word ()
324 rstrandh 1.32 (delete-word (point (win *application-frame*))))
325    
326 abridgewater 1.34 (define-named-command com-backward-delete-word ()
327 rstrandh 1.32 (backward-delete-word (point (win *application-frame*))))
328    
329 abridgewater 1.34 (define-named-command com-toggle-layout ()
330 ejohnson 1.27 (setf (frame-current-layout *application-frame*)
331     (if (eq (frame-current-layout *application-frame*) 'default)
332 rstrandh 1.45 'without-interactor
333 ejohnson 1.27 'default)))
334    
335     (define-command com-extended-command ()
336     (let ((item (accept 'command :prompt "Extended Command")))
337     (execute-frame-command *application-frame* item)))
338    
339 rstrandh 1.41 (eval-when (:compile-toplevel :load-toplevel)
340 ejohnson 1.35 (define-presentation-type completable-pathname ()
341     :inherit-from 'pathname))
342 ejohnson 1.27
343     (defun filename-completer (so-far mode)
344     (flet ((remove-trail (s)
345     (subseq s 0 (let ((pos (position #\/ s :from-end t)))
346     (if pos (1+ pos) 0)))))
347     (let* ((directory-prefix
348     (if (and (plusp (length so-far)) (eql (aref so-far 0) #\/))
349     ""
350     (namestring #+sbcl (car (directory ".")) #+cmu (ext:default-directory))))
351     (full-so-far (concatenate 'string directory-prefix so-far))
352     (pathnames
353     (loop with length = (length full-so-far)
354     for path in (directory (concatenate 'string
355     (remove-trail so-far)
356     "*.*"))
357     when (let ((mismatch (mismatch (namestring path) full-so-far)))
358     (or (null mismatch) (= mismatch length)))
359     collect path))
360     (strings (mapcar #'namestring pathnames))
361     (first-string (car strings))
362     (length-common-prefix nil)
363     (completed-string nil)
364     (full-completed-string nil))
365     (unless (null pathnames)
366     (setf length-common-prefix
367     (loop with length = (length first-string)
368     for string in (cdr strings)
369     do (setf length (min length (or (mismatch string first-string) length)))
370     finally (return length))))
371     (unless (null pathnames)
372     (setf completed-string
373     (subseq first-string (length directory-prefix)
374     (if (null (cdr pathnames)) nil length-common-prefix)))
375     (setf full-completed-string
376     (concatenate 'string directory-prefix completed-string)))
377     (case mode
378     ((:complete-limited :complete-maximal)
379     (cond ((null pathnames)
380     (values so-far nil nil 0 nil))
381     ((null (cdr pathnames))
382     (values completed-string t (car pathnames) 1 nil))
383     (t
384     (values completed-string nil nil (length pathnames) nil))))
385     (:complete
386     (cond ((null pathnames)
387     (values so-far t so-far 1 nil))
388     ((null (cdr pathnames))
389     (values completed-string t (car pathnames) 1 nil))
390     ((find full-completed-string strings :test #'string-equal)
391     (let ((pos (position full-completed-string strings :test #'string-equal)))
392     (values completed-string
393     t (elt pathnames pos) (length pathnames) nil)))
394     (t
395     (values completed-string nil nil (length pathnames) nil))))
396     (:possibilities
397     (values nil nil nil (length pathnames)
398     (loop with length = (length directory-prefix)
399     for name in pathnames
400     collect (list (subseq (namestring name) length nil)
401     name))))))))
402    
403     (define-presentation-method accept
404     ((type completable-pathname) stream (view textual-view) &key)
405     (multiple-value-bind (pathname success string)
406     (complete-input stream
407     #'filename-completer
408     :partial-completers '(#\Space)
409     :allow-any-input t)
410     (declare (ignore success))
411     (or pathname string)))
412    
413     (defun pathname-filename (pathname)
414     (if (null (pathname-type pathname))
415     (pathname-name pathname)
416     (concatenate 'string (pathname-name pathname)
417     "." (pathname-type pathname))))
418    
419 abridgewater 1.34 (define-named-command com-find-file ()
420 ejohnson 1.27 (let ((filename (accept 'completable-pathname
421     :prompt "Find File")))
422     (with-slots (buffer point syntax) (win *application-frame*)
423     (setf buffer (make-instance 'climacs-buffer)
424     point (make-instance 'standard-right-sticky-mark :buffer buffer)
425     syntax (make-instance 'texinfo-syntax :pane (win *application-frame*)))
426     (with-open-file (stream filename :direction :input :if-does-not-exist :create)
427     (input-from-stream stream buffer 0))
428     (setf (filename buffer) filename
429 rstrandh 1.28 (name buffer) (pathname-filename filename)
430     (needs-saving buffer) nil)
431 rstrandh 1.37 (beginning-of-buffer point)
432 rstrandh 1.28 ;; this one is needed so that the buffer modification protocol
433     ;; resets the low and high marks after redisplay
434 rstrandh 1.37 (redisplay-frame-panes *application-frame*))))
435 ejohnson 1.27
436 abridgewater 1.34 (define-named-command com-save-buffer ()
437 rstrandh 1.30 (let* ((buffer (buffer (win *application-frame*)))
438     (filename (or (filename buffer)
439     (accept 'completable-pathname
440     :prompt "Save Buffer to File"))))
441     (if (or (null (filename buffer))
442     (needs-saving buffer))
443     (progn (with-open-file (stream filename :direction :output :if-exists :supersede)
444     (output-to-stream stream buffer 0 (size buffer)))
445     (setf (filename buffer) filename
446     (name buffer) (pathname-filename filename))
447     (display-message "Wrote: ~a" (filename buffer)))
448     (display-message "No changes need to be saved from ~a" (name buffer)))
449     (setf (needs-saving buffer) nil)))
450 ejohnson 1.27
451 abridgewater 1.34 (define-named-command com-write-buffer ()
452 ejohnson 1.27 (let ((filename (accept 'completable-pathname
453     :prompt "Write Buffer to File"))
454     (buffer (buffer (win *application-frame*))))
455     (with-open-file (stream filename :direction :output :if-exists :supersede)
456     (output-to-stream stream buffer 0 (size buffer)))
457     (setf (filename buffer) filename
458 rstrandh 1.28 (name buffer) (pathname-filename filename)
459 rstrandh 1.30 (needs-saving buffer) nil)
460     (display-message "Wrote: ~a" (filename buffer))))
461 ejohnson 1.27
462 abridgewater 1.34 (define-named-command com-beginning-of-buffer ()
463 ejohnson 1.27 (beginning-of-buffer (point (win *application-frame*))))
464    
465 rstrandh 1.39 (define-named-command com-page-down ()
466     (let ((pane (win *application-frame*)))
467     (page-down pane (syntax pane))))
468    
469 rstrandh 1.40 (define-named-command com-page-up ()
470     (let ((pane (win *application-frame*)))
471     (page-up pane (syntax pane))))
472    
473 abridgewater 1.34 (define-named-command com-end-of-buffer ()
474 ejohnson 1.27 (end-of-buffer (point (win *application-frame*))))
475    
476 abridgewater 1.34 (define-named-command com-back-to-indentation ()
477 rstrandh 1.32 (let ((point (point (win *application-frame*))))
478     (beginning-of-line point)
479     (loop until (end-of-line-p point)
480     while (whitespacep (object-after point))
481     do (incf (offset point)))))
482    
483 abridgewater 1.34 (define-named-command com-goto-position ()
484 rstrandh 1.32 (setf (offset (point (win *application-frame*)))
485     (accept 'integer :prompt "Goto Position")))
486    
487 abridgewater 1.34 (define-named-command com-goto-line ()
488 rstrandh 1.32 (loop with mark = (make-instance 'standard-right-sticky-mark
489     :buffer (buffer (win *application-frame*)))
490     do (end-of-line mark)
491     until (end-of-buffer-p mark)
492     repeat (accept 'integer :prompt "Goto Line")
493     do (incf (offset mark))
494     (end-of-line mark)
495     finally (beginning-of-line mark)
496     (setf (offset (point (win *application-frame*)))
497     (offset mark))))
498    
499 abridgewater 1.34 (define-named-command com-browse-url ()
500 ejohnson 1.27 (accept 'url :prompt "Browse URL"))
501    
502 abridgewater 1.34 (define-named-command com-set-mark ()
503 ejohnson 1.27 (with-slots (point mark) (win *application-frame*)
504 rstrandh 1.45 (setf mark (clone-mark point))))
505    
506     (define-named-command com-exchange-point-and-mark ()
507     (with-slots (point mark) (win *application-frame*)
508     (psetf (offset mark) (offset point)
509     (offset point) (offset mark))))
510 rstrandh 1.38
511     (define-named-command com-set-syntax ()
512     (setf (syntax (win *application-frame*))
513     (make-instance (accept 'syntax :prompt "Set Syntax")
514     :pane (win *application-frame*))))
515 ejohnson 1.27
516     ;;;;;;;;;;;;;;;;;;;;
517     ;; Kill ring commands
518    
519 ejohnson 1.31 ;; Copies an element from a kill-ring to a buffer at the given offset
520 abridgewater 1.34 (define-named-command com-copy-in ()
521 ejohnson 1.31 (insert-sequence (point (win *application-frame*)) (kr-copy *kill-ring*)))
522 ejohnson 1.27
523 ejohnson 1.31 ;; Cuts an element from a kill-ring out to a buffer at a given offset
524 abridgewater 1.34 (define-named-command com-cut-in ()
525 ejohnson 1.31 (insert-sequence (point (win *application-frame*)) (kr-pop *kill-ring*)))
526 ejohnson 1.27
527 ejohnson 1.31 ;; Destructively cut a given buffer region into the kill-ring
528 abridgewater 1.34 (define-named-command com-cut-out ()
529 ejohnson 1.27 (with-slots (buffer point mark)(win *application-frame*)
530 ejohnson 1.31 (if (< (offset point) (offset mark))
531     ((lambda (b o1 o2)
532     (kr-push *kill-ring* (buffer-sequence b o1 o2))
533     (delete-buffer-range b o1 (- o2 o1)))
534     buffer (offset point) (offset mark))
535     ((lambda (b o1 o2)
536     (kr-push *kill-ring* (buffer-sequence b o2 o1))
537     (delete-buffer-range b o1 (- o2 o1)))
538     buffer (offset mark) (offset point)))))
539    
540 ejohnson 1.27
541 ejohnson 1.31 ;; Non destructively copies in buffer region to the kill ring
542 abridgewater 1.34 (define-named-command com-copy-out ()
543 ejohnson 1.27 (with-slots (buffer point mark)(win *application-frame*)
544     (let ((off1 (offset point))
545     (off2 (offset mark)))
546     (if (< off1 off2)
547 ejohnson 1.31 (kr-push *kill-ring* (buffer-sequence buffer off1 off2))
548     (kr-push *kill-ring* (buffer-sequence buffer off2 off1))))))
549 ejohnson 1.27
550     ;; Needs adjustment to be like emacs M-y
551 abridgewater 1.34 (define-named-command com-kr-rotate ()
552 ejohnson 1.27 (kr-rotate *kill-ring* -1))
553    
554     ;; Not bound to a key yet
555 abridgewater 1.34 (define-named-command com-kr-resize ()
556 ejohnson 1.46 (let ((size (accept 'integer :prompt "New kill ring size")))
557 ejohnson 1.27 (kr-resize *kill-ring* size)))
558    
559     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560     ;;;
561     ;;; Global command table
562    
563     (make-command-table 'global-climacs-table :errorp nil)
564    
565     (defun global-set-key (gesture command)
566     (add-command-to-command-table command 'global-climacs-table
567     :keystroke gesture :errorp nil))
568    
569     (loop for code from (char-code #\space) to (char-code #\~)
570     do (global-set-key (code-char code) 'com-self-insert))
571    
572     (global-set-key #\newline 'com-self-insert)
573     (global-set-key #\tab 'com-self-insert)
574     (global-set-key '(#\f :control) 'com-forward-object)
575     (global-set-key '(#\b :control) 'com-backward-object)
576     (global-set-key '(#\a :control) 'com-beginning-of-line)
577     (global-set-key '(#\e :control) 'com-end-of-line)
578     (global-set-key '(#\d :control) 'com-delete-object)
579     (global-set-key '(#\p :control) 'com-previous-line)
580     (global-set-key '(#\n :control) 'com-next-line)
581     (global-set-key '(#\o :control) 'com-open-line)
582     (global-set-key '(#\k :control) 'com-kill-line)
583 rstrandh 1.42 (global-set-key '(#\t :control) 'com-transpose-objects)
584 ejohnson 1.27 (global-set-key '(#\Space :control) 'com-set-mark)
585     (global-set-key '(#\y :control) 'com-copy-in)
586     (global-set-key '(#\w :control) 'com-cut-out)
587     (global-set-key '(#\f :meta) 'com-forward-word)
588     (global-set-key '(#\b :meta) 'com-backward-word)
589 rstrandh 1.43 (global-set-key '(#\t :meta) 'com-transpose-words)
590 ejohnson 1.27 (global-set-key '(#\x :meta) 'com-extended-command)
591     (global-set-key '(#\y :meta) 'com-kr-rotate) ;currently rotates only
592     (global-set-key '(#\w :meta) 'com-copy-out)
593 rstrandh 1.39 (global-set-key '(#\v :control) 'com-page-down)
594 rstrandh 1.40 (global-set-key '(#\v :meta) 'com-page-up)
595 ejohnson 1.27 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
596     (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
597     (global-set-key '(#\u :meta) 'com-browse-url)
598 rstrandh 1.32 (global-set-key '(#\m :meta) 'com-back-to-indentation)
599     (global-set-key '(#\d :meta) 'com-delete-word)
600     (global-set-key '(#\Backspace :meta) 'com-backward-delete-word)
601 ejohnson 1.27
602     (global-set-key '(:up) 'com-previous-line)
603     (global-set-key '(:down) 'com-next-line)
604     (global-set-key '(:left) 'com-backward-object)
605     (global-set-key '(:right) 'com-forward-object)
606     (global-set-key '(:left :control) 'com-backward-word)
607     (global-set-key '(:right :control) 'com-forward-word)
608     (global-set-key '(:home) 'com-beginning-of-line)
609     (global-set-key '(:end) 'com-end-of-line)
610     (global-set-key '(:home :control) 'com-beginning-of-buffer)
611     (global-set-key '(:end :control) 'com-end-of-buffer)
612     (global-set-key #\Rubout 'com-delete-object)
613     (global-set-key #\Backspace 'com-backward-delete-object)
614    
615     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616     ;;;
617     ;;; C-x command table
618    
619     (make-command-table 'c-x-climacs-table :errorp nil)
620    
621     (add-menu-item-to-command-table 'global-climacs-table "C-x"
622     :menu 'c-x-climacs-table
623     :keystroke '(#\x :control))
624    
625     (defun c-x-set-key (gesture command)
626     (add-command-to-command-table command 'c-x-climacs-table
627     :keystroke gesture :errorp nil))
628    
629     (c-x-set-key '(#\c :control) 'com-quit)
630     (c-x-set-key '(#\f :control) 'com-find-file)
631     (c-x-set-key '(#\s :control) 'com-save-buffer)
632 rstrandh 1.45 (c-x-set-key '(#\t :control) 'com-transpose-lines)
633 ejohnson 1.27 (c-x-set-key '(#\w :control) 'com-write-buffer)
634 rstrandh 1.45 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
635 rstrandh 1.44
636     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
637     ;;;
638     ;;; Some Unicode stuff
639    
640     (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
641     (insert-object (point (win *application-frame*)) (code-char code)))
642    
643     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
644     ;;;
645     ;;; Dead-acute command table
646    
647     (make-command-table 'dead-acute-climacs-table :errorp nil)
648    
649     (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
650     :menu 'dead-acute-climacs-table
651     :keystroke '(:dead--acute))
652    
653     (defun dead-acute-set-key (gesture command)
654     (add-command-to-command-table command 'dead-acute-climacs-table
655     :keystroke gesture :errorp nil))
656    
657     (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
658     (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
659     (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
660     (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
661     (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
662     (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
663     (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
664     (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
665     (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
666     (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
667     (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
668     (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
669     (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
670     (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
671     (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
672     (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
673     (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
674     (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
675     (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
676     (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
677    
678 rstrandh 1.45 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
679    
680     (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
681     :menu 'dead-acute-dead-accute-climacs-table
682     :keystroke '(:dead--acute))
683    
684     (defun dead-acute-dead-accute-set-key (gesture command)
685     (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
686     :keystroke gesture :errorp nil))
687    
688     (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
689     (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
690 rstrandh 1.44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
691     ;;;
692     ;;; Dead-grave command table
693    
694     (make-command-table 'dead-grave-climacs-table :errorp nil)
695    
696     (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
697     :menu 'dead-grave-climacs-table
698     :keystroke '(:dead--grave))
699    
700     (defun dead-grave-set-key (gesture command)
701     (add-command-to-command-table command 'dead-grave-climacs-table
702     :keystroke gesture :errorp nil))
703    
704     (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
705     (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
706     (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
707     (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
708     (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
709     (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
710     (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
711     (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
712     (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
713     (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
714     (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
715    
716     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
717     ;;;
718     ;;; Dead-diaeresis command table
719    
720     (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
721    
722     (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
723     :menu 'dead-diaeresis-climacs-table
724     :keystroke '(:dead--diaeresis :shift))
725    
726     (defun dead-diaeresis-set-key (gesture command)
727     (add-command-to-command-table command 'dead-diaeresis-climacs-table
728     :keystroke gesture :errorp nil))
729    
730     (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
731     (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
732     (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
733     (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
734     (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
735     (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
736     (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
737     (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
738     (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
739     (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
740     (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
741     (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
742    
743     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
744     ;;;
745     ;;; Dead-tilde command table
746    
747     (make-command-table 'dead-tilde-climacs-table :errorp nil)
748    
749     (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
750     :menu 'dead-tilde-climacs-table
751     :keystroke '(:dead--tilde :shift))
752    
753     (defun dead-tilde-set-key (gesture command)
754     (add-command-to-command-table command 'dead-tilde-climacs-table
755     :keystroke gesture :errorp nil))
756    
757     (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
758     (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
759     (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
760     (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
761     (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
762     (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
763     (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
764     (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
765     (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
766     (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
767     (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
768    
769     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
770     ;;;
771     ;;; Dead-circumflex command table
772    
773     (make-command-table 'dead-circumflex-climacs-table :errorp nil)
774    
775     (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
776     :menu 'dead-circumflex-climacs-table
777     :keystroke '(:dead--circumflex :shift))
778    
779     (defun dead-circumflex-set-key (gesture command)
780     (add-command-to-command-table command 'dead-circumflex-climacs-table
781     :keystroke gesture :errorp nil))
782    
783     (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
784     (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
785     (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
786     (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
787     (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
788     (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
789     (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
790     (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
791     (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
792     (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
793     (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))

  ViewVC Help
Powered by ViewVC 1.1.5