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: Mon, 06 Aug 2018 00:24:02 +0100 Message-ID: <87effc8kj1.fsf@konghq.com> References: <87h8k88l47.fsf@konghq.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1533511457 24378 195.159.176.226 (5 Aug 2018 23:24:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Aug 2018 23:24:17 +0000 (UTC) To: 32372@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 06 01:24:13 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 1fmSNe-0006Av-80 for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Aug 2018 01:24:10 +0200 Original-Received: from localhost ([::1]:60064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSPj-0007k9-6Z for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Aug 2018 19:26:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSPV-0007jm-6R for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:26:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSPR-0004ZL-Vm for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:26:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37094) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmSPR-0004ZB-PI for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:26:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fmSPR-0000TN-JA for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:26: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: Sun, 05 Aug 2018 23:26: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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15335115531800 (code B ref -1); Sun, 05 Aug 2018 23:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Aug 2018 23:25:53 +0000 Original-Received: from localhost ([127.0.0.1]:42112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmSPI-0000Sy-HD for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:25:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56073) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmSPG-0000Si-22 for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:25:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSP9-0004Uf-MF for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:25:45 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:48879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fmSP9-0004UU-Gt for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:25:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSP7-0007hP-KI for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:25:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSP4-0004Rf-Cs for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:25:41 -0400 Original-Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44591) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmSP3-0004PW-VT for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:25:38 -0400 Original-Received: by mail-wr1-x443.google.com with SMTP id r16-v6so10604894wrt.11 for ; Sun, 05 Aug 2018 16:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konghq.com; s=google; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=b2zoK92W9rEZYpccXNaWzmkRsBdXJLyLqco3Tl8nT5U=; b=E+HEhVUn8YV5IxhyYZ55acvhUbqyKP/XXgfoNvhBn1u9pYpBYYGmVT9stU/S74fuLT vZe4xmfWUKzot0C3vdjs/1JpAwfa4pvS33GCtfB3/3rwzr6f4Ce4X4HOHNb0rRMQvO80 M1Id64OQgeoTWA7Tvpnqdm3x4gw4eMDDvB9Ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=b2zoK92W9rEZYpccXNaWzmkRsBdXJLyLqco3Tl8nT5U=; b=ggzg4DGevwr9CsxzmR1UDKwNuSng4xcTzPtztBHARQ2IrxtJ5vzI5MQrGdY2ed3EI8 x3cwAem/T0qkgWrol3M5MnvO9c91yx0je4Oy3Z3LDyN8CRCkmoP6NzO8oSRSck7K+Ifc a9GfsKgXQ798ioubNwh3Ij5X1tGrFOVClF189JjvO95V3YfvNHxpgBFFbE1X1sLMsHoI N4CoboXz9qZql89RwL1rwXO1GlmORyMgAcAQHxriBR8amAJ/QGg+B5doWgLsDdWPpULt N1QwY6o08NmHG+6HYtLtEFvcZpXnzCEtDG1X3Qz9sVlN+xIu3Bo1bNR+oI4q3ZKeeaTq A/8Q== X-Gm-Message-State: AOUpUlFd7ydBFnSPe6vvVnJf22HvWdJ90dbN8j5w4EwznWbyHMqJwCWk oaTkjILmn/7KC/RgNsKCUPbmOR2Z1WI= X-Google-Smtp-Source: AAOMgpdyqjtve/Djstc2qlyKdPSOR9Znkp9AtDAVv9PNpGkmIc6qDhFCNgBRNilJyiAkRJI3TSJiWg== X-Received: by 2002:adf:a4d4:: with SMTP id h20-v6mr8127660wrb.167.1533511536613; Sun, 05 Aug 2018 16:25:36 -0700 (PDT) Original-Received: from raikong (81.61.106.180.dyn.user.ono.com. [81.61.106.180]) by smtp.gmail.com with ESMTPSA id g125-v6sm4915249wmf.16.2018.08.05.16.25.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Aug 2018 16:25:36 -0700 (PDT) X-Google-Original-From: Raimon Grau In-Reply-To: <87h8k88l47.fsf@konghq.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:149272 Archived-At: --=-=-= Content-Type: text/plain Raimon Grau 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-uuid-as-allowed-thingatpt-symbol.patch >From 8321b7af6f5249009bd1b76c0ccbf81b5dff70fb 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 * 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 ("" 1 url "mailto:foo@example.com") - ("" 1 url "ftp://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 --=-=-=--