From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: pp.el patch Date: Fri, 18 Apr 2008 14:12:59 -0700 Message-ID: <003d01c8a198$fb540e70$0200a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_003E_01C8A15E.4EF53670" X-Trace: ger.gmane.org 1208589538 13440 80.91.229.12 (19 Apr 2008 07:18:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Apr 2008 07:18:58 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 19 09:19:32 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JmxuU-0002o9-Sm for ged-emacs-devel@m.gmane.org; Fri, 18 Apr 2008 23:14:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jmxtp-0003Qf-TT for ged-emacs-devel@m.gmane.org; Fri, 18 Apr 2008 17:13:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jmxtl-0003QQ-Ru for emacs-devel@gnu.org; Fri, 18 Apr 2008 17:13:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jmxtj-0003QE-Fr for emacs-devel@gnu.org; Fri, 18 Apr 2008 17:13:32 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jmxtj-0003QB-8n for emacs-devel@gnu.org; Fri, 18 Apr 2008 17:13:31 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jmxtj-0005rR-0g for emacs-devel@gnu.org; Fri, 18 Apr 2008 17:13:31 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id m3ILDGJR027972 for ; Fri, 18 Apr 2008 15:13:17 -0600 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id m3I4tIcD019362 for ; Fri, 18 Apr 2008 15:13:16 -0600 Original-Received: from inet-141-146-46-1.oracle.com by acsmt351.oracle.com with ESMTP id 3652812741208553173; Fri, 18 Apr 2008 14:12:53 -0700 Original-Received: from dradamslap1 (/141.144.90.7) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 18 Apr 2008 14:12:52 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcihmPrtrsfVD/+fRmeirwgdkCdZvw== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:95438 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_003E_01C8A15E.4EF53670 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit The attached pp.el patch does the following: * Adds two user options used by `pp-eval-expression': `pp-eval-expression-print-length' `pp-eval-expression-print-level' * Changes `pp-eval-expression' in these ways: . Respects the new options and `eval-expression-debug-on-error'. . Reads the expression using keymap `pp-read-expression-map', which provides some Emacs-Lisp mode bindings. . Adds an optional arg INSERT-VALUE (prefix-arg), similar to what `eval-expression' has. See doc string. I find it useful. YMMV. I bind it to `M-:'. In minibuffer maps, I bind `M-:' to a command that calls this after binding `enable-recursive-minibuffers' to t. With a negative prefix arg, I yank string values (e.g. of variables) to the minibuffer (without double-quotes). ------=_NextPart_000_003E_01C8A15E.4EF53670 Content-Type: application/octet-stream; name="pp-2008-04-18.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pp-2008-04-18.patch" diff -u -w "pp-CVS-2008-04-18.el" "pp-patched-2008-04-18.el"=0A= --- pp-CVS-2008-04-18.el 2008-04-18 13:48:24.000000000 -0700=0A= +++ pp-patched-2008-04-18.el 2008-04-18 13:54:40.000000000 -0700=0A= @@ -39,6 +39,30 @@=0A= :type 'boolean=0A= :group 'pp)=0A= =0A= +(defcustom pp-eval-expression-print-length nil=0A= + "Value for `print-length' while printing value in = `pp-eval-expression'.=0A= +A value of nil means no limit."=0A= + :group 'pp :type '(choice (const :tag "No Limit" nil) integer))=0A= +=0A= +(defcustom pp-eval-expression-print-level nil=0A= + "Value for `print-level' while printing value in `pp-eval-expression'.=0A= +A value of nil means no limit."=0A= + :group 'pp :type '(choice (const :tag "No Limit" nil) integer))=0A= +=0A= +(defvar pp-read-expression-map nil=0A= + "`read-expression-map' with some Emacs-Lisp key bindings.")=0A= +(unless pp-read-expression-map=0A= + (let ((map (make-sparse-keymap)))=0A= + (define-key map "\M-\t" 'lisp-complete-symbol)=0A= + (define-key map "\t" 'lisp-indent-line)=0A= + (define-key map "\e\C-q" 'indent-sexp)=0A= + (define-key map "\e\t" 'lisp-complete-symbol)=0A= + (define-key map "\e\C-x" 'eval-defun)=0A= + (define-key map "\e\C-q" 'indent-pp-sexp)=0A= + ;;(define-key map "\177" 'backward-delete-char-untabify)=0A= + (set-keymap-parent map minibuffer-local-map)=0A= + (setq pp-read-expression-map map)))=0A= +=0A= ;;;###autoload=0A= (defun pp-to-string (object)=0A= "Return a string containing the pretty-printed representation of = OBJECT.=0A= @@ -97,14 +121,47 @@=0A= (princ (pp-to-string object) (or stream standard-output)))=0A= =0A= ;;;###autoload=0A= -(defun pp-eval-expression (expression)=0A= - "Evaluate EXPRESSION and pretty-print its value.=0A= -Also add the value to the front of the list in the variable `values'."=0A= +(defun pp-eval-expression (expression &optional insert-value)=0A= + "Evaluate an Emacs-Lisp expression and pretty-print its value.=0A= +Add the value to the front of the variable `values'.=0A= +With a prefix arg, insert the value into the current buffer at point.=0A= +With no prefix arg:=0A= + If the value fits on one line (frame width) show it in the echo area.=0A= + Otherwise, show the value in buffer *Pp Eval Output*.=0A= +=0A= +With a negative prefix arg, if the value is a string, then insert it=0A= +into the buffer without double-quotes (`\"').=0A= +=0A= +This command respects options `pp-eval-expression-print-length',=0A= +`pp-eval-expression-print-level', and=0A= +`eval-expression-debug-on-error'.=0A= +=0A= +Emacs-Lisp mode completion and indentation bindings are in effect."=0A= (interactive=0A= - (list (read-from-minibuffer "Eval: " nil read-expression-map t=0A= - 'read-expression-history)))=0A= + (list (read-from-minibuffer "Eval: " nil pp-read-expression-map t=0A= + 'read-expression-history)=0A= + current-prefix-arg))=0A= (message "Evaluating...")=0A= + (if (null eval-expression-debug-on-error)=0A= + (setq values (cons (eval expression) values))=0A= + (let ((old-value (make-symbol "t")) new-value)=0A= + ;; Bind `debug-on-error' to something unique so that we can=0A= + ;; detect when evaled code changes it.=0A= + (let ((debug-on-error old-value))=0A= (setq values (cons (eval expression) values))=0A= + (setq new-value debug-on-error))=0A= + ;; If evaled code has changed the value of `debug-on-error',=0A= + ;; propagate that change to the global binding.=0A= + (unless (eq old-value new-value) (setq debug-on-error = new-value))))=0A= + (let ((print-length pp-eval-expression-print-length)=0A= + (print-level pp-eval-expression-print-level))=0A= + (cond (insert-value=0A= + (message "Evaluating...done. Value inserted.")=0A= + (setq insert-value (prefix-numeric-value insert-value))=0A= + (if (or (not (stringp (car values))) (wholenump = insert-value))=0A= + (pp (car values) (current-buffer))=0A= + (princ (car values) (current-buffer))))=0A= + (t=0A= (let* ((old-show-function temp-buffer-show-function)=0A= ;; Use this function to display the buffer.=0A= ;; This function either decides not to display it at all=0A= @@ -130,14 +187,16 @@=0A= (select-window old-selected)=0A= (message "Evaluating...done. \=0A= See buffer *Pp Eval Output*.")))=0A= - (message "%s" (buffer-substring (point-min) (point)))=0A= - ))))))=0A= + (message "%s" (buffer-substring (point-min) = (point)))))))))=0A= (with-output-to-temp-buffer "*Pp Eval Output*"=0A= (pp (car values))=0A= (with-current-buffer standard-output=0A= - (emacs-lisp-mode)=0A= (setq buffer-read-only nil)=0A= - (set (make-local-variable 'font-lock-verbose) nil)))))=0A= + (let ((emacs-lisp-mode-hook nil)=0A= + (change-major-mode-hook nil))=0A= + (emacs-lisp-mode))=0A= + (set (make-local-variable 'font-lock-verbose) nil)=0A= + (font-lock-fontify-buffer))))))))=0A= =0A= ;;;###autoload=0A= (defun pp-eval-last-sexp (arg)=0A= =0A= Diff finished at Fri Apr 18 13:56:06=0A= ------=_NextPart_000_003E_01C8A15E.4EF53670--