From 04f5d5a3493465ea9876420a2515ece3fe7b6256 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 25 Sep 2026 07:22:42 +0700 Subject: [PATCH] Under Evil, a digit in the break buffer takes the restart, because the buffer's keys take precedence over Evil's --- emacs/flan-cnr.el | 8 ++++++++ emacs/test-flan-cider.el | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/emacs/flan-cnr.el b/emacs/flan-cnr.el index 72b3dbcd..6b2ffb75 100644 --- a/emacs/flan-cnr.el +++ b/emacs/flan-cnr.el @@ -702,6 +702,14 @@ anyone who would rather TAB always moved." map) "Keys in `flan-cnr-mode'.") +;; Evil's normal state binds 0, the other digits and RET above any major +;; mode's map, so under Evil a digit moved point or started a count and took +;; nothing. This map takes precedence over Evil's state maps instead; the keys +;; it does not bind, j and k among them, are still Evil's. +(with-eval-after-load 'evil + (when (fboundp 'evil-make-overriding-map) + (evil-make-overriding-map flan-cnr-mode-map))) + (define-derived-mode flan-cnr-mode special-mode "flan-break" "What a stopped Flan program is offering." (setq buffer-read-only t)) diff --git a/emacs/test-flan-cider.el b/emacs/test-flan-cider.el index a0247452..aacc92d5 100644 --- a/emacs/test-flan-cider.el +++ b/emacs/test-flan-cider.el @@ -1704,6 +1704,47 @@ stopped program, which is the case where it should fire." (file-name-directory load-file-name)) nil t) +;; The break buffer's keys under Evil, pressed through the command loop rather +;; than called. Evil's normal state binds 0 (beginning of line), 1-9 (a count) +;; and RET (next line) above any major mode's map, so without the buffer's map +;; taking precedence a digit moved point and took nothing. Run only where +;; Evil is installed: -Q loads no packages, so it is looked for in the two +;; places a package install puts it, and turned off again afterwards so nothing +;; above or below this runs under it. +(let* ((dirs (append (file-expand-wildcards "~/.config/emacs/elpa/evil-[0-9]*") + (file-expand-wildcards "~/.emacs.d/elpa/evil-[0-9]*") + (file-expand-wildcards "~/.config/emacs/elpa/goto-chg-*") + (file-expand-wildcards "~/.emacs.d/elpa/goto-chg-*"))) + (load-path (append dirs load-path))) + (if (not (require 'evil nil t)) + (message " skip the break buffer under Evil (Evil is not installed)") + (evil-mode 1) + (unwind-protect + (let* ((sent nil) + (flan-cnr-request-function + (lambda (form) (setq sent form) (list :status "ok"))) + (buf (test-flan--cnr + (list :condition "Missing" :restarts '("retry" "skip"))))) + (switch-to-buffer buf) + (evil-initialize-state) + (goto-char (point-min)) + (execute-kbd-macro (kbd "0")) + (test-flan--check "under Evil, 0 takes restart 0" + (equal sent '(:op "restart-at" :index 0 :name "retry"))) + (setq sent nil) + (switch-to-buffer buf) + (execute-kbd-macro (kbd "1")) + (test-flan--check "under Evil, 1 takes restart 1" + (equal sent '(:op "restart-at" :index 1 :name "skip"))) + (setq sent nil) + (switch-to-buffer buf) + (goto-char (point-min)) + (search-forward " 1: ") + (execute-kbd-macro (kbd "RET")) + (test-flan--check "under Evil, RET takes the restart on its line" + (equal sent '(:op "restart-at" :index 1 :name "skip")))) + (evil-mode -1)))) + (message "\n%d checks, %d failures" test-flan--ran test-flan--failures) (kill-emacs (if (> test-flan--failures 0) 1 0))