From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.help Subject: identifiing strings and comments in program source files (to skip them over) Date: Wed, 26 Apr 2006 08:38:52 +0200 Message-ID: <444F157C.8080409@gmx.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1146057907 24306 80.91.229.2 (26 Apr 2006 13:25:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 26 Apr 2006 13:25:07 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 26 15:24:54 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FYk0f-0002TC-Bk for geh-help-gnu-emacs@m.gmane.org; Wed, 26 Apr 2006 15:24:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FYk0e-0004a3-Pn for geh-help-gnu-emacs@m.gmane.org; Wed, 26 Apr 2006 09:24:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FYdx4-0003Fa-MI for help-gnu-emacs@gnu.org; Wed, 26 Apr 2006 02:56:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FYdx2-0003E3-F7 for help-gnu-emacs@gnu.org; Wed, 26 Apr 2006 02:56:41 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FYdx2-0003Du-7Y for help-gnu-emacs@gnu.org; Wed, 26 Apr 2006 02:56:40 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1FYdzf-0007RP-36 for help-gnu-emacs@gnu.org; Wed, 26 Apr 2006 02:59:23 -0400 Original-Received: (qmail invoked by alias); 26 Apr 2006 06:56:37 -0000 Original-Received: from N722P027.adsl.highway.telekom.at (EHLO [62.47.34.59]) [62.47.34.59] by mail.gmx.net (mp023) with SMTP; 26 Apr 2006 08:56:37 +0200 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: tury.peter@gmail.com X-Y-GMX-Trusted: 0 X-Mailman-Approved-At: Wed, 26 Apr 2006 09:24:38 -0400 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:34670 Archived-At: > Hi, > > isn't it a good idea to use the face property (get-text-property (point) > 'face) to decide if the point is after a string or comment? > > I have a mode what uses font-lock-mode and highlights everything nicely. Font-lock support modes like jit-lock try to avoid assigning faces to parts of a buffer that are not displayed. Hence, a default Emacs usually does not highlight everything nicely. > I > think I could use this (= the face set by font-lock-mode) for identifiing > if e.g. a search stopped in a string or comment. (I know font-lock-mode > must be enabled for this.) This way I could omit reparsing the buffer (with > parse-partial-sexp) e.g. in a function what searches something "real" (= > strings and comments should be skipped). > > What do you think: can a robust solution be built using this approach? Not really. Fontification is synchronized with redisplay. Determining whether a search stopped in a string or comment, on the other hand, should work independently of whether redisplay happened. In particular, contextual fontification - the thing you see happening when you insert a single double-quote in an elisp buffer - occurs by default not earlier than .5 seconds after you inserted the double-quote - so your search would have to wait until that has been done. Deferred fontification and syntax-table properties get things more complicated even. You could explicitly fontify the area you want to search through, but this might require fontifying the entire buffer and thus would not provide any advantage: After all font-lock would have to reparse the entire buffer for this purpose. To check whether searching stopped in a comment or string you could parse from `beginning-of-defun' or something similar instead - `syntax-ppss' does that.