emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/hyperbole 508c1e6 1/3: In defal uses, add support for %


From: Stefan Monnier
Subject: [elpa] externals/hyperbole 508c1e6 1/3: In defal uses, add support for %s format-style grouping 1 subst
Date: Mon, 22 Mar 2021 18:01:39 -0400 (EDT)

branch: externals/hyperbole
commit 508c1e60d48926ef48edd6b26f95ee03fcf07109
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    In defal uses, add support for %s format-style grouping 1 subst
---
 Changes            |   9 +++++-
 DEMO               |  38 +++++++++++++++++++++----
 HY-NEWS            |  48 ++++++++++++++++++++-----------
 hbut.el            |  81 ++++++++++++++++++++++++++---------------------------
 hyperbole.el       |   2 +-
 man/hyperbole.html |  14 ++++-----
 man/hyperbole.info | Bin 543680 -> 543707 bytes
 man/hyperbole.pdf  | Bin 1300951 -> 1300976 bytes
 man/hyperbole.texi |  16 +++++------
 9 files changed, 127 insertions(+), 81 deletions(-)

diff --git a/Changes b/Changes
index da33caa..66db242 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,10 @@
+2021-03-21  Bob Weiner  <rsw@gnu.org>
+
+* hbut.el (defal): Added support for use of %s format-style grouping 1 arg
+    substitution.
+  man/hyperbole.texi (Action Button Link Types): Documented.
+  DEMO (defal): Added new example of Google file type search button.
+
 2021-03-14  Bob Weiner  <rsw@gnu.org>
 
 * man/hyperbole.texi (Smart Key - Magit Mode):
@@ -13,7 +20,7 @@
     (hbut-ib-create-label-fails-if-label-exists): Check creation fails
     when label exists
 
-* test/hy-test-dependencies.el (package-installed-p): Add
+* test/hy-test-dependencies.el (package-installed-p): Added
     with-simulated-input
 
 2021-03-13  Bob Weiner  <rsw@gnu.org>
diff --git a/DEMO b/DEMO
index ae1c87a..bbec515 100644
--- a/DEMO
+++ b/DEMO
@@ -786,8 +786,8 @@ button.
 You can do a huge number of things with existing Action Button types
 but sometimes you may want to define your own types for more advanced
 usage.  Hyperbole let's you easily create your own Action Button link
-types without knowing Elisp, if you understand Emacs regular
-expressions (see "(elisp)Regular Expressions").
+types without knowing Elisp, if you understand basic pattern
+replacement.
 
 In your Emacs initialization file, e.g. ~/.emacs, you will add a line of
 the form:
@@ -797,7 +797,7 @@ the form:
 where:
 
     TYPE is the name of the new type you want to create;
-    LINK-EXPR is a regular expression containing a \\1 grouping
+    LINK-EXPR is a regular expression containing a %s
       replacement string into which Hyperbole will substitute
       the button text following the TYPE from each button activated of
       this type; alternatively, LINK-EXPR may be the name of a function
@@ -811,17 +811,18 @@ activated as one of these 4 kinds:
     (1) a brace-delimited key series;
     (2) a URL/web link;
     (3) a path (possibly with trailing colon-separated line and column 
numbers);
-    (4) or a function of one argument, the button text sans the function name.
+    (4) or a function or action type of one argument, the button text sans the
+        function name.
 
 Let's try an example.  If you use Python and have a PYTHONPATH
 environment variable, then pressing {C-x C-e} after this expression:
 
-   (defal pylib "${PYTHONPATH}/\\1")
+   (defal pylib "${PYTHONPATH}/%s")
 
 defines a new action button link type called 'pylib’ whose buttons
 take the form of:
 
-   <pylib PYTHON-LIBRARY-NAME>
+   <pylib PYTHON-LIBRARY-FILENAME>
 
 and display the associated Python libraries (typically Python source
 files).  Optional colon separated line and column numbers may be given
@@ -835,6 +836,31 @@ This will display the source for "string.py" (wherever it 
is installed
 on your system) from the Python standard library with point on the
 fifth line at the seventh character.
 
+----
+
+As another example, suppose you want to do a web search for Emacs Lisp 
libraries whose names may be very generic, like hyperbole.  For this, you can 
use a Google filetype-specific search.
+
+Define an action link type with:
+
+    (defal elsearch "https://www.google.com/search?q=%s+filetype:el"; "Find 
Elisp libraries via a Google file type search")
+
+Then, an Action Key press on:
+
+    <elsearch burly>
+
+will find major links to that library which makes window
+configurations and framesets persistent across Emacs sessions.
+
+This search is actually built in to the Hyperbole menus, so you could
+have defined it more simply (and sans docstring) with a key series
+definition:
+
+    (defal elsearch "{C-h h f w e %s RET}")
+
+as well.
+
+----
+
 For more advanced and flexible regular expression-based link type
 creation, see the 'defil' expression in "(hyperbole)Implicit Button
 Link Types".  For any type of implicit button type creation using
diff --git a/HY-NEWS b/HY-NEWS
index d96456d..7e6bb84 100644
--- a/HY-NEWS
+++ b/HY-NEWS
@@ -7,22 +7,23 @@
 
   PROGRAMMING
 
-   - Easy Action Link Button Type Creation: `defal' is a new,
-     easy-to-use macro that generates new action button types from a
-     type name and a single simple regular expression, allowing
-     non-programmers to create their own implicit action button types
-     that execute key series, display URLs or display the contents of
-     pathnames.  See "(hyperbole)Action Button Link Types" or the
-     "DEMO#Defining New Action Button Types" section.
+   - Simple Action Link Button Type Creation: `defal' is a new,
+     easy-to-use construct that generates new action button types from
+     a type name and a single simple format expression, allowing
+     non-programmers to create their own implicit action button link
+     types that execute key series, display URLs, display the contents
+     of pathnames or invoke functions.  See "(hyperbole)Action Button
+     Link Types" or the "DEMO#Defining New Action Button Types"
+     section.
 
    - Easy Implicit Link Button Type Creation: `defil' is a new,
-     easy-to-use macro for those familiar with regular expressions but
-     not much Emacs Lisp.  This macro creates more flexible implicit
+     construct for those familiar with regular expressions but not
+     much Emacs Lisp.  This macro creates more flexible implicit
      button types than `defal' where the delimiters and text
      substitution can be specified with regular expressions.  Actions
-     are limited to executing key series, displaying URLs or
-     displaying the contents of a pathname.  See "(hyperbole)Implicit
-     Button Link Types".
+     are limited to executing key series, displaying URLs, displaying
+     the contents of pathnames or invoking functions.  See
+     "(hyperbole)Implicit Button Link Types".
 
      Elisp programmers should use the existing `defib' macro for full
      flexibility in implicit button type creation.  See "hibytpes.el"
@@ -75,11 +76,15 @@
       evaluate: (symset:clear 'ibtypes) and then reload hibtypes.{el,elc},
       the priority order of all implicit button types is reset.
 
-    - Git Support: In Magit Log and Blame listing modes, the Action
-      Key displays the associated commit or file line.  The Action Key
-      also handles single line log entries that begin with the word
-      'commit' , displaying their commits even from shell and
-      compilation buffers.
+    - Magit Mode Support: Just click or press the Action Key somewhere and it
+      will typically display what you want.  Extensive Action Key support in
+      Magit modes for cycling through display views and displaying items.
+
+      Action Mouse clicks on the modeline cycles display of commits/diffs in
+      a buffer.  In Magit Log and Blame listing modes, the Action Key
+      displays the associated commit or file line.  The Action Key also
+      handles single line log entries that begin with the word 'commit' ,
+      displaying their commits even from shell and compilation buffers.
 
     - Org Mode: Lowered to near bottom implicit button priority so that all
       implicit button types will work in Org mode.
@@ -103,6 +108,15 @@
       See "DEMO#Displaying File and Buffer Items and Moving Buffers".
 
 
+  TEST CASES
+
+    - Hyperbole Automated Testing: Git-based distributions of Hyperbole now
+      include a test subdirectory with many tests of hyperbole's button
+      types.  Simply run 'make test' or 'make test-all' from the command-line
+      when in the Hyperbole source directory and you should see all tests
+      pass.  If any fail, you can press the Action Key to see the source of
+      the failure.
+
 ===========================================================================
 *                                   V7.1.3
 ===========================================================================
diff --git a/hbut.el b/hbut.el
index 607eb5a..7c7fd76 100644
--- a/hbut.el
+++ b/hbut.el
@@ -1223,38 +1223,30 @@ Return number of buttons reported on or nil if none."
         ;; Ensure these do not invoke with-output-to-temp-buffer a second time.
         (temp-buffer-show-hook)
         (temp-buffer-show-function))
-    (if lbl-lst
-       (progn
-         (with-help-window buf-name
-           (princ hbut:source-prefix)
-           (prin1 key-src)
-           (terpri)
-           (terpri)
-           (mapcar
-            (lambda (lbl)
-              (if (setq but
-                        (cond ((or (null arg) (symbolp arg)) but)
-                              (t (ebut:get (ebut:label-to-key lbl) key-buf)))
-                        attribs (hattr:list but))
-                  (progn
-                    (princ (if (ibut:is-p but)
-                               lbl
-                             (concat ebut:start lbl ebut:end)))
-                    (terpri)
-                    (let ((doc (actype:doc but (= 1 (length lbl-lst)))))
-                      (if doc
-                          (progn
-                            (princ "  ")
-                            (princ doc)
-                            (terpri))))
-                    (hattr:report
-                     ;;                       (if (eq (car (cdr (memq 'categ 
attribs))) 'explicit)
-                     ;;                           (memq 'action attribs)
-                     ;;                         (memq 'categ attribs))
-                     attribs)
-                    (terpri))))
-            lbl-lst))
-         (length lbl-lst)))))
+    (when lbl-lst
+      (with-help-window buf-name
+       (princ hbut:source-prefix)
+       (prin1 key-src)
+       (terpri)
+       (terpri)
+       (mapcar
+        (lambda (lbl)
+          (when (setq but (cond ((or (null arg) (symbolp arg)) but)
+                                (t (ebut:get (ebut:label-to-key lbl) key-buf)))
+                      attribs (hattr:list but))
+            (princ (if (ibut:is-p but)
+                       lbl
+                     (concat ebut:start lbl ebut:end)))
+            (terpri)
+            (let ((doc (actype:doc but (= 1 (length lbl-lst)))))
+              (when doc
+                (princ "  ")
+                (princ doc)
+                (terpri)))
+            (hattr:report attribs)
+            (terpri)))
+        lbl-lst))
+      (length lbl-lst))))
 
 (defun    hbut:source (&optional full)
   "Return Hyperbole source buffer or file given at point.
@@ -1801,20 +1793,27 @@ commit changes."
                                               ,end-regexp-flag))
                 actype)
             (when (and button-text (string-match ,text-regexp button-text))
+              ;; Get the action type when link-expr is a function
+              ;; symbol, symbol name or function body
               (setq actype (cond ((or (functionp ,link-expr) (subrp 
,link-expr))
                                   ,link-expr)
                                  (t (actype:action ,link-expr))))
               (if actype
                   (if (and (equal ,start-delim "<") (equal ,end-delim ">"))
                       ;; Is an Action Button; send only the non-space
-                      ;; text after the action to link-expr.
+                      ;; text after the action to link-expr
                       (hact actype (progn (string-match "\\s-+" button-text)
                                           (substring button-text (match-end 
0))))
                     (hact actype button-text))
-                (let ((referent (when (and button-text (stringp ,link-expr)
-                                           (string-match ,text-regexp 
button-text))
-                                  (replace-match ,link-expr t nil 
button-text))))
-                  (ibtype:activate-link referent))))))
+                (when (and (stringp ,link-expr) (string-match ,text-regexp 
button-text))
+                  ;; Change %s format syntax in link-expr to \\1 regexp 
replacement syntax
+                  (let ((referent (replace-match (save-match-data
+                                                   (if (string-match 
"\\(\\`\\|[^%]\\)\\(%s\\)" ,link-expr)
+                                                       (replace-match 
"\\1\\\\1" t nil ,link-expr)
+                                                     ,link-expr))
+                                                 t nil button-text)))
+                    ;; link-expr is a string
+                    (ibtype:activate-link referent)))))))
        (put (intern (format "ibtypes::%s" ',type))
            'function-documentation
            (or ,doc
@@ -1833,7 +1832,7 @@ commit changes."
            def-body))
 
 (defmacro defal (type link-expr &optional doc)
-  "Create Hyperbole action button link TYPE (an unquoted symbol) whose buttons 
look like: <TYPE link-text> where link-text is substituted into LINK-EXPR as 
grouping 1 (\\\\1).
+  "Create Hyperbole action button link TYPE (an unquoted symbol) whose buttons 
look like: <TYPE link-text> where link-text is substituted into LINK-EXPR as 
grouping 1 (specified either as %s or \\\\1).
 Hyperbole automatically creates a doc string for the type but you can
 override this by providing an optional DOC string.
 
@@ -1847,7 +1846,7 @@ LINK-EXPR may be:
 Prior to button activation, for the first three kinds of
 LINK-EXPR, a `replace-match' is done on the expression to
 generate the button-specific referent to display, substituting
-\\\\1 in the LINK-EXPR for the text/label from the button.
+%s or \\\\1 in the LINK-EXPR for the text/label from the button.
 
 For the fourth kind, LINK-EXPR is a function of one argument which is
 either the full button text or in the case of an Action Button, the
@@ -1857,12 +1856,12 @@ Here is a sample use case.  If you use Python and have a
 PYTHONPATH environment variable setup, then pressing
 \\[eval-last-sexp] after this expression:
 
-   (defal pylib \"${PYTHONPATH}/\\\\1\")
+   (defal pylib \"${PYTHONPATH}/%s\")
 
 defines a new action button link type called 'pylib' whose buttons
 take the form of:
 
-   <pylib PYTHON-LIBRARY-NAME>
+   <pylib PYTHON-LIBRARY-FILENAME>
 
 and display the associated Python libraries (typically Python source
 files).  Optional colon separated line and column numbers may be given
diff --git a/hyperbole.el b/hyperbole.el
index bf645ce..d6dc0d7 100644
--- a/hyperbole.el
+++ b/hyperbole.el
@@ -5,7 +5,7 @@
 ;; Author:           Bob Weiner
 ;; Maintainer:       Bob Weiner <rsw@gnu.org>, Mats Lidell <matsl@gnu.org>
 ;; Created:          06-Oct-92 at 11:52:51
-;; Released:         21-Feb-21
+;; Released:         21-Mar-21
 ;; Version:          7.1.4 (pre-release)
 ;; Keywords:         comm, convenience, files, frames, hypermedia, languages, 
mail, matching, mouse, multimedia, outlines, tools, wp
 ;; Package:          hyperbole
diff --git a/man/hyperbole.html b/man/hyperbole.html
index b2a821f..4828a86 100644
--- a/man/hyperbole.html
+++ b/man/hyperbole.html
@@ -363,7 +363,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</P>
 
 <PRE>
 Edition 7.1.4
-Printed March 14, 2021.
+Printed March 21, 2021.
 
   Published by the Free Software Foundation, Inc.
   Author:    Bob Weiner
@@ -7259,10 +7259,10 @@ number of buttons can be recognized within text) is to 
create an
 </p>
 <p>will create a Hyperbole action button link TYPE (an unquoted symbol)
 whose buttons always take the form of: <code>&lt;TYPE link-text&gt;</code> 
where
-<code>link-text</code> is substituted into LINK-EXPR as grouping 1 (\\1)
-to form the link referent that is displayed for each button.
-Hyperbole automatically creates a doc string for the type but you can
-override this by providing an optional DOC string.
+<code>link-text</code> is substituted into LINK-EXPR as grouping 1 (wherever
+%s or \\1 is found) to form the link referent that is displayed for
+each button.  Hyperbole automatically creates a doc string for the
+type but you can override this by providing an optional DOC string.
 </p>
 <p>When the Action Key is pressed in a buffer between the start and end
 delimiters and the text in-between matches to TEXT-REGEXP, then the
@@ -7279,12 +7279,12 @@ button is activated and does one of four things with 
LINK-EXPR:
 variable, then pressing <kbd>{C-x C-e}</kbd> <code>eval-last-sexp</code> after
 this expression:
 </p>
-<p><code>(defal pylib &quot;${PYTHONPATH}/\\1&quot;)</code>
+<p><code>(defal pylib &quot;${PYTHONPATH}/%s&quot;)</code>
 </p>
 <p>defines a new action button link type called ’pylib’ whose buttons
 take the form of:
 </p>
-<p><code>&lt;pylib PYTHON-LIBRARY-NAME&gt;</code>
+<p><code>&lt;pylib PYTHON-LIBRARY-FILENAME&gt;</code>
 </p>
 <p>and display the associated Python libraries (typically Python source
 files).  Optional colon separated line and column numbers may be given
diff --git a/man/hyperbole.info b/man/hyperbole.info
index 8484225..0caf29c 100644
Binary files a/man/hyperbole.info and b/man/hyperbole.info differ
diff --git a/man/hyperbole.pdf b/man/hyperbole.pdf
index efba952..ca44067 100644
Binary files a/man/hyperbole.pdf and b/man/hyperbole.pdf differ
diff --git a/man/hyperbole.texi b/man/hyperbole.texi
index f815264..873619a 100644
--- a/man/hyperbole.texi
+++ b/man/hyperbole.texi
@@ -155,7 +155,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</P>
 
 <PRE>
 Edition 7.1.4
-Printed March 14, 2021.
+Printed March 21, 2021.
 
   Published by the Free Software Foundation, Inc.
   Author:    Bob Weiner
@@ -197,7 +197,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 @example
 Edition 7.1.4
-March 14, 2021
+March 21, 2021
 
   Published by the Free Software Foundation, Inc.
   Author:    Bob Weiner
@@ -5991,10 +5991,10 @@ A call to the @code{defal} macro of the form:
 @noindent
 will create a Hyperbole action button link TYPE (an unquoted symbol)
 whose buttons always take the form of: @code{<TYPE link-text>} where
-@code{link-text} is substituted into LINK-EXPR as grouping 1 (\\1)
-to form the link referent that is displayed for each button.
-Hyperbole automatically creates a doc string for the type but you can
-override this by providing an optional DOC string.
+@code{link-text} is substituted into LINK-EXPR as grouping 1 (wherever
+%s or \\1 is found) to form the link referent that is displayed for
+each button.  Hyperbole automatically creates a doc string for the
+type but you can override this by providing an optional DOC string.
 
 When the Action Key is pressed in a buffer between the start and end
 delimiters and the text in-between matches to TEXT-REGEXP, then the
@@ -6011,13 +6011,13 @@ For example, if you use Python and have a 
@samp{PYTHONPATH} environment
 variable, then pressing @bkbd{C-x C-e} @code{eval-last-sexp} after
 this expression:
 
-@code{(defal pylib "$@{PYTHONPATH@}/\\1")}
+@code{(defal pylib "$@{PYTHONPATH@}/%s")}
 
 @noindent
 defines a new action button link type called ’pylib’ whose buttons
 take the form of:
 
-@code{<pylib PYTHON-LIBRARY-NAME>}
+@code{<pylib PYTHON-LIBRARY-FILENAME>}
 
 @noindent
 and display the associated Python libraries (typically Python source



reply via email to

[Prev in Thread] Current Thread [Next in Thread]