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:11:20 +0100 Message-ID: <87h8k88l47.fsf@konghq.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1533510733 9623 195.159.176.226 (5 Aug 2018 23:12:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Aug 2018 23:12:13 +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:12:09 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 1fmSBz-0002MJ-Ts for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Aug 2018 01:12:08 +0200 Original-Received: from localhost ([::1]:60032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSE5-0004sp-DH for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Aug 2018 19:14:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSDt-0004sT-T4 for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:14:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSDq-0008Gf-Me for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:14:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmSDq-0008GR-HG for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fmSDq-0000BM-9E for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:14:02 -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:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 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.1533510790629 (code B ref -1); Sun, 05 Aug 2018 23:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Aug 2018 23:13:10 +0000 Original-Received: from localhost ([127.0.0.1]:42106 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmSD0-0000A4-3D for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:13:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54410) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmSCy-00009q-3D for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:13:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSCr-0007XA-8Q for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:13:02 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:40995) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fmSCr-0007X4-2a for submit@debbugs.gnu.org; Sun, 05 Aug 2018 19:13:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmSCp-0004n2-H6 for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:13:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmSCm-0007UB-8S for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:12:59 -0400 Original-Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:33937) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmSCl-0007SX-R3 for bug-gnu-emacs@gnu.org; Sun, 05 Aug 2018 19:12:56 -0400 Original-Received: by mail-wm0-x22f.google.com with SMTP id l2-v6so9986058wme.1 for ; Sun, 05 Aug 2018 16:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konghq.com; s=google; h=from:to:subject:date:message-id:mime-version; bh=I7pPGo1mKPtAGLVq2vsshaMCIwYkR4L++d1DiMZNSLk=; b=MFZWhBtZHQdaJ/6neoSu8RLm4qaOrI/5H5PlEEPSei4s1o/V7jV8Qnk/VSriuN057W rbOVF5BZNgXeAI3XKmZkhF7kH10s1wzr4QXo98rmjwqcGVDj5a2jLoi+IAh5UTWZf1A7 8OJpC/yWQWih/RWp0BGv1HIGNJj9q5OLhGUEY= 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:date:message-id:mime-version; bh=I7pPGo1mKPtAGLVq2vsshaMCIwYkR4L++d1DiMZNSLk=; b=ghvmuxmeH+OY29aWHjf3x6/Wi8n1L6JkE9yA0VzCu41clqJDFY8UH4Xzdn9ZnHm7uF e8yEMm5++r5O/GB/kAt9Mt/KFhHO7O9y4/H0Hh1/DUiY3KFSwyw+7/6urdGcrTnp/vIu axe3XE/HCkSNDSlk66N68jPMpGRfbKPGPfaDfwflTHsyqypCEfyQ1Rb6ZedhMELLeGK1 0J+VdgQonuDUAt+obzbrnrofk0I49ypDyNXF7g/tevs55zZ/2XFI2aB1PUzQ2U0LwJ0T 2es+67T+z6FDVsJLhTxYJBYyk1p3qhvSvI0gUxvUomxL89hA69wuuA96lMd9zO4IkRBj bnkQ== X-Gm-Message-State: AOUpUlFe9LXffX9TXd1tNC056PTkm0CEuxVH2CtBfcGibkH6UBofrCSP oNQtVFTodmWy9Yy0zxA3coTTsBw3yzs= X-Google-Smtp-Source: AAOMgpct0GDGyTwmzU86w75mhrUxbRjuLquETjIL+1KsEYGFBCNYHvMJXe+gw0AJ+EnHKKSuEe/tNA== X-Received: by 2002:a1c:d942:: with SMTP id q63-v6mr10907269wmg.78.1533510774430; Sun, 05 Aug 2018 16:12:54 -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 b2-v6sm7088974wmh.3.2018.08.05.16.12.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Aug 2018 16:12:53 -0700 (PDT) X-Google-Original-From: Raimon Grau 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:149271 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-uuid-as-allowed-thingatpt-symbol.patch >From faacdadc1beba467b915b65ffd668b9e6c3a1d41 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 --- 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 --=-=-=--