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

Contents of /climacs/gui.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.55 - (hide annotations)
Sat Jan 8 06:30:25 2005 UTC (9 years, 3 months ago) by ejohnson
Branch: MAIN
Changes since 1.54: +8 -14 lines
Minor clean ups on com-cut-out and com-copy-out.  Basically leftover bits of code that could be factored out.
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.54 (let* ((pane (win *application-frame*))
351     (point (point pane))
352     (mark (offset point)))
353     (if (end-of-line-p point)
354     (forward-object point)
355 ejohnson 1.53 (progn
356 ejohnson 1.54 (end-of-line point)
357     (cond ((or (beginning-of-buffer-p point)
358     (end-of-buffer-p point)) nil)
359     ((beginning-of-line-p point)(forward-object point)))))
360     (if (eq (previous-command pane) 'com-kill-line)
361 ejohnson 1.51 (kill-ring-concatenating-push *kill-ring*
362 ejohnson 1.54 (region-to-sequence mark point))
363 ejohnson 1.51 (kill-ring-standard-push *kill-ring*
364 ejohnson 1.54 (region-to-sequence mark point)))
365     (delete-region mark point)))
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.55 (with-slots (point mark)(win *application-frame*)
576     (cond ((< (offset mark)(offset point))
577     (kill-ring-standard-push *kill-ring* (region-to-sequence mark point))
578     (delete-region (offset mark) point))
579     (t
580     (kill-ring-standard-push *kill-ring* (region-to-sequence point mark))
581     (delete-region (offset point) mark)))))
582 ejohnson 1.27
583 ejohnson 1.31 ;; Non destructively copies in buffer region to the kill ring
584 abridgewater 1.34 (define-named-command com-copy-out ()
585 ejohnson 1.54 (with-slots (point mark)(win *application-frame*)
586 ejohnson 1.55 (kill-ring-standard-push *kill-ring* (region-to-sequence point mark))))
587 ejohnson 1.50
588 ejohnson 1.27
589 ejohnson 1.50 (define-named-command com-rotate-yank ()
590 ejohnson 1.54 (let* ((pane (win *application-frame*))
591     (point (point pane))
592 ejohnson 1.50 (last-yank (kill-ring-yank *kill-ring*)))
593 ejohnson 1.54 (if (eq (previous-command pane)
594 ejohnson 1.50 'com-rotate-yank)
595 ejohnson 1.54 (progn
596     (delete-range point (* -1 (length last-yank)))
597     (rotate-yank-position *kill-ring*)))
598     (insert-sequence point (kill-ring-yank *kill-ring*))))
599 ejohnson 1.27
600 ejohnson 1.50 (define-named-command com-resize-kill-ring ()
601 ejohnson 1.46 (let ((size (accept 'integer :prompt "New kill ring size")))
602 ejohnson 1.50 (setf (kill-ring-max-size *kill-ring*) size)))
603 rstrandh 1.47
604     (define-named-command com-search-forward ()
605     (search-forward (point (win *application-frame*))
606     (accept 'string :prompt "Search Forward")
607     :test (lambda (a b)
608     (and (characterp b) (char-equal a b)))))
609    
610     (define-named-command com-search-backward ()
611     (search-backward (point (win *application-frame*))
612     (accept 'string :prompt "Search Backward")
613     :test (lambda (a b)
614     (and (characterp b) (char-equal a b)))))
615 ejohnson 1.27
616 rstrandh 1.49 (define-named-command com-dabbrev-expand ()
617     (let* ((win (win *application-frame*))
618     (point (point win)))
619     (with-slots (original-prefix prefix-start-offset dabbrev-expansion-mark) win
620     (flet ((move () (cond ((beginning-of-buffer-p dabbrev-expansion-mark)
621     (setf (offset dabbrev-expansion-mark)
622     (offset point))
623     (forward-word dabbrev-expansion-mark))
624     ((mark< dabbrev-expansion-mark point)
625     (backward-object dabbrev-expansion-mark))
626     (t (forward-object dabbrev-expansion-mark)))))
627     (unless (or (beginning-of-buffer-p point)
628     (not (constituentp (object-before point))))
629     (unless (and (eq (previous-command win) 'com-dabbrev-expand)
630     (not (null prefix-start-offset)))
631     (setf dabbrev-expansion-mark (clone-mark point))
632     (backward-word dabbrev-expansion-mark)
633     (setf prefix-start-offset (offset dabbrev-expansion-mark))
634     (setf original-prefix (region-to-sequence prefix-start-offset point))
635     (move))
636     (loop until (or (end-of-buffer-p dabbrev-expansion-mark)
637     (and (or (beginning-of-buffer-p dabbrev-expansion-mark)
638     (not (constituentp (object-before dabbrev-expansion-mark))))
639     (looking-at dabbrev-expansion-mark original-prefix)))
640     do (move))
641     (if (end-of-buffer-p dabbrev-expansion-mark)
642     (progn (delete-region prefix-start-offset point)
643     (insert-sequence point original-prefix)
644     (setf prefix-start-offset nil))
645     (progn (delete-region prefix-start-offset point)
646     (insert-sequence point
647     (let ((offset (offset dabbrev-expansion-mark)))
648     (prog2 (forward-word dabbrev-expansion-mark)
649     (region-to-sequence offset dabbrev-expansion-mark)
650     (setf (offset dabbrev-expansion-mark) offset))))
651     (move))))))))
652    
653 ejohnson 1.27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
654     ;;;
655     ;;; Global command table
656    
657     (make-command-table 'global-climacs-table :errorp nil)
658    
659     (defun global-set-key (gesture command)
660     (add-command-to-command-table command 'global-climacs-table
661     :keystroke gesture :errorp nil))
662    
663     (loop for code from (char-code #\space) to (char-code #\~)
664     do (global-set-key (code-char code) 'com-self-insert))
665    
666     (global-set-key #\newline 'com-self-insert)
667     (global-set-key #\tab 'com-self-insert)
668     (global-set-key '(#\f :control) 'com-forward-object)
669     (global-set-key '(#\b :control) 'com-backward-object)
670     (global-set-key '(#\a :control) 'com-beginning-of-line)
671     (global-set-key '(#\e :control) 'com-end-of-line)
672     (global-set-key '(#\d :control) 'com-delete-object)
673     (global-set-key '(#\p :control) 'com-previous-line)
674     (global-set-key '(#\n :control) 'com-next-line)
675     (global-set-key '(#\o :control) 'com-open-line)
676     (global-set-key '(#\k :control) 'com-kill-line)
677 rstrandh 1.42 (global-set-key '(#\t :control) 'com-transpose-objects)
678 ejohnson 1.27 (global-set-key '(#\Space :control) 'com-set-mark)
679 ejohnson 1.50 (global-set-key '(#\y :control) 'com-yank)
680 ejohnson 1.27 (global-set-key '(#\w :control) 'com-cut-out)
681     (global-set-key '(#\f :meta) 'com-forward-word)
682     (global-set-key '(#\b :meta) 'com-backward-word)
683 rstrandh 1.43 (global-set-key '(#\t :meta) 'com-transpose-words)
684 ejohnson 1.27 (global-set-key '(#\x :meta) 'com-extended-command)
685 ejohnson 1.50 (global-set-key '(#\y :meta) 'com-rotate-yank)
686 ejohnson 1.27 (global-set-key '(#\w :meta) 'com-copy-out)
687 rstrandh 1.39 (global-set-key '(#\v :control) 'com-page-down)
688 rstrandh 1.40 (global-set-key '(#\v :meta) 'com-page-up)
689 ejohnson 1.27 (global-set-key '(#\< :shift :meta) 'com-beginning-of-buffer)
690     (global-set-key '(#\> :shift :meta) 'com-end-of-buffer)
691     (global-set-key '(#\u :meta) 'com-browse-url)
692 rstrandh 1.32 (global-set-key '(#\m :meta) 'com-back-to-indentation)
693     (global-set-key '(#\d :meta) 'com-delete-word)
694     (global-set-key '(#\Backspace :meta) 'com-backward-delete-word)
695 rstrandh 1.49 (global-set-key '(#\/ :meta) 'com-dabbrev-expand)
696 ejohnson 1.27
697     (global-set-key '(:up) 'com-previous-line)
698     (global-set-key '(:down) 'com-next-line)
699     (global-set-key '(:left) 'com-backward-object)
700     (global-set-key '(:right) 'com-forward-object)
701     (global-set-key '(:left :control) 'com-backward-word)
702     (global-set-key '(:right :control) 'com-forward-word)
703     (global-set-key '(:home) 'com-beginning-of-line)
704     (global-set-key '(:end) 'com-end-of-line)
705     (global-set-key '(:home :control) 'com-beginning-of-buffer)
706     (global-set-key '(:end :control) 'com-end-of-buffer)
707     (global-set-key #\Rubout 'com-delete-object)
708     (global-set-key #\Backspace 'com-backward-delete-object)
709    
710     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
711     ;;;
712     ;;; C-x command table
713    
714     (make-command-table 'c-x-climacs-table :errorp nil)
715    
716     (add-menu-item-to-command-table 'global-climacs-table "C-x"
717     :menu 'c-x-climacs-table
718     :keystroke '(#\x :control))
719    
720     (defun c-x-set-key (gesture command)
721     (add-command-to-command-table command 'c-x-climacs-table
722     :keystroke gesture :errorp nil))
723    
724     (c-x-set-key '(#\c :control) 'com-quit)
725     (c-x-set-key '(#\f :control) 'com-find-file)
726     (c-x-set-key '(#\s :control) 'com-save-buffer)
727 rstrandh 1.45 (c-x-set-key '(#\t :control) 'com-transpose-lines)
728 ejohnson 1.27 (c-x-set-key '(#\w :control) 'com-write-buffer)
729 rstrandh 1.45 (c-x-set-key '(#\x :control) 'com-exchange-point-and-mark)
730 rstrandh 1.44
731     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732     ;;;
733     ;;; Some Unicode stuff
734    
735     (define-named-command com-insert-charcode ((code 'integer :prompt "Code point"))
736     (insert-object (point (win *application-frame*)) (code-char code)))
737    
738     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
739     ;;;
740     ;;; Dead-acute command table
741    
742     (make-command-table 'dead-acute-climacs-table :errorp nil)
743    
744     (add-menu-item-to-command-table 'global-climacs-table "dead-acute"
745     :menu 'dead-acute-climacs-table
746     :keystroke '(:dead--acute))
747    
748     (defun dead-acute-set-key (gesture command)
749     (add-command-to-command-table command 'dead-acute-climacs-table
750     :keystroke gesture :errorp nil))
751    
752     (dead-acute-set-key '(#\A) '(com-insert-charcode 193))
753     (dead-acute-set-key '(#\E) '(com-insert-charcode 201))
754     (dead-acute-set-key '(#\I) '(com-insert-charcode 205))
755     (dead-acute-set-key '(#\O) '(com-insert-charcode 211))
756     (dead-acute-set-key '(#\U) '(com-insert-charcode 218))
757     (dead-acute-set-key '(#\Y) '(com-insert-charcode 221))
758     (dead-acute-set-key '(#\a) '(com-insert-charcode 225))
759     (dead-acute-set-key '(#\e) '(com-insert-charcode 233))
760     (dead-acute-set-key '(#\i) '(com-insert-charcode 237))
761     (dead-acute-set-key '(#\o) '(com-insert-charcode 243))
762     (dead-acute-set-key '(#\u) '(com-insert-charcode 250))
763     (dead-acute-set-key '(#\y) '(com-insert-charcode 253))
764     (dead-acute-set-key '(#\C) '(com-insert-charcode 199))
765     (dead-acute-set-key '(#\c) '(com-insert-charcode 231))
766     (dead-acute-set-key '(#\x) '(com-insert-charcode 215))
767     (dead-acute-set-key '(#\-) '(com-insert-charcode 247))
768     (dead-acute-set-key '(#\T) '(com-insert-charcode 222))
769     (dead-acute-set-key '(#\t) '(com-insert-charcode 254))
770     (dead-acute-set-key '(#\s) '(com-insert-charcode 223))
771     (dead-acute-set-key '(#\Space) '(com-insert-charcode 39))
772    
773 rstrandh 1.45 (make-command-table 'dead-acute-dead-accute-climacs-table :errorp nil)
774    
775     (add-menu-item-to-command-table 'dead-acute-climacs-table "dead-acute-dead-accute"
776     :menu 'dead-acute-dead-accute-climacs-table
777     :keystroke '(:dead--acute))
778    
779     (defun dead-acute-dead-accute-set-key (gesture command)
780     (add-command-to-command-table command 'dead-acute-dead-accute-climacs-table
781     :keystroke gesture :errorp nil))
782    
783     (dead-acute-dead-accute-set-key '(#\A) '(com-insert-charcode 197))
784     (dead-acute-dead-accute-set-key '(#\a) '(com-insert-charcode 229))
785 rstrandh 1.44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
786     ;;;
787     ;;; Dead-grave command table
788    
789     (make-command-table 'dead-grave-climacs-table :errorp nil)
790    
791     (add-menu-item-to-command-table 'global-climacs-table "dead-grave"
792     :menu 'dead-grave-climacs-table
793     :keystroke '(:dead--grave))
794    
795     (defun dead-grave-set-key (gesture command)
796     (add-command-to-command-table command 'dead-grave-climacs-table
797     :keystroke gesture :errorp nil))
798    
799     (dead-grave-set-key '(#\A) '(com-insert-charcode 192))
800     (dead-grave-set-key '(#\E) '(com-insert-charcode 200))
801     (dead-grave-set-key '(#\I) '(com-insert-charcode 204))
802     (dead-grave-set-key '(#\O) '(com-insert-charcode 210))
803     (dead-grave-set-key '(#\U) '(com-insert-charcode 217))
804     (dead-grave-set-key '(#\a) '(com-insert-charcode 224))
805     (dead-grave-set-key '(#\e) '(com-insert-charcode 232))
806     (dead-grave-set-key '(#\i) '(com-insert-charcode 236))
807     (dead-grave-set-key '(#\o) '(com-insert-charcode 242))
808     (dead-grave-set-key '(#\u) '(com-insert-charcode 249))
809     (dead-grave-set-key '(#\Space) '(com-insert-charcode 96))
810    
811     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812     ;;;
813     ;;; Dead-diaeresis command table
814    
815     (make-command-table 'dead-diaeresis-climacs-table :errorp nil)
816    
817     (add-menu-item-to-command-table 'global-climacs-table "dead-diaeresis"
818     :menu 'dead-diaeresis-climacs-table
819     :keystroke '(:dead--diaeresis :shift))
820    
821     (defun dead-diaeresis-set-key (gesture command)
822     (add-command-to-command-table command 'dead-diaeresis-climacs-table
823     :keystroke gesture :errorp nil))
824    
825     (dead-diaeresis-set-key '(#\A) '(com-insert-charcode 196))
826     (dead-diaeresis-set-key '(#\E) '(com-insert-charcode 203))
827     (dead-diaeresis-set-key '(#\I) '(com-insert-charcode 207))
828     (dead-diaeresis-set-key '(#\O) '(com-insert-charcode 214))
829     (dead-diaeresis-set-key '(#\U) '(com-insert-charcode 220))
830     (dead-diaeresis-set-key '(#\a) '(com-insert-charcode 228))
831     (dead-diaeresis-set-key '(#\e) '(com-insert-charcode 235))
832     (dead-diaeresis-set-key '(#\i) '(com-insert-charcode 239))
833     (dead-diaeresis-set-key '(#\o) '(com-insert-charcode 246))
834     (dead-diaeresis-set-key '(#\u) '(com-insert-charcode 252))
835     (dead-diaeresis-set-key '(#\y) '(com-insert-charcode 255))
836     (dead-diaeresis-set-key '(#\Space) '(com-insert-charcode 34))
837    
838     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
839     ;;;
840     ;;; Dead-tilde command table
841    
842     (make-command-table 'dead-tilde-climacs-table :errorp nil)
843    
844     (add-menu-item-to-command-table 'global-climacs-table "dead-tilde"
845     :menu 'dead-tilde-climacs-table
846     :keystroke '(:dead--tilde :shift))
847    
848     (defun dead-tilde-set-key (gesture command)
849     (add-command-to-command-table command 'dead-tilde-climacs-table
850     :keystroke gesture :errorp nil))
851    
852     (dead-tilde-set-key '(#\A) '(com-insert-charcode 195))
853     (dead-tilde-set-key '(#\N) '(com-insert-charcode 209))
854     (dead-tilde-set-key '(#\a) '(com-insert-charcode 227))
855     (dead-tilde-set-key '(#\n) '(com-insert-charcode 241))
856     (dead-tilde-set-key '(#\E) '(com-insert-charcode 198))
857     (dead-tilde-set-key '(#\e) '(com-insert-charcode 230))
858     (dead-tilde-set-key '(#\D) '(com-insert-charcode 208))
859     (dead-tilde-set-key '(#\d) '(com-insert-charcode 240))
860     (dead-tilde-set-key '(#\O) '(com-insert-charcode 216))
861     (dead-tilde-set-key '(#\o) '(com-insert-charcode 248))
862     (dead-tilde-set-key '(#\Space) '(com-insert-charcode 126))
863    
864     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
865     ;;;
866     ;;; Dead-circumflex command table
867    
868     (make-command-table 'dead-circumflex-climacs-table :errorp nil)
869    
870     (add-menu-item-to-command-table 'global-climacs-table "dead-circumflex"
871     :menu 'dead-circumflex-climacs-table
872     :keystroke '(:dead--circumflex :shift))
873    
874     (defun dead-circumflex-set-key (gesture command)
875     (add-command-to-command-table command 'dead-circumflex-climacs-table
876     :keystroke gesture :errorp nil))
877    
878     (dead-circumflex-set-key '(#\A) '(com-insert-charcode 194))
879     (dead-circumflex-set-key '(#\E) '(com-insert-charcode 202))
880     (dead-circumflex-set-key '(#\I) '(com-insert-charcode 206))
881     (dead-circumflex-set-key '(#\O) '(com-insert-charcode 212))
882     (dead-circumflex-set-key '(#\U) '(com-insert-charcode 219))
883     (dead-circumflex-set-key '(#\a) '(com-insert-charcode 226))
884     (dead-circumflex-set-key '(#\e) '(com-insert-charcode 234))
885     (dead-circumflex-set-key '(#\i) '(com-insert-charcode 238))
886     (dead-circumflex-set-key '(#\o) '(com-insert-charcode 244))
887     (dead-circumflex-set-key '(#\u) '(com-insert-charcode 251))
888     (dead-circumflex-set-key '(#\Space) '(com-insert-charcode 94))

  ViewVC Help
Powered by ViewVC 1.1.5