* eval-to-texi
@ 2004-04-30 14:45 jemarch
2004-05-03 16:39 ` eval-to-texi Stefan Monnier
2004-05-03 20:48 ` eval-to-texi Kevin Rodgers
0 siblings, 2 replies; 11+ messages in thread
From: jemarch @ 2004-04-30 14:45 UTC (permalink / raw)
2004-04-30 Jose E. Marchesi <jemarch@gnu.org>
* textmodes/texinfo.el (texinfo-eval-to-texi): New function.
*** texinfo.el.~1.102.~ Sat Feb 21 14:48:44 2004
--- texinfo.el Fri Apr 30 16:42:38 2004
***************
*** 1050,1055 ****
--- 1050,1155 ----
;; 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))
+ (setq tform (replace-regexp-in-string "{" "@{" tform))
+ (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))
+ (setq output (replace-regexp-in-string "{" "@{" 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))
+ (setq met (replace-regexp-in-string "{" "@{" met))
+ (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))
+ (setq result (replace-regexp-in-string "{" "@{" 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)))
+
+
+
(provide 'texinfo)
;;; arch-tag: 005d7c38-43b9-4b7d-aa1d-aea69bae73e1
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-04-30 14:45 eval-to-texi jemarch
@ 2004-05-03 16:39 ` Stefan Monnier
2004-04-30 17:45 ` eval-to-texi jemarch
2004-05-03 20:48 ` eval-to-texi Kevin Rodgers
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2004-05-03 16:39 UTC (permalink / raw)
Cc: emacs-devel
> + (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))
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-05-03 16:39 ` eval-to-texi Stefan Monnier
@ 2004-04-30 17:45 ` jemarch
2004-05-03 18:21 ` eval-to-texi Adrian Aichner
0 siblings, 1 reply; 11+ messages in thread
From: jemarch @ 2004-04-30 17:45 UTC (permalink / raw)
Cc: emacs-devel
> + (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)))
+
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-04-30 17:45 ` eval-to-texi jemarch
@ 2004-05-03 18:21 ` Adrian Aichner
2004-04-30 18:38 ` eval-to-texi jemarch
0 siblings, 1 reply; 11+ messages in thread
From: Adrian Aichner @ 2004-05-03 18:21 UTC (permalink / raw)
jemarch@gnu.org writes:
> *** 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)
> +
Hi, just my two cents: why the excessive whitespace?
--
Adrian Aichner
mailto:adrian@xemacs.org
http://www.xemacs.org/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-05-03 18:21 ` eval-to-texi Adrian Aichner
@ 2004-04-30 18:38 ` jemarch
2004-05-04 7:40 ` eval-to-texi David Kastrup
0 siblings, 1 reply; 11+ messages in thread
From: jemarch @ 2004-04-30 18:38 UTC (permalink / raw)
Cc: emacs-devel
Adrian Aichner writes:
jemarch@gnu.org writes:
> + (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)
> +
Hi, just my two cents: why the excessive whitespace?
¿Do you mean the line spacing? In this way i found easier to read the
code. It is a personal taste, of course. The spacing can be reduced.
--
José E. Marchesi
<jemarch@gnu.org> http://www.gnu.org GNU No es Unix!
<jemarch@es.gnu.org> http://es.gnu.org GNU España
.---------------.
| .-[]--. |
| [] `>[]-| | BEE GNU/Hurd http://bee.es.gnu.org
| `-.[]<-' |
._______________.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-04-30 18:38 ` eval-to-texi jemarch
@ 2004-05-04 7:40 ` David Kastrup
2004-05-04 8:51 ` eval-to-texi Juri Linkov
0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2004-05-04 7:40 UTC (permalink / raw)
Cc: emacs-devel, Adrian Aichner
jemarch@gnu.org writes:
> Hi, just my two cents: why the excessive whitespace?
>
> ¿Do you mean the line spacing? In this way i found easier to read
> the code. It is a personal taste, of course. The spacing can be
> reduced.
Please do so. Emacs code is usually formatted in a particular
style. This style is also described in the Elisp manual AFAIR.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-05-04 7:40 ` eval-to-texi David Kastrup
@ 2004-05-04 8:51 ` Juri Linkov
2004-05-04 15:31 ` eval-to-texi Miles Bader
0 siblings, 1 reply; 11+ messages in thread
From: Juri Linkov @ 2004-05-04 8:51 UTC (permalink / raw)
Cc: emacs-devel, adrian, jemarch
David Kastrup <dak@gnu.org> writes:
> jemarch@gnu.org writes:
>> Hi, just my two cents: why the excessive whitespace?
>>
>> ¿Do you mean the line spacing? In this way i found easier to read
>> the code. It is a personal taste, of course. The spacing can be
>> reduced.
>
> Please do so. Emacs code is usually formatted in a particular
> style. This style is also described in the Elisp manual AFAIR.
Does anyone know about such already implemented function that formats
Emacs code according to a style described in the Elisp manual?
I'm thinking about calling it by typing `C-u C-M-q' which might do
a better job than `pp' does.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-05-04 8:51 ` eval-to-texi Juri Linkov
@ 2004-05-04 15:31 ` Miles Bader
0 siblings, 0 replies; 11+ messages in thread
From: Miles Bader @ 2004-05-04 15:31 UTC (permalink / raw)
Juri Linkov <juri@jurta.org> writes:
> I'm thinking about calling it by typing `C-u C-M-q' which might do
> a better job than `pp' does.
It could hardly do it worse...
[I have pleasant memories of lisps where pp would actually turn out
half-way decent looking code...]
-Miles
--
If you can't beat them, arrange to have them beaten. [George Carlin]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-04-30 14:45 eval-to-texi jemarch
2004-05-03 16:39 ` eval-to-texi Stefan Monnier
@ 2004-05-03 20:48 ` Kevin Rodgers
2004-05-03 21:24 ` eval-to-texi Stefan Monnier
2004-05-05 1:17 ` eval-to-texi Jose E. Marchesi
1 sibling, 2 replies; 11+ messages in thread
From: Kevin Rodgers @ 2004-05-03 20:48 UTC (permalink / raw)
jemarch@gnu.org wrote:
> + (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: ")
How about making its interface more like shell-command:
(defun texinfo-eval-to-texi (form &optional insert)
"Evaluate FORM, and display it and the result as 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")
...
(if insert
(insert texinfo-command)
(with-output-to-temp-buffer "*Texinfo*"
;; too bad we can't force the buffer into texinfo-mode
(princ texinfo-command)))
texinfo-command)
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
2004-05-03 20:48 ` eval-to-texi Kevin Rodgers
@ 2004-05-03 21:24 ` Stefan Monnier
2004-05-05 1:17 ` eval-to-texi Jose E. Marchesi
1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2004-05-03 21:24 UTC (permalink / raw)
Cc: emacs-devel
> How about making its interface more like shell-command:
You mean make it more like `eval-expression'? Agreed.
Actually, now that you mention it, it would be even neater to
extend `eval-expression' such that major modes can tune the format in which
the output is written in the current buffer. Then texinfo-mode can make it
do what texinfo-eval-to-texi does.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: eval-to-texi
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 ` Jose E. Marchesi
1 sibling, 0 replies; 11+ messages in thread
From: Jose E. Marchesi @ 2004-05-05 1:17 UTC (permalink / raw)
Cc: emacs-devel
jemarch@gnu.org wrote:
> + (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: ")
How about making its interface more like shell-command:
I think it is a good idea. With your permission, i am going to get
also your doc string.
--
José E. Marchesi
<jemarch@gnu.org> http://www.gnu.org GNU No es Unix!
<jemarch@es.gnu.org> http://es.gnu.org GNU Españaa
.---------------.
| .-[]--. |
| [] `>[]-| | BEE GNU/Hurd http://bee.es.gnu.org
| `-.[]<-' |
.---------------.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-05-05 1:17 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-30 14:45 eval-to-texi jemarch
2004-05-03 16:39 ` eval-to-texi Stefan Monnier
2004-04-30 17:45 ` eval-to-texi jemarch
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
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).