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

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