|
30 | 30 | :line-search-property |
31 | 31 | :line-search-property-range |
32 | 32 | :line-property-insert-pos |
33 | | - :line-property-delete-pos |
34 | | - :line-property-delete-line |
| 33 | + :line-delete-property-region |
35 | 34 | :line-string/attributes |
36 | 35 | :line-substring |
37 | 36 | :insert-string |
|
53 | 52 | :initarg :next |
54 | 53 | :initform nil |
55 | 54 | :accessor line-next) |
56 | | - (str |
57 | | - :initarg :str |
| 55 | + (string |
| 56 | + :initarg :string |
58 | 57 | :initform nil |
59 | | - :accessor line-string) |
| 58 | + :reader line-string |
| 59 | + :writer set-line-string) |
60 | 60 | (plist |
61 | 61 | :initarg :plist |
62 | 62 | :initform nil |
|
76 | 76 | (line-string object) |
77 | 77 | (line-plist object)))) |
78 | 78 |
|
79 | | -(defun make-line (previous next str) |
| 79 | +(defun make-line (previous next string) |
80 | 80 | (let ((line (make-instance 'line |
81 | 81 | :next next |
82 | 82 | :previous previous |
83 | | - :str str))) |
| 83 | + :string string))) |
84 | 84 | (when next |
85 | 85 | (setf (line-previous next) line)) |
86 | 86 | (when previous |
|
97 | 97 | (when (line-next line) |
98 | 98 | (setf (line-previous (line-next line)) |
99 | 99 | (line-previous line))) |
100 | | - (setf (line-previous line) nil |
101 | | - (line-next line) nil |
102 | | - (line-string line) nil |
103 | | - (line-points line) nil)) |
| 100 | + (setf (line-previous line) nil) |
| 101 | + (setf (line-next line) nil) |
| 102 | + (setf (line-points line) nil) |
| 103 | + (set-line-string nil line)) |
104 | 104 |
|
105 | 105 | (defun line-alive-p (line) |
106 | 106 | (not (null (line-string line)))) |
|
265 | 265 | (setf (getf new-plist (car plist-rest)) new-values)))) |
266 | 266 | (setf (line-plist next-line) new-plist))) |
267 | 267 |
|
268 | | -(defun line-property-delete-pos (line pos n) |
| 268 | +(defun line-delete-property-region (line start &optional end) |
| 269 | + (unless end (setf end (line-length line))) |
| 270 | + (assert (<= start end)) |
269 | 271 | (loop :for plist-rest :on (line-plist line) :by #'cddr |
270 | 272 | :do (setf (cadr plist-rest) |
271 | 273 | (loop :for elt :in (cadr plist-rest) |
272 | | - :for (start end value) := elt |
| 274 | + :for (start1 end1 value) := elt |
273 | 275 |
|
274 | | - :if (<= pos start end (+ pos n -1)) |
| 276 | + :if (<= start start1 end1 (1- end)) |
275 | 277 | :do (progn) |
276 | 278 |
|
277 | | - :else :if (<= pos (+ pos n) start) |
278 | | - :collect (list (- start n) (- end n) value) |
| 279 | + :else :if (<= start end start1) |
| 280 | + :collect (list (- start1 (- end start)) |
| 281 | + (- end1 (- end start)) |
| 282 | + value) |
279 | 283 |
|
280 | | - :else :if (< pos start (+ pos n)) |
281 | | - :collect (list pos (- end n) value) |
| 284 | + :else :if (< start start1 end) |
| 285 | + :collect (list start (- end1 (- end start)) value) |
282 | 286 |
|
283 | | - :else :if (<= start pos (+ pos n) end) |
284 | | - :collect (list start (- end n) value) |
| 287 | + :else :if (<= start1 start end end1) |
| 288 | + :collect (list start1 (- end1 (- end start)) value) |
285 | 289 |
|
286 | | - :else :if (<= start pos end (+ pos n)) |
287 | | - :collect (list start pos value) |
| 290 | + :else :if (<= start1 start end1 end) |
| 291 | + :collect (list start1 start value) |
288 | 292 |
|
289 | 293 | :else |
290 | 294 | :collect elt)))) |
291 | 295 |
|
292 | | -(defun line-property-delete-line (line pos) |
293 | | - (loop :for plist-rest :on (line-plist line) :by #'cddr |
294 | | - :do (setf (cadr plist-rest) |
295 | | - (loop :for elt :in (cadr plist-rest) |
296 | | - :for (start end value) := elt |
297 | | - :if (<= pos start) |
298 | | - :do (progn) |
299 | | - :else :if (<= pos end) |
300 | | - :collect (list start pos value) |
301 | | - :else |
302 | | - :collect elt |
303 | | - )))) |
304 | | - |
305 | 296 | (defun line-string/attributes (line) |
306 | 297 | (cons (line-string line) |
307 | 298 | (alexandria:if-let (sticky-attribute (getf (line-plist line) :sticky-attribute)) |
|
319 | 310 |
|
320 | 311 | (defun insert-string (line string index) |
321 | 312 | (line-property-insert-pos line index (length string)) |
322 | | - (setf (line-string line) |
323 | | - (concatenate 'string |
324 | | - (line-substring line :start 0 :end index) |
325 | | - string |
326 | | - (line-substring line :start index)))) |
| 313 | + (set-line-string (concatenate 'string |
| 314 | + (line-substring line :start 0 :end index) |
| 315 | + string |
| 316 | + (line-substring line :start index)) |
| 317 | + line)) |
327 | 318 |
|
328 | 319 | (defun insert-newline (line position) |
329 | 320 | (let ((before-string (line-substring line :start 0 :end position)) |
330 | 321 | (after-string (line-substring line :start position))) |
331 | | - (setf (line-string line) before-string) |
| 322 | + (set-line-string before-string line) |
332 | 323 | (let ((next (make-line line (line-next line) after-string))) |
333 | 324 | (line-property-insert-newline line next position)))) |
334 | 325 |
|
335 | 326 | (defun delete-region (line &key start end) |
336 | | - (setf (line-string line) |
337 | | - (concatenate 'string |
338 | | - (line-substring line :start 0 :end start) |
339 | | - (line-substring line :start (or end (line-length line)))))) |
| 327 | + (line-delete-property-region line start end) |
| 328 | + (set-line-string (concatenate 'string |
| 329 | + (line-substring line :start 0 :end start) |
| 330 | + (line-substring line :start (or end (line-length line)))) |
| 331 | + line)) |
340 | 332 |
|
341 | 333 | (defun merge-with-next-line (line &key (start 0)) |
342 | 334 | (assert (line-next line)) |
| 335 | + (line-delete-property-region line start) |
343 | 336 | (line-merge line (line-next line) start) |
344 | | - (setf (line-string line) |
345 | | - (concatenate 'string |
346 | | - (line-substring line :start 0 :end start) |
347 | | - (line-string (line-next line)))) |
| 337 | + (set-line-string (concatenate 'string |
| 338 | + (line-substring line :start 0 :end start) |
| 339 | + (line-string (line-next line))) |
| 340 | + line) |
348 | 341 | (line-free (line-next line))) |
0 commit comments