* texinfo-eval-to-texi
@ 2004-05-05 2:45 Jose E. Marchesi
0 siblings, 0 replies; only message in thread
From: Jose E. Marchesi @ 2004-05-05 2:45 UTC (permalink / raw)
New patch taking care compact line spacing suggested by Adrian, the
shell-command like interface suggested by Kevin and the tips on
writing function documentation strings from the elisp user manual.
2004-04-30 Jose E. Marchesi <jemarch@gnu.org>
* textmodes/texinfo.el (texinfo-eval-to-texi): New function.
*** texinfo.el 21 Feb 2004 14:48:44 +0100 1.102
--- texinfo.el 05 May 2004 04:44:26 +0200
***************
*** 1050,1055 ****
--- 1050,1120 ----
;; job-number"\n"))
(tex-recenter-output-buffer nil))
+
+ (defun texinfo-eval-to-texi (form &optional insert)
+ "Evaluate FORM, and display the result into a @lisp Texinfo command.
+ With a prefix argument, insert the Texinfo command in the current buffer.
+
+ When called from Lisp, the command is returned as a string."
+ (interactive "sForm to evaluate: \nP")
+
+ (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)) ; macrop???
+ (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 insert
+ (insert environment-text)
+ (with-output-to-temp-buffer "*Texinfo*"
+ (princ environment-text)))
+
+ environment-text))
+
+
+
(provide 'texinfo)
;;; arch-tag: 005d7c38-43b9-4b7d-aa1d-aea69bae73e1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-05-05 2:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-05 2:45 texinfo-eval-to-texi Jose E. Marchesi
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.