Changeset 6603


Ignore:
Timestamp:
May 25, 2007, 4:57:08 AM (18 years ago)
Author:
Gary Byers
Message:

INSERT-STRING: don't take start/end args; if embedded newlines, cons
up a region and do NINSERT-REGION.

Insertions try to adjust line-origins of subsequent lines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/hemlock/src/htext3.lisp

    r6580 r6603  
    7676                                      character)
    7777                                (incf *left-open-pos*)))))
     78                      (adjust-line-origins-forward line)
    7879                      (buffer-note-insertion buffer mark 1))))
    7980
    8081
    8182
    82 (defun insert-string (mark string &optional (start 0) (end (length string)))
     83(defun insert-string (mark string #| &optional (start 0) (end (length string))|#)
    8384  "Inserts the String at the Mark.  Do not use Start and End unless you
    8485  know what you're doing!"
    8586  (let* ((line (mark-line mark))
     87         (len (length string))
    8688         (buffer (line-%buffer line))
    8789         (string (coerce string 'simple-string))
     
    9193    (when region
    9294      (delete-region region))
    93     (unless (zerop (- end start))
    94       (if (%sp-find-character string start end #\newline)
    95         (with-mark ((mark mark :left-inserting))
    96            (do ((left-index start (1+ right-index))
    97                 (right-index
    98                  (%sp-find-character string start end #\newline)
    99                  (%sp-find-character string (1+ right-index) end #\newline)))
    100                ((null right-index)
    101                 (if (/= left-index end)
    102                   (insert-string mark string left-index end)))
    103              (insert-string mark string left-index right-index)
    104              (insert-character mark #\newline)))
    105         (modifying-buffer
    106          buffer
    107          (modifying-line line mark)
    108          (let ((length (- end start)))
    109            (if (<= *right-open-pos* (+ *left-open-pos* end))
    110              (grow-open-chars (* (+ *line-cache-length* end) 2)))
    111              
    112            (maybe-move-some-marks (charpos line) *left-open-pos*
    113                                   (+ charpos length))
    114            (cond
    115              ((eq (mark-%kind mark) :right-inserting)
    116               (let ((new (- *right-open-pos* length)))
    117                 (%sp-byte-blt string start *open-chars* new *right-open-pos*)
    118                 (setq *right-open-pos* new)))
    119              (t
    120               (let ((new (+ *left-open-pos* length)))
    121                 (%sp-byte-blt string start *open-chars* *left-open-pos* new)
    122                 (setq *left-open-pos* new)))))
    123          (buffer-note-insertion buffer mark (- end start)))))))
     95    (unless (zerop len)
     96      (if (%sp-find-character string 0 len #\newline)
     97        (ninsert-region mark (string-to-region string))
     98        (modifying-buffer
     99         buffer
     100         (progn
     101           (modifying-line line mark)
     102           (if (<= *right-open-pos* (+ *left-open-pos* len))
     103             (grow-open-chars (* (+ *line-cache-length* len) 2)))
     104           (maybe-move-some-marks (charpos line) *left-open-pos*
     105                                  (+ charpos len))
     106           (cond
     107             ((eq (mark-%kind mark) :right-inserting)
     108              (let ((new (- *right-open-pos* len)))
     109                (%sp-byte-blt string 0 *open-chars* new *right-open-pos*)
     110                (setq *right-open-pos* new)))
     111             (t
     112              (let ((new (+ *left-open-pos* len)))
     113                (%sp-byte-blt string 0 *open-chars* *left-open-pos* new)
     114                (setq *left-open-pos* new)))))
     115         (adjust-line-origins-forward line)
     116         (buffer-note-insertion buffer mark (length string)))))))
     117                       
     118 
    124119
    125120
     
    141136      ;; simple case -- just BLT the characters in with insert-string
    142137      (if (eq first-line *open-line*) (close-line))
    143       (insert-string mark (line-chars first-line) first-charpos last-charpos))
     138      (let* ((string (line-chars first-line)))
     139        (unless (and (eql first-charpos 0)
     140                     (eql last-charpos (length string)))
     141          (setq string (subseq string first-charpos last-charpos)))
     142        (insert-string mark string)))
    144143     (t
    145144      (close-line)
     
    193192                    (+ last-charpos (- this-charpos charpos)))))
    194193            (setf (line-next previous) new-line  previous new-line))
     194          (adjust-line-origins-forward line)
    195195          (buffer-note-insertion buffer  mark nins)))))))
    196196
     
    210210      ;; Simple case -- just BLT the characters in with insert-string.
    211211      (if (eq first-line *open-line*) (close-line))
    212       (insert-string mark (line-chars first-line) first-charpos last-charpos))
     212      (let* ((string (line-chars first-line)))
     213        (unless (and (eq first-charpos 0)
     214                     (eql last-charpos (length string)))
     215          (setq string (subseq string first-charpos last-charpos)))
     216        (insert-string mark string)))
    213217     (t
    214218      (when (bufferp (line-%buffer first-line))
     
    265269          (maybe-move-some-marks (this-charpos line last-line) charpos
    266270            (+ last-charpos (- this-charpos charpos)))
     271          (adjust-line-origins-forward line)
    267272          (buffer-note-insertion buffer mark nins)))))))
Note: See TracChangeset for help on using the changeset viewer.