From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: Basic emacs lisp question Date: Tue, 09 Sep 2014 23:05:50 +0200 Message-ID: <87mwa8y05t.fsf@gmail.com> References: <87egvkvb6o.fsf@gmail.com> <87sik0y3jz.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410296845 15346 80.91.229.3 (9 Sep 2014 21:07:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Sep 2014 21:07:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 09 23:07:13 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 1XRScy-00027B-W9 for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2014 23:07:05 +0200 Original-Received: from localhost ([::1]:51907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRScw-00081N-Eu for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2014 17:07:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRScd-000815-6m for help-gnu-emacs@gnu.org; Tue, 09 Sep 2014 17:06:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRScV-0000ri-MP for help-gnu-emacs@gnu.org; Tue, 09 Sep 2014 17:06:43 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:48561) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRScV-0000rY-Fu for help-gnu-emacs@gnu.org; Tue, 09 Sep 2014 17:06:35 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XRScO-0001hm-7e for help-gnu-emacs@gnu.org; Tue, 09 Sep 2014 23:06:28 +0200 Original-Received: from e178059041.adsl.alicedsl.de ([85.178.59.41]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2014 23:06:28 +0200 Original-Received: from tjolitz by e178059041.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2014 23:06:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 68 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e178059041.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:C5EBFXo7ZzntJql2YHVaxFwGC80= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:99750 Archived-At: Thorsten Jolitz writes: > 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)) > > try > > #+BEGIN_SRC emacs-lisp > (defun process-diary-file () > "Perform some manipulation of the diary file" > (interactive) > (find-file (expand-file-name "~/diary")) > (goto-char (point-min)) > (setq a (thing-at-point)) > (message "%s" a)) > #+END_SRC that was untested and has room for improvement (as mentioned in this thread). This is untested again, but hopefully better ;) #+BEGIN_SRC emacs-lisp (defun process-diary-file () "Perform some manipulation of the diary file" (interactive) (let (a) (find-file (expand-file-name "~/diary")) (goto-char (point-min)) (setq a (thing-at-point 'symbol)) (message "%s" a))) #+END_SRC see ,----[ C-h f thing-at-point RET ] | thing-at-point is an autoloaded compiled Lisp function in | `thingatpt.el'. | | (thing-at-point THING) | | Return the THING at point. | THING should be a symbol specifying a type of syntactic entity. | Possibilities include `symbol', `list', `sexp', `defun', | `filename', `url', `email', `word', `sentence', `whitespace', | `line', `number', and `page'. | | See the file `thingatpt.el' for documentation on how to define | a symbol as a valid THING. | | [back] `---- -- cheers, Thorsten