-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drracket:grouping-position
vs. {forward backward}-match
methods of color:text<%>
#527
Comments
Forward and back expression navigation are meant to be potentially different than just navigating matches. Shrubbery support does something different, for example. So, yes, using that when supplied and falling back to match-based navigation is the intent. Since |
Thanks for the quick reply. EDIT: See below instead.
(or/c
(cons/c 'none natural?) ;the old #f enhanced to be a failure position
'use-s-expression ;the old #t renamed to be more self-evident
natural?) ;a success position However I need to research the under-documented meaning of "the failure position" wrt Emacs |
If a lang lexer has produced tokens that open or close expressions/blocks, then it sure seems like forward/backward matching using those tokens would give the positions of the expressions/blocks. So when you have time, could you please say more about what group-positions could say differently than matching, and how/why? Maybe there's a simple example that would make me (and potentially other doc readers) say, "Oh, of course." Is it something like, the lang uses off-side rule indenting, but doesn't produce open/close tokens? I think some off-side rule langs tokenize indent as open/close curly braces (maybe Haskell?), which they also allow. But maybe some langs don't want to, or can't, and grouping-positions is for them? |
I think I figured out (at least part of) the rationale. I was confused because a year ago I had been thinking of a design where a lang lexer could produce open and close tokens for multi-character keyword lexemes like "begin" and "end", as well as single-char delimiters like parens. However that's not the design here; So I guess the story for such langs (using say "begin" and "end") is that forward/backward-match definitely can't/won't do anything interesting; the idea is to use |
To follow up on what Above I suggested having it return, not just
What this seems to be saying (setting aside the message, which is N/A), "please give the bounds of the token where it stopped". So it's two positions. [[[This is then used by Emacs functions like
Therefore: Combining these two, my wrapper of So I think the only open action for this issue, is to clarify the "can't move" return value --- is it supposed to be I think I'd prefer the latter. Since it's a brand new spec maybe it would be good to pick/enforce just one. Otherwise I guess I could defensively code for |
I left a comment then deleted it quickly; you may have gotten an email. I confused myself for a second, about a "count" argument that's not actually present in Here is what I'm doing to support a ;;; Something for Emacs forward-sexp-function etc.
(define/public (grouping gen pos dir limit count)
(cond
[(<= count 0) pos]
[else
(block-until-updated-thru gen
(case dir
[(up backward) min-position]
[(down forward) max-position]))
(let loop ([pos (sub1 pos)] ;1.. -> 0..
[count count])
(define (failure-result) ;can't/didn't move
(call-with-values (λ () (get-token-range pos)) list))
(match (grouping-position this pos limit dir)
[#f (failure-result)]
[#t 'use-default-s-expression]
[(? number? new-pos)
(cond [(< 1 count) (loop new-pos (sub1 count))]
[(= new-pos pos) (failure-result)]
[else (add1 new-pos)])]))])) ;0.. -> 1.. So if you're fine with users like me doing the defensive thing (I'm fine with that) you could just close this issue (maybe update a phrase in the docs). |
So far, it makes sense to me that |
TL;DR: I think the latter, although it's not a strong opinion. Although I don't want to over-think this: With APIs sometimes I try to think of mistakes people might make, and/or unnecessary "ceremony". From that point of view:
So I lean toward having it return the position (changed or not), or Having said all that, on the other hand:
On the tool/consuming end, I will probably do something defensive, regardless. |
@greghendershott Thanks for the explanation! I was convinced... but then looked at how the newly extracted Racket-navigation functions will end up providing the implementation of methods like |
I've pushed changes to The The default indentation implementation uses a table of rules that, in general, can be configured as a preference in DrRacket. The Finally, I think all those changes might close this issue, but I'm not sure. |
Thank you!! I caught up with these changes this morning, as well as applying some more of your recent commits in expeditor/object.rkt to my similar class. So I have commit 4854c32 and tests against snapshot pass. I'm still planning to move that to Although I'd like to follow up on racket/expeditor#10 I think we can close this one!! 🎉 |
In expeditor @mflatt defined a
like-text%
object that implements somecolor:text<%>
methods including{forward backward}-match
, IIUC to supply todrracket:indentation
and/ordrracket:range-indentation
functions.I'm trying to understand the relation of these to the
'forward
and'backward
flavors of the newdrracket:grouping-position
.Are they equivalent, or is there some subtle difference?
In some scenarios would a lang implement one using the other?
For a tool providing expression navigation commands, if a lang supplies
drracket:grouping-position
, should a tool prefer that (and{forward backward}-match
are just a get-info default)?Is
grouping-position
for forward/backward merely a preference/convenience --- or, could it be meaningfully different for some lang and a tool should definitely avoid using{forward backward}-match
?Maybe the answers are in the DrRacket and/or expeditor source code and eventually I'll go look, but I wanted to ask the question here since it goes to intent. (Also this might become a FR or PR to add a little explanation/discussion to the docs.)
More context for why I ask:
Emacs has the concept of a
forward-sexp-function
-- a variable the value of which is a function. Theforward-sexp
function uses that if non-nil. So ~= a parameter.(Note:
forward-sexp
is actually forward/backward in one function; there's acount
arg that may be negative. So this is about both directions.)One wrinkle is that if scanning fails, e.g. you can't move forward anymore,
forward-sexp
signals an exception with that failed position. And various Emacs commands built usingforward-sexp
, rely on that -- they might catch that signal and use the position. So this is behavior that aforward-sexp-function
needs to emulate.So I can do the failed-position behavior with something implemented much like
{forward backward}-match
, scanning tokens --- but could that possibly be wrong if a lang suppliesdrracket:grouping-position
?The text was updated successfully, but these errors were encountered: