Skip to content
Edit comment or docstring or code blocks inside them in separate buffers.
Emacs Lisp Makefile Shell
Branch: master
Clone or download

Latest commit

Latest commit fc3a769 Feb 29, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.githooks Renamed to separedit Feb 25, 2020
images Add README Dec 2, 2019
.gitignore Initial version Dec 2, 2019
.travis.yml Add travis file Dec 3, 2019
Cask Add key binding tests Feb 29, 2020
LICENSE Add LICENSE Jan 2, 2020
Makefile Renamed to separedit Feb 25, 2020
README.md Renamed to separedit Feb 25, 2020
cask-bootstrap.el Add make target `readme` to generate README.md Jan 2, 2020
run-test.example.sh Add run-test.example.sh Feb 14, 2020
separedit-test-helper.el Add key binding tests Feb 29, 2020
separedit-test.el Add key binding tests Feb 29, 2020
separedit.el Fix key binding of edit buffer Feb 29, 2020

README.md

Build Status

separedit.el

Edit comment or docstring or code block inside them with your favorite mode.

+----------+         Edit           +-----------+         Edit           +-----------+
|          | ---------------------> |   edit    | ---------------------> |   edit    | ...
|          |  point-at-comment?     |   buffer  |  point-at-comment?     |   buffer  |
|  source  |  point-at-string?      |           |  point-at-string?      |           | ...
|  buffer  |  point-at-codeblock?   | (markdown |  point-at-codeblock?   | (markdown | ...
|          |                        |  orgmode  |                        |  orgmode  |
|          | <--------------------- |   ...)    | <--------------------- |   ...)    | ...
+----------+     Commit changes     +-----------+     Commit changes     +-----------+

Installation

Clone this repository to ~/.emacs.d/site-lisp/separedit. Add the following to your .emacs:

(require 'separedit)
(define-key prog-mode-map (kbd "C-c '") #'separedit)
(setq separedit-default-mode 'markdown-mode) ;; or org-mode

Usage

  • Move the cursor to a comment or string, or a code block inside them.

  • C-c '.

    or press C-u C-c ' to starting edit with manually selected major mode.

Edit comment

separedit use continuity as basis for determing whether it is a comment block or line. Continuous means that there is no barrier (e.g. code or blank line) between the end of previous line and the beginning of next line, for example:

/*
 * this is a
 * comment block
 */

//
// this is also a
// comment block
//

//
// this is another
// comment block
//

code 1 /* all this are comment lines */
code 2 /* all this are comment lines */
code 3 // all this are comment lines
code 4 // all this are comment lines

By setting separedit-default-mode to choose the mode (e.g. markdown-mode or org-mode) for edit buffer. In edit buffer, the comment delimiter will be removed, for example:

source buffer     ->    edit buffer   ->    edit buffer

/*
 * # Example            # Example
 *
 * ``` C                ``` C
 * foo("bar");          foo("bar");         foo("bar");
 * ```                  ```
 */

// * Example            * Example
//
// #+BEGIN_SRC C        #+BEGIN_SRC C
// foo("bar");          foo("bar");         foo("bar");
// #+END_SRC            #+END_SRC

Edit string

separedit provides convenience for editing escaped strings, if there are nested string or code block, just continue press C-c ' to enter a new edit buffer:

source buffer     ->    edit buffer   ->    edit buffer

"a\"b\\\"c\\\"\""       a"b\"c\""           b"c"

Edit code block

separedit also support for editing code block directly in comment or string:

source buffer     ->    eidt buffer

",--- elisp
 | (foo \"bar\")        (foo "bar")
 `---"

/*
 * ``` C
 * foo("bar");          foo("bar");
 * ```
 */

If the language identifier of code block is omitted, the edit buffer uses the same mode as the source buffer.

Screencasts

P.S. The language identifier of code block can be omitted in these cases.

You can’t perform that action at this time.