rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 178 forks source link

editing documentation comments indirectly #352

Closed andreyorst closed 4 years ago

andreyorst commented 4 years ago

This feature request is sort of inspired by Org Mode's feature of indirect editing of source code blocks. Markdown also has this feature if you use Edit Inderect package. I think rust-edit-doc-comment would be nice name for a function. C-' as shortcut would be familiar for all Org Mode users.

What it should do in rust-mode is strip leading comments, and insert whole comment into indirect buffer with markdown-mode enabled, if we on the comment itself, or edit code only in indirect buffer with rust-mode if we're on code block in documentation comment while executing the command. For example ( represents the point):

/// comment text█
/// # heading
/// ```
/// fn code_block() {}
/// ```

If we execute rust-edit-doc-comment and this buffer is created:

comment text█
# heading
```
fn code_block() {}
```

With markdown-mode enabled.

If the point is anywhere inside code block like this:

/// comment text
/// # heading
/// ```█
/// fn code_block() {}
/// ```

And we execute rust-edit-doc-comment then this buffer is created:

fn code_block() {}

After we edit this buffer we can call rust-finish-doc-comment-edit and we get updated comment.

This makes more convenient editing for documentation comments with proper tools available for both markdown-mode and rust-mode.

condy0919 commented 4 years ago

Consider https://github.com/twlz0ne/separedit.el

andreyorst commented 4 years ago

Consider https://github.com/twlz0ne/separedit.el

seems like what I needed! Thanks