commit | author | age
|
5cb5f7
|
1 |
;;; smartparens-markdown.el --- Additional configuration for Markdown based modes. -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2017 Matus Goljer |
|
4 |
|
|
5 |
;; Author: Matus Goljer <matus.goljer@gmail.com> |
|
6 |
;; Maintainer: Matus Goljer <matus.goljer@gmail.com> |
|
7 |
;; Created: 11th May 2017 |
|
8 |
;; Keywords: abbrev convenience editing |
|
9 |
;; URL: https://github.com/Fuco1/smartparens |
|
10 |
|
|
11 |
;; This file is not part of GNU Emacs. |
|
12 |
|
|
13 |
;;; License: |
|
14 |
|
|
15 |
;; This file is part of Smartparens. |
|
16 |
|
|
17 |
;; Smartparens is free software; you can redistribute it and/or modify |
|
18 |
;; it under the terms of the GNU General Public License as published by |
|
19 |
;; the Free Software Foundation, either version 3 of the License, or |
|
20 |
;; (at your option) any later version. |
|
21 |
|
|
22 |
;; Smartparens is distributed in the hope that it will be useful, |
|
23 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
;; GNU General Public License for more details. |
|
26 |
|
|
27 |
;; You should have received a copy of the GNU General Public License |
|
28 |
;; along with Smartparens. If not, see <http://www.gnu.org/licenses/>. |
|
29 |
|
|
30 |
;;; Commentary: |
|
31 |
|
|
32 |
;; This file provides some additional configuration for Markdown based |
|
33 |
;; modes. To use it, simply add: |
|
34 |
;; |
|
35 |
;; (require 'smartparens-markdown) |
|
36 |
;; |
|
37 |
;; into your configuration. You can use this in conjunction with the |
|
38 |
;; default config or your own configuration. |
|
39 |
;; |
|
40 |
;; If you have good ideas about what should be added please file an |
|
41 |
;; issue on the github tracker. |
|
42 |
;; |
|
43 |
;; For more info, see github readme at |
|
44 |
;; https://github.com/Fuco1/smartparens |
|
45 |
|
|
46 |
;;; Code: |
|
47 |
|
|
48 |
(require 'smartparens) |
|
49 |
(require 'smartparens-text) |
|
50 |
(eval-when-compile |
|
51 |
(defvar markdown-gfm-use-electric-backquote)) |
|
52 |
|
|
53 |
|
|
54 |
(defun sp-gfm-electric-backquote-p (_id action _context) |
|
55 |
"Do not insert ```...``` pair if that would be handled by `markdown-electric-backquote'." |
|
56 |
(and (eq action 'insert) |
|
57 |
markdown-gfm-use-electric-backquote |
|
58 |
(sp--looking-back-p "^```"))) |
|
59 |
|
|
60 |
(defun sp--gfm-point-after-word-p (id action _context) |
|
61 |
"Return t if point is after a word, nil otherwise. |
|
62 |
This predicate is only tested on \"insert\" action." |
|
63 |
(when (eq action 'insert) |
|
64 |
(sp--looking-back-p (concat "\\(\\sw\\)" (regexp-quote id))))) |
|
65 |
|
|
66 |
(defun sp--gfm-skip-asterisk (_ms mb _me) |
|
67 |
"Non-nil if we should ignore this asterisk as a delimiter." |
|
68 |
(save-excursion |
|
69 |
(goto-char mb) |
|
70 |
(save-match-data (looking-at "^\\* ")))) |
|
71 |
|
|
72 |
(sp-with-modes '(markdown-mode gfm-mode) |
|
73 |
(sp-local-pair "*" "*" |
|
74 |
:unless '(sp--gfm-point-after-word-p sp-point-at-bol-p) |
|
75 |
:post-handlers '(("[d1]" "SPC")) |
|
76 |
:skip-match 'sp--gfm-skip-asterisk) |
|
77 |
(sp-local-pair "**" "**") |
|
78 |
(sp-local-pair "_" "_" :unless '(sp-point-after-word-p))) |
|
79 |
|
|
80 |
(sp-with-modes 'markdown-mode |
|
81 |
(sp-local-pair "```" "```")) |
|
82 |
|
|
83 |
(sp-with-modes 'gfm-mode |
|
84 |
(sp-local-pair "`" "`" :unless '(:add sp-gfm-electric-backquote-p)) |
|
85 |
(sp-local-pair "```" "```" :unless '(:add sp-gfm-electric-backquote-p))) |
|
86 |
|
|
87 |
(provide 'smartparens-markdown) |
|
88 |
;;; smartparens-markdown.el ends here |