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

Feature request: prettify symbols mode #2402

Closed
siegebell opened this issue Jan 27, 2016 · 12 comments
Closed

Feature request: prettify symbols mode #2402

siegebell opened this issue Jan 27, 2016 · 12 comments
Labels
feature-request Request for new features or functionality
Milestone

Comments

@siegebell
Copy link

Feature request: Emacs has a cool feature called "prettify symbols mode," demonstrated for Haskell here. This could also subsume #192.

The basic idea is to register a sequence of characters whose glyphs will be replaced with another glyph, but the original characters still appear in the text document. Ideally, the substitutions would be dependent on the context returned by a syntax highlighter or some other parser.

@egamma
Copy link
Member

egamma commented Jan 30, 2016

@siegebell the January update will support for font ligatures, this might help for your scenario, please give it a try.

@siegebell
Copy link
Author

@egamma: font ligatures won't really help me.

Use case: The Coq Proof Assistant allows one to write proofs about mathematics (category theory, real numbers, etc.), program behavior, program logics, type systems, etc. I am writing an extension to work with Coq proofs in vscode. It would be useful for the user to be able to define a set of symbol substitutions particular to the domain that they are writing proofs about. For example, set notation is useful for visualizing proofs about set theory.

#192 demonstrates that symbols are also useful for general programming.

Limitations of ligatures for symbol substitutions:

  • requires customizing a font -- I've tried this before and it is not easy;
  • assumes that a particular set of symbols will satisfy a large number of users, rather than allowing each user to pick & choose what works for them;
  • symbols are tied to a specific typeface; and
  • context unaware: ideally the symbol would depend on whether it is a keyword, in a comment, a variable etc. -- things that the editor is aware of but the typeface renderer is not.

Solution:

  • implement "prettify symbols mode," like the Emacs feature;
  • or more generally, provide the API hooks to override how a selection of text is rendered. This can be done by extending DecorationRenderOptions to allow the rendered text to be completely replaced by another string or image/svg. Then I could implement a "prettify symbols mode" extension myself.

@egamma
Copy link
Member

egamma commented Feb 1, 2016

@siegebell no doubt prettify symbols is more powerful than ligatures. Thanks for the clarifications.

@alexdima alexdima added feature-request Request for new features or functionality editor labels Feb 2, 2016
@siegebell
Copy link
Author

@egamma @aeschli - I've managed to implement a rudimentary prettify symbols mode using #7181 (before & after decorations) -- thanks!

But there are a couple bugs in #7181 and limitations elsewhere that need to be addressed, so I'll be filing a few more related issues soon.

@siegebell
Copy link
Author

Most of the features can be implemented as an extension, but here are a couple reasons it might be better to implement this in vscode itself:

  1. It uses code injection (DecorationRenderOptions / createTextEditorDecorationType doesn't support fontWeight? #6201) to hide the replaced text, which is not officially supported and has some bugs.
  2. Cursor movement still steps through each character of the hidden text. I have not found an ideal hook for overriding cursor movement: I can hook the 'cursorLeft' command, but there seems to be no way to restore the original behavior, or I can set up keybindings that hook cursor movement keys. Neither of these options play well with potential extensions that change cursor movement behavior or a user's custom keybindings that choose alternatives to e.g. the left key (e.g. the vim extensions).
  3. I've tried both display: none and font-size: 0pt to hide text, and both cause the cursor to disappear when at the left or right edges of the range where such a decoration is applied.

But my preference would be to have a supported way to hide text (e.g. through decorations) that handles cursor movement and cursor visibility properly, and then leave the rest to an extension.

@alexdima
Copy link
Member

alexdima commented Jul 5, 2016

👍 on implementing this in the core. Sounds like something the ViewModel should do -- it has the ability to transform view <-> model positions and randomly insert/remove text, etc.

Note: it is not trivial

@alexdima alexdima added this to the Backlog milestone Jul 5, 2016
@siegebell
Copy link
Author

siegebell commented Jul 5, 2016

@alexandrudima @aeschli this could also be resolved by #3422 if it gives extensions a flexible API to control code folding.

The API would need to allow specifying:

  • a range of text to be folded;
  • different rendering options for each range (or sets of ranges);
  • how to render "fold" (e.g. "-", an SVG, or none);
  • how to render "unfold" (e.g. "+", an SVG, or none);
  • how to render the hidden text (e.g. "..." or none); and
  • a hook to receive (and optionally cancel) requests to fold or unfold the region (e.g. in response to double-clicking, clicking "+" or "-", or a keyboard command).

@siegebell
Copy link
Author

@alexandrudima If I were to attempt a PR to support hiding text, do you think adding it as a decoration property would be a good idea?

E.g. add foldContent: boolean to ThemableDecorationRenderOptions? Unlike display: none, the behavior would not hide the attachments.

@voronoipotato
Copy link

This feature could in theory satisfy both Allow Unicode Operators and Remove Fun Keyword. Really hoping this feature gets implemented at some point.

@siegebell
Copy link
Author

@Miguel-Fontes
Copy link

Miguel-Fontes commented Dec 16, 2016

+1

@alexdima
Copy link
Member

To keep the number of issues in our inbox at a manageable level, we're closing issues that have been on the backlog for a long time but haven't gained traction: we look at the number of votes the issue has received and the number of duplicate issues filed. Thank you for your time and understanding.

P.S. If you disagree and feel that this issue is crucial: we're happy to listen and to reconsider.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants