[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole 730b06f: Fix four ebut and /tmp-related tests
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole 730b06f: Fix four ebut and /tmp-related tests that were failing |
Date: |
Sun, 26 Sep 2021 13:57:12 -0400 (EDT) |
branch: externals/hyperbole
commit 730b06f9f46fe7332cd99cde8795bcde8ccf9829
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>
Fix four ebut and /tmp-related tests that were failing
---
ChangeLog | 13 ++++++
hbut.el | 133 +++++++++++++++++++++++++++--------------------------
hmail.el | 7 +--
test/hbut-tests.el | 12 ++---
4 files changed, 89 insertions(+), 76 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7900030..ab053be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-09-26 Robert Weiner <bk@bka-iMac.lan>
+
+* hbut.el (ebut:operate): Rewrote to handle label modification properly and
thereby
+ fixed
hui-ebut-modify-link-to-www-url-keeping-all-values-should-not-modify-buffer-or-ebut
+ test.
+
+* hmail.el (hmail:hbdata-to-p): Update doc string and generalize to handle
button
+ data embedded in non-mail buffers, e.g. temp buffers for testing.
+ test/hbut-tests.el (hypb:program-create-ebut-in-buffer):
+ Above fix resolved bug that hbut:at-p did not recognize a button created
+ within a buffer without a file attached, causing this test to fail.
+ Also fixed ebut-delete-removes-ebut-and-returns-button-data test.
+
2021-09-26 Bob Weiner <rsw@gnu.org>
* kotl/kexport.el (kexport:html): Improve vertical alignment of expand/collapse
diff --git a/hbut.el b/hbut.el
index 6957751..6729b91 100644
--- a/hbut.el
+++ b/hbut.el
@@ -324,9 +324,7 @@ button is found in the current buffer."
(if modify (ebut:modify lbl-key) (ebut:create)))
(when (hmail:editor-p)
(hmail:msg-narrow))))
- (if instance-flag
- (progn
- (when modify
+ (cond (modify
;; Rename all occurrences of button - those with same label
(let* ((but-key-and-pos (ebut:label-p nil nil nil 'pos))
(at-but (equal (car but-key-and-pos)
@@ -346,69 +344,72 @@ button is found in the current buffer."
(at-but)
((hypb:error "(ebut:operate): No button matching: %s"
curr-label)))))
- ;; Add a new button recording its start and end positions
- (let (start end mark prev-point buf-lbl)
- (cond ((not curr-label)
- (setq start (point))
- (insert new-label)
- (setq end (point)))
- ((and (hmouse-use-region-p)
- (if (hyperb:stack-frame
- '(hui:ebut-create hui:ebut-edit
- hui:ebut-modify hui:gbut-create
- hui:gbut-modify
hui:link-create ebut:program))
- ;; Ignore action-key-depress-prev-point
- (progn (setq mark (marker-position
(hypb:mark-marker t))
- start (region-beginning)
- end (region-end)
- buf-lbl
(buffer-substring-no-properties start end))
- (equal buf-lbl curr-label))
- ;; Utilize any action-key-depress-prev-point
- (progn (setq mark (marker-position (hypb:mark-marker
t)))
- (setq prev-point (and
action-key-depress-prev-point
- (marker-position
action-key-depress-prev-point)))
- (setq start (if (and prev-point mark (<=
prev-point mark))
- prev-point
- (region-beginning))
- end (if (and prev-point mark (>
prev-point mark))
- prev-point
- (region-end))
- buf-lbl (buffer-substring-no-properties
start end))
- (equal buf-lbl curr-label))))
- nil)
- ((progn (when start (goto-char start))
- (looking-at (regexp-quote curr-label)))
- (setq start (point)
- end (match-end 0)))
- (t (setq start (point))
- (insert curr-label)
- (setq end (point))))
- (ebut:delimit start end instance-flag)
- (goto-char start))
-
- ;; Append any instance-flag string to the button label
- (when (stringp instance-flag)
- (setq new-label (concat new-label instance-flag))
- (hattr:set 'hbut:current 'lbl-key (ebut:label-to-key new-label)))
-
- ;; Position point
- (let ((new-key (ebut:label-to-key new-label)))
- (cond ((equal (ebut:label-p) new-key)
- ;; In case right before the start of the desired
- ;; button's delimiters.
- (forward-char 2) (search-backward ebut:start nil t)
- (goto-char (match-end 0)))
- ((let ((regexp (ebut:label-regexp new-key)))
- (or (re-search-forward regexp nil t)
- (re-search-backward regexp nil t)))
- (goto-char (+ (match-beginning 0) (length ebut:start))))))
-
- ;; instance-flag might be 't which we don't want to return.
- (when (stringp instance-flag) instance-flag))
-
- (hypb:error
- "(ebut:operate): Operation failed. Check button attribute permissions:
%s"
- hattr:filename))))
+ (instance-flag
+ ;; Add a new button recording its start and end positions
+ (let (start end mark prev-point buf-lbl)
+ (cond ((not curr-label)
+ (setq start (point))
+ (insert new-label)
+ (setq end (point)))
+ ((and (hmouse-use-region-p)
+ (if (hyperb:stack-frame
+ '(hui:ebut-create hui:ebut-edit
+ hui:ebut-modify hui:gbut-create
+ hui:gbut-modify
hui:link-create ebut:program))
+ ;; Ignore action-key-depress-prev-point
+ (progn (setq mark (marker-position
(hypb:mark-marker t))
+ start (region-beginning)
+ end (region-end)
+ buf-lbl
(buffer-substring-no-properties start end))
+ (equal buf-lbl curr-label))
+ ;; Utilize any action-key-depress-prev-point
+ (progn (setq mark (marker-position (hypb:mark-marker
t)))
+ (setq prev-point (and
action-key-depress-prev-point
+ (marker-position
action-key-depress-prev-point)))
+ (setq start (if (and prev-point mark (<=
prev-point mark))
+ prev-point
+ (region-beginning))
+ end (if (and prev-point mark (>
prev-point mark))
+ prev-point
+ (region-end))
+ buf-lbl (buffer-substring-no-properties
start end))
+ (equal buf-lbl curr-label))))
+ nil)
+ ((progn (when start (goto-char start))
+ (looking-at (regexp-quote curr-label)))
+ (setq start (point)
+ end (match-end 0)))
+ (t (setq start (point))
+ (insert curr-label)
+ (setq end (point))))
+ (ebut:delimit start end instance-flag)
+ (goto-char start)))
+
+ (t (hypb:error
+ "(ebut:operate): Operation failed. Check button attribute
permissions: %s"
+ hattr:filename)))
+
+ ;; Append any instance-flag string to the button label
+ (when (stringp instance-flag)
+ (setq new-label (concat new-label instance-flag))
+ (hattr:set 'hbut:current 'lbl-key (ebut:label-to-key new-label)))
+
+ ;; Position point
+ (let ((new-key (ebut:label-to-key new-label)))
+ (cond ((equal (ebut:label-p) new-key)
+ ;; In case right before the start of the desired
+ ;; button's delimiters.
+ (forward-char 2) (search-backward ebut:start nil t)
+ (goto-char (match-end 0)))
+ ((let ((regexp (ebut:label-regexp new-key)))
+ (or (re-search-forward regexp nil t)
+ (re-search-backward regexp nil t)))
+ (goto-char (+ (match-beginning 0) (length ebut:start))))))
+
+ ;; instance-flag might be 't which we don't want to return.
+ (when (stringp instance-flag) instance-flag)))
+
+
(defun ebut:program (label actype &rest args)
"Programmatically create an explicit Hyperbole button at point from LABEL,
ACTYPE (action type), and optional actype ARGS.
diff --git a/hmail.el b/hmail.el
index 59a62fa..94027e3 100644
--- a/hmail.el
+++ b/hmail.el
@@ -78,14 +78,15 @@ MSG-END."
(if (search-backward hmail:hbdata-sep msg-start t) (1- (point)) msg-end)))
(defun hmail:hbdata-to-p ()
- "Move point to Hyperbole but data start in an e-mail msg.
-Return t if button data is found."
+ "When in a buffer with embedded Hyperbole button data, move point to the
start of the button data.
+Return t if button data is found, else nil."
(and (cond ((memq major-mode (list hmail:reader hmail:modifier))
(hmail:msg-narrow) t)
((or (hmail:lister-p) (hnews:lister-p)) t)
((memq major-mode (list hmail:composer hnews:reader
hnews:composer))
- (widen) t))
+ (widen) t)
+ ((not buffer-file-name)))
(progn
(goto-char (point-max))
(if (search-backward hmail:hbdata-sep nil t)
diff --git a/test/hbut-tests.el b/test/hbut-tests.el
index b87caed..a107332 100644
--- a/test/hbut-tests.el
+++ b/test/hbut-tests.el
@@ -21,11 +21,10 @@
(require 'el-mock)
(defun hbut-tests:should-match-tmp-folder (tmp)
- "Check TMP match either regular /tmp or private/tmp.
+ "Check that TMP match either a list of a single element of \"/tmp\" or
\"private/tmp\".
Needed since hyperbole expands all links to absolute paths and
/tmp can be a symbolic link."
- (should (or (equal tmp '("/tmp"))
- (equal tmp '("private/tmp")))))
+ (should (member tmp '(("/tmp") ("./tmp") ("private/tmp")))))
(ert-deftest ebut-program-link-to-directory ()
"Programatically create ebut with link-to-directory."
@@ -35,7 +34,7 @@ Needed since hyperbole expands all links to absolute paths and
(find-file file)
(ebut:program "label" 'link-to-directory "/tmp")
(should (eq (hattr:get (hbut:at-p) 'actype)
'actypes::link-to-directory))
- (should (equal (hattr:get (hbut:at-p) 'args) '("/tmp")))
+ (hbut-tests:should-match-tmp-folder (hattr:get (hbut:at-p) 'args))
(should (equal (hattr:get (hbut:at-p) 'lbl-key) "label")))
(delete-file file))))
@@ -104,12 +103,11 @@ Needed since hyperbole expands all links to absolute
paths and
(should (equal (hattr:get (hbut:at-p) 'lbl-key) "global")))))))
(ert-deftest hypb:program-create-ebut-in-buffer ()
- "Create button with hypb:program in buffer.
-BUG: hbut:at-p does not recognise a button created within a buffer."
+ "Create button with hypb:program in buffer."
(with-temp-buffer
(ebut:program "label" 'link-to-directory "/tmp")
(should (eq (hattr:get (hbut:at-p) 'actype) 'actypes::link-to-directory))
- (should (equal (hattr:get (hbut:at-p) 'args) '("./tmp")))
+ (hbut-tests:should-match-tmp-folder (hattr:get (hbut:at-p) 'args))
(should (equal (hattr:get (hbut:at-p) 'lbl-key) "label"))))
(ert-deftest hypb:program-create-link-to-file-line-and-column-but-in-file ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/hyperbole 730b06f: Fix four ebut and /tmp-related tests that were failing,
ELPA Syncer <=