diff options
| -rw-r--r-- | modules/ui-navigation.el | 7 | ||||
| -rw-r--r-- | tests/test-ui-navigation-split-follow-undo-kill.el | 13 |
2 files changed, 18 insertions, 2 deletions
diff --git a/modules/ui-navigation.el b/modules/ui-navigation.el index f0d2ef527..f2181d97e 100644 --- a/modules/ui-navigation.el +++ b/modules/ui-navigation.el @@ -179,8 +179,11 @@ With numeric prefix ARG, re-open the ARGth most-recently-killed file (delq buf-file recently-killed-list))) buffer-files-list) (when recently-killed-list - (find-file - (nth (1- arg) recently-killed-list))))) + (let ((file (nth (1- arg) recently-killed-list))) + (if file + (find-file file) + (user-error "Only %d killed file(s) to choose from" + (length recently-killed-list))))))) (keymap-global-set "M-S-z" #'cj/undo-kill-buffer) ;; was M-Z, overrides zap-to-char ;; ---------------------------- Undo Layout Changes ---------------------------- diff --git a/tests/test-ui-navigation-split-follow-undo-kill.el b/tests/test-ui-navigation-split-follow-undo-kill.el index b1d990208..8e3900743 100644 --- a/tests/test-ui-navigation-split-follow-undo-kill.el +++ b/tests/test-ui-navigation-split-follow-undo-kill.el @@ -102,5 +102,18 @@ non-visited entry, not the second." (cj/undo-kill-buffer 0)) (should-not opened))) +(ert-deftest test-ui-navigation-undo-kill-buffer-out-of-range-arg-errors () + "Error: a prefix larger than the killed-file list signals a clear user-error, +not a wrong-type-argument from find-file on nil." + (let ((opened nil) + (recentf-mode t) + (recentf-list '("/tmp/a.org"))) + (cl-letf (((symbol-function 'require) (lambda (&rest _) t)) + ((symbol-function 'recentf-mode) (lambda (&rest _) t)) + ((symbol-function 'buffer-list) (lambda (&rest _) nil)) + ((symbol-function 'find-file) (lambda (f) (setq opened f)))) + (should-error (cj/undo-kill-buffer 5) :type 'user-error)) + (should-not opened))) + (provide 'test-ui-navigation-split-follow-undo-kill) ;;; test-ui-navigation-split-follow-undo-kill.el ends here |
