window-commands.lisp 5.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;;; -*- Mode: Lisp; Package: CLIMACS-GUI -*-

;;;  (c) copyright 2004-2005 by
;;;           Robert Strandh (strandh@labri.fr)
;;;  (c) copyright 2004-2005 by
;;;           Elliott Johnson (ejohnson@fasl.info)
;;;  (c) copyright 2005 by
;;;           Matthieu Villeneuve (matthieu.villeneuve@free.fr)
;;;  (c) copyright 2005 by
;;;           Aleksandar Bakic (a_bakic@yahoo.com)

;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA  02111-1307  USA.

;;; Windows commands for the Climacs editor. 

29
(in-package :climacs-commands)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 
;;; Commands for splitting windows

(define-command (com-split-window-vertically :name t :command-table window-table) ()
  (split-window t))

(set-key 'com-split-window-vertically
	 'window-table
	 '((#\x :control) (#\2)))

(define-command (com-split-window-horizontally :name t :command-table window-table) ()
  (split-window))

(set-key 'com-split-window-horizontally
	 'window-table
	 '((#\x :control) (#\3)))

(define-command (com-other-window :name t :command-table window-table) ()
  (other-window))

(set-key 'com-other-window
	 'window-table
	 '((#\x :control) (#\o)))

(defun click-to-offset (window x y)
  (with-slots (top bot) window
       (let ((new-x (floor x (stream-character-width window #\m)))
	     (new-y (floor y (stream-line-height window)))
	     (buffer (buffer window)))
	 (loop for scan from (offset top)
	       with lines = 0
	       until (= scan (offset bot))
	       until (= lines new-y)
	       when (eql (buffer-object buffer scan) #\Newline)
		 do (incf lines)
	       finally (loop for columns from 0
			     until (= scan (offset bot))
			     until (eql (buffer-object buffer scan) #\Newline)
			     until (= columns new-x)
			     do (incf scan))
		       (return scan)))))

(define-command (com-switch-to-this-window :name nil :command-table window-table)
    ((window 'pane) (x 'integer) (y 'integer))
  (other-window window)
77
  (when (buffer-pane-p window)
78
79
80
81
    (setf (offset (point window))
	  (click-to-offset window x y))))

(define-presentation-to-command-translator blank-area-to-switch-to-this-window
82
83
84
85
86
87
    (blank-area com-switch-to-this-window window-table
                :echo nil
                ;; Putting the point in typeout-panes can cause errors.
                :tester ((object presentation)
                         (declare (ignore presentation))
                         (not (typep object 'typeout-pane))))
88
89
90
91
92
93
94
    (window x y)
  (list window x y))

(define-gesture-name :select-other :pointer-button (:right) :unique nil)

(define-command (com-mouse-save :name nil :command-table window-table)
    ((window 'pane) (x 'integer) (y 'integer))
95
  (when (and (buffer-pane-p window)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	     (eq window (current-window)))
    (setf (offset (mark window))
	  (click-to-offset window x y))
    (com-exchange-point-and-mark)
    (com-copy-region)))

(define-presentation-to-command-translator blank-area-to-mouse-save
    (blank-area com-mouse-save window-table :echo nil :gesture :select-other)
    (window x y)
  (list window x y))

(define-gesture-name :middle-button :pointer-button (:middle) :unique nil)

(define-command (com-yank-here :name nil :command-table window-table)
    ((window 'pane) (x 'integer) (y 'integer))
111
  (when (buffer-pane-p window)
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    (other-window window)
    (setf (offset (point window))
	  (click-to-offset window x y))
    (com-yank)))

(define-presentation-to-command-translator blank-area-to-yank-here
    (blank-area com-yank-here window-table :echo nil :gesture :middle-button)
    (window x y)
  (list window x y))

(defun single-window ()
  (loop until (null (cdr (windows *application-frame*)))
	do (rotatef (car (windows *application-frame*))
		    (cadr (windows *application-frame*)))
	   (com-delete-window))
  (setf *standard-output* (car (windows *application-frame*))))

(define-command (com-single-window :name t :command-table window-table) ()
  (single-window))

(set-key 'com-single-window
	 'window-table
	 '((#\x :control) (#\1)))

(define-command (com-scroll-other-window :name t :command-table window-table) ()
  (let ((other-window (second (windows *application-frame*))))
    (when other-window
      (page-down other-window))))

(set-key 'com-scroll-other-window
	 'window-table
	 '((#\v :control :meta)))

(define-command (com-scroll-other-window-up :name t :command-table window-table) ()
  (let ((other-window (second (windows *application-frame*))))
    (when other-window
      (page-up other-window))))

(set-key 'com-scroll-other-window-up
	 'window-table
	 '((#\V :control :meta :shift)))

(define-command (com-delete-window :name t :command-table window-table) ()
  (delete-window))

(set-key 'com-delete-window
	 'window-table
	 '((#\x :control) (#\0)))