aglew@crhc.uiuc.edu (Andy Glew) (10/10/90)
A little while back somebody posted a package to pretty-print the internals of a GNU Emacs Lisp defun. (ie. it walked down the list structure, etc.) At the time I didn't need it, but today I have been doing some heavy macro hacking so I can't just look at the source for my defuns. Can anyone mail me, or point me towards, the pretty-printer of defun internals package? -- Andy Glew, a-glew@uiuc.edu [get ph nameserver from uxc.cso.uiuc.edu:net/qi]
merlyn@iwarp.intel.com (Randal Schwartz) (10/10/90)
In article <AGLEW.90Oct9161905@dwarfs.crhc.uiuc.edu>, aglew@crhc (Andy Glew) writes: | A little while back somebody posted a package to pretty-print the | internals of a GNU Emacs Lisp defun. (ie. it walked down the list | structure, etc.) | | At the time I didn't need it, but today I have been doing some heavy | macro hacking so I can't just look at the source for my defuns. Can | anyone mail me, or point me towards, the pretty-printer of defun | internals package? Here's the general *list* pretty-printer I have. It's been posted before, so it's in the archives, but I've made some mods since then. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: pp.el # Wrapped by merlyn@iwarpse on Tue Oct 9 21:33:59 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'pp.el' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'pp.el'\" else echo shar: Extracting \"'pp.el'\" \(3045 characters\) sed "s/^X//" >'pp.el' <<'END_OF_FILE' X;;; original version by merlyn X;;; LastEditDate="Mon May 1 16:04:07 1989" X;;; patch to pp-eval-expression inspired by Michael Elhadad <elhadad@cs.columbia.EDU> X X(defun pp-to-string (object) X "Return a string containing the pretty-printed representation of OBJECT, Xany Lisp object. Quoting characters are used when needed to make output Xthat `read' can handle, whenever this is possible." X (save-excursion X (set-buffer (generate-new-buffer " pp-to-string")) X (unwind-protect X (progn X (emacs-lisp-mode) X (let ((print-escape-newlines t)) X (prin1 object (current-buffer))) X (goto-char (point-min)) X (while (not (eobp)) X ;; (message "%06d" (- (point-max) (point))) X (cond X ((looking-at "\\s(") X (while (looking-at "\\s(") X (forward-char 1))) X ;; (looking-at "quote") X ((condition-case err-var X (prog1 t (down-list 1)) X (error nil)) X (backward-char 1) X (skip-chars-backward " \t") X (delete-region X (point) X (progn (skip-chars-forward " \t") (point))) X (insert ?\n)) X ((condition-case err-var X (prog1 t (up-list 1)) X (error nil)) X (while (looking-at "\\s)") X (forward-char 1)) X (skip-chars-backward " \t") X (delete-region X (point) X (progn (skip-chars-forward " \t") (point))) X (insert ?\n)) X (t (goto-char (point-max))))) X (goto-char (point-min)) X (indent-sexp) X (buffer-string)) X (kill-buffer (current-buffer))))) X X(defun pp (object &optional stream) X "Output the pretty-printed representation of OBJECT, any Lisp object. XQuoting characters are printed when needed to make output that `read' Xcan handle, whenever this is possible. XOutput stream is STREAM, or value of `standard-output' (which see)." X (princ (pp-to-string object) (or stream standard-output))) X X(defun pp-eval-expression (expression) X "Evaluate EXPRESSION and pretty-print value into a new display buffer. XIf the pretty-printed value fits on one line, the message line is used Xinstead. Value is also consed on to front of variable values 's Xvalue." X (interactive "xPp-eval: ") X (setq values (cons (eval expression) values)) X (let ((temp-buffer-show-hook X (function X (lambda (buf) X (save-excursion X (set-buffer buf) X (goto-char (point-min)) X (end-of-line 1) X (if (or (< (1+ (point)) (point-max)) X (>= (- (point) (point-min)) (screen-width))) X (display-buffer buf) X (message "%s" (buffer-substring (point-min) (point))) X (kill-buffer buf))))))) X (with-output-to-temp-buffer "*Pp Eval Output*" X (pp (car values))))) X X(defun pp-eval-last-sexp (arg) X "Run `pp-eval-expression' on sexp before point (which see). XWith argument, pretty-print output into current buffer." X (interactive "P") X (let ((stab (syntax-table)) X exp) X (set-syntax-table emacs-lisp-mode-syntax-table) X (save-excursion X (forward-sexp -1) X (setq exp (read (current-buffer)))) X (set-syntax-table stab) X (if arg X (insert (pp-to-string (eval exp))) X (pp-eval-expression exp)))) END_OF_FILE if test 3045 -ne `wc -c <'pp.el'`; then echo shar: \"'pp.el'\" unpacked with wrong size! fi # end of 'pp.el' fi echo shar: End of shell archive. exit 0 Just another Elisp hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/