From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Raimon Grau Newsgroups: gmane.emacs.bugs Subject: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 10:48:15 +0100 Message-ID: <878t5j9674.fsf@konghq.com> References: <87h8k88l47.fsf@konghq.com> <87effc8kj1.fsf@konghq.com> <8736vsz0mo.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1533548888 5988 195.159.176.226 (6 Aug 2018 09:48:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 6 Aug 2018 09:48:08 +0000 (UTC) Cc: 32372@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 06 11:48:04 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmc7O-0001Ro-MM for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Aug 2018 11:48:03 +0200 Original-Received: from localhost ([::1]:33200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmc9V-0007Zs-FQ for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Aug 2018 05:50:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmc9O-0007Zl-7Q for bug-gnu-emacs@gnu.org; Mon, 06 Aug 2018 05:50:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmc9L-0006K0-3B for bug-gnu-emacs@gnu.org; Mon, 06 Aug 2018 05:50:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmc9K-0006Jq-Pw for bug-gnu-emacs@gnu.org; Mon, 06 Aug 2018 05:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fmc9K-0006n7-Hn for bug-gnu-emacs@gnu.org; Mon, 06 Aug 2018 05:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Raimon Grau Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Aug 2018 09:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32372 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 32372-submit@debbugs.gnu.org id=B32372.153354899726091 (code B ref 32372); Mon, 06 Aug 2018 09:50:02 +0000 Original-Received: (at 32372) by debbugs.gnu.org; 6 Aug 2018 09:49:57 +0000 Original-Received: from localhost ([127.0.0.1]:42289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmc9F-0006mk-0d for submit@debbugs.gnu.org; Mon, 06 Aug 2018 05:49:57 -0400 Original-Received: from mail-wm0-f65.google.com ([74.125.82.65]:51572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmc9D-0006mX-5Z for 32372@debbugs.gnu.org; Mon, 06 Aug 2018 05:49:55 -0400 Original-Received: by mail-wm0-f65.google.com with SMTP id y2-v6so13174606wma.1 for <32372@debbugs.gnu.org>; Mon, 06 Aug 2018 02:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konghq.com; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=hzgxKNa1eUkgfvt9OhJK8NoXXAXHZ17PQ7hVoQAMSNw=; b=bA3ENvv8ubgghQEshM5zvtMQhwSXj3nPorqY/+ZiRwzp4ytMVvEOosLMC+VNZnu1oc O0H95YbkltSu1jwNOLlrN7creYhsBeOjbzRvH38e5m8OGHrRkkbP8s4BD1cFmxWGBabh CRUh6zBCq2n9l0W2h9TEsndOVJCOqFgRbwDP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=hzgxKNa1eUkgfvt9OhJK8NoXXAXHZ17PQ7hVoQAMSNw=; b=G3R78C537E6VfkIz8EVX3uthyYSf9tEUpV29doUdDyUN2fZZYVBXZ5QQBalwfLM9m2 5UPQmPxhi0U2Ul/uFRKlrm07WAMOUYwn7rXJEg7pl6pl4f2SA2NGtIdgIIuYOdiHQFUF dmJ872im0Ba09ZtWyuqLmlkX0gd3AXBmK1K1Xm/MFzH1GwWdbEbKZDLymlKwUnYQWWr8 HHg8FsEHnoO+o6+huRFRsG+4qI+uWaepltKHgwaCXTlLGNQbrE4JGa6U1Ay8KcXTvAy2 y0F2WADWnGk0itWHtFh8VIuDRtwx01bFKcbbG61nZncpKF79ZFUlTNxRxsPK35qM0sAF Ko2Q== X-Gm-Message-State: AOUpUlFayJKsYw+87y8zQ4IWfrpufxW1q75q+SJig5o9mbP4co4V75nG E++Kik0Jq4UBDgBPeoqIoN7HE/3UoCw= X-Google-Smtp-Source: AAOMgpcxT9bQ4NxXV91LrteT6nb48mM7ahS/tcUCmqu8UteB1Xot2OjbeswMNuEEC1UO9zfTjccS0A== X-Received: by 2002:a1c:b984:: with SMTP id j126-v6mr10725072wmf.25.1533548989126; Mon, 06 Aug 2018 02:49:49 -0700 (PDT) Original-Received: from raikong (81.61.106.180.dyn.user.ono.com. [81.61.106.180]) by smtp.gmail.com with ESMTPSA id v5-v6sm8991888wru.60.2018.08.06.02.49.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 02:49:48 -0700 (PDT) X-Google-Original-From: Raimon Grau In-Reply-To: <8736vsz0mo.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:149279 Archived-At: --=-=-= Content-Type: text/plain Noam Postavsky writes: > severity 32372 wishlist > quit > > Raimon Grau writes: > >> Subject: [PATCH] Add uuid as allowed thingatpt symbol >> >> * lisp/thingatpt.el (thing-at-point-uuid-regexp): Add regexp for uuid. > > I guess you should mention something about the ops as well here. Though > it's not 100% clear what kind of format you should use for those. Maybe > just (top-level): Add 'bounds-of-thing-at-point' operation for 'uuid'. Aha. Added it. > >> +;; UUID >> + >> +(defvar thing-at-point-uuid-regexp >> + (rx (and bow > > Using rx is okay, I think. There was some discussion about it on > emacs-devel a little time ago, with most people saying the increased > verbosity made them not want to use it, but I kind of like it myself. > However, Stefan made the point that `and' is potentially a bit > confusing, because it could be misread as intersection. It's better to > use one of the synonyms `seq' or `:'. > >> + (or >> + "00000000-0000-0000-0000-000000000000" >> + (and >> + (repeat 8 hex-digit) "-" >> + (repeat 4 hex-digit) "-" >> + (or "1" "2" "3" "4" "5") >> + (repeat 3 hex-digit) "-" >> + (or "8" "9" "a" "b" "A" "B") >> + (repeat 3 hex-digit) "-" >> + (repeat 12 hex-digit))) >> + eow)) >> + "A regular expression matching a UUID from versions 1 to 5. >> + >> + More info on uuid's format in >> + https://tools.ietf.org/html/rfc4122." ) > > So, in that RFC I see this grammar > > UUID = time-low "-" time-mid "-" > time-high-and-version "-" > clock-seq-and-reserved > clock-seq-low "-" node > time-low = 4hexOctet > time-mid = 2hexOctet > time-high-and-version = 2hexOctet > clock-seq-and-reserved = hexOctet > clock-seq-low = hexOctet > node = 6hexOctet > hexOctet = hexDigit hexDigit > hexDigit = > "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / > "a" / "b" / "c" / "d" / "e" / "f" / > "A" / "B" / "C" / "D" / "E" / "F" > > It looks like you crafted a regexp which is a tighter match for just the > UUID versions currently in use. I think we're better off with the > looser definition though, that way it will continue to be correct even > as new versions come out. > > Furthermore, I would guess a human user is going to be surprised if > (thing-at-point 'uuid) picks up this > > 12345678-1234-1234-8123-123456789012 > > but not this: > > 12345678-1234-1234-5123-123456789012 > Completely agree. Now using a simpler version that will be more predictable for users. > >> +(put 'uuid 'thing-at-point >> + (lambda () >> + (let ((boundary-pair (bounds-of-thing-at-point 'uuid))) >> + (if boundary-pair >> + (buffer-substring-no-properties >> + (car boundary-pair) (cdr boundary-pair)))))) > > I think this isn't needed, because the `thing-at-point' function already > does this for you: > > (let ((text > (if (get thing 'thing-at-point) > (funcall (get thing 'thing-at-point)) > (let ((bounds (bounds-of-thing-at-point thing))) > (when bounds > (buffer-substring (car bounds) (cdr bounds))))))) Right. I removed it. Thanks for the review! I fixed all the points raised. Cheers, Raimon Grau --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-uuid-as-allowed-thingatpt-symbol.patch >From ac14cf6841ae7c8aa09897e7e6f06814961462fa Mon Sep 17 00:00:00 2001 From: Raimon Grau Date: Sun, 5 Aug 2018 22:47:30 +0100 Subject: [PATCH] Add uuid as allowed thingatpt symbol * etc/NEWS: Mention changes in thingatpt.el. * lisp/thingatpt.el (thing-at-point-uuid-regexp): Add regexp for uuid. (top-level): Add 'bounds-of-thing-at-point' operation for 'uuid'. * test/lisp/thingatpt-tests.el: Add tests for uuid at point. --- etc/NEWS | 6 ++++++ lisp/thingatpt.el | 30 +++++++++++++++++++++++++++--- test/lisp/thingatpt-tests.el | 5 ++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index a1c12a6..ee94572 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -96,6 +96,12 @@ option 'vc-hg-symbolic-revision-styles' to the value '("{rev}")'. --- ** shadowfile.el has been rewritten to support Tramp file names. +--- +** thingatpt.el supports a new "thing" called 'uuid'. + +A symbol 'uuid' can be passed to thing-at-point and it returns the +uuid at point. + * New Modes and Packages in Emacs 26.2 diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 6a978fe..5523a34 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -58,7 +58,7 @@ forward-thing "Move forward to the end of the Nth next THING. THING should be a symbol specifying a type of syntactic entity. Possibilities include `symbol', `list', `sexp', `defun', -`filename', `url', `email', `word', `sentence', `whitespace', +`filename', `url', `email', `uuid', `word', `sentence', `whitespace', `line', and `page'." (let ((forward-op (or (get thing 'forward-op) (intern-soft (format "forward-%s" thing))))) @@ -73,7 +73,7 @@ bounds-of-thing-at-point "Determine the start and end buffer locations for the THING at point. THING should be a symbol specifying a type of syntactic entity. Possibilities include `symbol', `list', `sexp', `defun', -`filename', `url', `email', `word', `sentence', `whitespace', +`filename', `url', `email', `uuid', `word', `sentence', `whitespace', `line', and `page'. See the file `thingatpt.el' for documentation on how to define a @@ -131,7 +131,7 @@ thing-at-point "Return the THING at point. THING should be a symbol specifying a type of syntactic entity. Possibilities include `symbol', `list', `sexp', `defun', -`filename', `url', `email', `word', `sentence', `whitespace', +`filename', `url', `email', `uuid', `word', `sentence', `whitespace', `line', `number', and `page'. When the optional argument NO-PROPERTIES is non-nil, @@ -554,6 +554,30 @@ thing-at-point-email-regexp (put 'buffer 'end-op (lambda () (goto-char (point-max)))) (put 'buffer 'beginning-op (lambda () (goto-char (point-min)))) +;; UUID + +(defvar thing-at-point-uuid-regexp + (rx (seq bow + (repeat 8 hex-digit) "-" + (repeat 4 hex-digit) "-" + (repeat 4 hex-digit) "-" + (repeat 4 hex-digit) "-" + (repeat 12 hex-digit) + eow)) + "A regular expression matching a UUID. + + More info on uuid's format in + https://tools.ietf.org/html/rfc4122." ) + +(put 'uuid 'bounds-of-thing-at-point + (lambda () + (let ((thing (thing-at-point-looking-at + thing-at-point-uuid-regexp 500))) + (if thing + (let ((beginning (match-beginning 0)) + (end (match-end 0))) + (cons beginning end)))))) + ;; Aliases (defun word-at-point () diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index cfb57de..b4a5fd9 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -65,7 +65,10 @@ thing-at-point-test-data ("http://example.com/ab)c" 4 url "http://example.com/ab)c") ;; URL markup, lacking schema ("" 1 url "mailto:foo@example.com") - ("" 1 url "ftp://ftp.example.net/abc/")) + ("" 1 url "ftp://ftp.example.net/abc/") + ;; UUID, only hex is allowed + ("01234567-89ab-cdef-ABCD-EF0123456789" 1 uuid "01234567-89ab-cdef-ABCD-EF0123456789") + ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil)) "List of thing-at-point tests. Each list element should have the form -- 2.7.4 --=-=-=--