source: trunk/ccl/hemlock/src/line.lisp @ 60

Last change on this file since 60 was 60, checked in by gb, 16 years ago

More changes/fixes: line-buffered-p stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
1;;; -*- Log: hemlock.log; Package: Hemlock-Internals -*-
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.
7#+CMU (ext:file-comment
8  "$Header$")
10;;; **********************************************************************
12;;; This file contains definitions for the Line structure, and some
13;;; functions and macros to manipulate them.
15;;;    This stuff was allowed to become implementation dependant because
16;;; you make thousands of lines, so speed is real important.  In some
17;;; implementations (the Perq for example) it may be desirable to
18;;; not actually cons the strings in the line objects until someone
19;;; touches them, and just keep a pointer in the line to where the file
20;;; is mapped in memory.  Such lines are called "buffered".  This stuff
21;;; links up with the file-reading stuff and the line-image building stuff.
23(in-package :hemlock-internals)
25(setf (documentation 'linep 'function)
26  "Returns true if its argument is a Hemlock line object, Nil otherwise.")
27(setf (documentation 'line-previous 'function)
28  "Return the Hemlock line that precedes this one, or Nil if there is no
29  previous line.")
30(setf (documentation 'line-next 'function)
31  "Return the Hemlock line that follows this one, or Nil if there is no
32  next line.")
33(setf (documentation 'line-plist 'function)
34  "Return a line's property list.  This may be manipulated with Setf and Getf.")
37;;;; The line object:
39(declaim (inline %make-line))
40(defstruct (line (:print-function %print-hline)
41                 (:constructor %make-line)
42                 (:predicate linep))
43  "A Hemlock line object.  See Hemlock design document for details."
44  ;;
45  ;; Something that represents the contents of the line.  This is
46  ;; guaranteed to change (as compared by EQL) whenver the contents of the
47  ;; line changes, but might at arbitarary other times.  There are
48  ;; currently about three different cases:
49  ;;
50  ;; Normal:
51  ;;    A simple string holding the contents of the line.
52  ;;
53  ;; A cached line:
54  ;;    The line is eq to Open-Line, and the actual contents are in the
55  ;;    line cache.  The %Chars may be either the original contents or a
56  ;;    negative fixnum.
57  ;;
58  ;; A buffered line:
59  ;;    The line hasn't been touched since it was read from a file, and the
60  ;;    actual contents are in some system I/O area.  This is indicated by
61  ;;    the Line-Buffered-P slot being true.  In buffered lines on the RT,
62  ;;    the %Chars slot contains the system-area-pointer to the beginning
63  ;;    of the characters.
64  (%chars "")
65  ;;
66  ;; Pointers to the next and previous lines in the doubly linked list of
67  ;; line structures.
68  previous
69  next
70  ;;
71  ;; A list of all the permanent marks pointing into this line.
72  (marks ())
73  ;;
74  ;; The buffer to which this line belongs, or a *disembodied-buffer-count*
75  ;; if the line is not in any buffer.
76  %buffer
77  ;;
78  ;; A non-negative integer (fixnum) that represents the ordering of lines
79  ;; within continguous range of lines (a buffer or disembuffered region).
80  ;; The number of the Line-Next is guaranteed to be strictly greater than
81  ;; our number, and the Line-Previous is guaranteed to be strictly less.
82  (number 0)
83  ;;
84  ;; The line property list, used by user code to annotate the text.
85  plist
86  ;;
87  ;; A slot that indicates whether this line is a buffered line, and if so
88  ;; contains information about how the text is stored.  On the RT, this is
89  ;; the length of the text pointed to by the Line-%Chars.
90  (buffered-p ()))
95;;; If buffered lines are supported, then we create the string
96;;; representation for the characters when someone uses Line-Chars.  People
97;;; who are prepared to handle buffered lines or who just want a signature
98;;; for the contents can use Line-%chars directly.
100(defmacro line-chars (line)
101  `(the simple-string (line-%chars ,line)))
103(defsetf line-chars %set-line-chars)
105(defmacro %set-line-chars (line chars)
106  `(setf (line-%chars ,line) ,chars))
109;;; Line-Signature  --  Public
111;;;    We can just return the Line-%Chars.
113(declaim (inline line-signature))
114(defun line-signature (line)
115  "This function returns an object which serves as a signature for a line's
116  contents.  It is guaranteed that any modification of text on the line will
117  result in the signature changing so that it is not EQL to any previous value.
118  Note that the signature may change even when the text hasn't been modified, but
119  this probably won't happen often."
120  (line-%chars line))
123;;; Return a copy of Line in buffer Buffer with the same chars.  We use
124;;; this macro where we want to copy a line because it takes care of
125;;; the case where the line is buffered.
127(defmacro %copy-line (line &key previous number %buffer)
128  `(make-line :chars (line-%chars ,line)
129              :previous ,previous
130              :number ,number
131              :%buffer ,%buffer
132              :buffered-p
133              (line-buffered-p ,line) ))
135;;; Hide the fact that the slot isn't really called CHARS.
137(defmacro make-line (&rest keys)
138  `(%make-line ,@(substitute :%chars :chars keys)))
140(defmacro line-length* (line)
141  "Returns the number of characters on the line, but it's a macro!"
142  `(cond ((eq ,line *open-line*)
143          (+ *left-open-pos* (- *line-cache-length* *right-open-pos*)))
144         ((line-buffered-p ,line))
145         (t
146          (length (the simple-string (line-%chars ,line))))))
Note: See TracBrowser for help on using the repository browser.