Skip to content

Commit

Permalink
Improved paragraph and block movement
Browse files Browse the repository at this point in the history
Move Markdown block movement and marking commands to
C-M-{, C-M-}, and C-c M-h.

In their place, add syntax-aware Markdown paragraph movement commands:
M-{ (markdown-backward-paragraph),
M-} (markdown-forward-paragraph), and
M-h (markdown-mark-paragraph).

The "plain text block" movement commands introduced in development
since v2.2, which were not syntax-aware, have been removed.

These paragraph and block commands differ primarily in granularity,
with blocks being larger and containing multiple paragraphs.  Take
lists, for example: paragraph movement commands stop at each list item
while block commands move over entire lists.

This commit is related to GH-191.
  • Loading branch information
jrblevin committed Jul 6, 2017
1 parent ab9724d commit bdc2481
Show file tree
Hide file tree
Showing 5 changed files with 433 additions and 122 deletions.
16 changes: 11 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,16 @@
`markdown-mark-subtree` (<kbd>C-c C-M-h</kbd>) and
`markdown-narrow-to-subtree` (<kbd>C-x n s</kbd>).
([GH-191][])
- Add plain text block movement commands: <kbd>C-M-{</kbd>
(`markdown-beginning-of-text-block`) and <kbd>C-M-}</kbd>
(`markdown-end-of-text-block`). To mark a plain text block,
use <kbd>C-c M-h</kbd> (`markdown-mark-text-block`).
- Add syntax-aware Markdown paragraph movement commands:
<kbd>M-{</kbd> (`markdown-backward-paragraph`) and
<kbd>M-}</kbd> (`markdown-forward-paragraph`). To mark a
paragraph, use <kbd>M-h</kbd> (`markdown-mark-paragraph`).
These move at a more granular level than the block movement
commands. ([GH-191][])
- The previous block movement and marking commands are now at
<kbd>C-M-{</kbd>, <kbd>C-M-}</kbd>, and <kbd>C-c M-h</kbd>.
In terms of lists, paragraph movement commands now stop at
each list item while block commands move over entire lists.
([GH-191][])
- Add `subtree` as a possible value for
`markdown-reference-location` and
Expand Down Expand Up @@ -184,7 +190,7 @@
`:package-version` tags.
- Better consistency of function names: predicate functions
ending in `-p` shouldn't modify match data.
- Generalize rebinding of block movement commands in case users
- Generalize rebinding of paragraph movement commands in case users
have customized `{forward,backward,mark}-paragraph` bindings.
- Adjust point so that it is left at beginning of setext
headings in heading navigation commands.
Expand Down
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,26 @@ keybindings by pressing <kbd>C-c C-h</kbd>.
at the point. Finally, <kbd>C-c C-u</kbd> will move up to a lower-level
(higher precedence) visible heading.

* Movement by Markdown Blocks: <kbd>M-{</kbd> and <kbd>M-}</kbd>

These keys are usually bound to `forward-paragraph` and
`backward-paragraph`, but those built-in Emacs functions are
based on simple regular expressions and can fail in Markdown.
Blocks in `markdown-mode` are code blocks, blockquotes, list
items (which may contain other blocks), headings, horizontal
rules, or plain text paragraphs separated by whitespace.
Instead, they are bound to `markdown-forward-block` and
`markdown-backward-block`. To mark or narrow to a block, you
can use <kbd>M-h</kbd> (`markdown-mark-block`) and <kbd>C-x n b</kbd>
(`markdown-narrow-to-block`).
* Movement by Markdown paragraph: <kbd>M-{</kbd>, <kbd>M-}</kbd>, and <kbd>M-h</kbd>

Paragraphs in `markdown-mode` are regular paragraphs,
paragraphs inside blockquotes, individual list items, headings,
etc. These keys are usually bound to `forward-paragraph` and
`backward-paragraph`, but the built-in Emacs functions are
based on simple regular expressions that fail in Markdown
files. Instead, they are bound to `markdown-forward-paragraph`
and `markdown-backward-paragraph`. To mark a paragraph,
you can use <kbd>M-h</kbd> (`markdown-mark-paragraph`).

* Movement by Markdown block: <kbd>C-M-{</kbd>, <kbd>C-M-}</kbd>, and <kbd>C-c M-h</kbd>

Markdown blocks are regular paragraphs in many cases, but
contain many paragraphs in other cases: blocks are considered
to be entire lists, entire code blocks, and entire blockquotes.
To move backward one block use <kbd>C-M-{</kbd>
(`markdown-beginning-block`) and to move forward use <kbd>C-M-}</kbd>
(`markdown-end-of-block`). To mark a block, use <kbd>C-c M-h</kbd>
(`markdown-mark-block`).

* Movement by Defuns: <kbd>C-M-a</kbd>, <kbd>C-M-e</kbd>, and <kbd>C-M-h</kbd>

Expand All @@ -489,17 +497,6 @@ keybindings by pressing <kbd>C-c C-h</kbd>.
to the end of the current or following defun, and <kbd>C-M-h</kbd> will
put the region around the entire defun.

* Movement by Plain Text Blocks: <kbd>C-M-{</kbd>, <kbd>C-M-}</kbd>, and <kbd>C-c M-h</kbd>

While the block and defun movement commands respect Markdown
syntax, these commands simply move over whitespace-separated
plain text blocks without regard for the context. You can use
these commands to move over entire lists, whitespace separated
segments of code, etc. To move backward use <kbd>C-M-{</kbd>
(`markdown-beginning-of-text-block`) and to move forward use
<kbd>C-M-}</kbd> (`markdown-end-of-text-block`). To mark a plain text
block, use <kbd>C-c M-h</kbd> (`markdown-mark-text-block`).

* Miscellaneous Commands:

When the [`edit-indirect`][ei] package is installed, <kbd>C-c </kbd>`
Expand Down
Loading

0 comments on commit bdc2481

Please sign in to comment.