diff options
| author | Thien-Thi Nguyen | 2006-05-27 17:39:38 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2006-05-27 17:39:38 +0000 |
| commit | 2bbacc0e1b061be7f2d47d53c21cbb82c35d54ab (patch) | |
| tree | d377dac67d238094d19497c75756fc054e788b72 | |
| parent | 917b82275619a43263eacf113e843fa68b7330da (diff) | |
| download | emacs-2bbacc0e1b061be7f2d47d53c21cbb82c35d54ab.tar.gz emacs-2bbacc0e1b061be7f2d47d53c21cbb82c35d54ab.zip | |
(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.
| -rw-r--r-- | lisp/emacs-lisp/ewoc.el | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/ewoc.el b/lisp/emacs-lisp/ewoc.el index 2aa56f04683..8a448f1b47f 100644 --- a/lisp/emacs-lisp/ewoc.el +++ b/lisp/emacs-lisp/ewoc.el | |||
| @@ -94,7 +94,7 @@ | |||
| 94 | ;; In the mean time `grep '^(.*ewoc-[^-]' emacs-lisp/ewoc.el' can help | 94 | ;; In the mean time `grep '^(.*ewoc-[^-]' emacs-lisp/ewoc.el' can help |
| 95 | ;; you find all the exported functions: | 95 | ;; you find all the exported functions: |
| 96 | ;; | 96 | ;; |
| 97 | ;; (defun ewoc-create (pretty-printer &optional header footer) | 97 | ;; (defun ewoc-create (pretty-printer &optional header footer nosep) |
| 98 | ;; (defalias 'ewoc-data 'ewoc--node-data) | 98 | ;; (defalias 'ewoc-data 'ewoc--node-data) |
| 99 | ;; (defun ewoc-set-data (node data) | 99 | ;; (defun ewoc-set-data (node data) |
| 100 | ;; (defun ewoc-location (node) | 100 | ;; (defun ewoc-location (node) |
| @@ -182,7 +182,7 @@ and (ewoc--node-nth -1) returns the last node." | |||
| 182 | (:constructor nil) | 182 | (:constructor nil) |
| 183 | (:constructor ewoc--create (buffer pretty-printer dll)) | 183 | (:constructor ewoc--create (buffer pretty-printer dll)) |
| 184 | (:conc-name ewoc--)) | 184 | (:conc-name ewoc--)) |
| 185 | buffer pretty-printer header footer dll last-node) | 185 | buffer pretty-printer header footer dll last-node hf-pp) |
| 186 | 186 | ||
| 187 | (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms) | 187 | (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms) |
| 188 | "Execute FORMS with ewoc--buffer selected as current buffer, | 188 | "Execute FORMS with ewoc--buffer selected as current buffer, |
| @@ -253,12 +253,19 @@ NODE and leaving the new node's start there. Return the new node." | |||
| 253 | (goto-char m) | 253 | (goto-char m) |
| 254 | (funcall pp (ewoc--node-data node)) | 254 | (funcall pp (ewoc--node-data node)) |
| 255 | (ewoc--adjust m (point) R))) | 255 | (ewoc--adjust m (point) R))) |
| 256 | |||
| 257 | (defun ewoc--wrap (func) | ||
| 258 | (lexical-let ((ewoc--user-pp func)) | ||
| 259 | (lambda (data) | ||
| 260 | (funcall ewoc--user-pp data) | ||
| 261 | (insert "\n")))) | ||
| 262 | |||
| 256 | 263 | ||
| 257 | ;;; =========================================================================== | 264 | ;;; =========================================================================== |
| 258 | ;;; Public members of the Ewoc package | 265 | ;;; Public members of the Ewoc package |
| 259 | 266 | ||
| 260 | ;;;###autoload | 267 | ;;;###autoload |
| 261 | (defun ewoc-create (pretty-printer &optional header footer) | 268 | (defun ewoc-create (pretty-printer &optional header footer nosep) |
| 262 | "Create an empty ewoc. | 269 | "Create an empty ewoc. |
| 263 | 270 | ||
| 264 | The ewoc will be inserted in the current buffer at the current position. | 271 | The ewoc will be inserted in the current buffer at the current position. |
| @@ -271,14 +278,20 @@ several lines. The PRETTY-PRINTER should use `insert', and not | |||
| 271 | 278 | ||
| 272 | Optional second and third arguments HEADER and FOOTER are strings, | 279 | Optional second and third arguments HEADER and FOOTER are strings, |
| 273 | possibly empty, that will always be present at the top and bottom, | 280 | possibly empty, that will always be present at the top and bottom, |
| 274 | respectively, of the ewoc." | 281 | respectively, of the ewoc. |
| 282 | |||
| 283 | Normally, a newline is automatically inserted after the header, | ||
| 284 | the footer and every node's printed representation. Optional | ||
| 285 | fourth arg NOSEP non-nil inhibits this." | ||
| 275 | (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST)) | 286 | (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST)) |
| 276 | (dll (progn (setf (ewoc--node-right dummy-node) dummy-node) | 287 | (dll (progn (setf (ewoc--node-right dummy-node) dummy-node) |
| 277 | (setf (ewoc--node-left dummy-node) dummy-node) | 288 | (setf (ewoc--node-left dummy-node) dummy-node) |
| 278 | dummy-node)) | 289 | dummy-node)) |
| 290 | (wrap (if nosep 'identity 'ewoc--wrap)) | ||
| 279 | (new-ewoc (ewoc--create (current-buffer) | 291 | (new-ewoc (ewoc--create (current-buffer) |
| 280 | pretty-printer | 292 | (funcall wrap pretty-printer) |
| 281 | dll)) | 293 | dll)) |
| 294 | (hf-pp (funcall wrap 'insert)) | ||
| 282 | (pos (point)) | 295 | (pos (point)) |
| 283 | head foot) | 296 | head foot) |
| 284 | (ewoc--set-buffer-bind-dll new-ewoc | 297 | (ewoc--set-buffer-bind-dll new-ewoc |
| @@ -286,8 +299,9 @@ respectively, of the ewoc." | |||
| 286 | (unless header (setq header "")) | 299 | (unless header (setq header "")) |
| 287 | (unless footer (setq footer "")) | 300 | (unless footer (setq footer "")) |
| 288 | (setf (ewoc--node-start-marker dll) (copy-marker pos) | 301 | (setf (ewoc--node-start-marker dll) (copy-marker pos) |
| 289 | foot (ewoc--insert-new-node dll footer 'insert) | 302 | foot (ewoc--insert-new-node dll footer hf-pp) |
| 290 | head (ewoc--insert-new-node foot header 'insert) | 303 | head (ewoc--insert-new-node foot header hf-pp) |
| 304 | (ewoc--hf-pp new-ewoc) hf-pp | ||
| 291 | (ewoc--footer new-ewoc) foot | 305 | (ewoc--footer new-ewoc) foot |
| 292 | (ewoc--header new-ewoc) head)) | 306 | (ewoc--header new-ewoc) head)) |
| 293 | ;; Return the ewoc | 307 | ;; Return the ewoc |
| @@ -592,12 +606,13 @@ Return nil if the buffer has been deleted." | |||
| 592 | "Set the HEADER and FOOTER of EWOC." | 606 | "Set the HEADER and FOOTER of EWOC." |
| 593 | (ewoc--set-buffer-bind-dll-let* ewoc | 607 | (ewoc--set-buffer-bind-dll-let* ewoc |
| 594 | ((head (ewoc--header ewoc)) | 608 | ((head (ewoc--header ewoc)) |
| 595 | (foot (ewoc--footer ewoc))) | 609 | (foot (ewoc--footer ewoc)) |
| 610 | (hf-pp (ewoc--hf-pp ewoc))) | ||
| 596 | (setf (ewoc--node-data head) header | 611 | (setf (ewoc--node-data head) header |
| 597 | (ewoc--node-data foot) footer) | 612 | (ewoc--node-data foot) footer) |
| 598 | (save-excursion | 613 | (save-excursion |
| 599 | (ewoc--refresh-node 'insert head) | 614 | (ewoc--refresh-node hf-pp head) |
| 600 | (ewoc--refresh-node 'insert foot)))) | 615 | (ewoc--refresh-node hf-pp foot)))) |
| 601 | 616 | ||
| 602 | 617 | ||
| 603 | (provide 'ewoc) | 618 | (provide 'ewoc) |