ViewVC logotype

Contents of /src/hemlock/indent.lisp

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.4 - (show annotations)
Mon Oct 31 04:50:12 1994 UTC (19 years, 5 months ago) by ram
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, double-double-array-base, post-merge-intl-branch, release-19b-pre1, release-19b-pre2, merged-unicode-utf16-extfmt-2009-06-11, double-double-init-sparc-2, unicode-utf16-extfmt-2009-03-27, double-double-base, snapshot-2007-09, snapshot-2007-08, snapshot-2008-08, snapshot-2008-09, ppc_gencgc_snap_2006-01-06, sse2-packed-2008-11-12, snapshot-2008-05, snapshot-2008-06, snapshot-2008-07, snapshot-2007-05, snapshot-2008-01, snapshot-2008-02, snapshot-2008-03, intl-branch-working-2010-02-19-1000, snapshot-2006-11, snapshot-2006-10, double-double-init-sparc, snapshot-2006-12, unicode-string-buffer-impl-base, sse2-base, release-20b-pre1, release-20b-pre2, unicode-string-buffer-base, RELEASE_18d, sse2-packed-base, sparc-tramp-assem-2010-07-19, amd64-dd-start, snapshot-2003-10, snapshot-2004-10, release-18e-base, release-19f-pre1, snapshot-2008-12, snapshot-2008-11, intl-2-branch-base, snapshot-2004-08, snapshot-2004-09, remove_negative_zero_not_zero, snapshot-2007-01, snapshot-2007-02, snapshot-2004-05, snapshot-2004-06, snapshot-2004-07, release-19e, release-19d, GIT-CONVERSION, double-double-init-ppc, release-19c, dynamic-extent-base, unicode-utf16-sync-2008-12, LINKAGE_TABLE, release-19c-base, cross-sol-x86-merged, label-2009-03-16, release-19f-base, PRE_LINKAGE_TABLE, merge-sse2-packed, mod-arith-base, sparc_gencgc_merge, merge-with-19f, snapshot-2004-12, snapshot-2004-11, intl-branch-working-2010-02-11-1000, RELEASE_18a, RELEASE_18b, RELEASE_18c, unicode-snapshot-2009-05, unicode-snapshot-2009-06, amd64-merge-start, ppc_gencgc_snap_2005-12-17, double-double-init-%make-sparc, unicode-utf16-sync-2008-07, release-18e-pre2, unicode-utf16-sync-2008-09, unicode-utf16-extfmts-sync-2008-12, prm-before-macosx-merge-tag, cold-pcl-base, RELEASE_20b, snapshot-2008-04, snapshot-2003-11, snapshot-2005-07, unicode-utf16-sync-label-2009-03-16, RELEASE_19f, snapshot-2007-03, release-20a-base, cross-sol-x86-base, unicode-utf16-char-support-2009-03-26, unicode-utf16-char-support-2009-03-25, release-19a-base, unicode-utf16-extfmts-pre-sync-2008-11, snapshot-2008-10, sparc_gencgc, snapshot-2007-04, snapshot-2010-12, snapshot-2010-11, unicode-utf16-sync-2008-11, snapshot-2007-07, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2007-06, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, snapshot-2003-12, release-19a-pre1, release-19a-pre3, release-19a-pre2, pre-merge-intl-branch, release-19a, UNICODE-BASE, double-double-array-checkpoint, double-double-reader-checkpoint-1, release-19d-base, release-19e-pre1, double-double-irrat-end, release-19e-pre2, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-01, snapshot-2010-03, snapshot-2010-02, release-19d-pre2, release-19d-pre1, snapshot-2010-08, release-18e, double-double-init-checkpoint-1, double-double-reader-base, label-2009-03-25, snapshot-2005-03, release-19b-base, cross-sol-x86-2010-12-20, double-double-init-x86, sse2-checkpoint-2008-10-01, intl-branch-2010-03-18-1300, snapshot-2005-11, double-double-sparc-checkpoint-1, snapshot-2004-04, sse2-merge-with-2008-11, sse2-merge-with-2008-10, snapshot-2005-10, RELEASE_20a, snapshot-2005-12, release-20a-pre1, snapshot-2005-01, snapshot-2009-11, snapshot-2009-12, unicode-utf16-extfmt-2009-06-11, portable-clx-import-2009-06-16, unicode-utf16-string-support, release-19c-pre1, cross-sparc-branch-base, release-19e-base, intl-branch-base, double-double-irrat-start, snapshot-2005-06, snapshot-2005-05, snapshot-2005-04, ppc_gencgc_snap_2005-05-14, snapshot-2005-02, unicode-utf16-base, portable-clx-base, snapshot-2005-09, snapshot-2005-08, lisp-executable-base, snapshot-2009-08, snapshot-2007-12, snapshot-2007-10, snapshot-2007-11, snapshot-2009-02, snapshot-2009-01, snapshot-2009-07, snapshot-2009-05, snapshot-2009-04, snapshot-2006-02, snapshot-2006-03, release-18e-pre1, snapshot-2006-01, snapshot-2006-06, snapshot-2006-07, snapshot-2006-04, snapshot-2006-05, pre-telent-clx, snapshot-2006-08, snapshot-2006-09, HEAD
Branch point for: release-19b-branch, double-double-reader-branch, double-double-array-branch, mod-arith-branch, RELEASE-19F-BRANCH, portable-clx-branch, sparc_gencgc_branch, cross-sparc-branch, RELEASE-20B-BRANCH, RELENG_18, unicode-string-buffer-branch, sparc-tramp-assem-branch, dynamic-extent, UNICODE-BRANCH, release-19d-branch, ppc_gencgc_branch, sse2-packed-branch, lisp-executable, RELEASE-20A-BRANCH, amd64-dd-branch, double-double-branch, unicode-string-buffer-impl-branch, intl-branch, release-18e-branch, cold-pcl, unicode-utf16-branch, cross-sol-x86-branch, release-19e-branch, sse2-branch, release-19a-branch, release-19c-branch, intl-2-branch, unicode-utf16-extfmt-branch
Changes since 1.3: +1 -3 lines
Fix headed boilerplate.
1 ;;; -*- Log: hemlock.log; Package: Hemlock -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;;
7 (ext:file-comment
8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/indent.lisp,v 1.4 1994/10/31 04:50:12 ram Rel $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; Hemlock indentation commands
13 ;;;
14 ;;; Written by Bill Maddox and Bill Chiles
15 ;;;
16 (in-package "HEMLOCK")
20 (defhvar "Spaces per Tab"
21 "The number of spaces a tab is equivalent to. NOTE: This is not incorporated
22 everywhere in Hemlock yet, so do not change it."
23 :value 8)
25 (defun indent-using-tabs (mark column)
26 "Inserts at mark a maximum number of tabs and a minimum number of spaces to
27 move mark to column. This assumes mark is at the beginning of a line."
28 (multiple-value-bind (tabs spaces) (floor column (value spaces-per-tab))
29 (dotimes (i tabs) (insert-character mark #\tab))
30 (dotimes (i spaces) (insert-character mark #\space))))
32 (defhvar "Indent with Tabs"
33 "Function that takes a mark and a number of spaces and inserts tabs and spaces
34 to indent that number of spaces using \"Spaces per Tab\"."
35 :value #'indent-using-tabs)
38 (defun tab-to-tab-stop (mark)
39 (insert-character mark #\tab))
41 (defhvar "Indent Function"
42 "Indentation function which is invoked by \"Indent\" command.
43 It takes a :left-inserting mark that may be moved."
44 :value #'tab-to-tab-stop)
47 (defun generic-indent (mark)
48 (let* ((line (mark-line mark))
49 (prev (do ((line (line-previous line) (line-previous line)))
50 ((or (null line) (not (blank-line-p line))) line))))
51 (unless prev (editor-error))
52 (line-start mark prev)
53 (find-attribute mark :space #'zerop)
54 (let ((indentation (mark-column mark)))
55 (line-start mark line)
56 (delete-horizontal-space mark)
57 (funcall (value indent-with-tabs) mark indentation))))
60 (defcommand "Indent New Line" (p)
61 "Moves point to a new blank line and indents it.
62 Any whitespace before point is deleted. The value of \"Indent Function\"
63 is used for indentation unless there is a Fill Prefix, in which case it is
64 used. Any argument is passed onto \"New Line\"."
65 "Moves point to a new blank line and indents it.
66 Any whitespace before point is deleted. The value of \"Indent Function\"
67 is used for indentation unless there is a Fill Prefix, in which case it is
68 used. Any argument is passed onto \"New Line\"."
69 (let ((point (current-point))
70 (prefix (value fill-prefix)))
71 (delete-horizontal-space point)
72 (new-line-command p)
73 (if prefix
74 (insert-string point prefix)
75 (funcall (value indent-function) point))))
78 (defcommand "Indent" (p)
79 "Invokes function held by the Hemlock variable \"Indent Function\",
80 moving point past region if called with argument."
81 "Invokes function held by the Hemlock variable \"Indent Function\"
82 moving point past region if called with argument."
83 (let ((point (current-point)))
84 (with-mark ((mark point :left-inserting))
85 (cond ((or (not p) (zerop p))
86 (funcall (value indent-function) mark))
87 (t
88 (if (plusp p)
89 (unless (line-offset point (1- p))
90 (buffer-end point))
91 (unless (line-offset mark (1+ p))
92 (buffer-start mark)))
93 (indent-region-for-commands (region mark point))
94 (find-attribute (line-start point) :whitespace #'zerop))))))
96 (defcommand "Indent Region" (p)
97 "Invokes function held by Hemlock variable \"Indent Function\" on every
98 line between point and mark, inclusively."
99 "Invokes function held by Hemlock variable \"Indent Function\" on every
100 line between point and mark, inclusively."
101 (declare (ignore p))
102 (let* ((region (current-region)))
103 (with-mark ((start (region-start region) :left-inserting)
104 (end (region-end region) :left-inserting))
105 (indent-region-for-commands (region start end)))))
107 (defun indent-region-for-commands (region)
108 "Indents region undoably with INDENT-REGION."
109 (let* ((start (region-start region))
110 (end (region-end region))
111 (undo-region (copy-region (region (line-start start) (line-end end)))))
112 (indent-region region)
113 (make-region-undo :twiddle "Indent"
114 (region (line-start (copy-mark start :left-inserting))
115 (line-end (copy-mark end :right-inserting)))
116 undo-region)))
118 (defun indent-region (region)
119 "Invokes function held by Hemlock variable \"Indent Function\" on every
120 line of region."
121 (let ((indent-function (value indent-function)))
122 (with-mark ((start (region-start region) :left-inserting)
123 (end (region-end region)))
124 (line-start start)
125 (line-start end)
126 (loop (when (mark= start end)
127 (funcall indent-function start)
128 (return))
129 (funcall indent-function start)
130 (line-offset start 1 0)))))
132 (defcommand "Center Line" (p)
133 "Centers current line using \"Fill Column\". If an argument is supplied,
134 it is used instead of the \"Fill Column\"."
135 "Centers current line using fill-column."
136 (let* ((indent-function (value indent-with-tabs))
137 (region (if (region-active-p)
138 (current-region)
139 (region (current-point) (current-point))))
140 (end (region-end region)))
141 (with-mark ((temp (region-start region) :left-inserting))
142 (loop
143 (when (mark> temp end) (return))
144 (delete-horizontal-space (line-end temp))
145 (delete-horizontal-space (line-start temp))
146 (let* ((len (line-length (mark-line temp)))
147 (spaces (- (or p (value fill-column)) len)))
148 (if (and (plusp spaces)
149 (not (zerop len)))
150 (funcall indent-function temp (ceiling spaces 2)))
151 (unless (line-offset temp 1) (return))
152 (line-start temp))))))
155 (defcommand "Quote Tab" (p)
156 "Insert tab character."
157 "Insert tab character."
158 (if (and p (> p 1))
159 (insert-string (current-point) (make-string p :initial-element #\tab))
160 (insert-character (current-point) #\tab)))
163 (defcommand "Open Line" (p)
164 "Inserts a newline into the buffer without moving the point."
165 "Inserts a newline into the buffer without moving the point.
166 With argument, inserts p newlines."
167 (let ((point (current-point))
168 (count (if p p 1)))
169 (if (not (minusp count))
170 (dotimes (i count)
171 (insert-character point #\newline)
172 (mark-before point))
173 (editor-error))))
176 (defcommand "New Line" (p)
177 "Moves the point to a new blank line.
178 A newline is inserted if the next two lines are not already blank.
179 With an argument, repeats p times."
180 "Moves the point to a new blank line."
181 (let ((point (current-point))
182 (count (if p p 1)))
183 (if (not (minusp count))
184 (do* ((next (line-next (mark-line point))
185 (line-next (mark-line point)))
186 (i 1 (1+ i)))
187 ((> i count))
188 (cond ((and (blank-after-p point)
189 next (blank-line-p next)
190 (let ((after (line-next next)))
191 (or (not after) (blank-line-p after))))
192 (line-start point next)
193 (let ((len (line-length next)))
194 (unless (zerop len)
195 (delete-characters point len))))
196 (t
197 (insert-character point #\newline))))
198 (editor-error))))
201 (defattribute "Space"
202 "This attribute is used by the indentation commands to determine which
203 characters are treated as space."
204 '(mod 2) 0)
206 (setf (character-attribute :space #\space) 1)
207 (setf (character-attribute :space #\tab) 1)
209 (defun delete-horizontal-space (mark)
210 "Deletes all :space characters on either side of mark."
211 (with-mark ((start mark))
212 (reverse-find-attribute start :space #'zerop)
213 (find-attribute mark :space #'zerop)
214 (delete-region (region start mark))))
218 (defcommand "Delete Indentation" (p)
219 "Join current line with the previous one, deleting excess whitespace.
220 All whitespace is replaced with a single space, unless it is at the beginning
221 of a line, immmediately following a \"(\", or immediately preceding a \")\",
222 in which case the whitespace is merely deleted. If the preceeding character
223 is a sentence terminator, two spaces are left instead of one. If a prefix
224 argument is given, the following line is joined with the current line."
225 "Join current line with the previous one, deleting excess whitespace."
226 (with-mark ((m (current-point) :right-inserting))
227 (when p (line-offset m 1))
228 (line-start m)
229 (unless (delete-characters m -1) (editor-error "No previous line."))
230 (delete-horizontal-space m)
231 (let ((prev (previous-character m)))
232 (when (and prev (char/= prev #\newline))
233 (cond ((not (zerop (character-attribute :sentence-terminator prev)))
234 (insert-string m " "))
235 ((not (or (eq (character-attribute :lisp-syntax prev) :open-paren)
236 (eq (character-attribute :lisp-syntax (next-character m))
237 :close-paren)))
238 (insert-character m #\space)))))))
241 (defcommand "Delete Horizontal Space" (p)
242 "Delete spaces and tabs surrounding the point."
243 "Delete spaces and tabs surrounding the point."
244 (declare (ignore p))
245 (delete-horizontal-space (current-point)))
247 (defcommand "Just One Space" (p)
248 "Leave one space.
249 Surrounding space is deleted, and then one space is inserted.
250 with prefix argument insert that number of spaces."
251 "Delete surrounding space and insert P spaces."
252 (let ((point (current-point)))
253 (delete-horizontal-space point)
254 (dotimes (i (or p 1)) (insert-character point #\space))))
256 (defcommand "Back to Indentation" (p)
257 "Move point to the first non-whitespace character on the line."
258 "Move point to the first non-whitespace character on the line."
259 (declare (ignore p))
260 (let ((point (current-point)))
261 (line-start point)
262 (find-attribute point :whitespace #'zerop)))
264 (defcommand "Indent Rigidly" (p)
265 "Indent the region rigidly by p spaces.
266 Each line in the region is moved p spaces to the right (left if p is
267 negative). When moving a line to the left, tabs are converted to spaces."
268 "Indent the region rigidly p spaces to the right (left if p is negative)."
269 (let ((p (or p (value spaces-per-tab)))
270 (region (current-region)))
271 (with-mark ((mark1 (region-start region) :left-inserting)
272 (mark2 (region-end region) :left-inserting))
273 (line-start mark1)
274 (line-start mark2)
275 (do ()
276 ((mark= mark1 mark2))
277 (cond ((empty-line-p mark1))
278 ((blank-after-p mark1)
279 (delete-characters mark1 (line-length (mark-line mark1))))
280 (t (find-attribute mark1 :whitespace #'zerop)
281 (let ((new-column (+ p (mark-column mark1))))
282 (delete-characters mark1 (- (mark-charpos mark1)))
283 (if (plusp new-column)
284 (funcall (value indent-with-tabs) mark1 new-column)))))
285 (line-offset mark1 1 0)))))

  ViewVC Help
Powered by ViewVC 1.1.5