emacs-devel
[Top][All Lists]
Advanced

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

Re: ewoc--adjust ugliness


From: Thien-Thi Nguyen
Subject: Re: ewoc--adjust ugliness
Date: 27 May 2006 04:40:35 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Stefan Monnier <address@hidden> writes:

> Why not [more elegant `ewoc--wrap']

indeed, much better!

  * emacs-lisp/ewoc.el (ewoc): Add member `hf-pp' to this structure.
  (ewoc--wrap): New func.
  (ewoc-create): Take additional arg NOSEP.  If nil, wrap node and
  header/footer pretty-printers.  Save header/footer pretty-printer.
  (ewoc-set-hf): Use ewoc's header/footer pretty-printer.

thi

_______________________________________________________________________
diff -c -r1.30 ewoc.el
*** ewoc.el     26 May 2006 08:29:13 -0000      1.30
--- ewoc.el     27 May 2006 08:38:29 -0000
***************
*** 186,192 ****
            (:constructor ewoc--create
                          (buffer pretty-printer header footer dll))
            (:conc-name ewoc--))
!   buffer pretty-printer header footer dll last-node)
  
  (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms)
    "Execute FORMS with ewoc--buffer selected as current buffer,
--- 186,192 ----
            (:constructor ewoc--create
                          (buffer pretty-printer header footer dll))
            (:conc-name ewoc--))
!   buffer pretty-printer header footer dll last-node hf-pp)
  
  (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms)
    "Execute FORMS with ewoc--buffer selected as current buffer,
***************
*** 257,268 ****
      (goto-char m)
      (funcall pp (ewoc--node-data node))
      (ewoc--adjust m (point) R)))
  
  ;;; 
===========================================================================
  ;;;                  Public members of the Ewoc package
  
  ;;;###autoload
! (defun ewoc-create (pretty-printer &optional header footer)
    "Create an empty ewoc.
  
  The ewoc will be inserted in the current buffer at the current position.
--- 257,275 ----
      (goto-char m)
      (funcall pp (ewoc--node-data node))
      (ewoc--adjust m (point) R)))
+ 
+ (defun ewoc--wrap (func)
+   (lexical-let ((ewoc--user-pp func))
+     (lambda (data)
+       (funcall ewoc--user-pp data)
+       (insert "\n"))))
+ 
  
  ;;; 
===========================================================================
  ;;;                  Public members of the Ewoc package
  
  ;;;###autoload
! (defun ewoc-create (pretty-printer &optional header footer nosep)
    "Create an empty ewoc.
  
  The ewoc will be inserted in the current buffer at the current position.
***************
*** 275,288 ****
  
  Optional second and third arguments HEADER and FOOTER are strings,
  possibly empty, that will always be present at the top and bottom,
! respectively, of the ewoc."
    (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST))
           (dll (progn (setf (ewoc--node-right dummy-node) dummy-node)
                       (setf (ewoc--node-left dummy-node) dummy-node)
                       dummy-node))
!          (new-ewoc
!           (ewoc--create (current-buffer)
!                         pretty-printer nil nil dll))
           (pos (point))
           head foot)
      (ewoc--set-buffer-bind-dll new-ewoc
--- 282,301 ----
  
  Optional second and third arguments HEADER and FOOTER are strings,
  possibly empty, that will always be present at the top and bottom,
! respectively, of the ewoc.
! 
! Normally, a newline is automatically inserted after the header,
! the footer and every node's printed representation.  Optional
! fourth arg NOSEP non-nil inhibits this."
    (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST))
           (dll (progn (setf (ewoc--node-right dummy-node) dummy-node)
                       (setf (ewoc--node-left dummy-node) dummy-node)
                       dummy-node))
!          (wrap (if nosep 'identity 'ewoc--wrap))
!          (new-ewoc (ewoc--create (current-buffer)
!                                  (funcall wrap pretty-printer)
!                                  nil nil dll))
!          (hf-pp (funcall wrap 'insert))
           (pos (point))
           head foot)
      (ewoc--set-buffer-bind-dll new-ewoc
***************
*** 290,297 ****
        (unless header (setq header ""))
        (unless footer (setq footer ""))
        (setf (ewoc--node-start-marker dll) (copy-marker pos)
!             foot (ewoc--insert-new-node  dll footer 'insert)
!             head (ewoc--insert-new-node foot header 'insert)
              (ewoc--footer new-ewoc) foot
              (ewoc--header new-ewoc) head))
      ;; Return the ewoc
--- 303,311 ----
        (unless header (setq header ""))
        (unless footer (setq footer ""))
        (setf (ewoc--node-start-marker dll) (copy-marker pos)
!             foot (ewoc--insert-new-node  dll footer hf-pp)
!             head (ewoc--insert-new-node foot header hf-pp)
!             (ewoc--hf-pp new-ewoc) hf-pp
              (ewoc--footer new-ewoc) foot
              (ewoc--header new-ewoc) head))
      ;; Return the ewoc
***************
*** 596,607 ****
    "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)
--- 610,622 ----
    "Set the HEADER and FOOTER of EWOC."
    (ewoc--set-buffer-bind-dll-let* ewoc
        ((head (ewoc--header ewoc))
!        (foot (ewoc--footer ewoc))
!        (hf-pp (ewoc--hf-pp ewoc)))
      (setf (ewoc--node-data head) header
            (ewoc--node-data foot) footer)
      (save-excursion
!       (ewoc--refresh-node hf-pp head)
!       (ewoc--refresh-node hf-pp foot))))
  
  
  (provide 'ewoc)




reply via email to

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