From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: TomSW Newsgroups: gmane.emacs.help Subject: Re: TERRIBLE ERROR :: Invalid search bound - wrong side of point Date: Fri, 3 Jul 2009 00:47:51 -0700 (PDT) Organization: http://groups.google.com Message-ID: <675ce6e5-7321-483a-bbc0-7a9d8211dfdd@h11g2000yqb.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1246610538 28288 80.91.229.12 (3 Jul 2009 08:42:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 3 Jul 2009 08:42: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 Fri Jul 03 10:42:11 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MMeLS-00033J-Sb for geh-help-gnu-emacs@m.gmane.org; Fri, 03 Jul 2009 10:42:11 +0200 Original-Received: from localhost ([127.0.0.1]:47667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MMeLR-0007GM-UG for geh-help-gnu-emacs@m.gmane.org; Fri, 03 Jul 2009 04:42:09 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!postnews.google.com!h11g2000yqb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.lang.lisp,comp.lang.scheme,comp.unix.shell Original-Lines: 37 Original-NNTP-Posting-Host: 84.193.193.55 Original-X-Trace: posting.google.com 1246607272 15123 127.0.0.1 (3 Jul 2009 07:47:52 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 3 Jul 2009 07:47:52 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h11g2000yqb.googlegroups.com; posting-host=84.193.193.55; posting-account=gXCEPAoAAACaHNwa63AHlGuSCIcCahgr User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:170543 comp.lang.lisp:270407 comp.lang.scheme:81627 comp.unix.shell:228435 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65753 Archived-At: On Jul 3, 1:16=A0am, bolega wrote: > I am doing a very simple and trivial thing that you often do in bash > using sed. Replace the end of the line by a token such as #. > > I loath to use newline which is a break in emacs since it probably > does not accept \n. It does. > I only want to replace this on one line such as the current line. I > could narrow to the line but is it really necessary ? Cant I just > specify the limits in replace-regexp ? Either there is something > seriously wrong with my understanding of emacs so I must pursue this > for the sake of learning. If you specify the limits of a replace operation you normally ensure that the replacements don't add characters to the region being changed. Otherwise there is a chance that the replacements will push point beyond the end limit and you will get the error "Invalid search bound". Narrowing means you don't need to worry about this. Generally you should also avoid using replace-regexp in a program (as explained in the documentation). Since you only want to do one replacement, all you need is: (save-excursion (when (re-search-forward "$" nil :noerr) (replace-match "#"))) or even: (save-excursion (goto-char (line-end-position)) (insert "#")) regards, Tom SW