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

Adding support for rendering atx headers in the margin #272

Closed
algal opened this issue Oct 16, 2017 · 3 comments
Closed

Adding support for rendering atx headers in the margin #272

algal opened this issue Oct 16, 2017 · 3 comments

Comments

@algal
Copy link
Contributor

algal commented Oct 16, 2017

I'd like to add a new custom variable, markdown-marginalize-header, which will cause opening atx-style headers to be rendered into the left margin of the window. Together with a font face on headers, this creates a nice clean visual style where you can see the header levels without the header syntax marks cluttering up the text.

You can see it partly working, and partly broken, here:

marginalheaderwip

I would love any help or advice on how to make this work. I've never worked with window margins before, and I don't think I understand the re-parse and re-display cycle, so I'm not sure where the change should go.

The emacs documentation on rendering into the display margins is at https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Margins.html

My work on this is at: https://github.com/algal/markdown-mode/tree/feature/marginal-headers

@jrblevin
Copy link
Owner

This is great! Thanks for working on this. I once thought something like this would be nice, but I didn't know how to do it or if it was possible.

Markdown Mode processes the buffer in two-passes: 1) syntax-propertization, where the overall syntax is parsed and marked with text properties, and 2) fontification, where font lock properties are applied. As such, this code might be better placed in markdown-fontify-headings. In that function, the display property is already set when markup-hiding is enabled. You might be able to add another condition for heading marginalization, to set markup-props accordingly.

Another thought: since markdown only defines six levels of headings, can we just fix the margin width to 6 (or 7, if we need a space), set the (margin left-margin) value, and avoid the copy-string function? I haven't had a chance to run the code yet, so I might be missing something here.

@algal
Copy link
Contributor Author

algal commented Oct 17, 2017

Hi! Thanks for the guidance. That does indeed sound like a better place to put the new logic that sets the display properties. I’ll give it a try and see how it goes.

The copy-string function is there because I thought it would be simpler to use the actual header markup string to build the string that’s placed in the window margin, since then the window margin string will naturally use the same header mark character as the real header. But if we generate the window margin string, then we have to predefined the character or else take extra care to generate the same char as that line of that document is using. But maybe this is too cute, or there are risks or performance penalties associated with copy-string?

Yeah, 6 or 7 characters sounds like a good default. I’ll put that in.

@algal
Copy link
Contributor Author

algal commented Oct 17, 2017

Based on your pointers, I was able to implement it.

I think what I've got is correct. I hope it fits with your plan. I'll put the details in a pull request and close this issue:

#274

@algal algal closed this as completed Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants