emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: ewoc.el to permit node representation abutment


From: Thien-Thi Nguyen
Subject: Re: PATCH: ewoc.el to permit node representation abutment
Date: 13 May 2006 01:08:03 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Stefan Monnier <address@hidden> writes:

> Hmm... now it looks too complex to be installed before Emacs-22.

yeah, looks like toggling marker insertion type did not prove to be so
clean in practice.  i've installed a few (hopefully uncontroversial)
implementation touch-ups to ewoc.el (now at cvs revision 1.23) and have
prepared the following patch against it for review.

this one differs from the previous two in that pcvs.el is also involved.
(it's omission before shows a testing methodology bug, argh...)  as
before, changes to pcvs*.el are to preserve "look and feel" from the
user's perspective.

here is a suitable ChangeLog entry:

        * emacs-lisp/ewoc.el (ewoc--adjust): New func.
        (ewoc--insert-new-node): Don't insert trailing newline.
        Instead, adjust succesor nodes' start markers.
        (ewoc--refresh-node): Delete all text from current node's start
        marker to the next one's; adjust successor nodes' start markers.
        (ewoc--create): Doc fix.
        (ewoc--refresh): Don't insert newline.
        (ewoc--set-hf): Use `ewoc--set-buffer-bind-dll-let*'.
        * pcvs.el (cvs-make-cvs-buffer): Specify
        extra newline for ewoc's header and footer.
        (cvs-update-header): Update initial header recognition.
        Append newline to final header and footer values.
        * pcvs-info.el (cvs-fileinfo-pp): Insert trailing newline.

i will be off net for a few days but will be back to address comments
and hopefully wrap things up early next week.

thi


__________________________________________________________________
*** emacs-lisp/ewoc.el  Fri May 12 13:36:31 2006
--- emacs-lisp/ewoc.el.NEW      Sat May 13 06:11:24 2006
*************** (defsubst ewoc--filter-hf-nodes (ewoc no
*** 205,210 ****
--- 205,226 ----
              (eq node (ewoc--footer ewoc)))
      node))
  
+ (defun ewoc--adjust (beg end node)
+   ;; "Manually reseat" markers for NODE and its successors (including footer
+   ;; and dll), in the case where they originally shared start position with
+   ;; BEG, to END.  BEG and END are buffer positions describing NODE's left
+   ;; neighbor.  This operation is functionally equivalent to temporarily
+   ;; setting these nodes' markers' insertion type to t around the pretty-print
+   ;; call that precedes the call to `ewoc-adjust', and then changing them back
+   ;; to nil.
+   (when (< beg end)
+     (let (m)
+       (while (and (= beg (setq m (ewoc--node-start-marker node)))
+                   (progn
+                     (set-marker m end)
+                     (not (eq dll node))))
+         (setq node (ewoc--node-right node))))))
+ 
  (defun ewoc--insert-new-node (node data pretty-printer)
    "Insert before NODE a new node for DATA, displayed by PRETTY-PRINTER.
  Call PRETTY-PRINTER with point at NODE's start, thus pushing back
*************** (defun ewoc--insert-new-node (node data 
*** 215,243 ****
             (pos (marker-position m))
             (elemnode (ewoc--node-create m data)))
        (goto-char pos)
-       ;; Insert the trailing newline using insert-before-markers
-       ;; so that the start position for the next element is updated.
-       (insert-before-markers ?\n)
-       ;; Move back, and call the pretty-printer.
-       (backward-char 1)
        (funcall pretty-printer data)
        (setf (marker-position m) pos
              (ewoc--node-left  elemnode) (ewoc--node-left node)
              (ewoc--node-right elemnode)                  node
              (ewoc--node-right (ewoc--node-left node)) elemnode
              (ewoc--node-left                   node)  elemnode)
        elemnode)))
  
  (defun ewoc--refresh-node (pp node)
    "Redisplay the element represented by NODE using the pretty-printer PP."
!   (let ((inhibit-read-only t))
      ;; First, remove the string from the buffer:
!     (delete-region (ewoc--node-start-marker node)
!                    (1- (marker-position
!                         (ewoc--node-start-marker (ewoc--node-right node)))))
      ;; Calculate and insert the string.
!     (goto-char (ewoc--node-start-marker node))
!     (funcall pp (ewoc--node-data node))))
  
  ;;; 
===========================================================================
  ;;;                  Public members of the Ewoc package
--- 231,256 ----
             (pos (marker-position m))
             (elemnode (ewoc--node-create m data)))
        (goto-char pos)
        (funcall pretty-printer data)
        (setf (marker-position m) pos
              (ewoc--node-left  elemnode) (ewoc--node-left node)
              (ewoc--node-right elemnode)                  node
              (ewoc--node-right (ewoc--node-left node)) elemnode
              (ewoc--node-left                   node)  elemnode)
+       (ewoc--adjust pos (point) node)
        elemnode)))
  
  (defun ewoc--refresh-node (pp node)
    "Redisplay the element represented by NODE using the pretty-printer PP."
!   (let ((inhibit-read-only t)
!         (m (ewoc--node-start-marker node))
!         (R (ewoc--node-right node)))
      ;; First, remove the string from the buffer:
!     (delete-region m (ewoc--node-start-marker R))
      ;; Calculate and insert the string.
!     (goto-char m)
!     (funcall pp (ewoc--node-data node))
!     (ewoc--adjust m (point) R)))
  
  ;;; 
===========================================================================
  ;;;                  Public members of the Ewoc package
*************** (defun ewoc-create (pretty-printer &opti
*** 251,258 ****
  PRETTY-PRINTER should be a function that takes one argument, an
  element, and inserts a string representing it in the buffer (at
  point).  The string PRETTY-PRINTER inserts may be empty or span
! several lines.  A trailing newline will always be inserted
! automatically.  The PRETTY-PRINTER should use `insert', and not
  `insert-before-markers'.
  
  Optional second argument HEADER is a string that will always be
--- 264,270 ----
  PRETTY-PRINTER should be a function that takes one argument, an
  element, and inserts a string representing it in the buffer (at
  point).  The string PRETTY-PRINTER inserts may be empty or span
! several lines.  The PRETTY-PRINTER should use `insert', and not
  `insert-before-markers'.
  
  Optional second argument HEADER is a string that will always be
*************** (defun ewoc-refresh (ewoc)
*** 522,528 ****
        (while (not (eq node footer))
          (set-marker (ewoc--node-start-marker node) (point))
          (funcall pp (ewoc--node-data node))
-         (insert "\n")
          (setq node (ewoc--node-next dll node)))))
      (set-marker (ewoc--node-start-marker footer) (point))))
  
--- 534,539 ----
*************** (defun ewoc-get-hf (ewoc)
*** 561,571 ****
  
  (defun ewoc-set-hf (ewoc header footer)
    "Set the HEADER and FOOTER of EWOC."
!   (setf (ewoc--node-data (ewoc--header ewoc)) header)
!   (setf (ewoc--node-data (ewoc--footer ewoc)) footer)
!   (save-excursion
!     (ewoc--refresh-node 'insert (ewoc--header ewoc))
!     (ewoc--refresh-node 'insert (ewoc--footer ewoc))))
  
  
  (provide 'ewoc)
--- 572,585 ----
  
  (defun ewoc-set-hf (ewoc header footer)
    "Set the HEADER and FOOTER of EWOC."
!   (ewoc--set-buffer-bind-dll-let* ewoc
!       ((head (ewoc--header ewoc))
!        (foot (ewoc--footer ewoc)))
!     (setf (ewoc--node-data head) header
!           (ewoc--node-data foot) footer)
!     (save-excursion
!       (ewoc--refresh-node 'insert head)
!       (ewoc--refresh-node 'insert foot))))
  
  
  (provide 'ewoc)
*** pcvs.el     Sat May 13 06:16:33 2006
--- pcvs.el.NEW Sat May 13 06:35:42 2006
*************** (defun cvs-make-cvs-buffer (dir &optiona
*** 467,473 ****
         (cvs-mode)
         (set (make-local-variable 'list-buffers-directory) buffer-name)
         ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
!        (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n" "")))
           (set (make-local-variable 'cvs-cookies) cookies)
           (add-hook 'kill-buffer-hook
                     (lambda ()
--- 467,473 ----
         (cvs-mode)
         (set (make-local-variable 'list-buffers-directory) buffer-name)
         ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
!        (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n\n" "\n")))
           (set (make-local-variable 'cvs-cookies) cookies)
           (add-hook 'kill-buffer-hook
                     (lambda ()
*************** (defun cvs-update-header (cmd add)
*** 618,624 ****
         (str (car hf))
         (done "")
         (tin (ewoc-nth cvs-cookies 0)))
!     (if (eq (length str) 1) (setq str ""))
      ;; look for the first *real* fileinfo (to determine emptyness)
      (while
        (and tin
--- 618,624 ----
         (str (car hf))
         (done "")
         (tin (ewoc-nth cvs-cookies 0)))
!     (if (eq (length str) 2) (setq str ""))
      ;; look for the first *real* fileinfo (to determine emptyness)
      (while
        (and tin
*************** (defun cvs-update-header (cmd add)
*** 633,638 ****
--- 633,639 ----
        (setq str (replace-match "" t t str))
        (if (zerop (length str)) (setq str "\n"))
        (setq done (concat "-- last cmd: " cmd " --"))))
+     (setq str (concat str "\n") done (concat done "\n"))
      ;; set the new header and footer
      (ewoc-set-hf cvs-cookies
                 str (concat "\n--------------------- "
*** pcvs-info.el        Thu May  4 15:29:51 2006
--- pcvs-info.el.NEW    Fri May  5 12:43:07 2006
*************** (defun cvs-fileinfo-pp (fileinfo)
*** 379,385 ****
                      ;; or nothing
                      "")))
           (format "%-11s %s %-11s %-11s %s"
!                  side status type base file)))))))
  
  
  (defun cvs-fileinfo-update (fi fi-new)
--- 379,386 ----
                      ;; or nothing
                      "")))
           (format "%-11s %s %-11s %-11s %s"
!                  side status type base file))))
!      "\n")))
  
  
  (defun cvs-fileinfo-update (fi fi-new)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]