all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* search forward at point question
  2009-03-04 16:01 change bash for emacs lehe
@ 2009-03-05  6:42 ` Maindoor
  0 siblings, 0 replies; 3+ messages in thread
From: Maindoor @ 2009-03-05  6:42 UTC (permalink / raw)
  To: Help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

Hi,
     I have the following code to search forward from point.
     But If I have a string like SOMETHING_HERE=$(HI)

     then this code yanks the whole "SOMETHING_HERE=$"
     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))

Regards,
Maindoor.



      

[-- Attachment #2: Type: text/html, Size: 1277 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: search forward at point question
       [not found] <mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org>
@ 2009-03-06  2:01 ` Barry Margolin
  2009-03-06 17:21 ` Xah Lee
  1 sibling, 0 replies; 3+ messages in thread
From: Barry Margolin @ 2009-03-06  2:01 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

In article <mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org>,
 Maindoor <sanjeevfiles@yahoo.com> wrote:

> Hi,
>      I have the following code to search forward from point.
>      But If I have a string like SOMETHING_HERE=$(HI)
> 
>      then this code yanks the whole "SOMETHING_HERE=$"
>      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 "-". 

C-h f current-word

and see the really-word parameter.  However, you may also need to change 
the syntax table to make "_" and "-" be considered word constituents.

> 
>      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))
> 
> Regards,
> Maindoor.
> 




-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: search forward at point question
       [not found] <mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org>
  2009-03-06  2:01 ` search forward at point question Barry Margolin
@ 2009-03-06 17:21 ` Xah Lee
  1 sibling, 0 replies; 3+ messages in thread
From: Xah Lee @ 2009-03-06 17:21 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 4, 10:42 pm, Maindoor <sanjeevfi...@yahoo.com> wrote:
> Hi,
>      I have the following code to search forward from point.
>      But If I have a string like SOMETHING_HERE=$(HI)
>
>      then this code yanks the whole "SOMETHING_HERE=$"
>      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 “_” or “-” or any other such as “=”
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 “_” and “-” regardless what 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
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-06 17:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org>
2009-03-06  2:01 ` search forward at point question Barry Margolin
2009-03-06 17:21 ` Xah Lee
2009-03-04 16:01 change bash for emacs lehe
2009-03-05  6:42 ` search forward at point question Maindoor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.