]> git.eshelyaron.com Git - emacs.git/commitdiff
Add uuid as allowed thingatpt symbol (Bug#32372)
authorRaimon Grau <raimonster@gmail.com>
Sun, 5 Aug 2018 21:47:30 +0000 (22:47 +0100)
committerNoam Postavsky <npostavs@gmail.com>
Mon, 13 Aug 2018 11:46:35 +0000 (07:46 -0400)
* 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
lisp/thingatpt.el
test/lisp/thingatpt-tests.el

index decc5e3954113a8e2fc2a28ccf37a197b87cfbee..7695a96bb2efe5a14086c61bd5e0368c5ab0d42f 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -705,6 +705,12 @@ to signal the main thread, e.g., when they encounter an error.
 +++
 *** 'thread-join' returns the result of the finished thread now.
 
+---
+** 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 27.1
 
index 7fcb3bc2b73b99a02902df670f11b9631baf4774..679401eef1584cca655cc794a935d9db68d1d605 100644 (file)
@@ -61,7 +61,7 @@
   "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)))))
@@ -76,7 +76,7 @@ Possibilities include `symbol', `list', `sexp', `defun',
   "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
@@ -134,7 +134,7 @@ positions of the thing found."
   "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,
@@ -564,6 +564,24 @@ with angle brackets.")
 (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 ()
index cfb57de6189fa067ce04a6cc3ca555773a9ffea6..b4a5fd90ce46d3973dd4db20768feaf70c31b565 100644 (file)
     ("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