[climacs-cvs] CVS update: climacs/base.lisp climacs/gui.lisp climacs/packages.lisp climacs/pane.lisp climacs/syntax.lisp climacs/text-syntax.lisp

Matthieu Villeneuve mvilleneuve at common-lisp.net
Mon Jan 17 23:10:30 UTC 2005


Update of /project/climacs/cvsroot/climacs
In directory common-lisp.net:/tmp/cvs-serv3050

Modified Files:
	base.lisp gui.lisp packages.lisp pane.lisp syntax.lisp 
	text-syntax.lisp 
Log Message:
Added indent-line and newline-and-indent (bound to C-j)
Date: Mon Jan 17 15:10:25 2005
Author: mvilleneuve

Index: climacs/base.lisp
diff -u climacs/base.lisp:1.18 climacs/base.lisp:1.19
--- climacs/base.lisp:1.18	Sun Jan 16 12:04:59 2005
+++ climacs/base.lisp	Mon Jan 17 15:10:23 2005
@@ -89,6 +89,24 @@
 	(end-of-line mark)
 	(delete-region offset mark))))
 
+(defun empty-line-p (mark)
+  "Check whether the mark is in an empty line."
+  (and (beginning-of-line-p mark) (end-of-line-p mark)))
+
+(defun line-indentation (mark tab-width)
+  "Return the distance from the beginning of the line and the first
+constituent character of the line."
+  (let ((mark2 (clone-mark mark)))
+    (beginning-of-line mark2)
+    (loop with indentation = 0
+          until (end-of-buffer-p mark2)
+          as object = (object-after mark2)
+          while (or (eql object #\Space) (eql object #\Tab))
+          do (incf indentation
+                   (if (eql (object-after mark2) #\Tab) tab-width 1))
+             (incf (offset mark2))
+          finally (return indentation))))
+
 (defun buffer-number-of-lines-in-region (buffer offset1 offset2)
   "Helper function for number-of-lines-in-region.  Count newline
 characters in the region between offset1 and offset2"
@@ -328,7 +346,6 @@
              (loop repeat count
                    do (insert-buffer-object buffer offset #\Space))
              (incf offset (1- count))
-             (finish-output *error-output*)
              (incf offset2 (1- count)))))
 
 (defgeneric untabify-region (mark1 mark2 tab-width)
@@ -348,7 +365,24 @@
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; 
-;;; Delete indentation
+;;; 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."
+  (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))
+    (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))))))
 
 (defun delete-indentation (mark)
   (beginning-of-line mark)


Index: climacs/gui.lisp
diff -u climacs/gui.lisp:1.78 climacs/gui.lisp:1.79
--- climacs/gui.lisp:1.78	Mon Jan 17 05:35:52 2005
+++ climacs/gui.lisp	Mon Jan 17 15:10:23 2005
@@ -433,6 +433,27 @@
     (multiple-value-bind (start end) (region-limits pane)
       (untabify-region start end (tab-space-count (stream-default-view pane))))))
 
+(defun indent-current-line (pane point)
+  (let* ((buffer (buffer pane))
+         (view (stream-default-view pane))
+         (tab-space-count (tab-space-count view))
+         (indentation (syntax-line-indentation point
+                                               tab-space-count
+                                               (syntax buffer))))
+    (indent-line point indentation (and (indent-tabs-mode buffer)
+                                        tab-space-count))))
+
+(define-named-command com-indent-line ()
+  (let* ((pane (win *application-frame*))
+         (point (point pane)))
+    (indent-current-line pane point)))
+
+(define-named-command com-newline-and-indent ()
+  (let* ((pane (win *application-frame*))
+	 (point (point pane)))
+    (insert-object point #\Newline)
+    (indent-current-line pane point)))
+
 (define-named-command com-delete-indentation ()
   (delete-indentation (point (win *application-frame*))))
 
@@ -799,7 +820,8 @@
       do (global-set-key (code-char code) 'com-self-insert))
 
 (global-set-key #\newline 'com-self-insert)
-(global-set-key #\tab 'com-self-insert)
+(global-set-key #\tab 'com-indent-line)
+(global-set-key '(#\j :control) 'com-newline-and-indent)
 (global-set-key '(#\f :control) `(com-forward-object ,*numeric-argument-marker*))
 (global-set-key '(#\b :control) `(com-backward-object ,*numeric-argument-marker*))
 (global-set-key '(#\a :control) 'com-beginning-of-line)


Index: climacs/packages.lisp
diff -u climacs/packages.lisp:1.34 climacs/packages.lisp:1.35
--- climacs/packages.lisp:1.34	Sun Jan 16 12:04:59 2005
+++ climacs/packages.lisp	Mon Jan 17 15:10:24 2005
@@ -49,6 +49,8 @@
            #:forward-object #:backward-object
 	   #:previous-line #:next-line
 	   #:open-line #:kill-line
+           #:empty-line-p
+           #:line-indentation
 	   #:number-of-lines-in-region
 	   #:constituentp #:whitespacep
 	   #:forward-word #:backward-word
@@ -56,6 +58,7 @@
            #:upcase-region #:downcase-region #:capitalize-region
            #:upcase-word #:downcase-word #:capitalize-word
            #:tabify-region #:untabify-region
+           #:indent-line
            #:delete-indentation
 	   #:input-from-stream #:output-to-stream
 	   #:name-mixin #:name
@@ -74,6 +77,7 @@
   (:export #:syntax #:define-syntax
 	   #:basic-syntax
 	   #:update-syntax
+           #:syntax-line-indentation
 	   #:beginning-of-paragraph #:end-of-paragraph))
 
 (defpackage :climacs-kill-ring
@@ -90,6 +94,7 @@
 	   #:redisplay-pane #:full-redisplay
 	   #:page-down #:page-up
            #:tab-space-count
+           #:indent-tabs-mode
 	   #:url))
 
 (defpackage :climacs-gui


Index: climacs/pane.lisp
diff -u climacs/pane.lisp:1.3 climacs/pane.lisp:1.4
--- climacs/pane.lisp:1.3	Mon Jan 17 05:35:52 2005
+++ climacs/pane.lisp	Mon Jan 17 15:10:24 2005
@@ -2,6 +2,8 @@
 
 ;;;  (c) copyright 2005 by
 ;;;           Robert Strandh (strandh at labri.fr)
+;;;  (c) copyright 2005 by
+;;;           Matthieu Villeneuve (matthieu.villeneuve at free.fr)
 
 ;;; This library is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Library General Public
@@ -50,9 +52,13 @@
 (defclass filename-mixin ()
   ((filename :initform nil :accessor filename)))
 
+;(defgeneric indent-tabs-mode (climacs-buffer))
+
 (defclass climacs-buffer (standard-buffer abbrev-mixin filename-mixin name-mixin)
   ((needs-saving :initform nil :accessor needs-saving)
-   (syntax :initarg :syntax :initform (make-instance 'basic-syntax) :accessor syntax))
+   (syntax :initarg :syntax :initform (make-instance 'basic-syntax) :accessor syntax)
+   (indent-tabs-mode :initarg indent-tabs-mode :initform t
+                     :accessor indent-tabs-mode))
   (:default-initargs :name "*scratch*"))
 
 


Index: climacs/syntax.lisp
diff -u climacs/syntax.lisp:1.27 climacs/syntax.lisp:1.28
--- climacs/syntax.lisp:1.27	Mon Jan 17 05:35:52 2005
+++ climacs/syntax.lisp	Mon Jan 17 15:10:24 2005
@@ -26,6 +26,10 @@
 
 (defgeneric update-syntax (buffer syntax))
 
+(defgeneric syntax-line-indentation (mark tab-width syntax)
+  (:documentation "Return the correct indentation for the line containing
+the mark, according to the specified syntax."))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
 ;;; Syntax completion
@@ -62,3 +66,7 @@
 (defmethod update-syntax (buffer (syntax basic-syntax))
   (declare (ignore buffer))
   nil)
+
+(defmethod syntax-line-indentation (mark tab-width (syntax basic-syntax))
+  (declare (ignore mark tab-width))
+  0)


Index: climacs/text-syntax.lisp
diff -u climacs/text-syntax.lisp:1.4 climacs/text-syntax.lisp:1.5
--- climacs/text-syntax.lisp:1.4	Mon Jan 17 05:35:52 2005
+++ climacs/text-syntax.lisp	Mon Jan 17 15:10:24 2005
@@ -2,6 +2,8 @@
 
 ;;;  (c) copyright 2005 by
 ;;;           Robert Strandh (strandh at labri.fr)
+;;;  (c) copyright 2005 by
+;;;           Matthieu Villeneuve (matthieu.villeneuve at free.fr)
 
 ;;; This library is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Library General Public
@@ -119,3 +121,12 @@
 	       (if (typep (element* paragraphs pos1) 'left-sticky-mark)
 		   (offset (element* paragraphs (1+ pos1)))
 		   (offset (element* paragraphs pos1))))))))
+
+(defmethod syntax-line-indentation (mark tab-width (syntax text-syntax))
+  (loop with indentation = 0
+        with mark2 = (clone-mark mark)
+        until (beginning-of-buffer-p mark2)
+        do (previous-line mark2)
+           (setf indentation (line-indentation mark2 tab-width))
+        while (empty-line-p mark2)
+        finally (return indentation)))




More information about the Climacs-cvs mailing list