[climacs-cvs] CVS update: climacs/base-test.lisp climacs/base.lisp
Aleksandar Bakic
abakic at common-lisp.net
Sun Feb 6 16:33:52 UTC 2005
Update of /project/climacs/cvsroot/climacs
In directory common-lisp.net:/tmp/cvs-serv31702
Modified Files:
base-test.lisp base.lisp
Log Message:
Changes to indent-line, copyrights. Tests for indent-line.
Date: Sun Feb 6 17:33:50 2005
Author: abakic
Index: climacs/base-test.lisp
diff -u climacs/base-test.lisp:1.5 climacs/base-test.lisp:1.6
--- climacs/base-test.lisp:1.5 Sun Feb 6 01:03:26 2005
+++ climacs/base-test.lisp Sun Feb 6 17:33:50 2005
@@ -869,6 +869,15 @@
(deftest standard-buffer-indent-line.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
+ (let ((m (make-instance 'standard-left-sticky-mark
+ :buffer buffer :offset 0)))
+ (indent-line m 5 4)
+ (buffer-sequence buffer 0 (size buffer))))
+ " climacs ")
+
+(deftest standard-buffer-indent-line.test-3
+ (let ((buffer (make-instance 'standard-buffer)))
+ (insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
Index: climacs/base.lisp
diff -u climacs/base.lisp:1.32 climacs/base.lisp:1.33
--- climacs/base.lisp:1.32 Sun Feb 6 01:03:26 2005
+++ climacs/base.lisp Sun Feb 6 17:33:50 2005
@@ -6,6 +6,8 @@
;;; Elliott Johnson (ejohnson at fasl.info)
;;; (c) copyright 2005 by
;;; Matthieu Villeneuve (matthieu.villeneuve at free.fr)
+;;; (c) copyright 2005 by
+;;; Aleksandar Bakic (a_bakic at yahoo.com)
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
@@ -442,22 +444,33 @@
;;;
;;; Indentation
-(defun indent-line (mark indentation tab-width)
- "Indent the line containing mark with indentation spaces. Use tabs and spaces
-if tab-width is not nil, otherwise use spaces only."
+(defgeneric indent-line (mark indentation tab-width)
+ (:documentation "Indent the line containing mark with indentation
+spaces. Use tabs and spaces if tab-width is not nil, otherwise use
+spaces only."))
+
+(defun indent-line* (mark indentation tab-width left)
(let ((mark2 (clone-mark mark)))
(beginning-of-line mark2)
(loop until (end-of-buffer-p mark2)
- as object = (object-after mark2)
- while (or (eql object #\Space) (eql object #\Tab))
- do (delete-range mark2 1))
+ as object = (object-after mark2)
+ while (or (eql object #\Space) (eql object #\Tab))
+ do (delete-range mark2 1))
(loop until (zerop indentation)
- do (cond ((and tab-width (>= indentation tab-width))
- (insert-object mark2 #\Tab)
- (decf indentation tab-width))
- (t
- (insert-object mark2 #\Space)
- (decf indentation))))))
+ do (cond ((and tab-width (>= indentation tab-width))
+ (insert-object mark2 #\Tab)
+ (when left ; spaces must follow tabs
+ (forward-object mark2))
+ (decf indentation tab-width))
+ (t
+ (insert-object mark2 #\Space)
+ (decf indentation))))))
+
+(defmethod indent-line ((mark left-sticky-mark) indentation tab-width)
+ (indent-line* mark indentation tab-width t))
+
+(defmethod indent-line ((mark right-sticky-mark) indentation tab-width)
+ (indent-line* mark indentation tab-width nil))
(defun delete-indentation (mark)
(beginning-of-line mark)
More information about the Climacs-cvs
mailing list