From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Look for Text Skipping the Comments Date: Tue, 29 Sep 2009 22:27:30 +0200 Message-ID: <877hvhbiod.fsf@fh-trier.de> References: <4AC23266.8000706@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1254256157 31671 80.91.229.12 (29 Sep 2009 20:29:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Sep 2009 20:29:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 29 22:29:10 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MsjJs-0007N7-De for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Sep 2009 22:29:09 +0200 Original-Received: from localhost ([127.0.0.1]:56250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsjJr-000120-SC for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Sep 2009 16:29:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsjJJ-0000xy-4E for help-gnu-emacs@gnu.org; Tue, 29 Sep 2009 16:28:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsjJE-0000ww-7o for help-gnu-emacs@gnu.org; Tue, 29 Sep 2009 16:28:32 -0400 Original-Received: from [199.232.76.173] (port=37184 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsjJE-0000ws-2O for help-gnu-emacs@gnu.org; Tue, 29 Sep 2009 16:28:28 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:47784) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MsjJD-0007IM-Mu for help-gnu-emacs@gnu.org; Tue, 29 Sep 2009 16:28:27 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1MsjIo-0006pb-AJ for help-gnu-emacs@gnu.org; Tue, 29 Sep 2009 22:28:02 +0200 Original-Received: from dslb-084-059-220-159.pools.arcor-ip.net ([84.59.220.159]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Sep 2009 22:28:02 +0200 Original-Received: from politza by dslb-084-059-220-159.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Sep 2009 22:28:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 54 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-084-059-220-159.pools.arcor-ip.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:VdLp1gT4vqzp5R4boQicPkb5w/k= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68541 Archived-At: Lorenzo Isella 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