From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Low level trickery for changing character syntax? Date: Tue, 08 Apr 2014 19:00:34 +0200 Message-ID: <87lhvfzrgt.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1396976394 25548 80.91.229.3 (8 Apr 2014 16:59:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Apr 2014 16:59:54 +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 Apr 08 18:59:47 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 1WXZND-0005oN-J1 for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Apr 2014 18:59:47 +0200 Original-Received: from localhost ([::1]:41994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXZND-0003Bl-8N for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Apr 2014 12:59:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXZMw-0003Aj-Du for help-gnu-emacs@gnu.org; Tue, 08 Apr 2014 12:59:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXZMn-0006c0-RZ for help-gnu-emacs@gnu.org; Tue, 08 Apr 2014 12:59:30 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:42342) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXZMn-0006bW-KZ for help-gnu-emacs@gnu.org; Tue, 08 Apr 2014 12:59:21 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WXZMm-0005Xw-Aw for help-gnu-emacs@gnu.org; Tue, 08 Apr 2014 18:59:20 +0200 Original-Received: from g231233202.adsl.alicedsl.de ([92.231.233.202]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 08 Apr 2014 18:59:20 +0200 Original-Received: from tjolitz by g231233202.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 08 Apr 2014 18:59:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 73 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231233202.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:q+DBCmZkNU8dFT4KUWoU5FjGWA0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:97046 Archived-At: 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? -- cheers, Thorsten