/[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.1 - (show annotations) (vendor branch)
Sun Jun 17 12:18:22 1990 UTC (23 years, 10 months ago) by ram
Changes since 1.1: +8 -18 lines
Fixed line hackery to work in new compiler (and be portable too..).
1 ;;; -*- Log: hemlock.log; Package: Hemlock-Internals -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the Spice Lisp project at
5 ;;; Carnegie-Mellon University, and has been placed in the public domain.
6 ;;; Spice Lisp is currently incomplete and under active development.
7 ;;; If you want to use this code or any part of Spice Lisp, please contact
8 ;;; Scott Fahlman (FAHLMAN@CMUC).
9 ;;; **********************************************************************
10 ;;;
11 ;;; This file contains definitions for the Line structure, and some
12 ;;; functions and macros to manipulate them.
13 ;;;
14 ;;; This stuff was allowed to become implementation dependant because
15 ;;; you make thousands of lines, so speed is real important. In some
16 ;;; implementations (the Perq for example) it may be desirable to
17 ;;; not actually cons the strings in the line objects until someone
18 ;;; touches them, and just keep a pointer in the line to where the file
19 ;;; is mapped in memory. Such lines are called "buffered". This stuff
20 ;;; links up with the file-reading stuff and the line-image building stuff.
21 ;;;
22 (in-package 'hemlock-internals)
23 (export '(line linep line-previous line-next line-plist line-signature))
24
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.")
35
36
37 ;;;; The line object:
38
39 (proclaim '(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-Lines
91 (buffered-p ()))
92
93 ;;; Make Line-Chars the same as Line-%Chars on implementations without
94 ;;; buffered lines.
95 ;;;
96 #-Buffered-Lines
97 (defmacro line-chars (x)
98 `(line-%chars ,x))
99
100
101 ;;; If buffered lines are supported, then we create the string
102 ;;; representation for the characters when someone uses Line-Chars. People
103 ;;; who are prepared to handle buffered lines or who just want a signature
104 ;;; for the contents can use Line-%chars directly.
105 ;;;
106 #+Buffered-Lines
107 (defmacro line-chars (line)
108 `(the simple-string (if (line-buffered-p ,line)
109 (read-buffered-line ,line)
110 (line-%chars ,line))))
111 ;;;
112 #+Buffered-Lines
113 (defsetf line-chars %set-line-chars)
114 ;;;
115 #+Buffered-Lines
116 (defmacro %set-line-chars (line chars)
117 `(setf (line-%chars ,line) ,chars))
118
119
120 ;;; Line-Signature -- Public
121 ;;;
122 ;;; We can just return the Line-%Chars.
123 ;;;
124 (proclaim '(inline line-signature))
125 (defun line-signature (line)
126 "This function returns an object which serves as a signature for a line's
127 contents. It is guaranteed that any modification of text on the line will
128 result in the signature changing so that it is not EQL to any previous value.
129 Note that the signature may change even when the text hasn't been modified, but
130 this probably won't happen often."
131 (line-%chars line))
132
133
134 ;;; Return a copy of Line in buffer Buffer with the same chars. We use
135 ;;; this macro where we want to copy a line because it takes care of
136 ;;; the case where the line is buffered.
137 ;;;
138 (defmacro %copy-line (line &key previous number %buffer)
139 `(make-line :chars (line-%chars ,line)
140 :previous ,previous
141 :number ,number
142 :%buffer ,%buffer
143 #+Buffered-Lines :buffered-p
144 #+Buffered-Lines (line-buffered-p ,line)))
145
146 ;;; Hide the fact that the slot isn't really called CHARS.
147 ;;;
148 (defmacro make-line (&rest keys)
149 `(%make-line ,@(substitute :%chars :chars keys)))
150
151 (defmacro line-length* (line)
152 "Returns the number of characters on the line, but it's a macro!"
153 `(cond ((eq ,line open-line)
154 (+ left-open-pos (- line-cache-length right-open-pos)))
155 ((line-buffered-p ,line))
156 (t
157 (length (the simple-string (line-%chars ,line))))))

  ViewVC Help
Powered by ViewVC 1.1.5