From xemacs-m  Tue Sep  9 17:19:57 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id RAA13081
	for <xemacs-beta@xemacs.org>; Tue, 9 Sep 1997 17:19:53 -0500 (CDT)
Received: (from hniksic@localhost)
	by jagor.srce.hr (8.8.7/8.8.6) id AAA09161;
	Wed, 10 Sep 1997 00:19:34 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [PATCH] New option: `eval-expression-print-length'
X-Attribution: Hrvoje
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 10 Sep 1997 00:19:33 +0200
Message-ID: <kiglo16b05m.fsf@jagor.srce.hr>
Lines: 61
X-Mailer: Gnus v5.4.65/XEmacs 20.3(beta19) - "Kyiv"

How many times have you been bitten by `M-:' resulting in a circular
(or very long) expression?  Me, a zillion times!  Then XEmacs starts
garbage-collecting like crazy, and you must hit C-g like crazy to stop 
it, and you lose the result in the end.

A good solution for this might be to introduce an
`eval-expression-print-length' option, which would hold the value of
`print-length' right before the result is printed to the minibuffer.
So, if eval-expression-print-length is 80, no more than 80 characters
of print would be inserted to minibuffer.  After `eval-expression'
finishes, the value of `print-length' is restored, of course.

As a fallback to the old behaviour, `eval-expression-print-length' can 
have a value of `leave', which means that `eval-expression' simply
should not muck with `print-length'.

Here is the patch that implements all of this, with 2048 bytes as a
reasonable default (so we can still evaluate expressions with long
results and look them up with `C-h l').  Please let me know what you
think of it:

--- lisp/prim/simple.el.orig	Tue Sep  9 23:59:58 1997
+++ lisp/prim/simple.el	Wed Sep 10 00:17:25 1997
@@ -666,6 +666,18 @@
 
 ;(defvar read-expression-history nil)
 
+(defcustom eval-expression-print-length 2048
+  "*The maximum length of list or vector `eval-expression' is allowed to print.
+This works by temporarily setting the value of `print-length' when printing the
+result of eval-expression.  As with `print-length', nil means unlimited depth.
+
+If set to  `unchanged', do not change the value of `print-length' during
+`eval-expression'."
+  :type '(choice integer
+		 (const :tag "Unlimited" nil)
+		 (const :tag "Unchanged" 'unchanged))
+  :group 'lisp)
+
 ;; We define this, rather than making `eval' interactive,
 ;; for the sake of completion of names like eval-region, eval-current-buffer.
 (defun eval-expression (expression)
@@ -677,7 +689,10 @@
 			       nil read-expression-map t
 			       'read-expression-history)))
   (setq values (cons (eval expression) values))
-  (prin1 (car values) t))
+  (let ((print-length (if (eq eval-expression-print-length 'unchanged)
+			  print-length
+			eval-expression-print-length)))
+    (prin1 (car values) t)))
 
 ;; XEmacs -- extra parameter (variant, but equivalent logic)
 (defun edit-and-eval-command (prompt command &optional history)


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Contrary to popular belief, Unix is user friendly.  
It just happens to be selective about who it makes friends with.

