Closed nverno closed 6 months ago
Thanks for the report. It looks like there are a few issues related to narrowing.
The one you reported.
Fix: Temporarily widen before applying text properties.
Even if that's fixed, the narrowed text is a program fragment that check-syntax will complain isn't valid Racket, e.g. say there's an #%app is undefined
error.
Fix: Always give check-syntax the full buffer, i.e. ignore any narrowing.
What if you have narrowed to foo
, have point on bar
in the program below and press M-. a.k.a. M-x xref-find-definitions
. Status quo that's another range error.
Fix: ?? Instead should it widen
-- discard your narrowing, so it can actually go to and show you bar
? I think so, but I don't use use narrowing enough to know what's expected or best practice, so I'm curious what you think?
#lang racket
(define/contract (foo x)
(-> string? string?)
(bar x)) ;;;;;;;;;; <==== point on `bar` here
(define (bar x)
x)
What if you have narrowed to foo, have point on bar in the program below and press M-. a.k.a. M-x xref-find-definitions. Status quo that's another range error.
I think this should be covered since you're using xref
. The function xref--goto-char
handles potential narrowing by consulting the variable widen-automatically
, widening when permitted.
Hmm I saw it error in Emacs 28.2 (daily driver). Maybe this improved in 30. I can try build from source.
In any case, maybe it's fair to classify that as "not my problem to fix", instead that's up to xref, and it may in fact have improved this sometime after 28.2?
Oh you're right it does error on emacs 30 as well. I thought you were asking about how to handle the widening more generally. The following patch seems to fix the xref problem, letting xref
decide whether to allow it or not depending on widen-automatically
=diff --git a/racket-xp.el b/racket-xp.el
index fc4c43b..9f32778 100644
--- a/racket-xp.el
+++ b/racket-xp.el
@@ -1084,9 +1084,11 @@ around at the first and last errors."
(pcase (get-text-property 0 'racket-xp-use str)
(`(,beg ,end)
(list
- (xref-make (buffer-substring beg end)
- (xref-make-buffer-location (current-buffer)
- (marker-position beg))))))
+ (save-restriction
+ (widen)
+ (xref-make (buffer-substring beg end)
+ (xref-make-buffer-location (current-buffer)
+ (marker-position beg)))))))
;; Annotated by dr/cs as imported module; visit the module
(pcase (get-text-property 0 'racket-xp-def str)
(`(import ,id . ,_)
>
Thanks for the idea for xref!
Commit 483a1e7 seems to cover all the bases -- but just in my quick testing; so if it's convenient for you to try it, please let me know?
Otherwise I'll sleep on it, try to test a bit more myself, and merge within a few days.
It's working perfectly!
Merged; thanks for confirming, as well as for the xref idea!
During redisplay there are
args-out-of-range
errors when the source buffer is narrowed.Steps to reproduce:
Using the following source with
racket-xp-mode
enabled, callnarrow-to-defun
infoo
.Then, trigger redisplay, eg. modify and save the buffer.
At this point, I get a message
Or a backtrace with
debug-on-error
.Package
System values
Buffer values
Racket Mode values
Minor modes
Disabled minor modes