From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Why does this lisp function to grab text from buffer not work as I expect Date: Sat, 13 Apr 2013 00:53:52 +0200 Organization: Informatimago Message-ID: <877gk7bbsv.fsf@kuiper.lan.informatimago.com> References: <1365776306646-283560.post@n5.nabble.com> <87d2tzfqub.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1365807258 7855 80.91.229.3 (12 Apr 2013 22:54:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Apr 2013 22:54:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 13 00:54:19 2013 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 1UQmrK-0005QL-IF for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Apr 2013 00:54:18 +0200 Original-Received: from localhost ([::1]:33237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQmrK-0001Oa-8L for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Apr 2013 18:54:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQmr7-0001Nt-4t for help-gnu-emacs@gnu.org; Fri, 12 Apr 2013 18:54:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQmr5-00073n-4e for help-gnu-emacs@gnu.org; Fri, 12 Apr 2013 18:54:05 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:32890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQmr4-00073P-UJ for help-gnu-emacs@gnu.org; Fri, 12 Apr 2013 18:54:03 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UQmr3-00053A-JJ for help-gnu-emacs@gnu.org; Sat, 13 Apr 2013 00:54:01 +0200 Original-Received: from amontsouris-651-1-192-178.w82-123.abo.wanadoo.fr ([82.123.191.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Apr 2013 00:54:01 +0200 Original-Received: from pjb by amontsouris-651-1-192-178.w82-123.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Apr 2013 00:54:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 83 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-651-1-192-178.w82-123.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Cancel-Lock: sha1:ZmYyY2NmMmQzMWE0MDdhYTE1MTZmZDFlY2JlNjA5ZGY5MzQ2YjY3Zg== 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:90137 Archived-At: Stephen Berman writes: > On Fri, 12 Apr 2013 07:18:26 -0700 (PDT) acomber 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)). And on the other hand, myStr is a variable, so why is it called as a function in (insert (myStr)) ??? The OP seems to be totally confused between variables and functions… Also, I don't see the relationship between "Option Name" and the example text and problem statement… Let's take it again from the start: >> 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. (defun my-command () (interactive) (goto-char (point-min)) ; not in the problem statement, but assumed. ;; I want to grab the text berty between tab and end-of-line: (when (re-search-forward "\t\\(berty\\)$" nil t) ;; We don't know what "it" is, in "show it worked", but ;; let's assume that "grab" implies deleting that text. (delete-region (match-beginning 1) (match-end 1)) ;; Then to show it worked goto the end of the buffer (goto-char (point-max)) ;; and insert the text there. (insert "berty"))) So let's start with this buffer: ------------------------------------------------------------------------ qwerty berty merty serty ------------------------------------------------------------------------ and type M-x my-command RET we should get this buffer: ------------------------------------------------------------------------ qwerty merty serty berty ------------------------------------------------------------------------ -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.