From: Raimon Grau <raimon@konghq.com>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 32372@debbugs.gnu.org
Subject: bug#32372: [PATCH] Add "uuid" to thing-at-point.el
Date: Mon, 06 Aug 2018 10:48:15 +0100 [thread overview]
Message-ID: <878t5j9674.fsf@konghq.com> (raw)
In-Reply-To: <8736vsz0mo.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3598 bytes --]
Noam Postavsky <npostavs@gmail.com> writes:
> severity 32372 wishlist
> quit
>
> Raimon Grau <raimon@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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-uuid-as-allowed-thingatpt-symbol.patch --]
[-- Type: text/x-diff, Size: 4268 bytes --]
From ac14cf6841ae7c8aa09897e7e6f06814961462fa Mon Sep 17 00:00:00 2001
From: Raimon Grau <raimonster@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.
+
\f
* 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@example.com>" 1 url "mailto:foo@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
next prev parent reply other threads:[~2018-08-06 9:48 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-05 23:11 bug#32372: [PATCH] Add "uuid" to thing-at-point.el Raimon Grau
2018-08-05 23:24 ` Raimon Grau
2018-08-06 2:31 ` Noam Postavsky
2018-08-06 9:47 ` Basil L. Contovounesios
2018-08-06 9:48 ` Raimon Grau [this message]
2018-08-06 19:16 ` Noam Postavsky
2018-08-07 7:48 ` Raimon Grau
2018-08-07 13:17 ` Ivan Shmakov
2018-08-07 17:45 ` Basil L. Contovounesios
2018-08-09 16:03 ` Raimon Grau
2018-08-09 18:12 ` Ivan Shmakov
2018-08-09 18:50 ` Raimon Grau
2018-08-09 22:20 ` Basil L. Contovounesios
2018-08-10 6:37 ` Ivan Shmakov
2018-08-11 11:37 ` Raimon Grau
2018-08-13 11:49 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878t5j9674.fsf@konghq.com \
--to=raimon@konghq.com \
--cc=32372@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.