-
-
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
Proposal: New info key drracket:comments
#634
Comments
In C, I expect the configuration to be But in Python, if I make a selection that spans multiple lines and hit comment, it probably should add How do we distinguish these two scenarios? |
I like where this is heading and am happy to help out with DrRacket's comment/uncomment functionality (or whatever else seems useful!). Some thoughts:
|
I don't understand what you mean here? This claims that Rhombus has C-style comments? @rfindler I think the Emacs attitude is that multi-line comments are handled as just a series of lines with single-line comment delimiters... but I'm not entirely sure. However wrt the tool-agnostic proposal: I think it's fine to have a TL;DR maybe the value should be ~=
Does that sound better? |
Sorry, I edited to Python precisely because I thought you might have this response :) You can substitute it with any language that doesn't have block comment. |
Oh no worries, I just genuinely didn't understand your point. :) |
@greghendershott What is the UI for Emacs when entering a comment? Does it get a region as argument and then break it up into lines and put these delimiters around each line? |
@rfindler The Emacs UX varies depending on customization variables like I think the proposal's focus is: What info should a lang supply about comments? I'm not a lang designer or historian, but, it seems like there are three possible kinds of comments:
Does that seem about right? Is that the minimal info a lang would need to convey? p.s. When a lang supports both line and region comments, how to handle multi-line comments is user preference/style. (IIUC, orthogonal to this proposal.) C++ examplesI've seen all of...
|
The last of those C++ examples could not be automatically generated from a preference and the spec you've described, and thus would have to be custom for a particular language, but that's probably ok. |
@greghendershott I agree generally with what you write but with one concern, namely that we should have some idea of what we're going to support so we can make sure that we can actually implement the UI that we want on the DrRacket side. It sounds like the Emacs side already has some support for taking some specific pieces of information and turning them into various UIs and I'm more than happy to go along with that (i.e., to make DrRacket follow Emacs's lead) but it seems important to make sure that we actually know what we're going to be getting so we don't wish we'd done something slightly differently somewhere along the way. So (just to make sure we're on the same page), I think I'm more in the "make sure I know what we're getting into" mode than "I want something different" mode, if that makes sense. Right now, DrRacket has three commenty operations in the "Racket" menu:
Is that the plan? I guess the big question with that plan is whether or not we want to support comment/uncommenting via region comments where we don't do things line by line but instead put an open comment in one place and close comment in another place, possibly far away from each other. I'm not sure we need special IDE support for |
On the one hand: I'm inclined to say it's sufficient for the info key to supply all information only knowable by the lang. The end. On the other hand: I agree it's worth thinking through some examples of how tools would actually use the information. If I sounded dismissive, sorry, it's only because... On the third hand: A lot of the Emacs commenting code seems to be accreted over decades; I would love to avoid learning too much about it, if setting a few Setting aside the DrRacket comment box:
And... I think that's it? I mean, if a lang has some notion of region comments, for the sake of completeness I think the info key should allow communicating that. But that doesn't mean all tools must use all that information to do all possible things. So I don't think the info key per se would obligate DrRacket to add some new region commenting features. It would just make it possible to do so, someday/maybe... or never. If users haven't been clamoring for this, then it's probably not worth doing. (Subjective anecdata opinion warning: Over the years, the line-comment style has grown more popular than region-comments. The latter seem used just for a piece of a line, in langs that lack expression comments?) Having said all that, I wish we had a representative of e.g. vscode to speak up here, too. |
I think most (modern) IDEs/editors do not have comment and uncomment operations separately. Instead, there's only one operation, and the IDEs/editors automatically decide which mode it should be, based on whether the region is already commented. |
I see that Sublime Text does something like that, always looking at entire lines. So if you have a line that's partially commented out and hit the button, it becomes fully commented out. And if you select some region that includes multiple lines but only parts of the first and last line, then it comments/uncomments the entire lines. (Hope that this make sense -- it seems like the most sensible operations if you start from the premise that you're working with entire lines.) This was with the "toggle comment" menu item when in a python file. I see there is also a toggle-block-comment menu item, however. |
It looks like Emacs defines a fourth value, " By the way, another example I forgot: /* Line 1 */
/* Line 2 */ Indeed this seems to be the default for Emacs |
This morning I started digging into Emacs' I'm still digesting. Among other things, trying to sort through which aspects are clearly lang-specified vs. clearly per-user preference/customization. And maybe some aspects that straddle both? One quick observation: There are a few As an ultimate "escape" for scenarios and langs where a simple data-driven specification is insufficient, you can call a function to do the thing. This suggests we might want a lang info key to be able to supply callable functions, as well. |
I feel pretty comfortable with the line-based approach and am happy to go ahead if everyone else is. I'm a bit nervous about adding more callable functions into the lang-based configuration. From the Emacs perspective, one has to keep a connection alive so the state of the function is always there which may be a pain for GC reasons (or maybe it's fine?); from the DrRacket perspective, it is one more place where malicious code can cause trouble for the people (although there are a lot of these already, alas). Maybe I shouldn't worry about this that much.... |
? |
As an initial experiment I added this for modified pkgs/at-exp-lib/at-exp/lang/reader.rkt
@@ -13,30 +13,33 @@
;; Settings that apply just to the surface syntax:
(define (scribble-base-reader-info)
(lambda (key defval default)
(define (try-dynamic-require lib export)
(with-handlers ([exn:missing-module?
(λ (x) (default key defval))])
(dynamic-require lib export)))
(case key
[(color-lexer)
(try-dynamic-require 'syntax-color/scribble-lexer 'scribble-inside-lexer)]
[(drracket:indentation)
(try-dynamic-require 'scribble/private/indentation 'determine-spaces)]
[(drracket:keystrokes)
(try-dynamic-require 'scribble/private/indentation 'keystrokes)]
[(drracket:default-extension) "scrbl"]
+ [(drracket:comment-delimiters)
+ '("@;" "" " ")]
[else (default key defval)]))) "It works". But note this: modified pkgs/at-exp-lib/scribble/base/reader.rkt
@@ -9,41 +9,43 @@
(define-values (at-read at-read-syntax at-get-info)
(make-meta-reader
'at-exp
"language path"
lang-reader-module-paths
wrap-reader
(lambda (orig-read-syntax)
(define read-syntax (wrap-reader orig-read-syntax))
(lambda args
(define stx (apply read-syntax args))
(define old-prop (syntax-property stx 'module-language))
(define new-prop `#(at-exp/lang/language-info get-language-info ,old-prop))
(syntax-property stx 'module-language new-prop)))
(lambda (proc)
(lambda (key defval)
(define (fallback) (if proc (proc key defval) defval))
(define (try-dynamic-require lib export)
(with-handlers ([exn:missing-module?
(λ (x) (fallback))])
(dynamic-require lib export)))
(case key
[(color-lexer)
(try-dynamic-require 'syntax-color/scribble-lexer 'scribble-lexer)]
[(drracket:indentation)
(try-dynamic-require 'scribble/private/indentation 'determine-spaces)]
[(drracket:keystrokes)
(try-dynamic-require 'scribble/private/indentation 'keystrokes)]
+ ;; Note: Do /not/ supply drracket:comment-delimiters here;
+ ;; that would cause the at-exp meta-lang to overrule the
+ ;; main lang.
[else (fallback)]))))) In other words, we want something like (I suppose there exists some fancy spec to allow mixed comment styles for mixed lang sources, but it's kind of giving me a headache and I'm not sure how/if all tools could suport this.) |
I agree that a fancy spec for mixed comment styles seems like too much for now. What do you think about allowing a list of lists of length three (meaning that there are multiple comment style options that a language can supply)? Also, I'm happy with something more generically named, eg |
Yeah I think comments would be just one part of an entire conversation/spec about handling mixed/meta langs. It's almost as if the lang "get-info" function would need a position argument; many key values could vary by position. Definitely another, distinct, headache-y issue. :)
So you could present a GUI selection dialog, and, store the comment preference keyed by I think that's good.
I'm OK to keep using We seem to have converged, so I think I'll do a PR for at least the docs, in case reading that format suggests other details to tweak. |
The documentation portion of racket#634. Note that this commit does /not/ add to the documented list of keys read by Dr Racket, because this commit does not add the behavior of Dr Dracket doing that and using the comment styles to drive its (un)comment commands.
The documentation portion of racket#634. Note that this commit does /not/ add to the documented list of keys read by Dr Racket, because this commit does not add the behavior of Dr Dracket doing that and using the comment styles to drive its (un)comment commands.
The documentation portion of #634. Note that this commit does /not/ add to the documented list of keys read by Dr Racket, because this commit does not add the behavior of Dr Dracket doing that and using the comment styles to drive its (un)comment commands.
I have a question: in the My thinking is that, when uncommenting, we'd need a predicate saying "is this line commented out?" and that predicate would depend only on the first string (but that it would remove the second string if that string is present too). Is that right? If that's right, is this worth documenting? Is there any other interpretation of these strings that would make sense that a tool could use? (If not, then I'd argue we should document it so that language authors will have a better sense of which strings to list for their languages.) Also, I'm noticing that the default of |
For a predicate saying "is this line commented out?", should it be |
Specifically: - rackety - fix docs - add tests - generalize to abstract over the precise comment string Some questions remain, specifically what would a #:padding argument to uncomment-selection do?
Should the contracts disallow newlines (and returns?) in the strings? |
I think that's right. But, frankly, I'm following the lead of Emacs here, where So I'm not sure if it's standing on shoulders or cargo culting. But it seemed harmless (?) to present it distinctly rather than lossy-glomming it into the same values as Also one use case maybe N/A for DrRacket is Emacs commands that re-fill comments (re-flow for a width) after or during editing.
Oh. Sorry! I hadn't realized that. Yeah, in many lisps (including Scheme, from what I can tell from
Which I think shows that comments can get quickly into style/preference territory. I guess my assumption is that tools can offer ways to configure this kind of stuff, maybe, for users who really care. Trying to capture all that variety was a non-goal for this lang info proposal. Instead it's a way for lang to tell the tool (so the user doesn't have to) about basic commenting behavior that will work and be correct. But on both points maybe I'm being too lazy or "MVP", and it should be more complicated? |
Yes, that would be most correct. What would be the clearest way to write such a contract, do you think? |
for no newlines and no return characters, which would be my preference, given the way that |
I think what we settled on makes sense and including padding is a good idea. My only thought is that we could clarify the documentation to explain what the padding is, so that people who have the confusion that I had earlier today would find clarification in the docs. Does that seem okay to you?
This would be nice to have eventually so I'm glad that door isn't prematurely closed.
I'm happy to change DrRacket's behavior. I just wanted to make sure we all are and maybe discuss alternatives if someone is worried. I like the conventions you list above and am happy that DrRacket will be moving towards them. |
I've noticed an inconsistency in the region comment docs. At this spot and this spot, the order is start, continue, end, but in this spot and this spot the order is start, end, continue. Also, I am wondering if the padding is really meant to be added to the first line. Judging from the examples, I think this line should just say |
sensitive to the #lang line related to racket#634
Much like I forgot that DrRacket does Original:
DrRacket:
Emacs lisp modes (lisp, elisp, scheme, racket):
I've lived with these so long editing {elisp racket scheme} in Emacs I took it for granted. But it's taste not law. Anyway that assumption went into the docs. I don't know if it's something where, like |
I'm sorry-- this is a comment about the block comment specifications, not the line comment specifications. If we're going to insert the padding right at the same place as the opener is inserted (following the C++ example in the region section of the docs), we'll get things like this:
which doesn't look right. Or am I misunderstanding something else? |
sensitive to the #lang line related to #634
I think you might be confusing
So using the C++ example: The first line uses |
If you're reading only via email and GitHub doesn't email updates: I edited the end of my previous post. |
Oh yes! Thank you, that was exactly my problem. |
Things like DrRacket and Emacs offer commands to comment and un-comment a region.
Non-s-expression langs should be able to supply information for these commands, via a new info key named something like "
drracket:comments
".Open to improvements, but initially I'll suggest the value is a list:
where those three values as identical to three configuration variables in Emacs:
Examples:
(";;" "" " ")
("@;" "" " ")
("//" "" " ")
I'd suggest that when the key isn't supplied, it's OK to default to s-expression as the default. (Justification: There exist many more s-expression langs.)
Whatever the final form, I think the to-do list would be:
If agreed/confirmed, I would probably be able to make PRs easily for all but the last. (I'm not familiar with that code. I'm not sure about details like whether a "Racket" menu is where these should continue to live.)
Background: greghendershott/racket-mode#661 (comment)
The text was updated successfully, but these errors were encountered: