Skip to content

Commit

Permalink
Merge pull request #650 from rswgnu/rsw
Browse files Browse the repository at this point in the history
ert-should ibtype; hypb:with-macro; rewrite of Hyperbole {C-w} and {M-w} commands and updates to tests
  • Loading branch information
rswgnu authored Jan 20, 2025
2 parents bb7909e + 72ffc88 commit c91b745
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 134 deletions.
49 changes: 48 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
2025-01-20 Bob Weiner <[email protected]>

* hsys-ert.el (require 'hbut): For 'defib'.

* test/hui-tests.el (hui--kill-highlighted-region,
hui--kill-non-highlighted-region): Separate and rename
these tests. Rearrange letters in each subtest so can find which should
is being called.

* hui.el (hui:validate-region): Add to check for valid region args.
(hui-kill-ring-save): Call above function.

* test/hui-tests.el (hui--kill-region,
hui--kill-region-multiple-kill): Add let of
'mark-even-if-inactive'. Also, interactively, set beg and end only
if 'mark-active' is non-nil.

2025-01-19 Bob Weiner <[email protected]>

* hui.el (hui:kill-region): Complete doc string. Set 'region' arg to nil when
killing a delimited region at point. Also use 'hui-select-at-delimited-thing-p'
instead of 'hui-select-delimited-thing'.
(hui:delimited-selectable-thing)
hui:delimited-selectable-thing-and-bounds): Fix so doesn't create an
in-memory Hyperbole button at point if already doing so in a prior stack frame.
The latter is used in 'hui-kill-ring-save' bound to {M-w} in 'hyperbole-mode'.
(require 'hversion): Since 'hyperb:stack-frame' is defined there and
used herein.

* hsys-ert.el (ert-should): Add this new file and implicit button type.
See the Commentary therein for details.
hibtypes.el (load "hsys-ert"): Load above ibtype at near lowest priority.
hui-mouse.el (hkey-alist): Move priority of ert-results-mode to after
(hbut:at-p) so can define implicit buttons in this mode that override
the standard behavior.
man/hyperbole.texi (Smart Key - ERT Results Mode): Update order in the
Hyperbole manual. Also add `ert-should' ibtype.
MANIFEST, Makefile (EL_COMPILE): Add "hsys-ert.el".

* hypb.el (hypb:with-marker): Add context macro for setting a buffer marker
and automatically setting it to nil at the end of the context.

* hui.el (hui:kill-region): Update to only apply completion behavior when
'dynamic-completion-mode' is enabled and call subfunctions interactively
in interactive flag is set.
(hui-kill-region): Simplify 'hui-select-delimited-thing'.

2025-01-19 Mats Lidell <[email protected]>

* test/hui-tests.el (hui--kill-region-multiple-kill, hui--kill-region):
Test hui-kill-region.
Test hui-kill-region.

2025-01-18 Bob Weiner <[email protected]>

Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ topwin.py - Python script to find the topmost macOS app window at a s

* --- EXTERNAL SYSTEM ENCAPSULATIONS ---
hsys-consult.el - Hyperbole interactive consult-grep convenience functions
hsys-ert.el - Hyperbole support for jumping to ert 'should' source lines
hsys-flymake.el - Add missing source buffer keymap to flymake linter
hsys-org.el - GNU Hyperbole support functions for Org mode
hsys-org-roam.el - GNU Hyperbole support functions for Org Roam
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Bob Weiner
#
# Orig-Date: 15-Jun-94 at 03:42:38
# Last-Mod: 16-Dec-24 at 23:36:16 by Mats Lidell
# Last-Mod: 19-Jan-25 at 17:53:51 by Bob Weiner
#
# Copyright (C) 1994-2023 Free Software Foundation, Inc.
# See the file HY-COPY for license information.
Expand Down Expand Up @@ -209,7 +209,7 @@ EL_COMPILE = hact.el hactypes.el hargs.el hbdata.el hbmap.el hbut.el \
hinit.el hload-path.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 hproperty.el hrmail.el hsettings.el hsmail.el hsys-consult.el \
hsys-flymake.el \
hsys-ert.el hsys-flymake.el \
hsys-org.el hsys-org-roam.el hsys-www.el hsys-xref.el hsys-youtube.el htz.el \
hycontrol.el hui-jmenu.el hui-menu.el hui-mini.el hui-mouse.el hui-select.el \
hui-treemacs.el hui-window.el hui.el hvar.el hversion.el hynote.el hypb.el hyperbole.el \
Expand Down
8 changes: 7 additions & 1 deletion hibtypes.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Sep-91 at 20:45:31
;; Last-Mod: 5-Jan-25 at 11:15:09 by Bob Weiner
;; Last-Mod: 19-Jan-25 at 17:56:38 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -91,6 +91,12 @@
;; them. Use load instead to ensure are reloaded when resetting
;; ibtype priorities.

;;; ========================================================================
;;; Supports jumping to Emacs Regression Test (ert) 'should' source lines
;;; ========================================================================

(load "hsys-ert")

;;; ========================================================================
;;; Displays Org and Org Roam files and sections by name link
;;; ========================================================================
Expand Down
117 changes: 117 additions & 0 deletions hsys-ert.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
;;; hsys-ert.el --- Hyperbole support for jumping to ert 'should' source lines -*- lexical-binding: t -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Jan-25
;; Last-Mod: 20-Jan-25 at 02:00:12 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.

;;; Commentary:
;;
;; ERT is the Emacs Regression Test framework in "ert.el". Hyperbole uses
;; it for all of its regression testing as well.
;;
;; Sometimes when building Emacs Lisp tests with the ERT package, multiple
;; tests are added to a single test fixture/function. Each subtest
;; has its own `should'-type clause. But if one of these subtests fails,
;; ERT shows you the test name and the should clause in its results buffer
;; but if there are 12 subtests, it is difficult to match the displayed
;; should clause to the source line that ran it.
;;
;; The `ert-should' implicit button type defined herein solves this problem.
;; Hyperbole loads this and then a press of the Action Key within an ert
;; results buffer (or another buffer to which the results have been copied)
;; produces the following:
;;
;; - If on the first line of the result with the test name, jump to the
;; test definition.
;;
;; - If on a highlighted button, activate the button.
;;
;; - Otherwise if not at the end of a line and within a failed test result,
;; find the `should' clause and go to the matching line within the test
;; source code. An easy way to use it is to put point at the beginning
;; of a line other than the first within an ert result and press the
;; Action Key.

;;; Code:

;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'hbut) ;; For defib

;;; ************************************************************************
;;; Implicit button types
;;; ************************************************************************

(defib ert-should ()
"Jump to the source code definition of a should expr from an ert test failure.
If on the first line of a failure, jump to the source definition of the
associated test."
(when (or (derived-mode-p 'ert-results-mode)
(save-excursion
(forward-line 0)
(or (search-backward "(ert-test-failed\n" nil t)
(search-forward "(ert-test-failed\n" nil t))))
(catch 'exit
(save-excursion
(save-restriction
(forward-line 0)
(cond ((looking-at "\\`\\|^[AFPS] ")
;; On a result line with a test name, jump to the test
(goto-char (match-end 0))
;; Use the test definition name as the ibut label
(ibut:label-set (buffer-substring-no-properties
(+ 2 (line-beginning-position))
(line-end-position))
(+ 2 (line-beginning-position))
(line-end-position))
(let ((major-mode 'emacs-lisp-mode))
(if (button-at (point))
;; jump to source buffer
(push-button)
(throw 'exit (hact 'smart-lisp)))))
((looking-at "\\s-*(ert-test-failed\\s-")
(when (re-search-forward "^\\s-+(\\((should\\)\\(-\\|\\s-\\)" nil t)
(goto-char (match-beginning 1))))
((looking-at "\\s-*(\\((should\\)\\(-\\|\\s-\\)")
(goto-char (match-beginning 1)))
((re-search-backward "\\`\\|^[AFPS] " nil t)
(let ((start (point)))
(goto-char (1+ (point)))
(when (re-search-forward "^[AFPS] \\|\\'" nil t)
(goto-char (1- (match-beginning 0)))
(narrow-to-region start (point))
(goto-char start)
(when (re-search-forward "^\\s-+(\\((should\\)\\(-\\|\\s-\\)" nil t)
(goto-char (match-beginning 1)))))))
(when (looking-at "(should\\(-\\|\\s-\\)")
(let ((should-regexp (regexp-quote (thing-at-point 'sexp))))
(setq should-regexp (replace-regexp-in-string
"[ \t\n\r\f]+" "\\s-+" (string-trim should-regexp)
t t))
;; follow the function link to the source file of the function
(when (re-search-backward "^[AFPS] " nil t)
(goto-char (match-end 0))
(let ((major-mode 'emacs-lisp-mode))
(if (button-at (point))
;; jump to source buffer
(push-button)
(smart-lisp))
;; re-search-forward for should-regexp
(when (re-search-forward should-regexp nil t)
(goto-char (match-beginning 0))
(ibut:label-set "(should" (point) (+ (point) 7))
(hact 'identity t)))))))))))

(provide 'hsys-ert)

;;; hsys-ert.el ends here
12 changes: 6 additions & 6 deletions hui-mouse.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 04-Feb-89
;; Last-Mod: 29-Dec-24 at 12:29:33 by Mats Lidell
;; Last-Mod: 19-Jan-25 at 16:40:13 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -248,11 +248,6 @@ Its default value is `smart-scroll-down'. To disable it, set it to
((eq major-mode 'dired-sidebar-mode)
. ((smart-dired-sidebar) . (smart-dired-sidebar)))
;;
((and (eq major-mode 'ert-results-mode)
(featurep 'ert-results)
(setq hkey-value (ert-results-filter-status-p)))
. ((smart-ert-results hkey-value) . (smart-ert-results-assist hkey-value)))
;;
;; Handle Emacs push buttons in buffers
((and (fboundp 'button-at) (button-at (point)))
. ((smart-push-button nil (mouse-event-p last-command-event))
Expand Down Expand Up @@ -369,6 +364,11 @@ Its default value is `smart-scroll-down'. To disable it, set it to
(smart-helm-line-has-action))))
. ((smart-helm) . (smart-helm-assist)))
;;
((and (eq major-mode 'ert-results-mode)
(featurep 'ert-results)
(setq hkey-value (ert-results-filter-status-p)))
. ((smart-ert-results hkey-value) . (smart-ert-results-assist hkey-value)))
;;
;; Support the OO-Browser when available. It is a separate Emacs
;; package not included with Hyperbole. Within an OO-Browser
;; OOBR-FTR buffer, an *Implementors* listing buffer, or an
Expand Down
14 changes: 7 additions & 7 deletions hui-select.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Oct-96 at 02:25:27
;; Last-Mod: 9-Sep-24 at 22:25:55 by Bob Weiner
;; Last-Mod: 19-Jan-25 at 10:04:03 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -67,12 +67,12 @@
;; kill ring
;; `hui-select-and-kill-thing' - kill the syntactical unit at point
;; `hui-select-goto-matching-tag' - In modes listed in the variable,
;; `hui-select-markup-modes'), move point to the
;; start of the tag paired with the closest tag that point is within or
;; which it precedes, so you can quickly jump back and forth between
;; open and close tags. In these modes, this is bound to {C-c .}
;; `hui-select-at-p' - predicate to test if a buffer position (or point) starts
;; or ends a matching syntactical region (excluding a single character).
;; `hui-select-markup-modes', move point to the start of the tag paired
;; with the closest tag that point is within or which it precedes, so
;; you can quickly jump back and forth between open and close tags. In
;; these modes, this is bound to {C-c .}
;; `hui-select-at-p' - predicate to test if a buffer position (or point)
;; starts or ends a matching syntactical region (excluding a single character).
;;
;; ---------------
;; SETUP IF USED SEPARATELY FROM HYPERBOLE (otherwise ignore):
Expand Down
Loading

0 comments on commit c91b745

Please sign in to comment.