From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-15?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: Low level trickery for changing character syntax? Date: Wed, 09 Apr 2014 07:59:03 +0200 Message-ID: <5344E1A7.50900@easy-emacs.de> References: <87lhvfzrgt.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1397022892 6669 80.91.229.3 (9 Apr 2014 05:54:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Apr 2014 05:54:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 09 07:54:43 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WXlT8-00074x-Sp for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Apr 2014 07:54:42 +0200 Original-Received: from localhost ([::1]:44479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlT8-0002Qo-Fv for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Apr 2014 01:54:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlSr-0002Qj-D0 for help-gnu-emacs@gnu.org; Wed, 09 Apr 2014 01:54:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXlSj-0008SH-Tn for help-gnu-emacs@gnu.org; Wed, 09 Apr 2014 01:54:25 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.131]:53063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlSj-0008RM-Do for help-gnu-emacs@gnu.org; Wed, 09 Apr 2014 01:54:17 -0400 Original-Received: from purzel.sitgens (brln-4d0c5b3a.pool.mediaWays.net [77.12.91.58]) by mrelayeu.kundenserver.de (node=mreue007) with ESMTP (Nemesis) id 0MCT7F-1Wgo1H33PV-009BT6; Wed, 09 Apr 2014 07:54:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <87lhvfzrgt.fsf@gmail.com> X-Provags-ID: V02:K0:SE+5DCCWr+gnWc0/sGmi4XGXMbrNIY4j2wWy/izkOhf VTxdlTHN6bjW7yh0q2p2uqyebf7zqpZG14+FdGlIZLpO9jN5gK rmlIpBCDRp/QPTErq0i4+gwu1juWDGrQl7yR+NJCUhn0snHKhd 7NkaNXgCa35+LKqiVY1RYeBuoqRLiAnqAknUzKXeC84mlu9v9G VyjwfEOgbbkQApfg6GiYEZuYnryfKUduh/Jh8BL9T9iS4MqO/9 jc/rmf4EzQslN2+GZE+WgiOTUd6ETkD1xGRv32CwvXMLqRz4pz aFiY2bOVh7uwFflpDvKy0Aj2q0Cu1paDSix+VOiuyVDYTfB29N 8LIzdxFlJyMFzhpfrGFo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 212.227.126.131 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97050 Archived-At: Am 08.04.2014 19:00, schrieb Thorsten Jolitz: > > Hi List, > > assume an imaginary elisp library gro.el I cannot (or don't want to) > change that is used on files of type A, with functions matching these > kinds of strings: > > #+begin_src emacs-lisp > (defconst rgxp-1 "^[*] [*]Fat[*]$") > > (defun foo (strg) > (and (string-match "^\\*+[ \t]* \\*.+\\*" strg) > (string-match rgxp-1 strg))) > #+end_src > > #+results: > : foo > > #+begin_src emacs-lisp > (foo "* *Fat*") > #+end_src > > #+results: > : 0 > > #+begin_src emacs-lisp > (foo "+ *Fat*") > #+end_src > > #+results: > > Now assume I want to use gro.el functionality on files of type B > such that it matches strings likes this: > > #+begin_src emacs-lisp > (foo "// # *Fat*//" ) > #+end_src > > In short, when called from file.type-A, I want foo to match "// # > *Fat*//", while it should only match "* *Fat*" when called from > file.type-B (without changing foo or rgxp-1). > > Thus in rgxp-1 and in foo, "^" would need to be replaced with "^// ", > the first "*" would need to be replaced with "#" (the other occurences > not), and "$" would need to be replaced with "//$". > > Now I wonder what would be the best way (or at least a possible way) to > achieve this with Emacs low-level trickery (almost) without touching > gro.el. I don't enough know about syntax table low-level stuff besides > reading the manual, so these are only vague speculations: > > 1. Change the syntax-table of gro.el whenever it is applied to files of > type B such that "^" is seen as "^// ", "*" as "#" etc.? > > 2. Define new categories and put "^" "*" and "$" in them, and somehow > load/activate these categories conditional on the type of file gro.el > functionality is called upon. These categories should then achieve that > "^" is seen as "^// " etc when the categories are loaded? > > 3. Define "^" and "$", when found at beg/end of a string, as 'generic > comment delimiter, and define "/" as generic comment delimiter too, such > that "^//" and "//$" are matched by "^" and "$"? > > I know that these ideas do not and cannot work as described, but I'm > looking for a hint which idea could possibly work? What would be the way > to go? > > Or is this completely unrealistic and the only way to achieve it is to > change the hardcoded regexps in (imaginary) library gro.el? > You could define different syntax-tables and than call functions if type-A (with-syntax-table type-A ...