* symbols verses words
@ 2011-03-03 0:20 Perry Smith
2011-03-03 7:52 ` Andreas Röhler
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Perry Smith @ 2011-03-03 0:20 UTC (permalink / raw)
To: GNU Emacs List
I need some help understanding Emac's design. I use a lot of "word" constructs where I *think* I should be using symbol. For example, if I'm writing C code and I want to find foo but not foo_bar, I usually do \<foo\> but really it seems that I should be doing \_<foo\_> ... fine. I can make that adjustment. But when I do incremental search, I often hit ^w to pull in the next word but what I really want (often but not always) is to pull in the next symbol (into the search string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps) and pull in this_that instead of just this.
So, I started looking at isearch-yank-word-or-char and I was going to concoct isearch-yank-symbol-or-char and got stuck-- at least briefly. Because not only is _ marked as symbol, -, +, /, *, etc are marked as symbol characters too. So now, I'm confused...
If I have: this this_that this-that
and search for \_<this\_> I hit the first and third this -- which is exactly what I want. But how is it doing that since this_that and this-that are the same as far as looking at the syntax table entries? They are both wwww_wwww.
I'd like to understand how the \_< and \_> constructs work so I can make my isearch-yank-symbol-or-char work in a consistent manner.
Thanks,
Perry
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 0:20 Perry Smith
@ 2011-03-03 7:52 ` Andreas Röhler
2011-03-03 10:19 ` Tassilo Horn
2011-03-03 14:26 ` MBR
2 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2011-03-03 7:52 UTC (permalink / raw)
To: help-gnu-emacs
Am 03.03.2011 01:20, schrieb Perry Smith:
> I need some help understanding Emac's design. I use a lot of "word" constructs where I *think* I should be using symbol. For example, if I'm writing C code and I want to find foo but not foo_bar, I usually do \<foo\> but really it seems that I should be doing \_<foo\_> ... fine. I can make that adjustment. But when I do incremental search, I often hit ^w to pull in the next word but what I really want (often but not always) is to pull in the next symbol (into the search string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps) and pull in this_that instead of just this.
>
> So, I started looking at isearch-yank-word-or-char and I was going to concoct isearch-yank-symbol-or-char and got stuck-- at least briefly. Because not only is _ marked as symbol, -, +, /, *, etc are marked as symbol characters too. So now, I'm confused...
>
> If I have: this this_that this-that
>
> and search for \_<this\_> I hit the first and third this -- which is exactly what I want.
Which should not happen IMHO, as
`\_>'
matches the empty string, but only at the end of a symbol
and your third this of this-that is not at the end.
BTW can't reproduce this with C-M-s, isearch-repeat-forward
it doesn't match this-that, as expected.
Looks like a bug, maybe try the last pre-release, which works fine here:
ftp://alpha.gnu.org/gnu/emacs/pretest/emacs-23.3-rc1.tar.gz
Andreas
--
https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
https://code.launchpad.net/s-x-emacs-werkstatt/
But how is it doing that since this_that and this-that are the same as
far as looking at the syntax table entries? They are both wwww_wwww.
>
> I'd like to understand how the \_< and \_> constructs work so I can make my isearch-yank-symbol-or-char work in a consistent manner.
>
> Thanks,
> Perry
>
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 0:20 Perry Smith
2011-03-03 7:52 ` Andreas Röhler
@ 2011-03-03 10:19 ` Tassilo Horn
2011-03-03 14:14 ` Perry Smith
2011-03-04 9:06 ` Andreas Röhler
2011-03-03 14:26 ` MBR
2 siblings, 2 replies; 11+ messages in thread
From: Tassilo Horn @ 2011-03-03 10:19 UTC (permalink / raw)
To: help-gnu-emacs
Perry Smith <pedzsan@gmail.com> writes:
Hi Perry,
> I need some help understanding Emac's design. I use a lot of "word"
> constructs where I *think* I should be using symbol. For example, if
> I'm writing C code and I want to find foo but not foo_bar, I usually
> do \<foo\> but really it seems that I should be doing \_<foo\_>
> ... fine. I can make that adjustment. But when I do incremental
> search, I often hit ^w to pull in the next word but what I really want
> (often but not always) is to pull in the next symbol (into the search
> string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps)
> and pull in this_that instead of just this.
I think, something like that should do the trick:
--8<---------------cut here---------------start------------->8---
(defun isearch-yank-symbol-or-char ()
"Pull next character or symbol from buffer into search string."
(interactive)
(isearch-yank-internal
(lambda ()
(if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
(memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
(forward-symbol 1)
(forward-char 1))
(point))))
(define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
--8<---------------cut here---------------end--------------->8---
So when you are on a word constituent (?w) or on a symbol constituent
(?_), then do `forward-symbol', else `forward-char'.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 10:19 ` Tassilo Horn
@ 2011-03-03 14:14 ` Perry Smith
2011-03-03 14:48 ` Tassilo Horn
[not found] ` <mailman.9.1299163745.10269.help-gnu-emacs@gnu.org>
2011-03-04 9:06 ` Andreas Röhler
1 sibling, 2 replies; 11+ messages in thread
From: Perry Smith @ 2011-03-03 14:14 UTC (permalink / raw)
To: Tassilo Horn; +Cc: help-gnu-emacs
On Mar 3, 2011, at 4:19 AM, Tassilo Horn wrote:
> Perry Smith <pedzsan@gmail.com> writes:
>
> Hi Perry,
>
>> I need some help understanding Emac's design. I use a lot of "word"
>> constructs where I *think* I should be using symbol. For example, if
>> I'm writing C code and I want to find foo but not foo_bar, I usually
>> do \<foo\> but really it seems that I should be doing \_<foo\_>
>> ... fine. I can make that adjustment. But when I do incremental
>> search, I often hit ^w to pull in the next word but what I really want
>> (often but not always) is to pull in the next symbol (into the search
>> string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps)
>> and pull in this_that instead of just this.
>
> I think, something like that should do the trick:
>
> --8<---------------cut here---------------start------------->8---
> (defun isearch-yank-symbol-or-char ()
> "Pull next character or symbol from buffer into search string."
> (interactive)
> (isearch-yank-internal
> (lambda ()
> (if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
> (memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
> (forward-symbol 1)
> (forward-char 1))
> (point))))
>
> (define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
> --8<---------------cut here---------------end--------------->8---
>
> So when you are on a word constituent (?w) or on a symbol constituent
> (?_), then do `forward-symbol', else `forward-char'.
Thanks. The problem is that my emacs (GNU 23.2) doesn't have
forward-symbol. I didn't know how to do that.
Thanks again,
Perry
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 0:20 Perry Smith
2011-03-03 7:52 ` Andreas Röhler
2011-03-03 10:19 ` Tassilo Horn
@ 2011-03-03 14:26 ` MBR
2011-03-03 14:33 ` Perry Smith
2 siblings, 1 reply; 11+ messages in thread
From: MBR @ 2011-03-03 14:26 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]
Verses are made up of words and words are made up of symbols. So the
order should be "symbols words verses", not "symbols verses words".
Oh, you meant "vers_u_s" not "vers_e_s". OK. I'll shut up now.
Mark
On 3/2/2011 7:20 PM, Perry Smith wrote:
> I need some help understanding Emac's design. I use a lot of "word" constructs where I *think* I should be using symbol. For example, if I'm writing C code and I want to find foo but not foo_bar, I usually do \<foo\> but really it seems that I should be doing \_<foo\_> ... fine. I can make that adjustment. But when I do incremental search, I often hit ^w to pull in the next word but what I really want (often but not always) is to pull in the next symbol (into the search string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps) and pull in this_that instead of just this.
>
> So, I started looking at isearch-yank-word-or-char and I was going to concoct isearch-yank-symbol-or-char and got stuck-- at least briefly. Because not only is _ marked as symbol, -, +, /, *, etc are marked as symbol characters too. So now, I'm confused...
>
> If I have: this this_that this-that
>
> and search for \_<this\_> I hit the first and third this -- which is exactly what I want. But how is it doing that since this_that and this-that are the same as far as looking at the syntax table entries? They are both wwww_wwww.
>
> I'd like to understand how the \_< and \_> constructs work so I can make my isearch-yank-symbol-or-char work in a consistent manner.
>
> Thanks,
> Perry
>
>
>
[-- Attachment #2: Type: text/html, Size: 2102 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 14:26 ` MBR
@ 2011-03-03 14:33 ` Perry Smith
0 siblings, 0 replies; 11+ messages in thread
From: Perry Smith @ 2011-03-03 14:33 UTC (permalink / raw)
To: MBR; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1687 bytes --]
:-) Never could smell.
On Mar 3, 2011, at 8:26 AM, MBR wrote:
> Verses are made up of words and words are made up of symbols. So the order should be "symbols words verses", not "symbols verses words".
>
> Oh, you meant "versus" not "verses". OK. I'll shut up now.
>
> Mark
>
> On 3/2/2011 7:20 PM, Perry Smith wrote:
>>
>> I need some help understanding Emac's design. I use a lot of "word" constructs where I *think* I should be using symbol. For example, if I'm writing C code and I want to find foo but not foo_bar, I usually do \<foo\> but really it seems that I should be doing \_<foo\_> ... fine. I can make that adjustment. But when I do incremental search, I often hit ^w to pull in the next word but what I really want (often but not always) is to pull in the next symbol (into the search string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps) and pull in this_that instead of just this.
>>
>> So, I started looking at isearch-yank-word-or-char and I was going to concoct isearch-yank-symbol-or-char and got stuck-- at least briefly. Because not only is _ marked as symbol, -, +, /, *, etc are marked as symbol characters too. So now, I'm confused...
>>
>> If I have: this this_that this-that
>>
>> and search for \_<this\_> I hit the first and third this -- which is exactly what I want. But how is it doing that since this_that and this-that are the same as far as looking at the syntax table entries? They are both wwww_wwww.
>>
>> I'd like to understand how the \_< and \_> constructs work so I can make my isearch-yank-symbol-or-char work in a consistent manner.
>>
>> Thanks,
>> Perry
>>
>>
>>
[-- Attachment #2: Type: text/html, Size: 2225 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 14:14 ` Perry Smith
@ 2011-03-03 14:48 ` Tassilo Horn
2011-03-03 19:25 ` Perry Smith
[not found] ` <mailman.9.1299163745.10269.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 11+ messages in thread
From: Tassilo Horn @ 2011-03-03 14:48 UTC (permalink / raw)
To: Perry Smith; +Cc: help-gnu-emacs
Perry Smith <pedzsan@gmail.com> writes:
Hi Perry,
>> I think, something like that should do the trick:
>>
>> --8<---------------cut here---------------start------------->8---
>> (defun isearch-yank-symbol-or-char ()
>> "Pull next character or symbol from buffer into search string."
>> (interactive)
>> (isearch-yank-internal
>> (lambda ()
>> (if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
>> (memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
>> (forward-symbol 1)
>> (forward-char 1))
>> (point))))
>>
>> (define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
>> --8<---------------cut here---------------end--------------->8---
>>
>> So when you are on a word constituent (?w) or on a symbol constituent
>> (?_), then do `forward-symbol', else `forward-char'.
>
> Thanks. The problem is that my emacs (GNU 23.2) doesn't have
> forward-symbol. I didn't know how to do that.
Ah, that function is defined in thingatpt.el, so you are only missing a
(require 'thingatpt).
Bye,
Tassilo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
[not found] ` <mailman.9.1299163745.10269.help-gnu-emacs@gnu.org>
@ 2011-03-03 15:34 ` rusi
0 siblings, 0 replies; 11+ messages in thread
From: rusi @ 2011-03-03 15:34 UTC (permalink / raw)
To: help-gnu-emacs
On Mar 3, 7:48 pm, Tassilo Horn <tass...@member.fsf.org> wrote:
> Perry Smith <pedz...@gmail.com> writes:
>
> Hi Perry,
>
>
>
> >> I think, something like that should do the trick:
>
> >> --8<---------------cut here---------------start------------->8---
> >> (defun isearch-yank-symbol-or-char ()
> >> "Pull next character or symbol from buffer into search string."
> >> (interactive)
> >> (isearch-yank-internal
> >> (lambda ()
> >> (if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
> >> (memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
> >> (forward-symbol 1)
> >> (forward-char 1))
> >> (point))))
>
> >> (define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
> >> --8<---------------cut here---------------end--------------->8---
>
> >> So when you are on a word constituent (?w) or on a symbol constituent
> >> (?_), then do `forward-symbol', else `forward-char'.
>
> > Thanks. The problem is that my emacs (GNU 23.2) doesn't have
> > forward-symbol. I didn't know how to do that.
>
> Ah, that function is defined in thingatpt.el, so you are only missing a
> (require 'thingatpt).
>
> Bye,
> Tassilo
Its there but not documented (emacs 23.1.1)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 14:48 ` Tassilo Horn
@ 2011-03-03 19:25 ` Perry Smith
0 siblings, 0 replies; 11+ messages in thread
From: Perry Smith @ 2011-03-03 19:25 UTC (permalink / raw)
To: Tassilo Horn; +Cc: help-gnu-emacs
On Mar 3, 2011, at 8:48 AM, Tassilo Horn wrote:
> Perry Smith <pedzsan@gmail.com> writes:
>
> Hi Perry,
>
>>> I think, something like that should do the trick:
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> (defun isearch-yank-symbol-or-char ()
>>> "Pull next character or symbol from buffer into search string."
>>> (interactive)
>>> (isearch-yank-internal
>>> (lambda ()
>>> (if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
>>> (memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
>>> (forward-symbol 1)
>>> (forward-char 1))
>>> (point))))
>>>
>>> (define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> So when you are on a word constituent (?w) or on a symbol constituent
>>> (?_), then do `forward-symbol', else `forward-char'.
>>
>> Thanks. The problem is that my emacs (GNU 23.2) doesn't have
>> forward-symbol. I didn't know how to do that.
>
> Ah, that function is defined in thingatpt.el, so you are only missing a
> (require 'thingatpt).
Got it... thanks!
Perry
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
2011-03-03 10:19 ` Tassilo Horn
2011-03-03 14:14 ` Perry Smith
@ 2011-03-04 9:06 ` Andreas Röhler
1 sibling, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2011-03-04 9:06 UTC (permalink / raw)
To: help-gnu-emacs
Am 03.03.2011 11:19, schrieb Tassilo Horn:
> Perry Smith<pedzsan@gmail.com> writes:
>
> Hi Perry,
>
>> I need some help understanding Emac's design. I use a lot of "word"
>> constructs where I *think* I should be using symbol. For example, if
>> I'm writing C code and I want to find foo but not foo_bar, I usually
>> do \<foo\> but really it seems that I should be doing \_<foo\_>
>> ... fine. I can make that adjustment. But when I do incremental
>> search, I often hit ^w to pull in the next word but what I really want
>> (often but not always) is to pull in the next symbol (into the search
>> string). So if I'm sitting at this_that, I'd ilke to hit ^W (perhaps)
>> and pull in this_that instead of just this.
>
> I think, something like that should do the trick:
>
> --8<---------------cut here---------------start------------->8---
> (defun isearch-yank-symbol-or-char ()
> "Pull next character or symbol from buffer into search string."
> (interactive)
> (isearch-yank-internal
> (lambda ()
> (if (or (memq (char-syntax (or (char-after) 0)) '(?w ?_))
> (memq (char-syntax (or (char-after (1+ (point))) 0)) '(?w ?_)))
> (forward-symbol 1)
> (forward-char 1))
> (point))))
>
> (define-key isearch-mode-map (kbd "C-S-w") 'isearch-yank-symbol-or-char)
> --8<---------------cut here---------------end--------------->8---
>
> So when you are on a word constituent (?w) or on a symbol constituent
> (?_), then do `forward-symbol', else `forward-char'.
>
> Bye,
> Tassilo
>
>
>
Hi Tassilo,
maybe I'm missing the point.
In the case given may just extend input
from `\w+' onto `\w+.\w'
(?)
Andreas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: symbols verses words
[not found] <mailman.10.1299111607.15358.help-gnu-emacs@gnu.org>
@ 2011-03-05 4:36 ` Stefan Monnier
0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2011-03-05 4:36 UTC (permalink / raw)
To: help-gnu-emacs
> So, I started looking at isearch-yank-word-or-char and I was going to
> concoct isearch-yank-symbol-or-char and got stuck-- at least briefly.
> Because not only is _ marked as symbol, -, +, /, *, etc are marked as symbol
> characters too. So now, I'm confused...
Which syntax is assigned to which char depends on the major mode.
What you describe, for example, is not true of C-mode buffers.
> If I have: this this_that this-that
> and search for \_<this\_> I hit the first and third this -- which is exactly
> what I want.
I suspect this test was not performed in the same buffer as the one
in which you checked the syntax of those chars.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-03-05 4:36 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.10.1299111607.15358.help-gnu-emacs@gnu.org>
2011-03-05 4:36 ` symbols verses words Stefan Monnier
2011-03-03 0:20 Perry Smith
2011-03-03 7:52 ` Andreas Röhler
2011-03-03 10:19 ` Tassilo Horn
2011-03-03 14:14 ` Perry Smith
2011-03-03 14:48 ` Tassilo Horn
2011-03-03 19:25 ` Perry Smith
[not found] ` <mailman.9.1299163745.10269.help-gnu-emacs@gnu.org>
2011-03-03 15:34 ` rusi
2011-03-04 9:06 ` Andreas Röhler
2011-03-03 14:26 ` MBR
2011-03-03 14:33 ` Perry Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).