mirror of https://github.com/Chizi123/.emacs.d.git

Chizi123
2018-11-18 8f6f2705a38e2515b6c57fda12c5be29fb9a798f
commit | author | age
5cb5f7 1 ;;; smartparens-config.el --- Default configuration for smartparens package  -*- lexical-binding: t; -*-
C 2
3 ;; Copyright (C) 2013-2016 Matus Goljer
4
5 ;; Author: Matus Goljer <matus.goljer@gmail.com>
6 ;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
7 ;; Created: 30 Jan 2013
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 is a default configuration for smartparens package.  If you
33 ;; wish to set up everything by yourself, you can instead require
34 ;; smartparens directly.
35
36 ;; However, some configuration is always loaded by default, most
37 ;; notably the built-in list of supported pairs.  If you want to erase
38 ;; this list, simply use (setq sp-pairs nil) and then add your own
39 ;; pairs.
40
41 ;; For more info, see github readme at
42 ;; https://github.com/Fuco1/smartparens
43
44 ;;; Code:
45
46 (require 'smartparens)
47
48 (defun sp-lisp-invalid-hyperlink-p (_id action _context)
49   "Test if there is an invalid hyperlink in a Lisp docstring.
50 ID, ACTION, CONTEXT."
51   (when (eq action 'navigate)
52     ;; Ignore errors due to us being at the start or end of the
53     ;; buffer.
54     (ignore-errors
55       (or
56        ;; foo'|bar
57        (and (looking-at "\\sw\\|\\s_")
58             ;; do not consider punctuation
59             (not (looking-at "[?.,;!]"))
60             (save-excursion
61               (backward-char 2)
62               (looking-at "\\sw\\|\\s_")))
63        ;; foo|'bar
64        (and (save-excursion
65               (backward-char 1)
66               (looking-at "\\sw\\|\\s_"))
67             (save-excursion
68               (forward-char 1)
69               (looking-at "\\sw\\|\\s_")
70               ;; do not consider punctuation
71               (not (looking-at "[?.,;!]"))))))))
72
73 ;; emacs is lisp hacking enviroment, so we set up some most common
74 ;; lisp modes too
75 (sp-with-modes sp-lisp-modes
76   ;; disable ', it's the quote character!
77   (sp-local-pair "'" nil :actions nil))
78
79 (sp-with-modes (-difference sp-lisp-modes sp-clojure-modes)
80   ;; also only use the pseudo-quote inside strings where it serve as
81   ;; hyperlink.
82   (sp-local-pair "`" "'"
83                  :when '(sp-in-string-p
84                          sp-in-comment-p)
85                  :unless '(sp-lisp-invalid-hyperlink-p)
86                  :skip-match (lambda (ms _mb _me)
87                                (cond
88                                 ((equal ms "'")
89                                  (or (sp-lisp-invalid-hyperlink-p "`" 'navigate '_)
90                                      (not (sp-point-in-string-or-comment))))
91                                 (t (not (sp-point-in-string-or-comment)))))))
92
93 ;; TODO: this should only be active in docstring, otherwise we want
94 ;; the regexp completion \\{\\}.  To handle this feature, we must
95 ;; allow multiple pairs on same opening (therefore, the unique ID must
96 ;; become the opening and closing pair)
97 (sp-local-pair 'emacs-lisp-mode "\\\\{" "}" :when '(sp-in-docstring-p))
98
99 ;; NOTE: Normally, `sp-local-pair' accepts list of modes (or a single
100 ;; mode) as a first argument.  The macro `sp-with-modes' adds this
101 ;; automatically.  If you want to call sp-local-pair outside this
102 ;; macro, you MUST supply the major mode argument.
103
104 (eval-after-load 'clojure-mode             '(require 'smartparens-clojure))
105 (eval-after-load 'crystal-mode             '(require 'smartparens-crystal))
106 (eval-after-load 'elixir-mode              '(require 'smartparens-elixir))
107 (eval-after-load 'enh-ruby-mode            '(require 'smartparens-ruby))
108 (eval-after-load 'ess                      '(require 'smartparens-ess))
109 (eval-after-load 'haskell-interactive-mode '(require 'smartparens-haskell))
110 (eval-after-load 'haskell-mode             '(require 'smartparens-haskell))
111 (--each sp--html-modes
112   (eval-after-load it                      '(require 'smartparens-html)))
113 (eval-after-load 'latex                    '(require 'smartparens-latex))
114 (eval-after-load 'lua-mode                 '(require 'smartparens-lua))
115 (eval-after-load 'markdown-mode            '(require 'smartparens-markdown))
116 (--each '(python-mode python)
117   (eval-after-load it                      '(require 'smartparens-python)))
118 (eval-after-load 'org                      '(require 'smartparens-org))
119 (eval-after-load 'racket-mode              '(require 'smartparens-racket))
120 (eval-after-load 'ruby-mode                '(require 'smartparens-ruby))
121 (eval-after-load 'rust-mode                '(require 'smartparens-rust))
122 (eval-after-load 'scala-mode               '(require 'smartparens-scala))
123 (eval-after-load 'tex-mode                 '(require 'smartparens-latex))
124 (eval-after-load 'text-mode                '(require 'smartparens-text))
125 (eval-after-load 'tuareg                   '(require 'smartparens-ml))
126 (eval-after-load 'fsharp-mode              '(require 'smartparens-ml))
127 (--each '(js js2-mode)
128   (eval-after-load it                      '(require 'smartparens-javascript)))
129 (provide 'smartparens-config)
130
131 ;;; smartparens-config.el ends here