* Eval current sexp?
@ 2010-07-01 9:11 Elena
2010-12-11 2:04 ` Drew Adams
0 siblings, 1 reply; 2+ messages in thread
From: Elena @ 2010-07-01 9:11 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I can't find a function which evaluates the current (delimited) sexp.
I mean that in:
(defun fun ()
(setq var nil))
no matter where the point is inside the "setq" expression, I'd like
the "setq" sexp evaluated.
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: Eval current sexp?
2010-07-01 9:11 Eval current sexp? Elena
@ 2010-12-11 2:04 ` Drew Adams
0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2010-12-11 2:04 UTC (permalink / raw)
To: 'Elena', help-gnu-emacs
> From: Elena Sent: Thursday, July 01, 2010 2:11 AM
> I can't find a function which evaluates the current (delimited) sexp.
> I mean that in: (defun fun () (setq var nil))
> no matter where the point is inside the "setq" expression, I'd like
> the "setq" sexp evaluated.
This should help. You might need to tweak it a bit - dunno.
You will need library `thingatpt+.el', which is here:
http://www.emacswiki.org/emacs/thingatpt%2b.el.
It defines function `sexp-nearest-point'.
(defun sexp-value-nearest-point (&optional msgp)
"Return the value of the list sexp nearest point.
Climbs the list hierarchy until it gets to a list sexp.
Interactively, echo the sexp as well as the value."
(interactive "p")
(save-excursion
(cond ((looking-at "\\s-*\\s(") (skip-syntax-forward "-"))
((looking-at "\\s)\\s-*") (skip-syntax-backward "-")))
(let ((sexp (sexp-nearest-point)))
(condition-case nil ; Handle an `up-list' error.
(while (not (listp sexp))
(up-list -1)
(setq sexp (sexp-nearest-point)))
(error sexp))
(let ((value (eval sexp)))
(when msgp (message "Value: %s, Sexp: %s" value sexp))
value))))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-11 2:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-01 9:11 Eval current sexp? Elena
2010-12-11 2:04 ` Drew Adams
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).