From bab8c0e051703072e69f10ff9df42104b624a9cb Mon Sep 17 00:00:00 2001 From: Jason Blevins Date: Mon, 18 Mar 2013 23:19:52 -0400 Subject: [PATCH] Augmented paragraph movement commands Move by paragraph by default, but by block with C-u prefix. The addition of the separate keybindings M-[ and M-] for movement by block was problematic because the escape sequences sent for the delete key by some keyboards begin with M-[. When running in the terminal, this causes Emacs to trigger the block movement command and insert a control character (corresponding to the remainder of the sequence). To remedy this situation, the specific M-[ and M-] block movement keybindings have been removed. Instead, the usual M-{ and M-} paragraph movement commands have been augmented: skip by paragraphs, as defined, or by block when the C-u prefix is given. Some relevant Emacs history: > M-[ was an Emacs 18 binding which was moved to M-{ in Emacs 19, > precisely because it conflicted with the escape sequences produced by > some common keyboards. Source: --- markdown-mode.el | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/markdown-mode.el b/markdown-mode.el index 5094fdc..48ad3ef 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -122,7 +122,7 @@ ;; titling). The primary commands in each group will are described ;; below. You can obtain a list of all keybindings by pressing `C-c ;; C-h`. Movement and shifting commands tend to be associated with -;; paired delimiters such as `M-[` and `M-]` or `C-c <` and `C-c >`. +;; paired delimiters such as `M-{` and `M-}` or `C-c <` and `C-c >`. ;; Outline navigation keybindings the same as in `org-mode'. Finally, ;; commands for running Markdown or doing maintenance on an open file ;; are grouped under the `C-c C-c` prefix. The most commonly used @@ -367,15 +367,16 @@ ;; at the point. Finally, `C-c C-u` will move up to a lower-level ;; (higher precedence) visible heading. ;; -;; * Movement by Block: `M-[` and `M-]` +;; * Movement by Paragraph or Block: `M-{` and `M-}` ;; -;; markdown-mode supports the usual Emacs paragraph movement with -;; `M-{` and `M-}`. These commands treat list items as -;; paragraphs, so they will stop at each line within a block of -;; list items. Additionally, markdown-mode includes movement -;; commands, `M-[` and `M-]` for jumping to the beginning or end -;; of an entire block of text (with blocks being separated by at -;; least one blank line). +;; The definition of a "paragraph" is slightly different in +;; markdown-mode than, say, text-mode, because markdown-mode +;; supports filling for list items and respects hard line breaks, +;; both of which break paragraphs. So, markdown-mode overrides +;; the usual paragraph navigation commands `M-{` and `M-}` so that +;; with a `C-u` prefix, these commands jump to the beginning or +;; end of an entire block of text, respectively, where "blocks" +;; are separated by one or more lines. ;; ;; * Movement by Defun: `C-M-a`, `C-M-e`, and `C-M-h` ;; @@ -3187,8 +3188,8 @@ Assumes match data is available for `markdown-regex-italic'." (define-key map (kbd "M-") 'markdown-demote) (define-key map (kbd "M-") 'markdown-insert-list-item) ;; Movement - (define-key map (kbd "M-[") 'markdown-beginning-of-block) - (define-key map (kbd "M-]") 'markdown-end-of-block) + (define-key map (kbd "M-{") 'markdown-backward-paragraph) + (define-key map (kbd "M-}") 'markdown-forward-paragraph) (define-key map (kbd "M-n") 'markdown-next-link) (define-key map (kbd "M-p") 'markdown-previous-link) ;; Alternative keys (in case of problems with the arrow keys) @@ -3936,6 +3937,30 @@ move back to the ARG-th preceding section." (skip-syntax-backward "-") (forward-line)) +(defun markdown-forward-paragraph (arg) + "Move forward one or more paragraphs or by one block. +When ARG is nil or a numeric prefix, call `forward-paragraph' +with ARG. When called with \\[universal-argument], call +`markdown-end-of-block' instead." + (interactive "P") + (or arg (setq arg 1)) + (cond ((integerp arg) + (forward-paragraph arg)) + ((equal arg '(4)) + (markdown-end-of-block 1)))) + +(defun markdown-backward-paragraph (arg) + "Move backward one or more paragraphs or by one block. +When ARG is nil or a numeric prefix, call `backward-paragraph' +with ARG. When called with \\[universal-argument], call +`markdown-beginning-of-block' instead." + (interactive "P") + (or arg (setq arg 1)) + (cond ((integerp arg) + (backward-paragraph arg)) + ((equal arg '(4)) + (markdown-beginning-of-block 1)))) + (defun markdown-end-of-block-element () "Move the point to the start of the next block unit. Stops at blank lines, list items, headers, and horizontal rules." -- 2.11.4.GIT