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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32372 in the body.
You can then email your comments to 32372 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Sun, 05 Aug 2018 23:14:02 GMT) Full text and rfc822 format available.Raimon Grau <raimon <at> konghq.com>
:bug-gnu-emacs <at> gnu.org
.
(Sun, 05 Aug 2018 23:14:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Raimon Grau <raimon <at> konghq.com> To: bug-gnu-emacs <at> gnu.org Subject: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 00:11:20 +0100
[Message part 1 (text/plain, inline)]
Hi, I've added UUID to thing-at-point. I think it's a standard enough format that makes sense to have it in the core. It's my 2nd contribution, so still getting used to the tools and standards. The implementation relies on a regular expression to accept the different versions of uuids (versions 1 to 5), and also the "Nil UUID". I'm using rx as it makes clearer the intent of what we're parsing at each point. I hope it's ok to use it (I don't see it used a lot in emacs itself). If there are any comments or fixes to do, point them out and I'll make the changes accordingly. Thanks, Raimon Grau
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From faacdadc1beba467b915b65ffd668b9e6c3a1d41 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 | 6 ++++++ lisp/thingatpt.el | 41 ++++++++++++++++++++++++++++++++++++++--- test/lisp/thingatpt-tests.el | 11 ++++++++++- 3 files changed, 54 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..ca8a5bd 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,41 @@ 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 (and bow + (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." ) +(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)))))) + +(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)))))) + ;; Aliases (defun word-at-point () diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index cfb57de..e8e9b6e 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -65,7 +65,16 @@ 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 + ("12345678-1234-1234-8123-123456789012" 1 uuid "12345678-1234-1234-8123-123456789012") + ("12345678-1234-2234-9123-123456789012" 1 uuid "12345678-1234-2234-9123-123456789012") + ("12345678-1234-3234-a123-123456789012" 1 uuid "12345678-1234-3234-a123-123456789012") + ("12345678-1234-4234-b123-123456789012" 1 uuid "12345678-1234-4234-b123-123456789012") + ("12345678-1234-5234-b123-123456789012" 1 uuid "12345678-1234-5234-b123-123456789012") + ("00000000-0000-0000-0000-000000000000" 1 uuid "00000000-0000-0000-0000-000000000000") + ("12345678-1234-4234-1123-123456789012" 1 uuid nil) + ("12345678-1234-6aaa-1123-123456789012" 1 uuid nil)) "List of thing-at-point tests. Each list element should have the form -- 2.7.4
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Sun, 05 Aug 2018 23:26:01 GMT) Full text and rfc822 format available.Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Raimon Grau <raimon <at> konghq.com> To: bug-gnu-emacs <at> gnu.org Subject: Re: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 00:24:02 +0100
[Message part 1 (text/plain, inline)]
Raimon Grau <raimon <at> konghq.com> writes: > Hi, > > I've added UUID to thing-at-point. I think it's a standard enough > format that makes sense to have it in the core. It's my 2nd > contribution, so still getting used to the tools and standards. > > The implementation relies on a regular expression to accept the > different versions of uuids (versions 1 to 5), and also the "Nil UUID". > > I'm using rx as it makes clearer the intent of what we're parsing at > each point. I hope it's ok to use it (I don't see it used a lot in emacs > itself). > > If there are any comments or fixes to do, point them out and I'll make > the changes accordingly. > > Thanks, > > Raimon Grau Hi again, Sending here an updated patch with improved comment message. Sorry for the noise, hope this one is ok! Raimon Grau
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From 8321b7af6f5249009bd1b76c0ccbf81b5dff70fb 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 * lisp/thingatpt.el (thing-at-point-uuid-regexp): Add regexp for uuid. * test/lisp/thingatpt-tests.el: Add tests for uuid at point. --- etc/NEWS | 6 ++++++ lisp/thingatpt.el | 41 ++++++++++++++++++++++++++++++++++++++--- test/lisp/thingatpt-tests.el | 11 ++++++++++- 3 files changed, 54 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..ca8a5bd 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,41 @@ 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 (and bow + (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." ) +(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)))))) + +(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)))))) + ;; Aliases (defun word-at-point () diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index cfb57de..e8e9b6e 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -65,7 +65,16 @@ 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 + ("12345678-1234-1234-8123-123456789012" 1 uuid "12345678-1234-1234-8123-123456789012") + ("12345678-1234-2234-9123-123456789012" 1 uuid "12345678-1234-2234-9123-123456789012") + ("12345678-1234-3234-a123-123456789012" 1 uuid "12345678-1234-3234-a123-123456789012") + ("12345678-1234-4234-b123-123456789012" 1 uuid "12345678-1234-4234-b123-123456789012") + ("12345678-1234-5234-b123-123456789012" 1 uuid "12345678-1234-5234-b123-123456789012") + ("00000000-0000-0000-0000-000000000000" 1 uuid "00000000-0000-0000-0000-000000000000") + ("12345678-1234-4234-1123-123456789012" 1 uuid nil) + ("12345678-1234-6aaa-1123-123456789012" 1 uuid nil)) "List of thing-at-point tests. Each list element should have the form -- 2.7.4
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Mon, 06 Aug 2018 02:32:01 GMT) Full text and rfc822 format available.Message #11 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Noam Postavsky <npostavs <at> gmail.com> To: Raimon Grau <raimon <at> konghq.com> Cc: 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Sun, 05 Aug 2018 22:31:43 -0400
severity 32372 wishlist quit Raimon Grau <raimon <at> konghq.com> 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'. > +;; 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 > +(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)))))))
Noam Postavsky <npostavs <at> gmail.com>
to control <at> debbugs.gnu.org
.
(Mon, 06 Aug 2018 02:32:02 GMT) Full text and rfc822 format available.bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Mon, 06 Aug 2018 09:49:01 GMT) Full text and rfc822 format available.Message #16 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: "Basil L. Contovounesios" <contovob <at> tcd.ie> To: Noam Postavsky <npostavs <at> gmail.com> Cc: Raimon Grau <raimon <at> konghq.com>, 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 12:47:59 +0300
Noam Postavsky <npostavs <at> gmail.com> writes: > Raimon Grau <raimon <at> konghq.com> writes: > >> +;; 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 `:'. FWIW, the outer and/seq/: can be eliminated, as rx implicitly sequences its arguments. -- Basil
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Mon, 06 Aug 2018 09:50:02 GMT) Full text and rfc822 format available.Message #19 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Raimon Grau <raimon <at> konghq.com> To: Noam Postavsky <npostavs <at> gmail.com> Cc: 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 10:48:15 +0100
[Message part 1 (text/plain, inline)]
Noam Postavsky <npostavs <at> gmail.com> writes: > severity 32372 wishlist > quit > > Raimon Grau <raimon <at> konghq.com> 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
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From ac14cf6841ae7c8aa09897e7e6f06814961462fa 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 | 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 ("<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
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Mon, 06 Aug 2018 19:17:02 GMT) Full text and rfc822 format available.Message #22 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Noam Postavsky <npostavs <at> gmail.com> To: Raimon Grau <raimon <at> konghq.com> Cc: 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 06 Aug 2018 15:16:47 -0400
Raimon Grau <raimon <at> konghq.com> writes: > +(put 'uuid 'bounds-of-thing-at-point > + (lambda () > + (let ((thing (thing-at-point-looking-at > + thing-at-point-uuid-regexp 500))) I think since uuids are fixed size, we can just pass that length (36), rather than the somewhat arbitrary 500.
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Tue, 07 Aug 2018 07:51:02 GMT) Full text and rfc822 format available.Message #25 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Raimon Grau <raimon <at> konghq.com> To: Noam Postavsky <npostavs <at> gmail.com> Cc: 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Tue, 07 Aug 2018 08:48:26 +0100
[Message part 1 (text/plain, inline)]
Noam Postavsky <npostavs <at> gmail.com> writes: > Raimon Grau <raimon <at> konghq.com> writes: > >> +(put 'uuid 'bounds-of-thing-at-point >> + (lambda () >> + (let ((thing (thing-at-point-looking-at >> + thing-at-point-uuid-regexp 500))) > > I think since uuids are fixed size, we can just pass that length (36), > rather than the somewhat arbitrary 500. I adjusted it to 36 and removed the redundant `seq' on the rx expression. Attaching the updated patch. Thanks again for reviewing, Raimon Grau
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From 534c35917f17f3a73c780dcbcc4be86fafa97566 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 | 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..e0443f4 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 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 36))) + (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 ("<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
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Tue, 07 Aug 2018 13:18:02 GMT) Full text and rfc822 format available.Message #28 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Ivan Shmakov <ivan <at> siamics.net> To: 32372 <at> debbugs.gnu.org Cc: Raimon Grau <raimon <at> konghq.com>, Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Tue, 07 Aug 2018 13:17:21 +0000
>>>>> 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. […] > +;; 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.") > + > +(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))? > + > ;; Aliases > (defun word-at-point () […] -- FSF associate member #7257 http://am-1.org/~ivan/
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Tue, 07 Aug 2018 17:47:02 GMT) Full text and rfc822 format available.Message #31 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: "Basil L. Contovounesios" <contovob <at> tcd.ie> To: Ivan Shmakov <ivan <at> siamics.net> Cc: Raimon Grau <raimon <at> konghq.com>, Noam Postavsky <npostavs <at> gmail.com>, 32372 <at> debbugs.gnu.org Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Tue, 07 Aug 2018 20:45:54 +0300
Ivan Shmakov <ivan <at> siamics.net> writes: >>>>>> Raimon Grau <raimon <at> konghq.com> writes: > > + > > +(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))? If you're in the business of simplifying, why not take it all the way: (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) (cons (match-beginning 0) (match-end 0))) -- Basil
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Thu, 09 Aug 2018 16:05:01 GMT) Full text and rfc822 format available.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
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Thu, 09 Aug 2018 18:13:01 GMT) Full text and rfc822 format available.Message #37 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Ivan Shmakov <ivan <at> siamics.net> To: 32372 <at> debbugs.gnu.org Cc: Raimon Grau <raimon <at> konghq.com>, Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Thu, 09 Aug 2018 18:12:54 +0000
>>>>> Raimon Grau <raimon <at> konghq.com> writes: […] > +(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))))) While either ‘and’ or ‘if’ can be used here, to exactly the same effect, the indentation above is one for ‘if’; ‘and’ should instead look like: (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) (cons (match-beginning 0) (match-end 0))) I think in this case it’s marginally better to keep indentation and replace ‘and’ with ‘if’ than the other way around. Thanks. […] -- FSF associate member #7257 http://am-1.org/~ivan/
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Thu, 09 Aug 2018 18:52:01 GMT) Full text and rfc822 format available.Message #40 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 19:50:07 +0100
Ivan Shmakov <ivan <at> siamics.net> writes: > While either ‘and’ or ‘if’ can be used here, to exactly the same > effect, the indentation above is one for ‘if’; ‘and’ should instead > look like: > > (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) > (cons (match-beginning 0) (match-end 0))) > > I think in this case it’s marginally better to keep indentation > and replace ‘and’ with ‘if’ than the other way around. What about `when'? Is it ok to use it? One branch 'if' look funny to me but I don't see many (any?) `when' in the emacs codebase. Thanks, Raimon Grau
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Thu, 09 Aug 2018 22:21:02 GMT) Full text and rfc822 format available.Message #43 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: "Basil L. Contovounesios" <contovob <at> tcd.ie> To: Raimon Grau <raimon <at> konghq.com> Cc: 32372 <at> debbugs.gnu.org, Ivan Shmakov <ivan <at> siamics.net>, Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Fri, 10 Aug 2018 01:20:13 +0300
Raimon Grau <raimon <at> konghq.com> writes: > Ivan Shmakov <ivan <at> siamics.net> writes: > >> While either ‘and’ or ‘if’ can be used here, to exactly the same >> effect, the indentation above is one for ‘if’; ‘and’ should instead >> look like: >> >> (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) >> (cons (match-beginning 0) (match-end 0))) >> >> I think in this case it’s marginally better to keep indentation >> and replace ‘and’ with ‘if’ than the other way around. > > What about `when'? Is it ok to use it? > > One branch 'if' look funny to me but I don't see many (any?) `when' in the emacs > codebase. If you grep the codebase you will see countless occurences of and, or, if-then, if-then-else, when, unless, etc. What to use here is a mostly a matter of personal style, and a bit of a bikeshed at that, so you are likely to get varied opinions. At the end of the day it doesn't really matter what you go with. If you're interested in reading some opinions and common conventions on this, see https://emacs.stackexchange.com/q/14195/15748. FWIW, Ivan's argument to use 'if' instead of 'and' just to preserve indentation doesn't apply here, as your patch is adding new code, not modifying existing code in-place, where preserving surrounding indentation would create a cleaner diff. -- Basil
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Fri, 10 Aug 2018 06:38:02 GMT) Full text and rfc822 format available.Message #46 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Ivan Shmakov <ivan <at> siamics.net> To: 32372 <at> debbugs.gnu.org Cc: Raimon Grau <raimon <at> konghq.com>, "Basil L. Contovounesios" <contovob <at> tcd.ie>, Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Fri, 10 Aug 2018 06:37:12 +0000
>>>>> Basil L Contovounesios <contovob <at> tcd.ie> writes: >>>>> Raimon Grau <raimon <at> konghq.com> writes: >>>>> Ivan Shmakov <ivan <at> siamics.net> writes: >>> While either ‘and’ or ‘if’ can be used here, to exactly the same >>> effect, the indentation above is one for ‘if’; ‘and’ should instead >>> look like: >>> (and (thing-at-point-looking-at thing-at-point-uuid-regexp 36) >>> (cons (match-beginning 0) (match-end 0))) >>> I think in this case it’s marginally better to keep indentation and >>> replace ‘and’ with ‘if’ than the other way around. >> What about ‘when’? Is it ok to use it? Yes. Actually, I’ve somehow confused if with when in the above comment; with if, the indentation will be like: (if (thing-at-point-looking-at thing-at-point-uuid-regexp 36) (cons (match-beginning 0) (match-end 0))) >> One branch 'if' look funny to me but I don’t see many (any?) ‘when’ >> in the emacs codebase. > If you grep the codebase you will see countless occurrences of and, > or, if-then, if-then-else, when, unless, etc. > What to use here is a mostly a matter of personal style, and a bit of > a bikeshed at that, so you are likely to get varied opinions. At the > end of the day it doesn’t really matter what you go with. Yes. […] -- FSF associate member #7257 np. Undercurrent — Jami Sieber
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Sat, 11 Aug 2018 11:40:02 GMT) Full text and rfc822 format available.Message #49 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: "Basil L. Contovounesios" <contovob <at> tcd.ie>, Noam Postavsky <npostavs <at> gmail.com> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Sat, 11 Aug 2018 12:37:51 +0100
[Message part 1 (text/plain, inline)]
Ivan Shmakov <ivan <at> siamics.net> writes: > > What to use here is a mostly a matter of personal style, and a bit of > > a bikeshed at that, so you are likely to get varied opinions. At the > > end of the day it doesn’t really matter what you go with. > > Yes. I ended up using when (and indenting it correctly) if that's ok.
[0001-Add-uuid-as-allowed-thingatpt-symbol.patch (text/x-diff, inline)]
From f7c76007aef325abc31871db108e7e48fe46022c 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..abeb167 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 () + (when (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
bug-gnu-emacs <at> gnu.org
:bug#32372
; Package emacs
.
(Mon, 13 Aug 2018 11:50:02 GMT) Full text and rfc822 format available.Message #52 received at 32372 <at> debbugs.gnu.org (full text, mbox):
From: Noam Postavsky <npostavs <at> gmail.com> To: Raimon Grau <raimon <at> konghq.com> Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, 32372 <at> debbugs.gnu.org, Ivan Shmakov <ivan <at> siamics.net> Subject: Re: bug#32372: [PATCH] Add "uuid" to thing-at-point.el Date: Mon, 13 Aug 2018 07:49:43 -0400
tags 32372 fixed close 32372 27.1 quit Raimon Grau <raimon <at> konghq.com> writes: > I ended up using when (and indenting it correctly) if that's ok. That's fine, we've certainly had enough debate over it. I've pushed your patch (minus a few blank lines) to master. [1: eb787d749f]: 2018-08-13 07:46:35 -0400 Add uuid as allowed thingatpt symbol (Bug#32372) https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=eb787d749f28583906428269b926fa83aef092b9
Noam Postavsky <npostavs <at> gmail.com>
to control <at> debbugs.gnu.org
.
(Mon, 13 Aug 2018 11:50:03 GMT) Full text and rfc822 format available.Noam Postavsky <npostavs <at> gmail.com>
to control <at> debbugs.gnu.org
.
(Mon, 13 Aug 2018 11:50:03 GMT) Full text and rfc822 format available.Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Tue, 11 Sep 2018 11:24:05 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.