From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: phillip.lord@newcastle.ac.uk (Phillip Lord) Newsgroups: gmane.emacs.help Subject: Re: Basic emacs lisp question Date: Wed, 10 Sep 2014 14:12:33 +0100 Message-ID: <87egvjliv2.fsf@newcastle.ac.uk> References: <87egvkvb6o.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410354812 7437 80.91.229.3 (10 Sep 2014 13:13:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2014 13:13:32 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Ken Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 10 15:13:25 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XRhhp-0006ka-Js for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2014 15:13:05 +0200 Original-Received: from localhost ([::1]:56288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRhho-0003Td-Sf for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2014 09:13:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRhhU-0003St-PK for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 09:12:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRhhO-0005ky-Lb for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 09:12:44 -0400 Original-Received: from cheviot22.ncl.ac.uk ([128.240.234.22]:49430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRhhO-0005kA-Fa for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 09:12:38 -0400 Original-Received: from smtpauth-vm.ncl.ac.uk ([10.8.233.129] helo=smtpauth.ncl.ac.uk) by cheviot22.ncl.ac.uk with esmtp (Exim 4.63) (envelope-from ) id 1XRhhK-0007BJ-Dc; Wed, 10 Sep 2014 14:12:34 +0100 Original-Received: from jangai.ncl.ac.uk ([10.66.67.223] helo=localhost) by smtpauth.ncl.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1XRhhK-00058m-3z; Wed, 10 Sep 2014 14:12:34 +0100 In-Reply-To: <87egvkvb6o.fsf@gmail.com> (Ken's message of "Tue, 9 Sep 2014 15:35:59 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 128.240.234.22 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:99778 Archived-At: Ken 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