-
Notifications
You must be signed in to change notification settings - Fork 181
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
Indent example-code blocks in comments #563
Conversation
This can be used as the indent-line-function, as an alternative to rust-mode-indent-line. In addition to indenting the current line as rust-mode-indent-line does, it also checks to see whether we are editing a Markdown code block inside a comment (either a documentation comment or a normal comment.) If we are inside a Markdown code block, it extracts that code block, treats it as Rust code, and indents the current line accordingly. Note that this behavior is only triggered if point is inside the comment body: placing point at the start of the line and pressing tab will only re-indent the comment line, but placing point at the end of the line and pressing tab will re-indent the both comment line and its contents.
rust-prog-mode.el
Outdated
@@ -1457,7 +1574,7 @@ whichever comes first." | |||
(setq-local syntax-propertize-function #'rust-syntax-propertize) | |||
|
|||
;; Indentation | |||
(setq-local indent-line-function 'rust-mode-indent-line) | |||
(setq-local indent-line-function 'rust-doc-indent-line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this variable to rust-mode-indent-line
and tweak the functionality in that function. 🤔
I'm not sure what you're saying. I could rename the function rust-mode-indent-line to rust-simple-indent-line and rename rust-doc-indent-line to rust-mode-indent-line. If you're suggesting to turn it into one massive function, I think that's unwise. There is very little overlap in logic/functionality between those two functions: rust-doc-indent-line is concerned with rustdoc syntax, not with rust syntax. It's almost completely orthogonal to the programming language. |
@jcs090218 Do you agree with the comments of @bemoody ? @bemoody Thanks for the PR, LGTM from a high level. Is it possible to have a test for this functionality ? |
I suggest renaming rust-mode-indent-line to rust-mode--indent-line (or name anything logical) and creating a new rust-mode-indent-line to call the other two functions, etc. I think it doesn't really matter since it requires little to no refactoring right now. 🤔 |
Got it, Thanks! @bemoody Do you think you can do the following renames:
Adding a test would be nice and I think there are already some test related to indentation in rust-mode-tests.el from which you can take inspiration from. |
Sure, sounds good! I haven't worked with ert before, but I think this should do the trick. |
Allow pressing Tab to indent example code blocks inside comments.
For example, if the buffer contains this:
Move to the word "world" and press Tab, and you should see: