Skip to content

Commit

Permalink
Add markdown-edit-code-block-default-mode
Browse files Browse the repository at this point in the history
Based on a suggestion in GH-251.
  • Loading branch information
jrblevin committed Nov 8, 2017
1 parent 5535e1a commit 3b92618
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- Support double-backslash math delimiters. ([GH-270][])
- New user option `markdown-export-kill-buffer` to kill or preserve
HTML export output buffer. ([GH-224][])
- Add `markdown-edit-code-block-default-mode` to specify default
mode for indirect editing of code blocks. ([GH-251][])

* Bug fixes:

Expand Down Expand Up @@ -60,6 +62,7 @@
[gh-238]: https://github.com/jrblevin/markdown-mode/issues/238
[gh-246]: https://github.com/jrblevin/markdown-mode/issues/246
[gh-248]: https://github.com/jrblevin/markdown-mode/issues/248
[gh-251]: https://github.com/jrblevin/markdown-mode/issues/251
[gh-252]: https://github.com/jrblevin/markdown-mode/pull/252
[gh-254]: https://github.com/jrblevin/markdown-mode/issues/254
[gh-255]: https://github.com/jrblevin/markdown-mode/issues/255
Expand Down
12 changes: 11 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,14 @@ This applies to insertions done with
:group 'markdown
:type 'boolean)

(defcustom markdown-edit-code-block-default-mode 'normal-mode
"Default mode to use for editing code blocks.
This mode is used when automatic detection fails, such as for GFM
code blocks with no language specified."
:group 'markdown
:type 'symbol
:package-version '(markdown-mode . "2.4"))

(defcustom markdown-gfm-uppercase-checkbox nil
"If non-nil, use [X] for completed checkboxes, [x] otherwise."
:group 'markdown
Expand Down Expand Up @@ -9059,7 +9067,9 @@ position."
(end (and bounds (goto-char (nth 1 bounds)) (point-at-bol 1))))
(if (and begin end)
(let* ((lang (markdown-code-block-lang))
(mode (and lang (markdown-get-lang-mode lang)))
(mode (if lang
(markdown-get-lang-mode lang)
markdown-edit-code-block-default-mode))

This comment has been minimized.

Copy link
@blaenk

blaenk Nov 14, 2017

Been a while since I've looked at elisp but it seems to me like this assumes that markdown-get-lang-mode will always find a mode for the given lang, which isn't the case. If I'm right, this may be the cause of #284. I think either:

  • the lang can be nil if none was written in the codeblock and so it should fallback onto markdown-edit-code-block-default-mode (as it's doing right now)
  • it may be a language for which no mapping exists and so markdown-get-lang-mode may return nil, in which case it should fallback onto markdown-edit-code-block-default-mode
  • it may be a language for which there is a mapping which markdown-get-lang-mode returns, and so it should be used
(edit-indirect-guess-mode-function
(lambda (_parent-buffer _beg _end)
(funcall mode))))
Expand Down

0 comments on commit 3b92618

Please sign in to comment.