unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: jemarch@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: eval-to-texi
Date: Fri, 30 Apr 2004 19:45:50 +0200	[thread overview]
Message-ID: <16530.37070.624001.570085@termi.eui.upm.es> (raw)
In-Reply-To: <jwv3c6h1n6g.fsf-monnier+emacs@gnu.org>




   > + 		     (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)))    
+ 

  reply	other threads:[~2004-04-30 17:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-30 14:45 eval-to-texi jemarch
2004-05-03 16:39 ` eval-to-texi Stefan Monnier
2004-04-30 17:45   ` jemarch [this message]
2004-05-03 18:21     ` eval-to-texi Adrian Aichner
2004-04-30 18:38       ` eval-to-texi jemarch
2004-05-04  7:40         ` eval-to-texi David Kastrup
2004-05-04  8:51           ` eval-to-texi Juri Linkov
2004-05-04 15:31             ` eval-to-texi Miles Bader
2004-05-03 20:48 ` eval-to-texi Kevin Rodgers
2004-05-03 21:24   ` eval-to-texi Stefan Monnier
2004-05-05  1:17   ` eval-to-texi Jose E. Marchesi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16530.37070.624001.570085@termi.eui.upm.es \
    --to=jemarch@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).