diff options
| author | Richard M. Stallman | 1992-10-08 06:44:24 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-10-08 06:44:24 +0000 |
| commit | 92ad69b62e62455ca7dfd42d141fce3f15ff3fcc (patch) | |
| tree | 3748de81bf6ca3996823c28b4e9f49e31beee823 | |
| parent | 7984cdcb4444f31f47e81967a0902319a995aaa5 (diff) | |
| download | emacs-92ad69b62e62455ca7dfd42d141fce3f15ff3fcc.tar.gz emacs-92ad69b62e62455ca7dfd42d141fce3f15ff3fcc.zip | |
(custom-prin1-chars): Var defined, and renamed from prin1-chars.
(circle-tree, circle-table): Define vars.
(cust-print-vector, cust-print-list): Rename level to circle-level.
(cust-print-top-level): Likewise.
(circle-level): Var defined.
| -rw-r--r-- | lisp/emacs-lisp/cust-print.el | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/lisp/emacs-lisp/cust-print.el b/lisp/emacs-lisp/cust-print.el index 6ce301cd3d5..965b52e4b81 100644 --- a/lisp/emacs-lisp/cust-print.el +++ b/lisp/emacs-lisp/cust-print.el | |||
| @@ -107,7 +107,7 @@ max-lisp-eval-depth being exceeded or an untrappable error may occur: | |||
| 107 | Also see `print-length' and `print-circle'. | 107 | Also see `print-length' and `print-circle'. |
| 108 | 108 | ||
| 109 | If non-nil, components at levels equal to or greater than `print-level' | 109 | If non-nil, components at levels equal to or greater than `print-level' |
| 110 | are printed simply as \"#\". The object to be printed is at level 0, | 110 | are printed simply as `#'. The object to be printed is at level 0, |
| 111 | and if the object is a list or vector, its top-level components are at | 111 | and if the object is a list or vector, its top-level components are at |
| 112 | level 1.") | 112 | level 1.") |
| 113 | 113 | ||
| @@ -231,15 +231,17 @@ Output stream is STREAM, or value of `standard-output' (which see)." | |||
| 231 | "Same as `custom-prin1' except no quoting." | 231 | "Same as `custom-prin1' except no quoting." |
| 232 | (cust-print-top-level object stream 'cust-print-internal-princ)) | 232 | (cust-print-top-level object stream 'cust-print-internal-princ)) |
| 233 | 233 | ||
| 234 | (defvar custom-prin1-chars) | ||
| 235 | |||
| 234 | (defun custom-prin1-to-string-func (c) | 236 | (defun custom-prin1-to-string-func (c) |
| 235 | "Stream function for `custom-prin1-to-string'." | 237 | "Stream function for `custom-prin1-to-string'." |
| 236 | (setq prin1-chars (cons c prin1-chars))) | 238 | (setq custom-prin1-chars (cons c custom-prin1-chars))) |
| 237 | 239 | ||
| 238 | (defun custom-prin1-to-string (object) | 240 | (defun custom-prin1-to-string (object) |
| 239 | "Replacement for standard `prin1-to-string'." | 241 | "Replacement for standard `prin1-to-string'." |
| 240 | (let ((prin1-chars nil)) | 242 | (let ((custom-prin1-chars nil)) |
| 241 | (custom-prin1 object 'custom-prin1-to-string-func) | 243 | (custom-prin1 object 'custom-prin1-to-string-func) |
| 242 | (concat (nreverse prin1-chars)))) | 244 | (concat (nreverse custom-prin1-chars)))) |
| 243 | 245 | ||
| 244 | 246 | ||
| 245 | (defun custom-print (object &optional stream) | 247 | (defun custom-print (object &optional stream) |
| @@ -287,11 +289,15 @@ string argument will also work. The string is generated with | |||
| 287 | ;;========================================= | 289 | ;;========================================= |
| 288 | ;; Support for custom prin1 and princ | 290 | ;; Support for custom prin1 and princ |
| 289 | 291 | ||
| 292 | (defvar circle-table) | ||
| 293 | (defvar circle-tree) | ||
| 294 | (defvar circle-level) | ||
| 295 | |||
| 290 | (defun cust-print-top-level (object stream internal-printer) | 296 | (defun cust-print-top-level (object stream internal-printer) |
| 291 | "Set up for printing." | 297 | "Set up for printing." |
| 292 | (let ((standard-output (or stream standard-output)) | 298 | (let ((standard-output (or stream standard-output)) |
| 293 | (circle-table (and print-circle (cust-print-preprocess-circle-tree object))) | 299 | (circle-table (and print-circle (cust-print-preprocess-circle-tree object))) |
| 294 | (level (or print-level -1)) | 300 | (circle-level (or print-level -1)) |
| 295 | ) | 301 | ) |
| 296 | 302 | ||
| 297 | (fset 'cust-print-internal-printer internal-printer) | 303 | (fset 'cust-print-internal-printer internal-printer) |
| @@ -387,9 +393,9 @@ Otherwise, print normally." | |||
| 387 | 393 | ||
| 388 | ;; Print a list using print-length, print-level, and print-circle. | 394 | ;; Print a list using print-length, print-level, and print-circle. |
| 389 | (defun cust-print-list (list) | 395 | (defun cust-print-list (list) |
| 390 | (if (= level 0) | 396 | (if (= circle-level 0) |
| 391 | (cust-print-internal-princ "#") | 397 | (cust-print-internal-princ "#") |
| 392 | (let ((level (1- level))) | 398 | (let ((circle-level (1- circle-level))) |
| 393 | (cust-print-internal-princ "(") | 399 | (cust-print-internal-princ "(") |
| 394 | (let ((length (or print-length 0))) | 400 | (let ((length (or print-length 0))) |
| 395 | 401 | ||
| @@ -422,9 +428,9 @@ Otherwise, print normally." | |||
| 422 | 428 | ||
| 423 | ;; Print a vector according to print-length, print-level, and print-circle. | 429 | ;; Print a vector according to print-length, print-level, and print-circle. |
| 424 | (defun cust-print-vector (vector) | 430 | (defun cust-print-vector (vector) |
| 425 | (if (= level 0) | 431 | (if (= circle-level 0) |
| 426 | (cust-print-internal-princ "#") | 432 | (cust-print-internal-princ "#") |
| 427 | (let ((level (1- level)) | 433 | (let ((circle-level (1- circle-level)) |
| 428 | (i 0) | 434 | (i 0) |
| 429 | (len (length vector))) | 435 | (len (length vector))) |
| 430 | (cust-print-internal-princ "[") | 436 | (cust-print-internal-princ "[") |
| @@ -523,50 +529,45 @@ Otherwise, print normally." | |||
| 523 | 529 | ||
| 524 | ;;======================================= | 530 | ;;======================================= |
| 525 | 531 | ||
| 526 | (quote | 532 | ;; Example. |
| 527 | examples | 533 | |
| 528 | 534 | ;;;; Create some circular structures. | |
| 529 | (progn | 535 | ;;(setq circ-sym (let ((x (make-symbol "FOO"))) (list x x))) |
| 530 | ;; Create some circular structures. | 536 | ;;(setq circ-list (list 'a 'b (vector 1 2 3 4) 'd 'e 'f)) |
| 531 | (setq circ-sym (let ((x (make-symbol "FOO"))) (list x x))) | 537 | ;;(setcar (nthcdr 3 circ-list) circ-list) |
| 532 | (setq circ-list (list 'a 'b (vector 1 2 3 4) 'd 'e 'f)) | 538 | ;;(aset (nth 2 circ-list) 2 circ-list) |
| 533 | (setcar (nthcdr 3 circ-list) circ-list) | 539 | ;;(setq dotted-circ-list (list 'a 'b 'c)) |
| 534 | (aset (nth 2 circ-list) 2 circ-list) | 540 | ;;(setcdr (cdr (cdr dotted-circ-list)) dotted-circ-list) |
| 535 | (setq dotted-circ-list (list 'a 'b 'c)) | 541 | ;;(setq circ-vector (vector 1 2 3 4 (list 'a 'b 'c 'd) 6 7)) |
| 536 | (setcdr (cdr (cdr dotted-circ-list)) dotted-circ-list) | 542 | ;;(aset circ-vector 5 (make-symbol "-gensym-")) |
| 537 | (setq circ-vector (vector 1 2 3 4 (list 'a 'b 'c 'd) 6 7)) | 543 | ;;(setcar (cdr (aref circ-vector 4)) (aref circ-vector 5)) |
| 538 | (aset circ-vector 5 (make-symbol "-gensym-")) | 544 | |
| 539 | (setcar (cdr (aref circ-vector 4)) (aref circ-vector 5)) | 545 | ;;(install-custom-print-funcs) |
| 540 | nil) | 546 | ;;;; (setq print-circle t) |
| 541 | 547 | ||
| 542 | (install-custom-print-funcs) | 548 | ;;(let ((print-circle t)) |
| 543 | ;; (setq print-circle t) | 549 | ;; (or (equal (prin1-to-string circ-list) "#1=(a b [1 2 #1# 4] #1# e f)") |
| 544 | 550 | ;; (error "circular object with array printing"))) | |
| 545 | (let ((print-circle t)) | 551 | |
| 546 | (or (equal (prin1-to-string circ-list) "#1=(a b [1 2 #1# 4] #1# e f)") | 552 | ;;(let ((print-circle t)) |
| 547 | (error "circular object with array printing"))) | 553 | ;; (or (equal (prin1-to-string dotted-circ-list) "#1=(a b c . #1#)") |
| 548 | 554 | ;; (error "circular object with array printing"))) | |
| 549 | (let ((print-circle t)) | 555 | |
| 550 | (or (equal (prin1-to-string dotted-circ-list) "#1=(a b c . #1#)") | 556 | ;;(let* ((print-circle t) |
| 551 | (error "circular object with array printing"))) | 557 | ;; (x (list 'p 'q)) |
| 552 | 558 | ;; (y (list (list 'a 'b) x 'foo x))) | |
| 553 | (let* ((print-circle t) | 559 | ;; (setcdr (cdr (cdr (cdr y))) (cdr y)) |
| 554 | (x (list 'p 'q)) | 560 | ;; (or (equal (prin1-to-string y) "((a b) . #1=(#2=(p q) foo #2# . #1#))" |
| 555 | (y (list (list 'a 'b) x 'foo x))) | 561 | ;; ) |
| 556 | (setcdr (cdr (cdr (cdr y))) (cdr y)) | 562 | ;; (error "circular list example from CL manual"))) |
| 557 | (or (equal (prin1-to-string y) "((a b) . #1=(#2=(p q) foo #2# . #1#))" | 563 | |
| 558 | ) | 564 | ;;;; There's no special handling of uninterned symbols in custom-print. |
| 559 | (error "circular list example from CL manual"))) | 565 | ;;(let ((print-circle nil)) |
| 560 | 566 | ;; (or (equal (prin1-to-string circ-sym) "(#:FOO #:FOO)") | |
| 561 | ;; There's no special handling of uninterned symbols in custom-print. | 567 | ;; (error "uninterned symbols in list"))) |
| 562 | (let ((print-circle nil)) | 568 | ;;(let ((print-circle t)) |
| 563 | (or (equal (prin1-to-string circ-sym) "(#:FOO #:FOO)") | 569 | ;; (or (equal (prin1-to-string circ-sym) "(#1=FOO #1#)") |
| 564 | (error "uninterned symbols in list"))) | 570 | ;; (error "circular uninterned symbols in list"))) |
| 565 | (let ((print-circle t)) | 571 | ;;(uninstall-custom-print-funcs) |
| 566 | (or (equal (prin1-to-string circ-sym) "(#1=FOO #1#)") | ||
| 567 | (error "circular uninterned symbols in list"))) | ||
| 568 | |||
| 569 | (uninstall-custom-print-funcs) | ||
| 570 | ) | ||
| 571 | 572 | ||
| 572 | ;;; cust-print.el ends here | 573 | ;;; cust-print.el ends here |