From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Regexps and strings once again Date: Mon, 15 Sep 2014 01:27:51 +0200 Organization: Programmerer Ingebrigtsen Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410737435 13139 80.91.229.3 (14 Sep 2014 23:30:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Sep 2014 23:30:35 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 15 01:30:29 2014 Return-path: Envelope-to: ged-emacs-devel@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 1XTJFL-0006nx-HA for ged-emacs-devel@m.gmane.org; Mon, 15 Sep 2014 01:30:19 +0200 Original-Received: from localhost ([::1]:56507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTJFK-0003Rs-U0 for ged-emacs-devel@m.gmane.org; Sun, 14 Sep 2014 19:30:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTJFC-0003Qo-0n for emacs-devel@gnu.org; Sun, 14 Sep 2014 19:30:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTJF5-0005ra-Px for emacs-devel@gnu.org; Sun, 14 Sep 2014 19:30:09 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:59176) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTJF5-0005ns-It for emacs-devel@gnu.org; Sun, 14 Sep 2014 19:30:03 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XTJEQ-0006Cd-DF for emacs-devel@gnu.org; Mon, 15 Sep 2014 01:29:22 +0200 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 15 Sep 2014 01:29:22 +0200 Original-Received: from larsi by cm-84.215.51.58.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 15 Sep 2014 01:29:22 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 62 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.215.51.58.getinternet.no Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEUxKx/+/rNuZkrm4Z22 rHr69qi1I0waAAACVElEQVQ4jXWTzZKlIAyFU7QvYHnZU5G7Hw3s6STux+by/q8yQaye7poeFmrx mZMfDtDO+ccF/9mf4X639gOoIklIiM7vgLYslAxUoe0rWEiEtOWWyNb2F+SWZRfNSXLXo8+qGpHU F6ntyTYbzTdItUtUe9aU5/wQyZ8R2ddzOc/FvpLukmWAzQtZalVqPVSfjwGq1GNmdKqs5LtsklHV Qs8dbN+AivckN7DaGQBiiMwaxW9Lr8ukPFWYqCIoKmOShfzIkX1ZqaXgkgriHtvVfh/7sh9KtbjM iK44md/rKDfxE9fGKBVxKi6efSx97Agr0guchUQFh0cdUsseA+btY8JYwmpAlpF8WSQ4oeJItawA Lm75npUGYATQGItC16JRFRVrrwYIqGU34GgZUqm4Sc4PAIx7sdk4aRd4KHPMi4XgegGIo6qqGrRa IsermqoCDvAr2pjk8DCl1cqACPH9Ah9BWeppgEosFziG1OOtPLf5AZOwhF6VjgbtCHGa598mpam3 gfsAfkkfuwqXSSsDAnJ4XuD1Sq9kaXZ3VLaagWFEsA0cMFCKZ0LEAOUGOwYXop2inYllsHbcAP03 O6CJjtbNUhxPA1AnDl3KidGmYKe7johDFUM3nBmCTapg7OA0N3tzm0ZVF5VhAh0RRVrN3bVmHwu1 zu8Im3Q0v7ea+jZAGKD1UqxdxBi5v6wQni7wMuFum57EjG1nwCPCbgar/ReTXIVZ+AAvZWcy2P/X 1I0dbmCXoO8ms88FY3kbUt+WXVq7iee/oK/Tf404zUzn9WXbs/8DGYi/i6QsQTsAAAAASUVORK5C YII= Mail-Copies-To: never X-Now-Playing: Baby Dee's _Goes Down to Amsterdam (2)_: "Dance of Diminishing Possibilities" User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:GeYNHiuqU+WKblsXXX2V8EU1wgc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:174299 Archived-At: (Skip to 1) if you're not interested in why I started thinking about this now.) I was just fiddling around with a DOM traversal library (i.e., "document object model", or something -- HTML traversal, like), and it has functions for finding nodes by various criteria, like IDs. So there are functions like `dom-by-id' that take a DOM fragment and an ID and returns the matching nodes. I wrote the function as taking a regexp. And I find what I'm doing wrong 90% of the time when using it is that I expect an exact match, but instead I'm getting all matching nodes. This reminded me of this pretty general problem once again. We have oodles of functions in Emacs that does matching either on exact(ish) strings, or regexps, and then we have an optional parameter that says whether we want to interpret the string as an exact string or a parameter. It's kinda annoying, especially when the function defaults to the interpretation you don't want. And you have to remember which optional parameter you're supposed to set. So: Here's yet another suggestion for how to deal with regexps in a more general way in Emacs. Or rather two. 1) New Special Syntax A while ago, there was some suggestion about introducing a special syntax for string literals, and it didn't really go anywhere, because introducing a new syntax to Emacs is kinda a big deal. But let's just suggest it anyway: (dom-by-id dom #/I (can)?haz new syntax/) And see! Perl Regexp syntax as well! No more backslashitis! Anyway, I assume that everybody would want this, but that it's too much work for anybody to actually commit to. 2) Cheat; i.e., introduce a convention What if we just mark a string as a regexp? (dom-by-id dom (regexp "I \\(couldn't\\)?haz new syntax")) It would basically just put a text property on the string, and functions like `dom-by-id' would just do (if (regexp-p match) (string-match match id) (string= match id)) Of course, both `regexp' and the proposed new syntax could compile the regexp and return a regexp object and stuff if we wanted to be more efficient... But the regexp cache is already quite efficient, isn't it? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no