Skip to content

Commit

Permalink
markdown: cleanup auto-modes for mmm and add support ini files
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Apr 29, 2017
1 parent 7fc758e commit 4fd895a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
4 changes: 4 additions & 0 deletions layers/+lang/markdown/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ list of `("language" "mode")`:
(markdown :variables markdown-mmm-auto-modes '("c" "c++" "python" "scala" ("elisp" "emacs-lisp"))
#+END_SRC

*Note:* Spacemacs already defines the variable =markdown-mmm-auto-modes= to a
bunch of languages. Consider opening a PR on the Spacemacs repository to add
new languages instead of overriding the variable in your dotfile.

* Usage
** Generate a TOC
To generate a table of contents type on top of the buffer:
Expand Down
21 changes: 19 additions & 2 deletions layers/+lang/markdown/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,22 @@
"Possibe values are `eww' (built-in browser) or `vmd' (installed with `npm').")

(defvar markdown-mmm-auto-modes
'("c" "c++" "css" "java" "javascript" "python" "ruby" "rust" "scala" ("html" "web") ("elisp" "emacs-lisp") ("ess" "R"))
"List of language names or lists of language and mode names for which to generate mmm classes.")
'(
;; in alphabetical order, symbols first then lists
"c"
"c++"
"css"
"java"
"javascript"
"python"
"ruby"
"rust"
"scala"

("elisp" "emacs-lisp")
("ess" "R")
("ini" "conf-unix")
("html" "web")
)
"List of language names or lists of language and mode names for which to
generate mmm classes.")
21 changes: 21 additions & 0 deletions layers/+lang/markdown/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,24 @@
(defun spacemacs/activate-mmm-mode ()
;; Enable `mmm-mode'.
(mmm-mode 1))

;; stolen from http://stackoverflow.com/a/26297700
;; makes markdown tables saner via orgtbl-mode
(defun spacemacs//cleanup-org-tables ()
(require 'org-table)
(save-excursion
(goto-char (point-min))
(while (search-forward "-+-" nil t) (replace-match "-|-"))))

;; Insert key for org-mode and markdown a la C-h k
;; from SE endless http://emacs.stackexchange.com/questions/2206/i-want-to-have-the-kbd-tags-for-my-blog-written-in-org-mode/2208#2208
(defun spacemacs/insert-keybinding-markdown (key)
"Ask for a key then insert its description.
Will work on both org-mode and any mode that accepts plain html."
(interactive "kType key sequence: ")
(let* ((tag "~%s~"))
(if (null (equal key "\r"))
(insert
(format tag (help-key-description key nil)))
(insert (format tag ""))
(forward-char -6))))
24 changes: 1 addition & 23 deletions layers/+lang/markdown/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,8 @@
:defer t
:config
(progn
;; stolen from http://stackoverflow.com/a/26297700
;; makes markdown tables saner via orgtbl-mode
(require 'org-table)
(defun cleanup-org-tables ()
(save-excursion
(goto-char (point-min))
(while (search-forward "-+-" nil t) (replace-match "-|-"))))
(add-hook 'markdown-mode-hook 'orgtbl-mode)
(add-hook 'markdown-mode-hook
(lambda()
(add-hook 'before-save-hook 'cleanup-org-tables nil 'make-it-local)))
;; Insert key for org-mode and markdown a la C-h k
;; from SE endless http://emacs.stackexchange.com/questions/2206/i-want-to-have-the-kbd-tags-for-my-blog-written-in-org-mode/2208#2208
(defun spacemacs/insert-keybinding-markdown (key)
"Ask for a key then insert its description.
Will work on both org-mode and any mode that accepts plain html."
(interactive "kType key sequence: ")
(let* ((tag "~%s~"))
(if (null (equal key "\r"))
(insert
(format tag (help-key-description key nil)))
(insert (format tag ""))
(forward-char -6))))

(add-hook 'markdown-mode-hook 'spacemacs//cleanup-org-tables nil 'local)
;; Declare prefixes and bind keys
(dolist (prefix '(("mc" . "markdown/command")
("mh" . "markdown/header")
Expand Down

1 comment on commit 4fd895a

@sdwolfz
Copy link
Contributor

@sdwolfz sdwolfz commented on 4fd895a May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks the org table cleanup functionality. I had to add:

(add-hook 'markdown-mode-hook
  (lambda()
    (add-hook 'before-save-hook 'spacemacs//cleanup-org-tables nil 'local)))

to my .spacemacs file inside user-config in order to bring the functionality back.
The function needs to be called at the 'before-save-hook for markdown files.

Please sign in to comment.