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

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

Re: Why does this lisp function to grab text from buffer not work as I e


From: Stephen Berman
Subject: Re: Why does this lisp function to grab text from buffer not work as I expect
Date: Fri, 12 Apr 2013 22:15:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

On Fri, 12 Apr 2013 07:18:26 -0700 (PDT) acomber <deedexy@gmail.com> wrote:

> I have some text like this:
>
> qwerty\tberty
> merty\tserty
>
> I want to grab the text berty between the tab character and end of line. 
> Then to show it worked goto the end of the buffer and insert the text there.
>
> But this code doesn't work.  Any ideas why not?
>
> (defun do-test ()
>   "tester"
>   (interactive)
>   (goto-char (point-min))
>   (if (search-forward "Option Name" nil t)
>      (delete-char 1) ;;delete tab
>      (setq myStr (buffer-substring point end-of-line)) ;add text to variable
>      ;goto end of buffer and insert text as demonstration it works
>      (goto-char (point-max))
>      (insert(myStr))
>   )
> )

point and end-of-line are functions, not variables, so they need to be
surrounded by parens.  But end-of-line moves point to the end of the
line and returns nil; that's also why you got the error you noted in
your other posting.  You should instead use the function
line-end-position: (buffer-substring (point) (line-end-position)).

Steve Berman




reply via email to

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