Package: emacs;
Reported by: Raimon Grau <raimon <at> konghq.com>
Date: Sun, 5 Aug 2018 23:14:02 UTC
Severity: wishlist
Tags: fixed, patch
Fixed in version 27.1
Done: Noam Postavsky <npostavs <at> gmail.com>
Bug is archived. No further changes may be made.
Message #34 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Raimon Grau <raimon <at> konghq.com> To: Ivan Shmakov <ivan <at> siamics.net>, 32372 <at> debbugs.gnu.org Cc: Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Thu, 09 Aug 2018 17:03:03 +0100
[Message part 1 (text/plain, inline)]
Ivan Shmakov <ivan <at> siamics.net> writes: >>>>>> Raimon Grau <raimon <at> konghq.com> writes: > > A few minor points. > > […] > > > +--- > > +** 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’d 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 other places of the same file in a future patch. Thanks all for the suggestions, Raimon Grau
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From 0c7e3baea026acb83b1ba4fc7035675edce0e3bf Mon Sep 17 00:00:00 2001 From: Raimon Grau <raimonster <at> gmail.com> 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 ("<url:foo <at> example.com>" 1 url "mailto:foo <at> example.com") - ("<url:ftp.example.net/abc/>" 1 url "ftp://ftp.example.net/abc/")) + ("<url: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
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.