[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole 6665a78470 2/5: Fix a number of ibut recognit
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole 6665a78470 2/5: Fix a number of ibut recognition issues |
Date: |
Sun, 18 Jun 2023 03:58:39 -0400 (EDT) |
branch: externals/hyperbole
commit 6665a78470e7a8578f4ef12dd5858dd7eb51c79b
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>
Fix a number of ibut recognition issues
---
hbut.el | 70 +++++++++++++++++++++++++++++++++---------------------
hui.el | 6 ++---
test/hbut-tests.el | 31 +++++++++++++++++-------
3 files changed, 68 insertions(+), 39 deletions(-)
diff --git a/hbut.el b/hbut.el
index 5ab00eaaad..356873ffa9 100644
--- a/hbut.el
+++ b/hbut.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 18-Sep-91 at 02:57:09
-;; Last-Mod: 11-Jun-23 at 13:42:14 by Bob Weiner
+;; Last-Mod: 11-Jun-23 at 21:32:08 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1652,13 +1652,17 @@ excluding delimiters, not just one."
;; Skip past any optional name and separators
(when name-end
(goto-char name-end)
- (if (looking-at ibut:label-separator-regexp)
- ;; Move past up to 2 possible characters of ibut
- ;; delimiters; this prevents recognizing named,
- ;; delimited ibuts of a single character since no one
- ;; should need that.
- (goto-char (min (+ 2 (match-end 0)) (point-max)))
- (goto-char opoint)))
+ (hattr:set 'hbut:current 'lbl-start
+ (if (looking-at ibut:label-separator-regexp)
+ (progn
+ ;; Move past up to 2 possible characters of ibut
+ ;; delimiters; this prevents recognizing named,
+ ;; delimited ibuts of a single character since no
one
+ ;; should need that.
+ (goto-char (min (+ 2 (match-end 0)) (point-max)))
+ (match-end 0))
+ (prog1 (point)
+ (goto-char opoint)))))
(setq lbl-start-end (if (and start-delim end-delim)
(ibut:label-p nil start-delim end-delim t t)
@@ -1743,9 +1747,9 @@ Store new button attributes in the symbol, 'hbut:current."
(unwind-protect
(progn (setq text-start (or (hattr:get 'hbut:current
'lbl-start)
(point))
- text-end (or (hattr:get 'hbut:current 'lbl-end)
- (point)))
+ text-end (hattr:get 'hbut:current 'lbl-end))
(unless (and (<= text-start (point))
+ text-end
(>= text-end (point)))
;; Move to text of ibut before trying to activate it
;; (may be on name)
@@ -2167,17 +2171,13 @@ Summary of operations based on inputs:
| nil | newname | region | mod: add newname to lbl-key ibut (skip region) |
|-------+----------+--------+------------------------------------------------|"
;; !! TODO: Code does not yet fully match what is in docstring table
- (let* ((lbl-key (hattr:get 'hbut:current 'lbl-key))
- (actype (hattr:get 'hbut:current 'actype))
+ (let* ((actype (hattr:get 'hbut:current 'actype))
(name (hattr:get 'hbut:current 'name))
(name-regexp (ibut:label-regexp (ibut:label-to-key name)))
(modify new-name)
(region-flag (hmouse-use-region-p))
;; (new-name-key)
(instance-flag))
- (unless (and (stringp lbl-key) (not (string-empty-p lbl-key)))
- (hypb:error "(ibut:operate): hbut:current ibut lbl-key (%s) must be
non-nil"
- lbl-key))
(unless actype
(hypb:error "(ibut:operate): hbut:current ibut actype (%s) must be
non-nil"
actype))
@@ -2239,7 +2239,7 @@ Summary of operations based on inputs:
(cond ((not (and name new-name))
;; No name to insert, just insert ibutton text below
)
- ((not name)
+ ((and (not name) new-name)
(setq start (point))
(insert new-name)
(setq end (point)))
@@ -2270,17 +2270,20 @@ Summary of operations based on inputs:
(equal buf-lbl name)))
nil)
((progn (when start (goto-char start))
- (looking-at (regexp-quote name)))
+ (when name (looking-at (regexp-quote name))))
(setq start (point)
end (match-end 0)))
- (t (setq start (point))
- (insert name)
- (setq end (point))))
+ (name
+ (setq start (point))
+ (insert name)
+ (setq end (point))))
+
(when (and start end)
(ibut:delimit start end instance-flag))
(ibut:insert-text 'hbut:current)
- (when start
- (goto-char start))))
+ (if start
+ (goto-char start)
+ (goto-char (max (- (point) 2) (point-min))))))
(t (hypb:error
"(ibut:operate): Operation failed. Check button attribute
permissions: %s"
@@ -2294,16 +2297,26 @@ Summary of operations based on inputs:
;; Position point
(let ((new-key (ibut:label-to-key new-name)))
- (cond ((equal (ibut:label-p) new-key)
+ (cond ((and new-key (equal (ibut:label-p) new-key))
;; In case right before the start of the desired
;; button's delimiters.
- (forward-char 2) (search-backward ibut:label-start nil t)
- (goto-char (match-end 0)))
- ((let ((regexp (ibut:label-regexp new-key)))
+ (goto-char (min (+ (point) 2) (point-max)))
+ (when (search-backward ibut:label-start nil t)
+ (goto-char (match-end 0))))
+ (new-key
+ (let ((regexp (ibut:label-regexp new-key)))
(or (re-search-forward regexp nil t)
(re-search-backward regexp nil t)))
(goto-char (+ (match-beginning 0) (length ibut:label-start))))))
+ (let ((lbl-key (hattr:get 'hbut:current 'lbl-key)))
+ (unless lbl-key
+ (when (ibut:set-name-and-label-key-p)
+ (setq lbl-key (hattr:get 'hbut:current 'lbl-key))))
+ (unless (and (stringp lbl-key) (not (string-empty-p lbl-key)))
+ (hypb:error "(ibut:operate): hbut:current ibut lbl-key (%s) must be
non-nil"
+ lbl-key)))
+
;; instance-flag might be 't which we don't want to return.
(when (stringp instance-flag) instance-flag)))
@@ -2318,7 +2331,10 @@ Summary of operations based on inputs:
(arg2 (nth 1 args))
(arg3 (nth 2 args)))
(pcase actype
- ('actypes::kbd-key (insert "{" arg1 "}" ))
+ ('actypes::kbd-key
+ (if (and (stringp arg1) (string-match "\\s-*{.+}\\s-*" arg1))
+ (insert arg1)
+ (insert "{" arg1 "}")))
((or 'actypes::link-to-directory 'actypes::link-to-Info-node
'actypes::link-to-Info-index-item)
(insert "\"" arg1 "\""))
('actypes::annot-bib (insert "[" arg1 "]"))
diff --git a/hui.el b/hui.el
index e4b2c19c47..2e591c1d41 100644
--- a/hui.el
+++ b/hui.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Sep-91 at 21:42:03
-;; Last-Mod: 11-Jun-23 at 12:04:31 by Bob Weiner
+;; Last-Mod: 11-Jun-23 at 21:13:08 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1035,7 +1035,7 @@ Signal an error when no such button is found in the
current buffer."
(hui:buf-writable-err but-buf "ibut-rename"))
(unless (ibut:get lbl-key but-buf)
- (hypb:error "(ibut-rename): Invalid button: '%s'." lbl))
+ (hypb:error "(ibut-rename): Invalid button: '%s'" lbl))
(setq new-lbl
(hargs:read
@@ -1043,7 +1043,7 @@ Signal an error when no such button is found in the
current buffer."
(lambda (lbl)
(and (not (string-equal lbl "")) (<= (length lbl) (hbut:max-len))))
lbl
- (format "(ibut-rename): Enter a string of at most %s chars."
+ (format "(ibut-rename): Enter a string of at most %s chars"
(hbut:max-len))
'string))
diff --git a/test/hbut-tests.el b/test/hbut-tests.el
index 4a36f097dc..e8c4e943a6 100644
--- a/test/hbut-tests.el
+++ b/test/hbut-tests.el
@@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 30-may-21 at 09:33:00
-;; Last-Mod: 11-Jun-23 at 11:29:30 by Bob Weiner
+;; Last-Mod: 11-Jun-23 at 21:39:38 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -246,14 +246,27 @@ Needed since hyperbole expands all links to absolute
paths and
(ert-deftest hbut-tests-ibut-insert-kbd-key ()
"Insert ibut to kbd-key."
- (with-temp-buffer
- (ibut:program "label" 'kbd-key "{ C-h h }")
- (should (string= "<[label]> - { C-h h }" (buffer-string)))
- (goto-char 3)
- (let ((but (ibut:at-p)))
- (with-temp-buffer
- (ibut:insert-text but)
- (should (string= "" (buffer-string)))))))
+ (let ((kbd-key-file (make-temp-file "kbd-key" nil ".txt"))
+ kbd-key-buf
+ but)
+ (unwind-protect
+ (progn
+ ;; Test with name
+ (setq kbd-key-buf (find-file kbd-key-file))
+ (ibut:program "label" 'kbd-key "{ C-f C-f }")
+ (save-buffer)
+ (should (string-match (concat (regexp-quote "<[label]> - { C-f C-f }")
+ "\\s-*")
+ (buffer-string)))
+ ;; Test without name
+ (erase-buffer)
+ (ibut:program nil 'kbd-key "{ C-f C-f }")
+ (save-buffer)
+ (should (string-match (concat (regexp-quote "{ C-f C-f }")
+ "\\s-*")
+ (buffer-string))))
+ (kill-buffer kbd-key-buf)
+ (hy-test-helpers:kill-buffer kbd-key-file))))
(ert-deftest hbut-tests-ibut-insert-text-temp-buffer ()
"Insert ibut text using an ibut in a temp buffer as source."
- [elpa] externals/hyperbole updated (26402fa498 -> 655df928af), ELPA Syncer, 2023/06/18
- [elpa] externals/hyperbole ef3a180e4b 3/5: Fix ibut-instance functions, ibut:operate and actypes hbut-tests, ELPA Syncer, 2023/06/18
- [elpa] externals/hyperbole ef9c00eaa8 1/5: Snapshot of still in progress ibut updates; see Todo list, ELPA Syncer, 2023/06/18
- [elpa] externals/hyperbole 6665a78470 2/5: Fix a number of ibut recognition issues,
ELPA Syncer <=
- [elpa] externals/hyperbole 655df928af 5/5: Merge branch 'rsw', ELPA Syncer, 2023/06/18
- [elpa] externals/hyperbole bcbb612de9 4/5: Fix all issues causing any test cases to fail., ELPA Syncer, 2023/06/18