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: Thorsten Jolitz
Subject: Re: Basic emacs lisp question
Date: Tue, 09 Sep 2014 23:05:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:

> Ken <address@hidden> 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




reply via email to

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