unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Load file and return evaluation result (instead of t)?
@ 2013-10-09 19:25 Thorsten Jolitz
  2013-10-10 22:30 ` Michael Heerdegen
  2013-10-15 13:51 ` Kevin Rodgers
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Jolitz @ 2013-10-09 19:25 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

the manual says

 ,----------------------------------------------
 | load returns t if the file loads successfully
 `----------------------------------------------

but I would rather like to write a (big) Elisp expression into a file,
load the file, and get the expression's return value instead of just
't'. 

Something like 

,------------------------------
| (eval-buffer (find-file ...))
`------------------------------

does not do the job either. 

Did I overlook the simple and canonical way to do this? 
This is mainly to avoid that shell commands like 

,-------------------------------------------------------------
| $ emacsclient -s my-server -e "( ... elisp expressions ...)"
`-------------------------------------------------------------

become too long, and thus replace them with something like:

,-------------------------------------------------------------
| $ emacsclient -s my-server -e "(load-file \"/my/file.el\")"
`-------------------------------------------------------------

where /my/file.el contains those elisp expressions.

-- 
cheers,
Thorsten





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Load file and return evaluation result (instead of t)?
  2013-10-09 19:25 Load file and return evaluation result (instead of t)? Thorsten Jolitz
@ 2013-10-10 22:30 ` Michael Heerdegen
  2013-10-15 13:51 ` Kevin Rodgers
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2013-10-10 22:30 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:

>  ,----------------------------------------------
>  | load returns t if the file loads successfully
>  `----------------------------------------------
>
> but I would rather like to write a (big) Elisp expression into a file,
> load the file, and get the expression's return value instead of just
> 't'. 

You could find the file, use `read' to get the expression, and `eval'
it.  That's probably the canonical way.

Or you could, instead of just saving an expression to a file, save a
sexp that evals the expression and stores it to a global variable.  Then
after loading the file, this variable is bound to the result of the
evaluated expression.



Regards,

Michael.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Load file and return evaluation result (instead of t)?
  2013-10-09 19:25 Load file and return evaluation result (instead of t)? Thorsten Jolitz
  2013-10-10 22:30 ` Michael Heerdegen
@ 2013-10-15 13:51 ` Kevin Rodgers
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2013-10-15 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

On 10/9/13 1:25 PM, Thorsten Jolitz wrote:
>
> Hi List,
>
> the manual says
>
>   ,----------------------------------------------
>   | load returns t if the file loads successfully
>   `----------------------------------------------
>
> but I would rather like to write a (big) Elisp expression into a file,
> load the file, and get the expression's return value instead of just
> 't'.
>
> Something like
>
> ,------------------------------
> | (eval-buffer (find-file ...))
> `------------------------------
>
> does not do the job either.

(eval (read (find-file-noselect "/my/file.el")))

> Did I overlook the simple and canonical way to do this?
> This is mainly to avoid that shell commands like
>
> ,-------------------------------------------------------------
> | $ emacsclient -s my-server -e "( ... elisp expressions ...)"
> `-------------------------------------------------------------
>
> become too long, and thus replace them with something like:
>
> ,-------------------------------------------------------------
> | $ emacsclient -s my-server -e "(load-file \"/my/file.el\")"
> `-------------------------------------------------------------
>
> where /my/file.el contains those elisp expressions.

Of course, (eval-buffer (find-file-noselect "/my/file.el")) works in this
context as well, because the result of the -e EXPRESSION is discarded anyway.

Which leads back to emacsclient -l "/my/file.el"

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-15 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-09 19:25 Load file and return evaluation result (instead of t)? Thorsten Jolitz
2013-10-10 22:30 ` Michael Heerdegen
2013-10-15 13:51 ` Kevin Rodgers

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).