From 619a3959162729d0cb423bfa2febbc9e9420ce69 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 7 Sep 2026 14:14:01 +0100 Subject: [PATCH] VC-Dir: Fix error on `n' before "./" has appeared If you typed `n' before "./" had appeared, Emacs signalled a wrong-type-argument error. Now it signals a better one. * lisp/vc/vc-dir.el (vc-dir--before-dotname-p): Return nil if the "./" entry hasn't appeared yet. * test/lisp/vc/vc-tests/vc-test-misc.el (vc-test-vc-dir-next/previous): Simulate the problem case. * lisp/emacs-lisp/ewoc.el (ewoc-goto-next): Signal a user-error instead of a plain error. This makes sense for all the current call sites. (This is secondary to the bug fix above: this code was never reached, previously.) --- lisp/emacs-lisp/ewoc.el | 2 +- lisp/vc/vc-dir.el | 6 ++++-- test/lisp/vc/vc-tests/vc-test-misc.el | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/emacs-lisp/ewoc.el b/lisp/emacs-lisp/ewoc.el index 118b66eb15f..fcb8ca7d42c 100644 --- a/lisp/emacs-lisp/ewoc.el +++ b/lisp/emacs-lisp/ewoc.el @@ -505,7 +505,7 @@ Return the node (or nil if we just passed the last node)." ;; (unless (ewoc--filter-hf-nodes ewoc node) ;; (setq node (ewoc--node-nth dll -2))) (unless node - (error "No next")) + (user-error "No next")) (ewoc-goto-node ewoc node))) (defun ewoc-goto-node (ewoc node) diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index b6ba3cb02a9..b3d2dbb677a 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -730,8 +730,10 @@ information." ;; entry, as determined by the following function. See bug#81248 for ;; further details. (defun vc-dir--before-dotname-p () - "Return non-nil if point is before the \"./\" entry." - (< (point) (ewoc-location (ewoc-nth vc-ewoc 0)))) + "Return non-nil if point is before the \"./\" entry. +If that entry hasn't appeared yet, return nil." + (and-let* ((zeroth (ewoc-nth vc-ewoc 0))) + (< (point) (ewoc-location zeroth)))) (defun vc-dir-next-line (arg) "Go to the next line. diff --git a/test/lisp/vc/vc-tests/vc-test-misc.el b/test/lisp/vc/vc-tests/vc-test-misc.el index adbe9c1240b..df680aa9e75 100644 --- a/test/lisp/vc/vc-tests/vc-test-misc.el +++ b/test/lisp/vc/vc-tests/vc-test-misc.el @@ -298,6 +298,8 @@ See bug#80803 and bug#80967." (should (equal (vc-dir-fileinfo->state data) 'edited)))))))))) +;; FIXME: This test only passes once. Then there is some state left +;; behind such that it doesn't pass if run again. (ert-deftest vc-test-vc-dir-next/previous () ; bug#81248 "Test navigating with `vc-dir-{next,previous}-{line,directory}'." (skip-unless (executable-find vc-git-program)) @@ -356,6 +358,11 @@ See bug#80803 and bug#80967." (should (and (looking-at "\\./$") (looking-back "^ +" (pos-bol)))) (vc-dir-previous-directory) (should (and (looking-at "\\./$") (looking-back "^ +" (pos-bol)))) + ;; Simulate the case in which the status lines haven't come + ;; back yet. This used to give a cryptic non-`user-error'. + (goto-char (point-min)) + (ewoc-filter vc-ewoc #'ignore) + (should-error (vc-dir-next-line 1) :type 'user-error) (kill-buffer vc-dir-buf)))))) (ert-deftest vc-test-vc-dir-mark/unmark-all-dir-entry () ; bug#81249