unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Look for Text Skipping the Comments
@ 2009-09-29 16:14 Lorenzo Isella
  2009-09-29 18:51 ` Peter Dyballa
  2009-09-29 20:27 ` Andreas Politz
  0 siblings, 2 replies; 3+ messages in thread
From: Lorenzo Isella @ 2009-09-29 16:14 UTC (permalink / raw)
  To: help-gnu-emacs

Dear All,
Suppose you are writing some code with a lot of documentation in the 
form of comments within the code itself. Now, if you use C-s to look for 
a word, emacs will also search though the comments.
Is there a way to tell emacs that it should look for a 
word/expression/string skipping the comments?
Many thanks

Lorenzo




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

* Re: Look for Text Skipping the Comments
  2009-09-29 16:14 Look for Text Skipping the Comments Lorenzo Isella
@ 2009-09-29 18:51 ` Peter Dyballa
  2009-09-29 20:27 ` Andreas Politz
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Dyballa @ 2009-09-29 18:51 UTC (permalink / raw)
  To: Lorenzo Isella; +Cc: help-gnu-emacs


Am 29.09.2009 um 18:14 schrieb Lorenzo Isella:

> Is there a way to tell emacs that it should look for a word/ 
> expression/string skipping the comments?

Isearch-forward-regexp? With a regexp which does exclude the comment  
character?

--
Greetings

   Pete

Let's face it; we don't want a free market economy either.
		– James Farley, president, Coca-Cola Export Corp., 1959







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

* Re: Look for Text Skipping the Comments
  2009-09-29 16:14 Look for Text Skipping the Comments Lorenzo Isella
  2009-09-29 18:51 ` Peter Dyballa
@ 2009-09-29 20:27 ` Andreas Politz
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Politz @ 2009-09-29 20:27 UTC (permalink / raw)
  To: help-gnu-emacs

Lorenzo Isella <lorenzo.isella@gmail.com> writes:

> Dear All,
> Suppose you are writing some code with a lot of documentation in the
> form of comments within the code itself. Now, if you use C-s to look
> for a word, emacs will also search though the comments.
> Is there a way to tell emacs that it should look for a
> word/expression/string skipping the comments?
> Many thanks
>
> Lorenzo

Originally I wrote this for following buttons in a help buffer.

(defun isearch-with-predicate (predicate
                               indicator
                               &optional backward regexp)
  (let ((isearch-search-fun-function
         #'(lambda nil
             #'(lambda (string &optional bound no-error)
                 (isearch-with-predicate-search-fn
                  predicate string bound no-error))))
        (isearch-message-prefix-add indicator))
    (isearch-mode (not backward) regexp nil t)))

(defun isearch-with-predicate-search-fn (predicate
                                         string
                                         &optional bound no-error)
  (let* (isearch-search-fun-function
         (search-fun  (isearch-search-fun))
         found
         limit)
    (save-excursion
      (while (and (setq found
                        (funcall search-fun string bound no-error))
                  (not (setq found
                             (and (save-match-data
                                    (funcall predicate)) found)))))
        
      (setq limit (point)))
    (if found
        (goto-char found)
      (when (not (eq no-error t))
        (goto-char limit)
        nil))))

(defun isearch-nocomment (&optional backward regexp)
  (interactive)
  (isearch-with-predicate #'(lambda nil
                              (not (nth 4 (syntax-ppss))))
                          "(NoComments)"
                          backward regexp))

-ap





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

end of thread, other threads:[~2009-09-29 20:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-29 16:14 Look for Text Skipping the Comments Lorenzo Isella
2009-09-29 18:51 ` Peter Dyballa
2009-09-29 20:27 ` Andreas Politz

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).