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

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

[elpa] externals/hyperbole aa04634 14/51: Handle null key sent to link-t


From: Stefan Monnier
Subject: [elpa] externals/hyperbole aa04634 14/51: Handle null key sent to link-to-ibut and ibut:to
Date: Sun, 12 Jul 2020 18:10:10 -0400 (EDT)

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

    Handle null key sent to link-to-ibut and ibut:to
---
 Changes            |   7 +++++++
 hactypes.el        |  20 ++++++++++++++------
 hbut.el            |  53 +++++++++++++++++++++++++++--------------------------
 man/hyperbole.html |  13 +++++++------
 man/hyperbole.info | Bin 519705 -> 519773 bytes
 man/hyperbole.pdf  | Bin 1280037 -> 1280066 bytes
 man/hyperbole.texi |  13 +++++++------
 7 files changed, 62 insertions(+), 44 deletions(-)

diff --git a/Changes b/Changes
index 797965d..6b6c253 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,10 @@
+2020-01-25  Bob Weiner  <rsw@gnu.org>
+
+* hactypes.el (link-to-ibut): Handled null 'defaults' when called 
interactively; needed when
+    interactively creating a link-to-ibut and there is no ibut at point.  Also 
improved
+    error message when a link-to-ibut is invalid, i.e. has a null button 
reference.
+  hbut.el (ibut:to): Handled null lbl-key arg.
+
 2020-01-21  Bob Weiner  <rsw@gnu.org>
 
 * hbut.el (ibut:at-p): Fixed to recognize non-labeled ibuttons in programming 
modes.
diff --git a/hactypes.el b/hactypes.el
index eb99b55..f992a13 100644
--- a/hactypes.el
+++ b/hactypes.el
@@ -466,8 +466,13 @@ and its buffer must have a file attached."
    (let ((ibut-key (ibut:at-p t)))
      (if (and ibut-key buffer-file-name)
         (list ibut-key buffer-file-name (point))
+       ;; TODO: If default is null below and are creating, rather than 
modifying,
+       ;; the link, it would be better to throw an error than create
+       ;; an invalid link, but it is difficult to tell which operation
+       ;; is in progress, so ignore this for now.  -- RSW, 01-25-20020
+
        ;; When not on an ibut and moddifying the link, use existing arguments
-       (if (and (boundp 'defaults) (listp defaults))
+       (if (and (boundp 'defaults) defaults (listp defaults))
           defaults
         (list nil nil nil)))))
   (let (but
@@ -483,11 +488,14 @@ and its buffer must have a file attached."
        (widen)
        (if (integerp point) (goto-char (min point (point-max))))
        (setq but (ibut:to key))))
-    (if but
-       (hbut:act but)
-      (hypb:error "(link-to-ibut): No button `%s' in `%s'"
-                 (ibut:key-to-label key)
-                 (or key-file (buffer-name))))))
+    (cond (but
+          (hbut:act but))
+         (key
+          (hypb:error "(link-to-ibut): No implicit button `%s' found in `%s'"
+                      (ibut:key-to-label key)
+                      (or key-file (buffer-name))))
+         (t
+          (hypb:error "(link-to-ibut): Link reference is null/empty")))))
 
 (defact link-to-kcell (file cell-ref)
   "Display FILE with kcell given by CELL-REF at window top.
diff --git a/hbut.el b/hbut.el
index 17e2c5b..0a01a9f 100644
--- a/hbut.el
+++ b/hbut.el
@@ -1459,32 +1459,33 @@ move to the first occurrence of the button."
   "Find the nearest implicit button with LBL-KEY (a label or label key) within 
the visible portion of the current buffer.
 Leave point inside the button text or its optional label, if it has one.
 Return the symbol for the button, else nil."
-  ;; Handle a label given rather than a label key
-  (if (string-match-p "\\s-" lbl-key)
-      (setq lbl-key (ibut:label-to-key lbl-key)))
-  (let ((regexp (hbut:label-regexp lbl-key t))
-       pos
-       found)
-    (save-excursion
-      ;; Since point might be in the middle of the matching button,
-      ;; move to the start of line to ensure don't miss it when
-      ;; searching forward.
-      (forward-line 0)
-      ;; re-search forward
-      (while (and (not found) (re-search-forward regexp nil t))
-       (setq pos (match-beginning 0)
-             ;; Point might be on closing delimiter of ibut in which
-             ;; case ibut:label-p returns nil; move back one
-             ;; character to prevent this.
-             found (progn (goto-char (1- (point)))
-                          (equal (ibut:at-p t) lbl-key))))
-      ;; re-search backward
-      (while (and (not found) (re-search-backward regexp nil t))
-       (setq pos (match-beginning 0)
-             found (equal (ibut:label-p nil nil nil nil t) lbl-key))))
-    (when found
-      (goto-char pos)
-      (ibut:at-p))))
+  (when lbl-key
+    ;; Handle a label given rather than a label key
+    (if (string-match-p "\\s-" lbl-key)
+       (setq lbl-key (ibut:label-to-key lbl-key)))
+    (let ((regexp (hbut:label-regexp lbl-key t))
+         pos
+         found)
+      (save-excursion
+       ;; Since point might be in the middle of the matching button,
+       ;; move to the start of line to ensure don't miss it when
+       ;; searching forward.
+       (forward-line 0)
+       ;; re-search forward
+       (while (and (not found) (re-search-forward regexp nil t))
+         (setq pos (match-beginning 0)
+               ;; Point might be on closing delimiter of ibut in which
+               ;; case ibut:label-p returns nil; move back one
+               ;; character to prevent this.
+               found (progn (goto-char (1- (point)))
+                            (equal (ibut:at-p t) lbl-key))))
+       ;; re-search backward
+       (while (and (not found) (re-search-backward regexp nil t))
+         (setq pos (match-beginning 0)
+               found (equal (ibut:label-p nil nil nil nil t) lbl-key))))
+      (when found
+       (goto-char pos)
+       (ibut:at-p)))))
 
 ;;; ------------------------------------------------------------------------
 (defconst ibut:label-start "<["
diff --git a/man/hyperbole.html b/man/hyperbole.html
index 163bfd3..2b96e9d 100644
--- a/man/hyperbole.html
+++ b/man/hyperbole.html
@@ -2227,19 +2227,20 @@ Next: <a href="#Implicit-Buttons" accesskey="n" 
rel="next">Implicit Buttons</a>,
 <span id="index-button_002c-global-1"></span>
 <span id="index-button-label-1"></span>
 <span id="index-label_002c-button-1"></span>
-<p>Access to explicit buttons depends upon the information on your screen
-since they are embedded within particular buffers.  Sometimes it is
+<p>Sometimes it is
 useful to activate buttons without regard to the information with which
 you are working.  In such instances, you use <em>global buttons</em>, which
 are buttons that may be activated or otherwise operated upon by typing
 their labels/names when they are prompted for, rather than selecting the
-buttons within a buffer.
+buttons within a buffer.  In contrast, activation of explicit buttons
+depends upon the information on your screen since they are accessible
+only from within their particular buffers.
 </p>
 <p>If you want a permanent link to a file section that you can follow at
 any time, you can use a global button.  Or what about an Emacs keyboard
-macro that you use frequently?  Create an <code>exec-kbd-macro</code> button
-with an easy to type name and then you can activate it whenever the need
-arises.
+macro that you use frequently?  Create a global button with an action type
+of <code>exec-kbd-macro</code> button and an easy to type name.  Then you can
+activate it whenever the need arises.
 </p>
 <span id="index-C_002dh-h-g"></span>
 <span id="index-menu_002c-Gbut"></span>
diff --git a/man/hyperbole.info b/man/hyperbole.info
index 15cd0bf..79da4d4 100644
Binary files a/man/hyperbole.info and b/man/hyperbole.info differ
diff --git a/man/hyperbole.pdf b/man/hyperbole.pdf
index f8b38e1..246b9bb 100644
Binary files a/man/hyperbole.pdf and b/man/hyperbole.pdf differ
diff --git a/man/hyperbole.texi b/man/hyperbole.texi
index 7b23dde..0ab2669 100644
--- a/man/hyperbole.texi
+++ b/man/hyperbole.texi
@@ -1720,19 +1720,20 @@ asking for help on a button.
 @cindex button, global
 @cindex button label
 @cindex label, button
-Access to explicit buttons depends upon the information on your screen
-since they are embedded within particular buffers.  Sometimes it is
+Sometimes it is
 useful to activate buttons without regard to the information with which
 you are working.  In such instances, you use @dfn{global buttons}, which
 are buttons that may be activated or otherwise operated upon by typing
 their labels/names when they are prompted for, rather than selecting the
-buttons within a buffer.
+buttons within a buffer.  In contrast, activation of explicit buttons
+depends upon the information on your screen since they are accessible
+only from within their particular buffers.
 
 If you want a permanent link to a file section that you can follow at
 any time, you can use a global button.  Or what about an Emacs keyboard
-macro that you use frequently?  Create an @code{exec-kbd-macro} button
-with an easy to type name and then you can activate it whenever the need
-arises.
+macro that you use frequently?  Create a global button with an action type
+of @code{exec-kbd-macro} button and an easy to type name.  Then you can
+activate it whenever the need arises.
 
 @kindex C-h h g
 @cindex menu, Gbut



reply via email to

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