Commit 61f9ef63 authored by Aleksandar Bakic's avatar Aleksandar Bakic

Changes to indent-line, copyrights. Tests for indent-line.

parent 584c7d66
......@@ -864,6 +864,15 @@ climacs ")
" climacs ")
(deftest binseq-buffer-indent-line.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
(deftest binseq-buffer-indent-line.test-3
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-right-sticky-mark
......@@ -1716,6 +1725,15 @@ climacs ")
" climacs ")
(deftest obinseq-buffer-indent-line.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
(deftest obinseq-buffer-indent-line.test-3
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-right-sticky-mark
......
......@@ -145,16 +145,6 @@ PERSISTENT-BUFFER."))
(setf high-mark (make-instance 'persistent-right-sticky-mark
:buffer buffer))))
;; (defmethod clone-mark ((mark persistent-left-sticky-mark) &optional type)
;; (unless type
;; (setf type 'persistent-left-sticky-mark))
;; (make-instance type :buffer (buffer mark) :offset (offset mark)))
;; (defmethod clone-mark ((mark persistent-right-sticky-mark) &optional type)
;; (unless type
;; (setf type 'persistent-right-sticky-mark))
;; (make-instance type :buffer (buffer mark) :offset (offset mark)))
(defmethod size ((buffer binseq-buffer))
(binseq-length (slot-value buffer 'contents)))
......
......@@ -867,6 +867,15 @@ climacs ")
" climacs ")
(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
......
......@@ -6,6 +6,8 @@
;;; 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
......@@ -442,22 +444,33 @@ delimited by mark1 and mark2."))
;;;
;;; 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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment