From 834c39c2fdbf00a9828a8704853aad49d291d32b Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Wed, 6 Jun 2018 01:15:48 -0400 Subject: [PATCH] Update promotion and demotion conventions and apply them to markdown --- doc/CONVENTIONS.org | 13 ++++++++++++- layers/+lang/markdown/README.org | 12 ++++++------ layers/+lang/markdown/funcs.el | 12 ++++++++++++ layers/+lang/markdown/packages.el | 14 +++++++------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/doc/CONVENTIONS.org b/doc/CONVENTIONS.org index cedc64e5c..4c6ba1bc8 100644 --- a/doc/CONVENTIONS.org +++ b/doc/CONVENTIONS.org @@ -301,7 +301,8 @@ In normal mode Vim style movement should be enabled with these keybindings: *** Promotion, Demotion and element movement Promotion, demotion and movement of headings or list elements (whatever is -possible) should be enabled with the following keys in any mode +possible) should be enabled with the following keys when in Vim style or +Hybrid with hjkl movements enabled: | Key Binding | Description | |-------------+------------------------------| @@ -310,6 +311,16 @@ possible) should be enabled with the following keys in any mode | ~M-k~ | Move element up | | ~M-l~ | Demote heading by one level | +In all editing styles promotion and demotion can be done with the following +keys: + +| Key Binding | Description | +|-------------+------------------------------| +| ~M-down~ | Move element down | +| ~M-left~ | Promote heading by one level | +| ~M-right~ | Demote heading by one level | +| ~M-up~ | Move element up | + *** Table editing If table specific commands are available the they are grouped under the ~SPC m t~ group. diff --git a/layers/+lang/markdown/README.org b/layers/+lang/markdown/README.org index 1e9726aef..0ddb20715 100644 --- a/layers/+lang/markdown/README.org +++ b/layers/+lang/markdown/README.org @@ -188,12 +188,12 @@ To generate a table of contents type on top of the buffer: ** Promotion, Demotion -| Evil | Holy | Command | -|-------+-------------+--------------------| -| ~M-k~ | ~C-c C-x u~ | markdown-move-up | -| ~M-j~ | ~C-c C-x d~ | markdown-move-down | -| ~M-h~ | ~C-c C-x l~ | markdown-promote | -| ~M-l~ | ~C-c C-x r~ | markdown-demote | +| Key Binding | Command | +|--------------------+--------------------| +| ~M-k~ or ~M-up~ | markdown-move-up | +| ~M-j~ or ~M-down~ | markdown-move-down | +| ~M-h~ or ~M-left~ | markdown-promote | +| ~M-l~ or ~M-right~ | markdown-demote | ** Toggles diff --git a/layers/+lang/markdown/funcs.el b/layers/+lang/markdown/funcs.el index 5b05f489f..f93eb1918 100644 --- a/layers/+lang/markdown/funcs.el +++ b/layers/+lang/markdown/funcs.el @@ -51,3 +51,15 @@ Will work on both org-mode and any mode that accepts plain html." :back back))) (dolist (mode markdown--key-bindings-modes) (mmm-add-mode-ext-class mode nil class)))) + +(defun spacemacs//markdown-hjkl-promotion-demotion (style) + "Set promotion/demotiion on 'hjkl' for the given editing STYLE." + (when (or (eq 'vim style) + (and (eq 'hybrid style) + hybrid-mode-enable-hjkl-bindings)) + (dolist (s '(normal insert)) + (evil-define-key s markdown-mode-map + (kbd "M-h") 'markdown-promote + (kbd "M-j") 'markdown-move-down + (kbd "M-k") 'markdown-move-up + (kbd "M-l") 'markdown-demote)))) diff --git a/layers/+lang/markdown/packages.el b/layers/+lang/markdown/packages.el index 7de4460d6..8c5a8c69d 100644 --- a/layers/+lang/markdown/packages.el +++ b/layers/+lang/markdown/packages.el @@ -143,13 +143,13 @@ ;; next visible heading is not exactly what we want but close enough "gl" 'outline-next-visible-heading) ;; Promotion, Demotion - (mapc (lambda (state) - (evil-define-key state markdown-mode-map - (kbd "M-h") 'markdown-promote - (kbd "M-j") 'markdown-move-down - (kbd "M-k") 'markdown-move-up - (kbd "M-l") 'markdown-demote)) - '(normal insert))))) + (add-hook 'spacemacs-editing-style-hook + 'spacemacs//markdown-hjkl-promotion-demotion) + (spacemacs//markdown-hjkl-promotion-demotion dotspacemacs-editing-style) + (define-key markdown-mode-map (kbd "M-") 'markdown-move-down) + (define-key markdown-mode-map (kbd "M-") 'markdown-promote) + (define-key markdown-mode-map (kbd "M-") 'markdown-demote) + (define-key markdown-mode-map (kbd "M-") 'markdown-move-up)))) (defun markdown/init-markdown-toc () (use-package markdown-toc