From fbc772f83ff6a79bdfc84b3b15dcd46087fd285c Mon Sep 17 00:00:00 2001 From: Bob Weiner Date: Thu, 21 Jul 2016 10:40:16 -0400 Subject: * hibtypes.el (mail-address-regexp): Simplified and modernized address matching to better distinguish from @username social media references. (mail-address-mode-list): Added lisp-interaction-mode and fundamental-mode. (mail-address-tld-regexp): Added to match most common top-level domains to tell if a match is really an email address or not. (mail-address-at-p): Tightened by using mail-address-tld-regexp. DEMO (Email Addresses, Social Media Hashtags and Usernames): Added descriptions. 2016-07-20 Bob Weiner * MANIFEST: Makefile: hibtypes.el (hib-social): man/hyperbole.texi (Implicit Buttons): Added social-reference. hib-social.el: Added this file to follow social media hashtag and username references. --- ChangeLog | 17 +++++++++ DEMO | 26 ++++++++++++++ HY-NEWS | 10 ++++++ MANIFEST | 1 + Makefile | 6 ++-- hib-social.el | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hibtypes.el | 60 +++++++++++++++++++++++++------ hmoccur.el | 16 ++++----- hyperbole-pkg.el | 6 +--- man/hyperbole.html | 21 +++++++++-- man/hyperbole.info | Bin 423572 -> 424298 bytes man/hyperbole.pdf | Bin 784625 -> 784910 bytes man/hyperbole.texi | 15 ++++++-- 13 files changed, 251 insertions(+), 30 deletions(-) create mode 100644 hib-social.el diff --git a/ChangeLog b/ChangeLog index 05f6a85..c138d03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,24 @@ -- Almost all changes listed herein are new as of 2016. -- +2016-07-21 Bob Weiner + +* hibtypes.el (mail-address-regexp): Simplified and modernized address matching + to better distinguish from @username social media references. + (mail-address-mode-list): Added lisp-interaction-mode and fundamental-mode. + (mail-address-tld-regexp): Added to match most common top-level + domains to tell if a match is really an email address or not. + (mail-address-at-p): Tightened by using mail-address-tld-regexp. + DEMO (Email Addresses, Social Media Hashtags and Usernames): Added descriptions. + 2016-07-20 Bob Weiner +* MANIFEST: + Makefile: + hibtypes.el (hib-social): + man/hyperbole.texi (Implicit Buttons): Added social-reference. + hib-social.el: Added this file to follow social media hashtag and username + references. + * Makefile (help): Added as the default target, explaining major targets. * HY-ABOUT: diff --git a/DEMO b/DEMO index 84578d0..403c7e0 100644 --- a/DEMO +++ b/DEMO @@ -390,6 +390,32 @@ Try using the Action Key on: "http://www.gnu.org". Full and abbreviated web and ftp URLs, e.g. www.gnu.org, are recognized with or without quotes. +** Email Addresses + +An Action Key press on an email address of any common domain name will start +composing an email message to that name within Emacs. This is limited to +major modes listed in the variable, mail-address-mode-list. Try composing a +message to and tell us what you think of Hyperbole. +Even better, a press of or on {C-h h m c} composes mail to the list that +includes your system information. + +** Social Media Hashtags and Usernames + +An Action Key press a social media hashtag or username reference at point +displays the web page associated with the reference at the associated +service. References are of the form: +[facebook|instagram|twitter]?[#@] or +[fb|in|tw]?[#@]. If no service is given, it defaults to +the value of @code{hibtypes-social-default-service} which is initially +"twitter". + +So all of the following make the same hashtag reference: #gnu twitter#gnu +tw#gnu and display the page for tweets with that hashtag. Similarly, +in@lostart or instagram@lostart would display the page for the user lostart +at instagram. Try pressing the Action Key on these if you like. + +The file "hib-social.el" has more details on this. + ** Grep, Occurrence, Debugger and Compiler Error Buttons, and Cscope Analyzer Lines diff --git a/HY-NEWS b/HY-NEWS index a2ef41a..e133638 100644 --- a/HY-NEWS +++ b/HY-NEWS @@ -9,6 +9,16 @@ * V6.01 =========================================================================== + BUTTONS + + - New implicit button type for social media hashtag or username + references, social-reference. Action key activation displays + the web page associated with the hashtag or username. References + can look like #hashtag or @username for Twitter references. + fb#hashtag or facebook@username for Facebook references or + in#hashtag or instagram@username for Instagram references. + See the new file "hib-social.el" for more information. + VARIABLES - hsite.el is now included in the Hyperbole package rather than diff --git a/MANIFEST b/MANIFEST index cc96853..739023f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -77,6 +77,7 @@ hibtypes.el - GNU Hyperbole default implicit button types hib-debbugs.el - Implicit button type for browsing GNU debbugs issues hib-doc-id.el - Implicit button type for document id index entries hib-kbd.el - Implicit button type for key sequences delimited with {} +hib-social.el - Implicit button type for social media hashtag and username references hinit.el - Standard initializations for GNU Hyperbole hload-path.el - GNU Hyperbole load-path setup hlvar.el - GNU Hyperbole variables in local variable lists diff --git a/Makefile b/Makefile index b03b4eb..524ca17 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,8 @@ VPATH = kotl man EL_SRC = hui-em-but.el hui-xe-but.el EL_COMPILE = hact.el hactypes.el hargs.el hbdata.el hbmap.el hbut.el \ - hgnus.el hhist.el hib-debbugs.el hib-doc-id.el hib-kbd.el hibtypes.el \ + hgnus.el hhist.el hib-debbugs.el hib-doc-id.el hib-kbd.el \ + hib-social.el hibtypes.el \ hinit.el hload-path.el hlvar.el hmail.el hmh.el hmoccur.el hmouse-info.el \ hmouse-drv.el hmouse-key.el hmouse-mod.el hmouse-sh.el hmouse-tag.el \ hpath.el hrmail.el hsite.el hsmail.el hsys-org.el hsys-w3.el htz.el \ @@ -147,7 +148,8 @@ EL_KOTL = kotl/kexport.el kotl/kfile.el kotl/kfill.el kotl/kimport.el kotl/klabe kotl/kcell.el kotl/kproperty.el kotl/kprop-em.el \ kotl/kprop-xe.el kotl/kview.el kotl/kvspec.el -ELC_COMPILE = hactypes.elc hibtypes.elc hib-debbugs.elc hib-kbd.elc hib-doc-id.elc hact.elc \ +ELC_COMPILE = hactypes.elc hibtypes.elc hib-debbugs.elc hib-doc-id.elc hib-kbd.elc \ + hib-social.elc hact.elc \ hargs.elc hbdata.elc hbmap.elc hbut.elc hgnus.elc hhist.elc \ hinit.elc hload-path.elc hlvar.elc hmail.elc hmh.elc hmoccur.elc hmouse-info.elc \ hmouse-drv.elc hmouse-key.elc hmouse-mod.elc hmouse-sh.elc hmouse-tag.elc \ diff --git a/hib-social.el b/hib-social.el new file mode 100644 index 0000000..e3d3b78 --- /dev/null +++ b/hib-social.el @@ -0,0 +1,103 @@ +;;; hib-social.el --- Implicit button type for social media hashtag and username references +;; +;; Author: Bob Weiner +;; +;; Orig-Date: 20-Jul-16 at 22:41:34 +;; +;; Copyright (C) 2016 Free Software Foundation, Inc. +;; See the "HY-COPY" file for license information. +;; +;; This file is part of GNU Hyperbole. + +;;; Commentary: +;; +;; This defines an implicit button type, social-reference, that displays +;; the web page associated with the given hashtag or username. +;; +;; A hashtag reference is either: [facebook|instagram|twitter]?# +;; or [fb|in|tw]?#. +;; +;; A username reference is either: [facebook|instagram|twitter]?@ +;; or [fb|in|tw]?@. +;; +;; If the social media service is not given, it defaults to \"twitter\". + +;;; Code: +;;; ************************************************************************ +;;; Other required Elisp libraries +;;; ************************************************************************ + +(eval-when-compile (require 'browse-url)) + +;;; ************************************************************************ +;;; Public variables +;;; ************************************************************************ + +(defcustom hibtypes-social-default-service "twitter" + "Lowercase string matching the name of the default social media service to use when none is specified." + :type 'string + :group 'hyperbole-button) + +(defcustom hibtypes-social-display-function #'browse-url + "Function of one argument, a url, to display when a social media reference is activated." + :type 'function + :group 'hyperbole-button) + +;;; ************************************************************************ +;;; Private variables +;;; ************************************************************************ + +(defconst hibtypes-social-hashtag-alist + '(("\\`\\(fb\\|facebook\\)\\'" . "https://www.facebook.com/hashtag/%s") + ("\\`\\(tw\\|twitter\\)\\'" . "https://twitter.com/search?q=%%23%s&src=hashtag") + ("\\`\\(in\\|instagram\\)\\'" . "https://www.instagram.com/explore/tags/%s/")) + "Alist of (social-media-service-regexp . url-with-%s-for-hashtag) elements.") + +(defconst hibtypes-social-username-alist + '(("\\`\\(fb\\|facebook\\)\\'" . "https://www.facebook.com/%s") + ("\\`\\(tw\\|twitter\\)\\'" . "https://twitter.com/search?q=@%s") + ("\\`\\(in\\|instagram\\)\\'" . "https://www.instagram.com/%s/")) + "Alist of (social-media-service-regexp . url-with-%s-for-username) elements.") + +(defconst hibtypes-social-regexp "\\([[:alpha:]]*\\)\\([#@]\\)\\([._[:alnum:]]*[_[:alnum:]]\\)" + "Regular expression that matches a social media hashtag or username reference. +See `ibtypes::social-reference' for format details.") + +;;; ************************************************************************ +;;; Public Button Types +;;; ************************************************************************ + +(defib social-reference () + "Displays the web page associated with a social media hashtag or username reference at point. +Reference format is: [facebook|instagram|twitter]?[#@] or +\[fb|in|tw]?[#@]. Service defaults to the value of +`hibtypes-social-default-service' when not given." + (when (and (not (memq major-mode '(texinfo-mode para-mode))) + (save-excursion + (if (looking-at "[#@._[:alnum:]]") + (skip-chars-backward "#@._[:alnum:]")) + (and (looking-at hibtypes-social-regexp) + (save-match-data + ;; Heuristic to ensure this is not an email address + (not (and (looking-at mail-address-regexp) + (string-match mail-address-tld-regexp + (match-string-no-properties 1)))))))) + (save-match-data + (ibut:label-set (match-string-no-properties 0) (match-beginning 0) (match-end 0))) + (hact 'social-reference (match-string-no-properties 1) + (match-string-no-properties 2) (match-string-no-properties 3)))) + +(defact social-reference (service ref-type-char hashtag-or-username) + "Display the web page at social media SERVICE for REF-TYPE-CHAR and HASHTAG-OR-USERNAME. +REF-TYPE-CHAR is either \"#\" for a hashtag reference or \"@\" for a username reference." + (if (or (null service) (equal service "")) (setq service hibtypes-social-default-service)) + (let (url-to-format) + (when (or (and (equal ref-type-char "#") + (setq url-to-format + (assoc-default service hibtypes-social-hashtag-alist #'string-match))) + (and (equal ref-type-char "@") + (setq url-to-format + (assoc-default service hibtypes-social-username-alist #'string-match)))) + (funcall hibtypes-social-display-function (format url-to-format hashtag-or-username))))) + +(provide 'hib-social) diff --git a/hibtypes.el b/hibtypes.el index 71c410f..1705bd9 100644 --- a/hibtypes.el +++ b/hibtypes.el @@ -22,6 +22,42 @@ (require 'hactypes) ;;; ************************************************************************ +;;; Public variables +;;; ************************************************************************ + +(defconst mail-address-tld-regexp + (format "\\.%s\\'" + (regexp-opt + '("aero" "arpa" "asia" "biz" "cat" "com" "coop" "edu" "gov" "info" + "int" "jobs" "mil" "mobi" "museum" "name" "net" "org" "pro" "tel" + "travel" "uucp" + "ac" "ad" "ae" "af" "ag" "ai" "al" "am" "an" "ao" "aq" + "ar" "as" "at" "au" "aw" "ax" "az" "ba" "bb" "bd" "be" "bf" "bg" "bh" + "bi" "bj" "bl" "bm" "bn" "bo" "br" "bs" "bt" "bv" "bw" "by" "bz" "ca" + "cc" "cd" "cf" "cg" "ch" "ci" "ck" "cl" "cm" "cn" "co" "cr" "cu" "cv" + "cx" "cy" "cz" "de" "dj" "dk" "dm" "do" "dz" "ec" "ee" "eg" "eh" "er" + "es" "et" "eu" "fi" "fj" "fk" "fm" "fo" "fr" "ga" "gb" "gd" "ge" "gf" + "gg" "gh" "gi" "gl" "gm" "gn" "gp" "gq" "gr" "gs" "gt" "gu" "gw" "gy" + "hk" "hm" "hn" "hr" "ht" "hu" "id" "ie" "il" "im" "in" "io" "iq" "ir" + "is" "it" "je" "jm" "jo" "jp" "ke" "kg" "kh" "ki" "km" "kn" "kp" "kr" + "kw" "ky" "kz" "la" "lb" "lc" "li" "lk" "lr" "ls" "lt" "lu" "lv" "ly" + "ma" "mc" "md" "me" "mf" "mg" "mh" "mk" "ml" "mm" "mn" "mo" "mp" "mq" + "mr" "ms" "mt" "mu" "mv" "mw" "mx" "my" "mz" "na" "nc" "ne" "nf" "ng" + "ni" "nl" "no" "np" "nr" "nu" "nz" "om" "pa" "pe" "pf" "pg" "ph" "pk" + "pl" "pm" "pn" "pr" "ps" "pt" "pw" "py" "qa" "re" "ro" "rs" "ru" "rw" + "sa" "sb" "sc" "sd" "se" "sg" "sh" "si" "sj" "sk" "sl" "sm" "sn" "so" + "sr" "st" "su" "sv" "sy" "sz" "tc" "td" "tf" "tg" "th" "tj" "tk" "tl" + "tm" "tn" "to" "tp" "tr" "tt" "tv" "tw" "tz" "ua" "ug" "uk" "um" "us" + "uy" "uz" "va" "vc" "ve" "vg" "vi" "vn" "vu" "wf" "ws" "ye" "yt" "yu" + "za" "zm" "zw") + t)) + "Regular expression of most common Internet top-level domain names.") + +(defconst mail-address-regexp + "\\([_a-zA-Z][-_a-zA-Z0-9.!@+%]*@[-_a-zA-Z0-9.!@+%]+\\.[a-zA-Z0-9][-_a-zA-Z0-9]+\\)\\($\\|[^a-zA-Z0-9@%]\\)" + "Regexp with group 1 matching an Internet email address.") + +;;; ************************************************************************ ;;; Public implicit button types ;;; ************************************************************************ @@ -174,6 +210,12 @@ current major mode is one handled by func-menu." ;; (hact 'imenu-display-item-where item-name item-pos))))))) ;;; ======================================================================== +;;; Handles social media hashtag and username references, e.g. twitter#myhashtag +;;; ======================================================================== + +(require 'hib-social) + +;;; ======================================================================== ;;; Handles Gnu debbugs issue ids, e.g. bug#45678 or just 45678. ;;; ======================================================================== @@ -683,9 +725,9 @@ Patch applies diffs to source code." ;;; ======================================================================== (defvar mail-address-mode-list - '(emacs-lisp-mode scheme-mode lisp-mode c-mode c++-mode html-mode - java-mode js2-mode objc-mode python-mode smalltalk-mode text-mode - indented-text-mode web-mode) + '(emacs-lisp-mode lisp-interaction-mode lisp-mode scheme-mode c-mode + c++-mode html-mode java-mode js2-mode objc-mode python-mode + smalltalk-mode fundamental-mode text-mode indented-text-mode web-mode) "List of major modes in which mail address implicit buttons are active.") (defib mail-address () @@ -717,17 +759,15 @@ any buffer attached to a file in `hyrolo-file-list', or any buffer with (ibut:label-set address (match-beginning 1) (match-end 1)) (hact 'mail-other-window nil address)))))) -(defconst mail-address-regexp - "\\([_a-zA-Z][-_a-zA-Z0-9.!@+%]*@[-_a-zA-Z0-9.!@+%]+\\.[a-zA-Z][-_a-zA-Z][-_a-zA-Z]?\\|[a-zA-Z][-_a-zA-Z0-9.!+%]+@[-_a-zA-Z0-9@]+\\)\\($\\|[^a-zA-Z0-9.!@%]\\)" - "Regexp with group 1 matching an Internet email address.") - (defun mail-address-at-p () "Return e-mail address, a string, that point is within or nil." (save-excursion (skip-chars-backward "^ \t\n\r\f\"\'(){}[];:<>|") - (if (or (looking-at mail-address-regexp) - (looking-at (concat "mailto:" mail-address-regexp))) - (match-string-no-properties 1)))) + (and (or (looking-at mail-address-regexp) + (looking-at (concat "mailto:" mail-address-regexp))) + (save-match-data + (string-match mail-address-tld-regexp (match-string-no-properties 1))) + (match-string-no-properties 1)))) ;;; ======================================================================== ;;; Displays Texinfo or Info node associated with Texinfo @xref, @pxref or @ref at point. diff --git a/hmoccur.el b/hmoccur.el index d880489..37e1d61 100644 --- a/hmoccur.el +++ b/hmoccur.el @@ -214,15 +214,13 @@ Signal an error if not on a valid occurrence line." ;;; Private variables ;;; ************************************************************************ -(defvar moccur-mode-map ()) -(if moccur-mode-map - () - (setq moccur-mode-map (make-sparse-keymap)) - (define-key moccur-mode-map "\C-c\C-c" 'moccur-to) - (define-key moccur-mode-map "\C-o" 'moccur-mode-display-occurrence) - (define-key moccur-mode-map " " 'moccur-to) - (define-key moccur-mode-map "\C-m" 'moccur-to) -) +(defvar moccur-mode-map nil) +(unless moccur-mode-map + (setq moccur-mode-map (make-sparse-keymap)) + (define-key moccur-mode-map "\C-c\C-c" 'moccur-to) + (define-key moccur-mode-map "\C-o" 'moccur-mode-display-occurrence) + (define-key moccur-mode-map " " 'moccur-to) + (define-key moccur-mode-map "\C-m" 'moccur-to)) (provide 'hmoccur) diff --git a/hyperbole-pkg.el b/hyperbole-pkg.el index 5f9f956..85ced10 100644 --- a/hyperbole-pkg.el +++ b/hyperbole-pkg.el @@ -1,3 +1,4 @@ +;; -*- no-byte-compile: t -*- (define-package "hyperbole" "6.0.1" "GNU Hyperbole: The Everyday Hypertextual Information Manager" '((emacs "24.4")) :url "http://www.gnu.org/software/hyperbole" @@ -5,8 +6,3 @@ "mail" "matching" "mouse" "multimedia" "outlines" "tools" "wp")) (setq byte-compile-warnings '(not interactive-p find-tag)) - - -;; Local Variables: -;; no-byte-compile: t -;; End: diff --git a/man/hyperbole.html b/man/hyperbole.html index bb86c83..e633548 100644 --- a/man/hyperbole.html +++ b/man/hyperbole.html @@ -320,7 +320,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 Edition 6.0.1
-Printed July 20, 2016.
+Printed July 21, 2016.
 
   Published by the Free Software Foundation, Inc.
   Author:    Bob Weiner
@@ -2166,7 +2166,19 @@ any attribute):
 of bug.  See the documentation at the top of
 the hib-debbugs.el file for detailed query format information.
 

- + +
social-reference
+
function-in-buffer
+
+ + + + +

Displays the web page associated with a social media hashtag or username reference at point. +Reference format is: [facebook|instagram|twitter]?[#@]<hashtag-or-username> or +[fb|in|tw]?[#@]<hashtag-or-username>. Service defaults to the value of +hibtypes-social-default-service when not given. +

function-in-buffer
@@ -10340,6 +10352,7 @@ Next: , Previ hbut:label-to-keyButton Label Normalization hibtypes-begin-load-hookHook Variables hibtypes-end-load-hookHook Variables +hibtypes-social-default-serviceImplicit Buttons hkey-alistQuestions and Answers hkey-always-display-menuSmart Key - Smart Menus hkey-initGlobal Key Bindings @@ -10465,6 +10478,7 @@ Next: , Previ ibtypes pathname-line-and-columnImplicit Buttons ibtypes rfcImplicit Buttons ibtypes rfc-tocImplicit Buttons +ibtypes social-referenceImplicit Buttons ibtypes texinfo-refImplicit Buttons ibtypes text-tocImplicit Buttons ibtypes www-urlImplicit Buttons @@ -11067,6 +11081,7 @@ Previous: , Up: groupwareGlossary
H +hashtagImplicit Buttons help bufferSmart Key - Help Buffers help, menu itemsMenus help, Smart KeySmart Key Operations @@ -11503,6 +11518,7 @@ Previous: , Up: Smart Mouse Key toggleSmart Key Bindings Smart Mouse KeysSmart Mouse Keys smart selectionSmart Key Thing Selection +social mediaImplicit Buttons source lineImplicit Buttons splitting a cellSplitting and Appending stack frameImplicit Buttons @@ -11572,6 +11588,7 @@ Previous: , Up: URLs, using with find-fileUsing URLs with Find-File USENETButtons in Mail USENETButtons in News +usernameImplicit Buttons
V variable settingConfiguration diff --git a/man/hyperbole.info b/man/hyperbole.info index a5c1bc7..d25c59f 100644 Binary files a/man/hyperbole.info and b/man/hyperbole.info differ diff --git a/man/hyperbole.pdf b/man/hyperbole.pdf index 49e3d11..7fe571b 100644 Binary files a/man/hyperbole.pdf and b/man/hyperbole.pdf differ diff --git a/man/hyperbole.texi b/man/hyperbole.texi index e4765f1..a648fb7 100644 --- a/man/hyperbole.texi +++ b/man/hyperbole.texi @@ -142,7 +142,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 Edition 6.0.1
-Printed July 20, 2016.
+Printed July 21, 2016.
 
   Published by the Free Software Foundation, Inc.
   Author:    Bob Weiner
@@ -166,7 +166,7 @@ Printed July 20, 2016.
 
 @center The Everyday Hypertextual Information Manager
 
-@center Edition 6.0.1, July 20, 2016.
+@center Edition 6.0.1, July 21, 2016.
 
 @sp 2
 @noindent
@@ -1642,6 +1642,17 @@ Note that @emph{issue} or @emph{debbugs} may be used as well in place
 of @emph{bug}.  See the documentation at the top of
 the @file{hib-debbugs.el} file for detailed query format information.
 
+@item social-reference
+@item function-in-buffer
+@findex ibtypes social-reference
+@cindex hashtag
+@cindex username
+@cindex social media
+@vindex hibtypes-social-default-service
+Displays the web page associated with a social media hashtag or username reference at point.
+Reference format is: [facebook|instagram|twitter]?[#@@] or
+[fb|in|tw]?[#@@].  Service defaults to the value of
+@code{hibtypes-social-default-service} when not given.
 
 @c Handled instead by @xref{Smart Key - Identifier Menu Mode}.
 @c @item imenu-item
-- 
cgit v1.0