help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Look for Text Skipping the Comments


From: Andreas Politz
Subject: Re: Look for Text Skipping the Comments
Date: Tue, 29 Sep 2009 22:27:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]