[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode 6724a2c 5/8: Added optional support for inse
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode 6724a2c 5/8: Added optional support for inserting braces in GFM code block header |
Date: |
Wed, 6 Jan 2021 19:57:12 -0500 (EST) |
branch: elpa/markdown-mode
commit 6724a2cb23853cb1aea62e2839be17e71bab2525
Author: plantarum <tyler@plantarum.ca>
Commit: Shohei YOSHIDA <syohex@gmail.com>
Added optional support for inserting braces in GFM code block header
---
CHANGES.md | 1 +
README.md | 6 +++++
markdown-mode.el | 77 +++++++++++++++++++++++++++++++-------------------------
3 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 9a1d580..0953909 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -24,6 +24,7 @@
- Enable flyspell check at yaml metadata[GH-560][]
- Clean up Makefile
- Support to display local image with percent encoding file path
+ - Support including braces around the language specification in GFM code
blocks
* Bug fixes:
- Fix remaining flyspell overlay in code block or comment issue
[GH-311][]
diff --git a/README.md b/README.md
index bd4e891..216e180 100644
--- a/README.md
+++ b/README.md
@@ -991,6 +991,12 @@ by `markdown-mode` and `gfm-mode` as described below.
region will be placed inside the code block. You will be
prompted for the name of the language, but may press enter to
continue without naming a language.
+
+ In addition, in `gfm-mode`, GFM code blocks can be inserted via the
+ option `markdown-gfm-use-electric-backquote`. If the option
+ `markdown-code-block-braces` is set to `t`, code blocks inserted with
+ <kbd>C-c C-s C</kbd> or electric backquotes will include braces ("{}")
+ around the language attributes.
* **Strikethrough:** Strikethrough text is supported in both
`markdown-mode` and `gfm-mode`. It can be inserted (and toggled)
diff --git a/markdown-mode.el b/markdown-mode.el
index b27ad49..6c80f95 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -4301,6 +4301,11 @@ opening code fence and an info string."
:safe #'natnump
:package-version '(markdown-mode . "2.3"))
+(defcustom markdown-code-block-braces nil
+ "When non-nil, automatically insert braces for GFM code blocks."
+ :group 'markdown
+ :type 'boolean)
+
(defun markdown-insert-gfm-code-block (&optional lang edit)
"Insert GFM code block for language LANG.
If LANG is nil, the language will be queried from user. If a
@@ -4321,45 +4326,49 @@ code block in an indirect buffer after insertion."
(quit "")))
current-prefix-arg))
(unless (string= lang "") (markdown-gfm-add-used-language lang))
- (when (> (length lang) 0)
+ (when (and (> (length lang) 0)
+ (not markdown-code-block-braces))
(setq lang (concat (make-string markdown-spaces-after-code-fence ?\s)
lang)))
- (if (use-region-p)
- (let* ((b (region-beginning)) (e (region-end)) end
- (indent (progn (goto-char b) (current-indentation))))
- (goto-char e)
- ;; if we're on a blank line, don't newline, otherwise the ```
- ;; should go on its own line
- (unless (looking-back "\n" nil)
- (newline))
+ (let ((gfm-open-brace (if markdown-code-block-braces "{" ""))
+ (gfm-close-brace (if markdown-code-block-braces "}" "")))
+ (if (use-region-p)
+ (let* ((b (region-beginning)) (e (region-end)) end
+ (indent (progn (goto-char b) (current-indentation))))
+ (goto-char e)
+ ;; if we're on a blank line, don't newline, otherwise the ```
+ ;; should go on its own line
+ (unless (looking-back "\n" nil)
+ (newline))
+ (indent-to indent)
+ (insert "```")
+ (markdown-ensure-blank-line-after)
+ (setq end (point))
+ (goto-char b)
+ ;; if we're on a blank line, insert the quotes here, otherwise
+ ;; add a new line first
+ (unless (looking-at-p "\n")
+ (newline)
+ (forward-line -1))
+ (markdown-ensure-blank-line-before)
+ (indent-to indent)
+ (insert "```" gfm-open-brace lang gfm-close-brace)
+ (markdown-syntax-propertize-fenced-block-constructs (point-at-bol)
end))
+ (let ((indent (current-indentation))
+ start-bol)
+ (delete-horizontal-space :backward-only)
+ (markdown-ensure-blank-line-before)
+ (indent-to indent)
+ (setq start-bol (point-at-bol))
+ (insert "```" gfm-open-brace lang gfm-close-brace "\n")
+ (indent-to indent)
+ (unless edit (insert ?\n))
(indent-to indent)
(insert "```")
(markdown-ensure-blank-line-after)
- (setq end (point))
- (goto-char b)
- ;; if we're on a blank line, insert the quotes here, otherwise
- ;; add a new line first
- (unless (looking-at-p "\n")
- (newline)
- (forward-line -1))
- (markdown-ensure-blank-line-before)
- (indent-to indent)
- (insert "```" lang)
- (markdown-syntax-propertize-fenced-block-constructs (point-at-bol)
end))
- (let ((indent (current-indentation)) start-bol)
- (delete-horizontal-space :backward-only)
- (markdown-ensure-blank-line-before)
- (indent-to indent)
- (setq start-bol (point-at-bol))
- (insert "```" lang "\n")
- (indent-to indent)
- (unless edit (insert ?\n))
- (indent-to indent)
- (insert "```")
- (markdown-ensure-blank-line-after)
- (markdown-syntax-propertize-fenced-block-constructs start-bol (point)))
- (end-of-line 0)
- (when edit (markdown-edit-code-block))))
+ (markdown-syntax-propertize-fenced-block-constructs start-bol (point)))
+ (end-of-line 0)
+ (when edit (markdown-edit-code-block)))))
(defun markdown-code-block-lang (&optional pos-prop)
"Return the language name for a GFM or tilde fenced code block.
- [nongnu] elpa/markdown-mode updated (e250a84 -> 137696f), ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode fc733be 1/8: feat: Add resize inline image without imagemagick, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 0085875 4/8: Merge pull request #579 from nobiot/feat/inline-image-size-no-imagemagick, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 6724a2c 5/8: Added optional support for inserting braces in GFM code block header,
ELPA Syncer <=
- [nongnu] elpa/markdown-mode 6f97180 3/8: Update CHANGELOG, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode da7b9df 2/8: Update CHANGELOG, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode d5106ff 6/8: Add unit test for markdown code block braces, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode ec6ae58 7/8: Merge remote-tracking branch 'origin/master' into pr-581, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 137696f 8/8: Merge branch 'pr-581', ELPA Syncer, 2021/01/06