From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: Re: ewoc--adjust ugliness Date: 26 May 2006 18:49:38 -0400 Message-ID: References: <7dbe73ed0605260349v104c2d7al17f59064c303f8ac@mail.gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1148683798 2319 80.91.229.2 (26 May 2006 22:49:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 26 May 2006 22:49:58 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 27 00:49:56 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fjl7y-0005fC-1g for ged-emacs-devel@m.gmane.org; Sat, 27 May 2006 00:49:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fjl7x-0005WP-Gd for ged-emacs-devel@m.gmane.org; Fri, 26 May 2006 18:49:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fjl7l-0005Vh-Dr for emacs-devel@gnu.org; Fri, 26 May 2006 18:49:41 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fjl7j-0005VV-TK for emacs-devel@gnu.org; Fri, 26 May 2006 18:49:40 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fjl7j-0005VS-N1 for emacs-devel@gnu.org; Fri, 26 May 2006 18:49:39 -0400 Original-Received: from [67.59.132.6] (helo=mail.agora-net.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FjlCi-0006cu-Mp for emacs-devel@gnu.org; Fri, 26 May 2006 18:54:48 -0400 Original-Received: from ttn by mail.agora-net.com with local (Exim 4.50) id 1Fjl7i-0007T4-OF for emacs-devel@gnu.org; Fri, 26 May 2006 18:49:38 -0400 Original-To: emacs-devel@gnu.org In-Reply-To: Original-Lines: 190 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55342 Archived-At: Stefan Monnier writes: > I think it's more important to make it backward compatible, than to > allow clients to test easily whether the new feature is present. > First things first. i disagree (looks like i was too hasty concluding there was a concensus), but more out of laziness than any contrarian sentiment. hmm, writing that last sentence has shamed me into exerting a little more effort [munge munge]... please find below another patch. i have tested it lightly w/ pcvs.el and pcvs-info.el prior to 2006-05-18, and also w/ current sources, modified to specify NOSEP in the call to `ewoc-create'. * emacs-lisp/ewoc.el (ewoc): Add member `hf-pp' to this structure. (ewoc--refresh-node): Reseat node's start marker. (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. thanks go to Stefan for suggesting NOSEP. thi _______________________________________________________ diff -c -r1.30 ewoc.el *** ewoc.el 26 May 2006 08:29:13 -0000 1.30 --- ewoc.el 26 May 2006 22:33:06 -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, *************** *** 248,268 **** (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 ;;;###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. --- 248,281 ---- (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)) ! (pos (marker-position m)) ! (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)) + ;; If the ewoc was created w/ NOSEP, then this node's start marker will + ;; have been pushed back by the wrapped pretty printer (sigh). Reseat it. + (set-marker m pos) (ewoc--adjust m (point) R))) + + (defun ewoc--wrap (func) + (lexical-let ((ewoc--user-pp func)) + (lambda (data) + (insert-before-markers "\n") + (forward-char -1) + (funcall ewoc--user-pp data) + (forward-char 1)))) + ;;; =========================================================================== ;;; 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,297 **** 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 ;; Set default values (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 --- 288,316 ---- 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) + (setf (ewoc--hf-pp new-ewoc) hf-pp) (ewoc--set-buffer-bind-dll new-ewoc ;; Set default values (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--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) --- 615,627 ---- "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) ===end===