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: Thu, 09 Aug 2018 17:03:03 +0100 Message-ID: <8736vny1c8.fsf@konghq.com> References: <87h8k88l47.fsf@konghq.com> <87effc8kj1.fsf@konghq.com> <8736vsz0mo.fsf@gmail.com> <878t5j9674.fsf@konghq.com> <87mutzxq3k.fsf@gmail.com> <87600m8vn9.fsf@konghq.com> <87600m48pq.fsf@violet.siamics.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1533830594 17111 195.159.176.226 (9 Aug 2018 16:03:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 9 Aug 2018 16:03:14 +0000 (UTC) Cc: Noam Postavsky To: Ivan Shmakov , 32372@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 09 18:03:09 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 1fnnP1-0004JW-TB for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Aug 2018 18:03:08 +0200 Original-Received: from localhost ([::1]:51756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnnR8-0006eD-BZ for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Aug 2018 12:05:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnnQy-0006ZC-HD for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2018 12:05:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnnQs-00057F-Bw for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2018 12:05:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnnQs-000579-4n for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2018 12:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fnnQr-00019m-QP for bug-gnu-emacs@gnu.org; Thu, 09 Aug 2018 12:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Raimon Grau Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 Aug 2018 16:05:01 +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.15338306904424 (code B ref 32372); Thu, 09 Aug 2018 16:05:01 +0000 Original-Received: (at 32372) by debbugs.gnu.org; 9 Aug 2018 16:04:50 +0000 Original-Received: from localhost ([127.0.0.1]:46074 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnnQf-00019I-DN for submit@debbugs.gnu.org; Thu, 09 Aug 2018 12:04:49 -0400 Original-Received: from mail-wm0-f51.google.com ([74.125.82.51]:39814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnnQd-000194-Bg for 32372@debbugs.gnu.org; Thu, 09 Aug 2018 12:04:48 -0400 Original-Received: by mail-wm0-f51.google.com with SMTP id q8-v6so815020wmq.4 for <32372@debbugs.gnu.org>; Thu, 09 Aug 2018 09:04:47 -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=lYkdO+CxVv1UAUFPwxl1XizaEHPx1WOEQkEQw8F95nw=; b=QicUhiee2+7nN74Cr+mGKhWrx+7/7bQ8uOaw4lq14Cxvwt5rz0mXUzR5V3iAHEWIx7 T2tG7lUvee6jh9bQFLSf77I2FhHO0PkK1572khvz89zYrUr41CaKwdXUJApDB8DKFrS2 PkPjuVE1R8xmWrAO3tlIjZnkloiAPSE8ESnc8= 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=lYkdO+CxVv1UAUFPwxl1XizaEHPx1WOEQkEQw8F95nw=; b=LByDC0LOncWcx90Q17ssS6gas0lWvOdGCZDEGX3Ag5eK8AXPZu0VyfI+CcCQU3Jzac POlidFagTsi7I0XnROqCHeyWL0OT4XP6ru/+pb3SVmeSgYCgO33Q5NQma9xumSkCo+6s j0QifII+7WsFygriK7Vs9z8p9xOoqWJk6atpVrABYmdR/qfadv2G0C1JwF5lwU5dxhmP mqwDVuATAqme9ArD/mf1xK0ivehZqgBMJOkkIybY0GklFeD3x/NQJrJnsNHYVvK4DiAj xFXYag2Ei86g+jDxcHONJY+eHemxtBimrkii0KDDx3Q6BCivWpFex+K3fdrz7P4gwV9L NJoA== X-Gm-Message-State: AOUpUlFR4D7Orwh2igynhuKjfg/aMAr9ukLwGzWmZnxYpLS+wweBKu0N ZXSxqt9gqK39F4M62AE3cVpmbQ== X-Google-Smtp-Source: AA+uWPwvUo0YVIkbvpOd3bMCjHIX9/4xlR/EGNS40vOxBCK/FhctY94DVUf+78wZ/GVyaI8kwYzy4w== X-Received: by 2002:a7b:c013:: with SMTP id c19-v6mr2045280wmb.53.1533830681720; Thu, 09 Aug 2018 09:04:41 -0700 (PDT) Original-Received: from raikong (55.19.183.185.dyn.akiwifi.com. [185.183.19.55]) by smtp.gmail.com with ESMTPSA id f6-v6sm7433856wrw.78.2018.08.09.09.04.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 09:04:40 -0700 (PDT) X-Google-Original-From: Raimon Grau In-Reply-To: <87600m48pq.fsf@violet.siamics.net> 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:149382 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ivan Shmakov writes: >>>>>> Raimon Grau writes: > > A few minor points. > > [=E2=80=A6] > > > +--- > > +** 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. > > I think the latter UUID should be spelled in all-caps. > Done. > > > +;; UUID > > + > > +(defvar thing-at-point-uuid-regexp > > There seem to be no precedent on the use of defconst in > thingatpt.el, but given that the UUID format is ought to be > stable, I guess this would be exactly the place for one. Or? > > > + (rx 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." ) > > AIUI, the docstrings are not indented like that; also, there > should be no blank before the closing parenthesis. > > Given that there seem to be no URL references in thingatpt.el > docstrings, either, I=E2=80=99d rather rewrite this one as: > > + "A regular expression matching a UUID. > + > +See RFC 4122 for the description of the format.") > True that there usually aren't urls in the docstrings like that , I used your suggested string now. > > + > > +(put 'uuid 'bounds-of-thing-at-point > > + (lambda () > > + (let ((thing (thing-at-point-looking-at > > + thing-at-point-uuid-regexp 36))) > > + (if thing > > + (let ((beginning (match-beginning 0)) > > + (end (match-end 0))) > > + (cons beginning end)))))) > > Why not simplify to (cons (match-beginning 0) (match-end 0))? > I used the even more succint form of a single `and'. I hope it doesn't hurt= readability. If the consensus is "yes, it's ok" I'll unify the style in o= ther places of the same file in a future patch. Thanks all for the suggestions, Raimon Grau --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-uuid-as-allowed-thingatpt-symbol.patch >From 0c7e3baea026acb83b1ba4fc7035675edce0e3bf 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 | 25 ++++++++++++++++++++++--- test/lisp/thingatpt-tests.el | 5 ++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index a1c12a6..57b2586 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..1e82e7b 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,25 @@ thing-at-point-email-regexp (put 'buffer 'end-op (lambda () (goto-char (point-max)))) (put 'buffer 'beginning-op (lambda () (goto-char (point-min)))) +;; UUID + +(defconst thing-at-point-uuid-regexp + (rx 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. + +See RFC 4122 for the description of the format.") + +(put 'uuid 'bounds-of-thing-at-point + (lambda () + (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) + (cons (match-beginning 0) (match-end 0))))) + ;; 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 --=-=-=--