Skip to content

Commit

Permalink
racket-repl-mode and racket-xp-mode: set next-error-last-buffer
Browse files Browse the repository at this point in the history
Set next-error-last-buffer:

1. On each run, to the racket-repl-mode buffer used by the run.

This means next-error-find-buffer will look to that REPL buffer (as
opposed to e.g. some compilation-mode buffer that happens to exist).

2. On each racket-xp-mode annotation, to the edit buffer IFF there were
expansion errors.

This means the standard next-error and previous-error will work to
show racket-xp-mode expansion errors, if any, else they'll defer to
some other buffer such as racket-repl-mode.

As a result we can mark our special racket-xp-{next previous}-error
commands as obsolete. Change the menu and default keymap to use
{next previous}-error.

Fix obsolete.
  • Loading branch information
greghendershott committed Nov 21, 2023
1 parent 53b8173 commit 2d1fb86
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
8 changes: 5 additions & 3 deletions racket-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1491,14 +1491,16 @@ See also the command `racket-repl-clear-leaving-last-prompt'."
(defun racket--repl-forget-errors ()
"Forget existing errors in the REPL.
Although they remain clickable they will be ignored by
`next-error' and `previous-error'"
`next-error' and `previous-error'."
(with-racket-repl-buffer
(setq racket--errors-reset t)
(setq racket--errors-point-min (point-max))))
(setq racket--errors-point-min (point-max))
;; Set this so `next-error-find-buffer' chooses us.
(setq next-error-last-buffer (current-buffer))))
(add-hook 'racket--repl-before-run-hook #'racket--repl-forget-errors)

(defun racket-repl-next-error (count reset)
"A value for `next-error-function'."
"A value for the variable `next-error-function'."
(let ((prop 'racket-error-loc))
(cl-flet* ((get () (get-text-property (point) prop))
(next () (next-single-property-change (point) prop))
Expand Down
49 changes: 28 additions & 21 deletions racket-xp.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ everything. If you find that too \"noisy\", set this to nil.")
(">" ,#'racket-xp-tail-next-sibling)
("<" ,#'racket-xp-tail-previous-sibling)
("g" ,#'racket-xp-annotate)
("N" ,#'racket-xp-next-error)
("P" ,#'racket-xp-previous-error))))
("N" ,#'next-error)
("P" ,#'previous-error))))

(defvar racket-xp-mode-map
(racket--easy-keymap-define
Expand All @@ -67,8 +67,8 @@ everything. If you find that too \"noisy\", set this to nil.")
(easy-menu-define racket-xp-mode-menu racket-xp-mode-map
"Menu for `racket-xp-mode'."
'("Racket-XP"
["Next Error" racket-xp-next-error]
["Previous Error" racket-xp-previous-error]
["Next Error" next-error]
["Previous Error" previous-error]
"---"
["Next Definition" racket-xp-next-definition]
["Previous Definition" racket-xp-previous-definition]
Expand Down Expand Up @@ -225,10 +225,10 @@ and use the `racket-xp-annotate' command manually.
The mode line changes to reflect the current status of
annotations, and whether or not you had a syntax error.
If you have one or more syntax errors, `racket-xp-next-error' and
`racket-xp-previous-error' navigate among them. Although most
languages will stop after the first syntax error, some like Typed
Racket will try to collect and report multiple errors.
If you have one or more syntax errors, `next-error' and
`previous-error' navigate among them. Although most languages
will stop after the first syntax error, some like Typed Racket
will try to collect and report multiple errors.
You may use `xref-find-definitions' \\[xref-find-definitions],
`xref-pop-marker-stack' \\[xref-pop-marker-stack], and
Expand Down Expand Up @@ -283,6 +283,7 @@ commands directly to whatever keys you prefer.
#'racket-xp-xref-backend-function
nil t)
(setq-local imenu-create-index-function #'racket-xp-imenu-create-index-function)
(setq-local next-error-function #'racket-xp-next-error-function)
(add-hook 'pre-redisplay-functions
#'racket-xp-pre-redisplay
nil t))
Expand All @@ -298,6 +299,7 @@ commands directly to whatever keys you prefer.
(add-hook 'completion-at-point-functions
#'racket-complete-at-point
t t)
(setq-local next-error-function nil)
(setq-local imenu-create-index-function #'racket-imenu-create-index-function)
(remove-hook 'xref-backend-functions
#'racket-xp-xref-backend-function
Expand Down Expand Up @@ -417,6 +419,11 @@ manually."
(completions . ,completions)
(imenu . ,imenu)
(annotations . ,annotations))
;; We have no errors; allow `next-error-find-buffer' to
;; pick some other buffer, such as a `racket-repl-mode'
;; buffer that set this when it ran.
(when (equal next-error-last-buffer (current-buffer))
(setq next-error-last-buffer nil))
(racket--xp-clear)
(setq racket--xp-binding-completions completions)
(setq racket--xp-imenu-index imenu)
Expand All @@ -427,6 +434,8 @@ manually."
(`(check-syntax-errors
(errors . ,errors)
(annotations . ,annotations))
;; Set this so `next-error-find-buffer' chooses us.
(setq next-error-last-buffer (current-buffer))
;; Don't do full `racket--xp-clear': The old completions and
;; some old annotations may be helpful to user while editing
;; to correct the error. However do clear things related to
Expand Down Expand Up @@ -976,20 +985,16 @@ Moving before/after the first/last tail wraps around."
(vconcat racket--xp-errors
(vector (list path beg str)))))

(defun racket--xp-next-error (&optional amt reset)
(defun racket-xp-next-error-function (&optional amt reset)
"Move AMT errors, if any.
If there are any check-syntax errors, moves among them, wrapping
around at the first and last errors.
A value for the variable `next-error-function'.
Otherwise delegate to `next-error'. That way, things still work
as you would want when using `racket-run' -- e.g. for runtime
evaluation errors that won't be found merely from expansion -- or
`compilation-mode'."
If there are any check-syntax errors, moves among them, wrapping
around at the first and last errors."
(interactive)
(let ((len (length racket--xp-errors)))
(if (zerop len)
(next-error amt reset)
(unless (zerop len)
(if reset
(setq racket--xp-errors-index 0)
(setq racket--xp-errors-index
Expand All @@ -1005,15 +1010,17 @@ evaluation errors that won't be found merely from expansion -- or
(goto-char pos)))
(message "%s" str)))))

(make-obsolete 'racket-xp-next-error 'next-error "2023-11-20")
(defun racket-xp-next-error ()
"Go to the next error."
"An obsolete alias for `next-error'."
(interactive)
(racket--xp-next-error 1 nil))
(next-error))

(make-obsolete 'racket-xp-previous-error 'previous-error "2023-11-20")
(defun racket-xp-previous-error ()
"Go to the previous error."
"An obsolete alias for `previous-error'."
(interactive)
(racket--xp-next-error -1 nil))
(previous-error))

;;; xref

Expand Down

0 comments on commit 2d1fb86

Please sign in to comment.