From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: search forward at point question Date: Fri, 6 Mar 2009 09:21:34 -0800 (PST) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1236378824 18822 80.91.229.12 (6 Mar 2009 22:33:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Mar 2009 22:33:44 +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 Mar 06 23:35:01 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 1Lfid9-0004DX-E0 for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Mar 2009 23:34:59 +0100 Original-Received: from localhost ([127.0.0.1]:48047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lfibi-00070Q-RW for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Mar 2009 17:33:30 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!z6g2000pre.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 50 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1236360094 7759 127.0.0.1 (6 Mar 2009 17:21:34 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 6 Mar 2009 17:21:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z6g2000pre.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167398 comp.emacs:97937 X-Mailman-Approved-At: Fri, 06 Mar 2009 17:32:46 -0500 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:62706 Archived-At: On Mar 4, 10:42 pm, Maindoor wrote: > Hi, > I have the following code to search forward from point. > But If I have a string like SOMETHING_HERE=3D$(HI) > > then this code yanks the whole "SOMETHING_HERE=3D$" > and searches for it forward. How do I limit it to > "SOMETHING_HERE". I want it to stop if it encounters > any special characters except "_" and "-". > > Here is the code: > > (defun my-viper-search-yank-word (arg forward) > "Search forward for ARG occurance of word under point. > If FORWARD is nil, searches backward instead." > (let ((viper-re-search t)) > (viper-search > (concat "\\<" (regexp-quote (current-word)) "\\>") forward arg))) > > (defun my-viper-search-forward-yank-word (arg) > "Search forward for ARG occurance of word under point. > Like the Vim command \"*\" (but not exactly)." > (interactive "P") > (my-viper-search-yank-word arg t)) As Barry Margolin suggested, you might try to use the optional paramter in the function current-word. However, as Barry also suggested, current-word relies on emacs's syntax table. Which means, whether =E2=80=9C_=E2=80=9D or =E2=80=9C-=E2=80= =9D or any other such as =E2=80=9C=3D=E2=80=9D is considered part of the word depends on the current major mode. You could, write your own so that your function always works on alphanumerics plus =E2=80=9C_=E2=80=9D and =E2=80=9C-=E2=80=9D regardless w= hat syntax table there is. (This problem also bugged me a few times. Emacs's concept syntax table seems to me questionable. It is not really powerful enough to model most coding problems dealing with syntax, yet it does gets in the way sometimes, and is quite complex to use.) To code your own current-word, just use search-backward-regexp with a regex something like [-_A-Za-z], then get the cursor position. Do same by search forward. Then, use buffer-substring-no-properties to grab the string. Xah =E2=88=91 http://xahlee.org/ =E2=98=84