From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: syntax parsing of non-contiguous regions Date: Tue, 22 Sep 2009 07:42:57 +0200 Message-ID: <4AB863E1.6070309@easy-emacs.de> References: <4AB7FBA8.3040404@googlemail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1253598322 12766 80.91.229.12 (22 Sep 2009 05:45:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Sep 2009 05:45:22 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Alexander Katovsky Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 22 07:45:15 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 1MpyBe-0000BC-Rx for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2009 07:45:15 +0200 Original-Received: from localhost ([127.0.0.1]:34653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MpyBe-0006IR-1u for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2009 01:45:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MpyAv-0006Fj-6q for help-gnu-emacs@gnu.org; Tue, 22 Sep 2009 01:44:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MpyAp-0006AY-7D for help-gnu-emacs@gnu.org; Tue, 22 Sep 2009 01:44:27 -0400 Original-Received: from [199.232.76.173] (port=33514 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MpyAo-0006AS-SM for help-gnu-emacs@gnu.org; Tue, 22 Sep 2009 01:44:22 -0400 Original-Received: from moutng.kundenserver.de ([212.227.17.10]:65500) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MpyAn-0006Ht-Sn for help-gnu-emacs@gnu.org; Tue, 22 Sep 2009 01:44:22 -0400 Original-Received: from [192.168.178.27] (p54BE9DF3.dip0.t-ipconnect.de [84.190.157.243]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MKt72-1MpyAj3u0G-000guE; Tue, 22 Sep 2009 07:44:18 +0200 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: <4AB7FBA8.3040404@googlemail.com> X-Provags-ID: V01U2FsdGVkX18fB+z72tPbzL02R76cxsFHxikl95+6Iq45zOD gkrzBlD8wRFSmZljp36D/PyFhN8m4GECTNMRnQpi6eOnCKYRgt oLZWE8rs5Xl/eaPRCa1RoKvSui3WUVGklT9mFcoBlU= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:68365 Archived-At: Alexander Katovsky wrote: > I'm afraid I'm being a little slow understanding you're suggestion. > I've already defined comment-start and comment-end as '!' and '\n' > respectively. Also, I need all the syntax motion functions > (forward-sexp, parse-partial-sexp et al) to treat the embedded code as > a comment so that the embedded code does not disrupt syntax motion > outside. For example, suppose that my primary mode is for code > consisting of named blocks with comments starting with '!' and ending > with newline, and my embedded code is C. Then we could have > > named-block ! some comment > { > %{ > if(a != b){} > }% > } > > Then the syntax motion functions would completely ignore the embedded > code, just as it would a comment. So if point is before the first > opening brace then, no matter what's inside %{}%, forward-sexp would > place point at the last closing brace. And all the other syntax > functions would just 'work' as well! > > I'd be very grateful if could explain in a little more detail exactly > what the 'hide-or-ignore' functions that you suggest are and how they > could be used to achieve this effect. > > Thanks, > Alex > > > > Below a test-implementation, where `forward-sexp' works as expected: (defun my-syntax-mode (arg &optional beg end) " " (interactive "p") (let ((beg (cond (beg beg) ((region-active-p) (region-beginning)) (t (point-min)))) (end (cond (end end) ((region-active-p) (copy-marker (region-end))) (t (point-max)))) ) (save-restriction (narrow-to-region beg end) (goto-char beg)) (my-syntax-mode-intern arg beg end ) (widen))) (defun my-syntax-mode-intern (arg beg end) (let ((comment-start (concat comment-start "\\|%{")) (comment-end (concat comment-end"\|}%"))) (forward-sexp) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Mode was emacs-lisp, tested with (defun foo (&optional beg end) " " (interactive "*") ;; (let ((beg (cond (beg beg) { %{ if(a != b){} }% } ((region-active-p) (region-beginning)) (t (point-min)))) (end (cond (end (copy-marker end)) ((region-active-p) (copy-marker (region-end))) (t (copy-marker (point-max)))))) (save-excursion (goto-char beg)) (when (interactive-p) (message "%s %s" beg end)))) ;;;;;;;;;;;;;;;;;; Cursor starts behind (interactive "*"), passes both comments. So far Andreas