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

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

Re: Basic emacs lisp question


From: Phillip Lord
Subject: Re: Basic emacs lisp question
Date: Wed, 10 Sep 2014 14:12:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Ken <kensubuntu@gmail.com> writes:

> I want to capture whatever is at point in a file into a variable
> something like the following, but it doesn't seem to work. Can any one
> suggest what I an doing wrong. It is probably a silly mistake I am
> unable to see. I am just learning Emacs lisp.
>
> (defun process-diary-file ()
>   "Perform some manipulation of the diary file"
>   (interactive)
>   (find-file "~/diary")
>   (goto-char 1)
>   (set a (thing-at-point))
>   (message a))

Immediately solution is let. 

(defun process-diary-file ()
  "Perform some manipulation of the diary file"
  (interactive)
  (find-file "~/.signature")
  (goto-char 1)
  (let ((a (thing-at-point 'word)))
    (message a)))

Nicer solution is to not use a variable at all which works in this case.

(defun process-diary-file ()
  "Perform some manipulation of the diary file"
  (interactive)
  (find-file "~/.signature")
  (goto-char 1)
  (message
   (thing-at-point 'word)))

Do you want to capture the value into some *existing* variable a or is
it just for use in this function. In the former case you need setq
rather than set (let won't work!). However, if you can avoid or minimize
using global state in this way, it will make your life easier.

Phil





reply via email to

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