commit | author | age
|
5cb5f7
|
1 |
;;; smartparens-lua.el --- Additional configuration for Lua based modes. -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2013-2014 Matus Goljer |
|
4 |
|
|
5 |
;; Author: Matus Goljer <matus.goljer@gmail.com> |
|
6 |
;; Maintainer: Matus Goljer <matus.goljer@gmail.com> |
|
7 |
;; Created: 3 August 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 file provides some additional configuration for Lua based |
|
33 |
;; modes. To use it, simply add: |
|
34 |
;; |
|
35 |
;; (require 'smartparens-lua) |
|
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 |
|
|
50 |
(defun sp-lua-post-keyword-insert (id action _context) |
|
51 |
"ID, ACTION, CONTEXT." |
|
52 |
(cond |
|
53 |
((eq action 'insert) |
|
54 |
(cond |
|
55 |
((member id '("while" "for")) |
|
56 |
(insert " do") |
|
57 |
(save-excursion (newline-and-indent)) |
|
58 |
(backward-char 3)) |
|
59 |
((equal id "if") |
|
60 |
(insert " then") |
|
61 |
(save-excursion (newline-and-indent)) |
|
62 |
(backward-char 5)) |
|
63 |
((equal id "function") |
|
64 |
(save-excursion (newline-and-indent)) |
|
65 |
(insert " ")))))) |
|
66 |
|
|
67 |
;; all the pairs are expanded only if followed by "SPC" event. This |
|
68 |
;; will reduce false positives like 'dIFficult' to trigger. |
|
69 |
(sp-with-modes '(lua-mode) |
|
70 |
(sp-local-pair "if" "end" |
|
71 |
:when '(("SPC")) |
|
72 |
:unless '(sp-in-comment-p sp-in-string-p) |
|
73 |
:post-handlers '(sp-lua-post-keyword-insert)) |
|
74 |
(sp-local-pair "function" "end" |
|
75 |
:when '(("SPC")) |
|
76 |
:unless '(sp-in-comment-p sp-in-string-p) |
|
77 |
:post-handlers '(sp-lua-post-keyword-insert)) |
|
78 |
(sp-local-pair "for" "end" |
|
79 |
:when '(("SPC")) |
|
80 |
:unless '(sp-in-comment-p sp-in-string-p) |
|
81 |
:post-handlers '(sp-lua-post-keyword-insert)) |
|
82 |
(sp-local-pair "while" "end" |
|
83 |
:when '(("SPC")) |
|
84 |
:unless '(sp-in-comment-p sp-in-string-p) |
|
85 |
:post-handlers '(sp-lua-post-keyword-insert)) |
|
86 |
) |
|
87 |
|
|
88 |
(provide 'smartparens-lua) |
|
89 |
|
|
90 |
;;; smartparens-lua.el ends here |