Mercurial > emacs
comparison lisp/emacs-lisp/ewoc.el @ 71006:103ed71d4639
(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.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Sat, 27 May 2006 17:39:38 +0000 |
parents | 9a4ed4323ed7 |
children | 04ef040bae36 |
comparison
equal
deleted
inserted
replaced
71005:1755e59e9a8a | 71006:103ed71d4639 |
---|---|
92 ;; Texinfo manual. | 92 ;; Texinfo manual. |
93 | 93 |
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) |
101 ;; (defun ewoc-enter-first (ewoc data) | 101 ;; (defun ewoc-enter-first (ewoc data) |
102 ;; (defun ewoc-enter-last (ewoc data) | 102 ;; (defun ewoc-enter-last (ewoc data) |
180 | 180 |
181 (defstruct (ewoc | 181 (defstruct (ewoc |
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, |
189 `ewoc--current-dll' bound to the dll, and VARLIST bound as in a let*. | 189 `ewoc--current-dll' bound to the dll, and VARLIST bound as in a let*. |
190 `ewoc--current-dll' will be bound when VARLIST is initialized, but | 190 `ewoc--current-dll' will be bound when VARLIST is initialized, but |
251 (delete-region m (ewoc--node-start-marker R)) | 251 (delete-region m (ewoc--node-start-marker R)) |
252 ;; Calculate and insert the string. | 252 ;; Calculate and insert the string. |
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. |
265 | 272 |
266 PRETTY-PRINTER should be a function that takes one argument, an | 273 PRETTY-PRINTER should be a function that takes one argument, an |
269 several lines. The PRETTY-PRINTER should use `insert', and not | 276 several lines. The PRETTY-PRINTER should use `insert', and not |
270 `insert-before-markers'. | 277 `insert-before-markers'. |
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 |
285 ;; Set default values | 298 ;; Set default values |
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 |
294 new-ewoc)) | 308 new-ewoc)) |
295 | 309 |
590 | 604 |
591 (defun ewoc-set-hf (ewoc header footer) | 605 (defun ewoc-set-hf (ewoc header footer) |
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) |
604 | 619 |
605 ;;; Local Variables: | 620 ;;; Local Variables: |