/[cmucl]/src/hemlock/line.lisp
ViewVC logotype

Contents of /src/hemlock/line.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.2 - (show annotations) (vendor branch)
Fri Feb 8 16:35:54 1991 UTC (23 years, 2 months ago) by ram
Changes since 1.1.1.1: +8 -5 lines
Added new header with RCS FILE-COMMENT.
1 ;;; -*- Log: hemlock.log; Package: Hemlock-Internals -*-
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 ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8 ;;;
9 (ext:file-comment
10 "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/line.lisp,v 1.1.1.2 1991/02/08 16:35:54 ram Exp $")
11 ;;;
12 ;;; **********************************************************************
13 ;;;
14 ;;; This file contains definitions for the Line structure, and some
15 ;;; functions and macros to manipulate them.
16 ;;;
17 ;;; This stuff was allowed to become implementation dependant because
18 ;;; you make thousands of lines, so speed is real important. In some
19 ;;; implementations (the Perq for example) it may be desirable to
20 ;;; not actually cons the strings in the line objects until someone
21 ;;; touches them, and just keep a pointer in the line to where the file
22 ;;; is mapped in memory. Such lines are called "buffered". This stuff
23 ;;; links up with the file-reading stuff and the line-image building stuff.
24 ;;;
25 (in-package 'hemlock-internals)
26 (export '(line linep line-previous line-next line-plist line-signature))
27
28 (setf (documentation 'linep 'function)
29 "Returns true if its argument is a Hemlock line object, Nil otherwise.")
30 (setf (documentation 'line-previous 'function)
31 "Return the Hemlock line that precedes this one, or Nil if there is no
32 previous line.")
33 (setf (documentation 'line-next 'function)
34 "Return the Hemlock line that follows this one, or Nil if there is no
35 next line.")
36 (setf (documentation 'line-plist 'function)
37 "Return a line's property list. This may be manipulated with Setf and Getf.")
38
39
40 ;;;; The line object:
41
42 (proclaim '(inline %make-line))
43 (defstruct (line (:print-function %print-hline)
44 (:constructor %make-line)
45 (:predicate linep))
46 "A Hemlock line object. See Hemlock design document for details."
47 ;;
48 ;; Something that represents the contents of the line. This is
49 ;; guaranteed to change (as compared by EQL) whenver the contents of the
50 ;; line changes, but might at arbitarary other times. There are
51 ;; currently about three different cases:
52 ;;
53 ;; Normal:
54 ;; A simple string holding the contents of the line.
55 ;;
56 ;; A cached line:
57 ;; The line is eq to Open-Line, and the actual contents are in the
58 ;; line cache. The %Chars may be either the original contents or a
59 ;; negative fixnum.
60 ;;
61 ;; A buffered line:
62 ;; The line hasn't been touched since it was read from a file, and the
63 ;; actual contents are in some system I/O area. This is indicated by
64 ;; the Line-Buffered-P slot being true. In buffered lines on the RT,
65 ;; the %Chars slot contains the system-area-pointer to the beginning
66 ;; of the characters.
67 (%chars "")
68 ;;
69 ;; Pointers to the next and previous lines in the doubly linked list of
70 ;; line structures.
71 previous
72 next
73 ;;
74 ;; A list of all the permanent marks pointing into this line.
75 (marks ())
76 ;;
77 ;; The buffer to which this line belongs, or a *disembodied-buffer-count*
78 ;; if the line is not in any buffer.
79 %buffer
80 ;;
81 ;; A non-negative integer (fixnum) that represents the ordering of lines
82 ;; within continguous range of lines (a buffer or disembuffered region).
83 ;; The number of the Line-Next is guaranteed to be strictly greater than
84 ;; our number, and the Line-Previous is guaranteed to be strictly less.
85 (number 0)
86 ;;
87 ;; The line property list, used by user code to annotate the text.
88 plist
89 ;;
90 ;; A slot that indicates whether this line is a buffered line, and if so
91 ;; contains information about how the text is stored. On the RT, this is
92 ;; the length of the text pointed to by the Line-%Chars.
93 #+Buffered-Lines
94 (buffered-p ()))
95
96 ;;; Make Line-Chars the same as Line-%Chars on implementations without
97 ;;; buffered lines.
98 ;;;
99 #-Buffered-Lines
100 (defmacro line-chars (x)
101 `(line-%chars ,x))
102
103
104 ;;; If buffered lines are supported, then we create the string
105 ;;; representation for the characters when someone uses Line-Chars. People
106 ;;; who are prepared to handle buffered lines or who just want a signature
107 ;;; for the contents can use Line-%chars directly.
108 ;;;
109 #+Buffered-Lines
110 (defmacro line-chars (line)
111 `(the simple-string (if (line-buffered-p ,line)
112 (read-buffered-line ,line)
113 (line-%chars ,line))))
114 ;;;
115 #+Buffered-Lines
116 (defsetf line-chars %set-line-chars)
117 ;;;
118 #+Buffered-Lines
119 (defmacro %set-line-chars (line chars)
120 `(setf (line-%chars ,line) ,chars))
121
122
123 ;;; Line-Signature -- Public
124 ;;;
125 ;;; We can just return the Line-%Chars.
126 ;;;
127 (proclaim '(inline line-signature))
128 (defun line-signature (line)
129 "This function returns an object which serves as a signature for a line's
130 contents. It is guaranteed that any modification of text on the line will
131 result in the signature changing so that it is not EQL to any previous value.
132 Note that the signature may change even when the text hasn't been modified, but
133 this probably won't happen often."
134 (line-%chars line))
135
136
137 ;;; Return a copy of Line in buffer Buffer with the same chars. We use
138 ;;; this macro where we want to copy a line because it takes care of
139 ;;; the case where the line is buffered.
140 ;;;
141 (defmacro %copy-line (line &key previous number %buffer)
142 `(make-line :chars (line-%chars ,line)
143 :previous ,previous
144 :number ,number
145 :%buffer ,%buffer
146 #+Buffered-Lines :buffered-p
147 #+Buffered-Lines (line-buffered-p ,line)))
148
149 ;;; Hide the fact that the slot isn't really called CHARS.
150 ;;;
151 (defmacro make-line (&rest keys)
152 `(%make-line ,@(substitute :%chars :chars keys)))
153
154 (defmacro line-length* (line)
155 "Returns the number of characters on the line, but it's a macro!"
156 `(cond ((eq ,line open-line)
157 (+ left-open-pos (- line-cache-length right-open-pos)))
158 ((line-buffered-p ,line))
159 (t
160 (length (the simple-string (line-%chars ,line))))))

  ViewVC Help
Powered by ViewVC 1.1.5