Skip to content
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

How about supporting "sweet" expressions aka readable Lisp syntax in the imenu? #527

Open
GReagle opened this issue Apr 1, 2021 · 5 comments

Comments

@GReagle
Copy link

GReagle commented Apr 1, 2021

Please note that I am NOT asking for anything like full support for sweet expressions in this mode. I only want the imenu to work. I can make this happen now by changing to text mode and evaluating
(setq imenu-generic-expression '((nil "^define\\(/contract\\)? \\([^[:space:](]+\\)" 2))) but then I lose other racket-mode features like C-c C-c runs the command racket-run

I am referring to the syntax or notation described at https://readable.sourceforge.io/ and implemented at https://docs.racket-lang.org/sweet/index.html and https://pkgs.racket-lang.org/package/sweet-exp

@greghendershott
Copy link
Owner

Thanks for the request.

I don't have an ideal quick answer, but a few thoughts, in a braindump:

  1. If sweet were a full #lang it could provide hooks for DrRacket to automatically adapt to its syntax highlighting and indentation. Now, that's doubly moot because (1) it looks like sweet does not, and (2) Racket Mode can't use that. However I have a WIP branch for Racket Mode to do that, someday/maybe. Longer term, that's theoretically the idea/best way to handle non-sexp langs.

  2. One thing I typically do with, say, Scribble files, is switch the buffer between scribble-mode and racket-mode, as desired. Maybe you could define a tiny Emacs mode, sweet-mode, which is effectively already what you're doing: normal-mode plus setting one or two other vars like imenu-generic-expression. And switch between that and racket-mode. Not ideal, but maybe some (small) improvement on the status quo.

  3. If you like sweet mostly because of infix, then keep in mind there are other "handle this expression as infix" packages or macros, I think?

  4. If you like sweet mostly because you dislike parens, have you tried using paren-mode and setting the paren face to e.g. a barely visible light grey? I don't dislike parens. But I do that to de-emphasize some visual clutter, and because I use paredit-mode for navigation so I hardly need to see them. Anyway the parens are still there, and make things indent nicely.

Having said all that maybe there is some way to make the Racket Mode back end work (mostly, at least for things like Run) when the major mode is not racket-mode. My queue is pretty full at the moment but I'll try to think about that more when I can!

@GReagle
Copy link
Author

GReagle commented Apr 2, 2021

Thank you very much for your thoughtful response.

  1. I am new to Racket so I don't know enough to make this happen myself. Maybe one day?
  2. Thanks for that suggestion. Switching to a different major mode every time I want to navigate to a top level definition (which is frequently) using imenu seems impractical. Not to mention switching back. And when I switch back to racket-mode, it erases the imenu index that was created in text-mode.
  3. I do like infix, but it is not a problem. It works well with Emacs because already Emacs considers curly braces to be s-exp markers. I could use just the curly braces feature and racket-mode would work fairly well with it.
  4. I dislike parens, but not because I have to look at them, because I have to deal with them. :> For example if I want to reorder the last two lines in a function, I don't know how to do so easily. The last line ends with ))])] but the next to last line ends with ])). When I re-order (swap) them, I have to totally start from scratch in figuring out the closing brackets to use. Or, for another example, if I comment-out a line that has closing brackets for a structure above it, then there is syntax error.

I do not know paren-mode. I looked for it to no avail. I use show-paren-mode. Maybe that's what you mean? I haven't tried paredit-mode.

FYI, since I wrote the original comment on this issue, I have subsequently discovered Wisp syntax https://srfi.schemers.org/srfi-119/srfi-119.html which I like more than sweet syntax.

@GReagle
Copy link
Author

GReagle commented Apr 2, 2021

Here is the code for wisp syntax, fairly similar to the code for sweet syntax that I posted above:

(setq imenu-generic-expression '((nil "^define\\(/contract\\)? +:? *\\([^[:space:](;]+\\)" 2)))

@greghendershott
Copy link
Owner

I do not know paren-mode. I looked for it to no avail. I use show-paren-mode. Maybe that's what you mean?

Yes, sorry, I meant paren-face-mode.

I dislike parens, but not because I have to look at them, because I have to deal with them. :> For example if I want to reorder the last two lines in a function, I don't know how to do so easily. The last line ends with ))])] but the next to last line ends with ])). When I re-order (swap) them, I have to totally start from scratch in figuring out the closing brackets to use. Or, for another example, if I comment-out a line that has closing brackets for a structure above it, then there is syntax error.

On the one hand, paredit-mode definitely helps with all that. Various edit commands are enhanced to preserve balanced parentheses. Even typing a ; for a comment, like in your example, will automatically split the line and keep a valid s-expression. Also basic things like tying ( automatically types the ) for you, although you can also get that with electric-parens-mode these days.

On the other hand, many people try to use paredit-mode, find it "too strict", and give up. Sometimes they try again, months later, and give up again. I think for me, it took 3 tries, before it "clicked" for me. :)

So you can focus on editing the structure of your code, which is both wonderful when you realize you want that... and a PITA before then. Someone joked, "If paredit isn't for you, then you need to become the kind of person paredit is for". I wish that weren't true but alas it seems to be.

@GReagle
Copy link
Author

GReagle commented Apr 7, 2021

Thank you, I did not know it was possible to comment-out a line easily in Lisp (meaning without "manually" adjusting closing parentheses). Very good to know. Maybe I'll try paredit-mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants