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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5