* pp.el patch
@ 2008-04-18 21:12 Drew Adams
2008-04-22 15:42 ` Michael Olson
0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2008-04-18 21:12 UTC (permalink / raw)
To: Emacs-Devel
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
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).
[-- Attachment #2: pp-2008-04-18.patch --]
[-- Type: application/octet-stream, Size: 4908 bytes --]
diff -u -w "pp-CVS-2008-04-18.el" "pp-patched-2008-04-18.el"
--- pp-CVS-2008-04-18.el 2008-04-18 13:48:24.000000000 -0700
+++ pp-patched-2008-04-18.el 2008-04-18 13:54:40.000000000 -0700
@@ -39,6 +39,30 @@
:type 'boolean
:group 'pp)
+(defcustom pp-eval-expression-print-length nil
+ "Value for `print-length' while printing value in `pp-eval-expression'.
+A value of nil means no limit."
+ :group 'pp :type '(choice (const :tag "No Limit" nil) integer))
+
+(defcustom pp-eval-expression-print-level nil
+ "Value for `print-level' while printing value in `pp-eval-expression'.
+A value of nil means no limit."
+ :group 'pp :type '(choice (const :tag "No Limit" nil) integer))
+
+(defvar pp-read-expression-map nil
+ "`read-expression-map' with some Emacs-Lisp key bindings.")
+(unless pp-read-expression-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\M-\t" 'lisp-complete-symbol)
+ (define-key map "\t" 'lisp-indent-line)
+ (define-key map "\e\C-q" 'indent-sexp)
+ (define-key map "\e\t" 'lisp-complete-symbol)
+ (define-key map "\e\C-x" 'eval-defun)
+ (define-key map "\e\C-q" 'indent-pp-sexp)
+ ;;(define-key map "\177" 'backward-delete-char-untabify)
+ (set-keymap-parent map minibuffer-local-map)
+ (setq pp-read-expression-map map)))
+
;;;###autoload
(defun pp-to-string (object)
"Return a string containing the pretty-printed representation of OBJECT.
@@ -97,14 +121,47 @@
(princ (pp-to-string object) (or stream standard-output)))
;;;###autoload
-(defun pp-eval-expression (expression)
- "Evaluate EXPRESSION and pretty-print its value.
-Also add the value to the front of the list in the variable `values'."
+(defun pp-eval-expression (expression &optional insert-value)
+ "Evaluate an Emacs-Lisp expression and pretty-print its value.
+Add the value to the front of the variable `values'.
+With a prefix arg, insert the value into the current buffer at point.
+With no prefix arg:
+ If the value fits on one line (frame width) show it in the echo area.
+ Otherwise, show the value in buffer *Pp Eval Output*.
+
+With a negative prefix arg, if the value is a string, then insert it
+into the buffer without double-quotes (`\"').
+
+This command respects options `pp-eval-expression-print-length',
+`pp-eval-expression-print-level', and
+`eval-expression-debug-on-error'.
+
+Emacs-Lisp mode completion and indentation bindings are in effect."
(interactive
- (list (read-from-minibuffer "Eval: " nil read-expression-map t
- 'read-expression-history)))
+ (list (read-from-minibuffer "Eval: " nil pp-read-expression-map t
+ 'read-expression-history)
+ current-prefix-arg))
(message "Evaluating...")
+ (if (null eval-expression-debug-on-error)
+ (setq values (cons (eval expression) values))
+ (let ((old-value (make-symbol "t")) new-value)
+ ;; Bind `debug-on-error' to something unique so that we can
+ ;; detect when evaled code changes it.
+ (let ((debug-on-error old-value))
(setq values (cons (eval expression) values))
+ (setq new-value debug-on-error))
+ ;; If evaled code has changed the value of `debug-on-error',
+ ;; propagate that change to the global binding.
+ (unless (eq old-value new-value) (setq debug-on-error new-value))))
+ (let ((print-length pp-eval-expression-print-length)
+ (print-level pp-eval-expression-print-level))
+ (cond (insert-value
+ (message "Evaluating...done. Value inserted.")
+ (setq insert-value (prefix-numeric-value insert-value))
+ (if (or (not (stringp (car values))) (wholenump insert-value))
+ (pp (car values) (current-buffer))
+ (princ (car values) (current-buffer))))
+ (t
(let* ((old-show-function temp-buffer-show-function)
;; Use this function to display the buffer.
;; This function either decides not to display it at all
@@ -130,14 +187,16 @@
(select-window old-selected)
(message "Evaluating...done. \
See buffer *Pp Eval Output*.")))
- (message "%s" (buffer-substring (point-min) (point)))
- ))))))
+ (message "%s" (buffer-substring (point-min) (point)))))))))
(with-output-to-temp-buffer "*Pp Eval Output*"
(pp (car values))
(with-current-buffer standard-output
- (emacs-lisp-mode)
(setq buffer-read-only nil)
- (set (make-local-variable 'font-lock-verbose) nil)))))
+ (let ((emacs-lisp-mode-hook nil)
+ (change-major-mode-hook nil))
+ (emacs-lisp-mode))
+ (set (make-local-variable 'font-lock-verbose) nil)
+ (font-lock-fontify-buffer))))))))
;;;###autoload
(defun pp-eval-last-sexp (arg)
Diff finished at Fri Apr 18 13:56:06
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: pp.el patch
2008-04-18 21:12 pp.el patch Drew Adams
@ 2008-04-22 15:42 ` Michael Olson
2008-04-22 16:37 ` Drew Adams
0 siblings, 1 reply; 3+ messages in thread
From: Michael Olson @ 2008-04-22 15:42 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 959 bytes --]
"Drew Adams" <drew.adams@oracle.com> writes:
> 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-:'.
This looks interesting to me. Can you provide a ChangeLog entry?
--
| Michael Olson | FSF Associate Member #652 |
| http://mwolson.org/ | Hobbies: Lisp, HCoop |
| Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |
`-------------------------------------------------------'
[-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: pp.el patch
2008-04-22 15:42 ` Michael Olson
@ 2008-04-22 16:37 ` Drew Adams
0 siblings, 0 replies; 3+ messages in thread
From: Drew Adams @ 2008-04-22 16:37 UTC (permalink / raw)
To: 'Michael Olson', emacs-devel
> > 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-:'.
>
> This looks interesting to me. Can you provide a ChangeLog entry?
2008-04-22 Drew Adams <drew.adams@oracle.com>
* pp.el:
(pp-eval-expression-print-length,
pp-eval-expression-print-level,
pp-read-expression-map):
New variables.
(pp-eval-expression):
Added optional argument INSERT-VALUE.
Read expression using keymap pp-read-expression-map.
Respect pp-eval-expression-print-length,
pp-eval-expression-print-level, and
eval-expression-debug-on-error.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-22 16:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18 21:12 pp.el patch Drew Adams
2008-04-22 15:42 ` Michael Olson
2008-04-22 16:37 ` Drew Adams
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).