unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@gnu.org>
Subject: Re: PATCH: ewoc.el to permit node representation abutment
Date: 13 May 2006 01:08:03 -0400	[thread overview]
Message-ID: <jkvesawlzg.fsf@glug.org> (raw)
In-Reply-To: <jwv4q00zidd.fsf-monnier+emacs@gnu.org>

Stefan Monnier <monnier@iro.umontreal.ca> 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))))
  \f
  ;;; ===========================================================================
  ;;;                  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)))
  \f
  ;;; ===========================================================================
  ;;;                  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))))
  
  \f
  (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))))
  
  \f
  (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	other threads:[~2006-05-13  5:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-05 12:03 PATCH: ewoc.el to permit node representation abutment Thien-Thi Nguyen
2006-05-05 13:20 ` Stefan Monnier
2006-05-05 21:43   ` ttn
2006-05-08  8:48     ` Thien-Thi Nguyen
2006-05-08 15:04       ` Stefan Monnier
2006-05-13  5:08         ` Thien-Thi Nguyen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jkvesawlzg.fsf@glug.org \
    --to=ttn@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).