From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: jemarch@gnu.org Newsgroups: gmane.emacs.devel Subject: Re: eval-to-texi Date: Fri, 30 Apr 2004 19:45:50 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <16530.37070.624001.570085@termi.eui.upm.es> References: <16530.26245.472519.384112@termi.eui.upm.es> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1083607364 24122 80.91.224.253 (3 May 2004 18:02:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 3 May 2004 18:02:44 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon May 03 20:02:17 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BKhlg-0007t4-00 for ; Mon, 03 May 2004 20:02:16 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BKhlg-0004AF-00 for ; Mon, 03 May 2004 20:02:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BKha1-00071t-SB for emacs-devel@quimby.gnus.org; Mon, 03 May 2004 13:50:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BKhZw-00071G-M4 for emacs-devel@gnu.org; Mon, 03 May 2004 13:50:08 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BKhVI-0005WW-6n for emacs-devel@gnu.org; Mon, 03 May 2004 13:45:51 -0400 Original-Received: from [138.100.152.2] (helo=fenix.eui.upm.es) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BKhVH-0005WF-Fc for emacs-devel@gnu.org; Mon, 03 May 2004 13:45:19 -0400 Original-Received: from termi.eui.upm.es.gnu.org (zorzal.eui.upm.es [138.100.158.159]) by fenix.eui.upm.es (Postfix) with ESMTP id E3164B6F5C; Mon, 3 May 2004 19:45:18 +0200 (CEST) Original-To: Stefan Monnier In-Reply-To: X-Mailer: VM 7.17 under Emacs 21.2.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:22637 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22637 > + (setq tform (replace-regexp-in-string "@" "@@" tform)) > + (setq tform (replace-regexp-in-string "{" "@{" tform)) > + (setq tform (replace-regexp-in-string "}" "@}" tform)) Aka (setq tform (replace-regexp-in-string "[@{}]" "@\\&" tform)) Ok, thanks. Changed in the following patch. *** texinfo.el.~1.102.~ Sat Feb 21 14:48:44 2004 --- texinfo.el Fri Apr 30 19:43:07 2004 *************** *** 1050,1055 **** --- 1050,1147 ---- ;; job-number"\n")) (tex-recenter-output-buffer nil)) + + (defun texinfo-eval-to-texi (form &optional tostring) + "Evaluates FORM, dumping a @lisp texinfo environment with the evaluation + description. + + If TOSTRING is t, then the @lisp environment is returned into a string, + rather than being inserted into the current buffer." + + (interactive "sForm to evaluate: ") + + (let (environment-text) + + (setq environment-text + + (with-temp-buffer + + (condition-case error-description + + (let (expression result output) + + ;; Begin of the sample + (insert "@lisp\n") + + ;; Dump the form itself into the sample + (let ((tform form)) + + (setq tform (replace-regexp-in-string "[@{}]" "@\\&" tform)) + + (insert tform "\n")) + + ;; Parse the form to a valid expression + (setq expression (read form)) + + + + ;; Get the result of the eval, and the output if there is one + (setq output + (with-output-to-string + (setq result (prin1-to-string (eval expression))))) + + ;; If there is any output, dump a @print{} entry into the sample + (if (not (equal output "")) + + (progn + ;; Escape texinfo special characters on the output + (setq output (replace-regexp-in-string "[@{}]" "@\\&" output)) + + ;; Indent multilines + (setq output (replace-regexp-in-string "\n" "\n " output)) + + (insert " @print{} " output "\n"))) + + ;; If the expression is a macro, dump an @expansion{} + (let ((macroexp (macroexpand expression))) + (if (not (equal macroexp expression)) ; macro-p??? + + (let ((met (prin1-to-string macroexp))) + + ;; Escape texinfo special characters on the macro expansion text + (setq met (replace-regexp-in-string "[@{}]" "@\\&" met)) + + ;; Indent multilines + (setq met (replace-regexp-in-string "\n" "\n " met)) + + (insert " @expansion{} " met "\n")))) + + ;; Escape texinfo special characters on the result + (setq result (replace-regexp-in-string "[@{}]" "@\\&" result)) + + ;; Indent multilines + (setq result (replace-regexp-in-string "\n" "\n " result)) + + ;; Dump the @result{} entry into the sample + (insert " @result{} " result "\n")) + + ;; Was an error => Dump an @error{} entry into the sample with the error + ;; description from the interpreter + (error (insert " @error{} " (error-message-string error-description) "\n"))) + + ;; End of the sample + (insert "@end lisp") + + ;; Return buffer's contents + (buffer-substring (point-min) (point-max)))) + + + (if (not tostring) + (insert environment-text) + environment-text))) +