all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ignoring comments and/or strings (in source files) by _any_ search function?
@ 2007-06-25 11:18 Peter Tury
  2007-06-25 14:12 ` Peter Tury
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Tury @ 2007-06-25 11:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I am working on a simple major mode for a specific programming
language. I found that I need a variant of more and more (now: two
:-)) search functions (e.g. re-search-backward, skip-chars-backward)
what ignore comments and/or strings.

Do you know about a general implementation for this problem? Now I
think it can be solved only with macros (nicely with the loop
facility?), and I'll try to create it, but don't want to reinvent the
wheel (especially because I am new to macros ;-).

The idea is to have a function/macro (let's call it `ignore-comm-str')
what:

1. calls any (search) function with proper parameters (received as
&rest arguments) and then:

2. if resulted (found) point is inside a comment/string, then repeat
1...

Ignoring comments or strings should be driven by parameters (e.g.
ignore-comm-p, ...?). It seems to be logical to require
`font-lock-mode' and proper syntax settings for comments and strings:
then `syntax-ppss' can be used.

I think about something like this:

(defun ignore-comm-str fun str &optional ignore-comm ignore-str &rest
r).

Then it could be called e.g. like
(ignore-comm-str #'re-search-backward "a-nice-re" nil t 100 t) or
(ignore-comm-str #'skip-chars-backward "a-string" t).

I could simply implement this as a function if I would know how to
pass
R to FUN? (I know only macro's `,@' -- is there an equivalent for
functions?)

Could this be solved with advices somehow? (I don't want generally
"redefine" those search functions: instead I would like to have a
comment/string-ignoring variant of them: an ancestor in OO terms...)

Thanks,
P

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

* Re: ignoring comments and/or strings (in source files) by _any_ search function?
  2007-06-25 11:18 ignoring comments and/or strings (in source files) by _any_ search function? Peter Tury
@ 2007-06-25 14:12 ` Peter Tury
  2007-06-29 14:34   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Tury @ 2007-06-25 14:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Jun 25, 1:18 pm, Peter Tury <tury.pe...@gmail.com> wrote:

> I could simply implement this as a function if I would know how to
> pass
> R to FUN? (I know only macro's `,@' -- is there an equivalent for
> functions?)

Meanwhile I realized I can use `apply' for this: (apply fun r) works
fine. Is there another, "better" solution also?

Thanks,
P

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

* Re: ignoring comments and/or strings (in source files) by _any_ search function?
  2007-06-25 14:12 ` Peter Tury
@ 2007-06-29 14:34   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2007-06-29 14:34 UTC (permalink / raw)
  To: help-gnu-emacs

>> I could simply implement this as a function if I would know how to pass
>> R to FUN? (I know only macro's `,@' -- is there an equivalent
>> for functions?)

> Meanwhile I realized I can use `apply' for this: (apply fun r) works
> fine.

That's the way to do it (either `apply' or `funcall' depending on the
situation).

> Is there another, "better" solution also?

The only better way I can think of is to use another language where
`funcall' can be dropped, but since you'll probably need `apply' instead,
I can't think of any way it could be better, really.


        Stefan

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

end of thread, other threads:[~2007-06-29 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-25 11:18 ignoring comments and/or strings (in source files) by _any_ search function? Peter Tury
2007-06-25 14:12 ` Peter Tury
2007-06-29 14:34   ` Stefan Monnier

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.