help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Evaluating a variable under point?


From: Xah Lee
Subject: Re: Evaluating a variable under point?
Date: Wed, 08 Dec 2010 15:16:33 -0000
User-agent: G2/1.0

On Jun 30, 7:33 am, Elena <egarr...@gmail.com> wrote:
> Hello,
>
> I'm trying to write an interactive function which evaluates variable
> at point, unless region is active. Currently it looks like this:
>
> (defun smart-eval ()
>         (interactive)
>         (if mark-active
>                 (eval-region)
>                 (case (char-syntax  (char-after))
>                   ((?w ?_)
>                    (eval-expression (string (thing-at-point 'symbol))))
>                   (t
>                    (message "Nothing to evaluate.")))))
>
> However, I'm not getting results. What's wrong?
>
> Thanks.

it's not clear what's your intention. From your code, i see lots of
things wrong.

note that you can eval a variable by just eval-last-sexp (Ctrl+x Ctrl
+e). Nothing extra you need to do.

if you want to eval currently selected text.... there's several
issues. Do you want to just eval the current word/symbol? It doesn't
make sense to eval a text selection that contain several symbols.

assume if you just want to eval current word the cursor is on, then
there's no need to check for  mark-active. Your code for checking
region is so wrong anyway...

basically, i assume you want this: With no text selection, eval the
word under cursor, but if there's text selection, eval the region. You
can find code and explanation here:

• Emacs: What's Region, Active Region, transient-mark-mode?
  http://xahlee.org/emacs/emacs_region.html

• Emacs Lisp Idioms
  http://xahlee.org/emacs/elisp_idioms.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]