Skip to content

Commit 7080e7f

Browse files
authored
Merge pull request #981 from conao3/add-c-config
Integration of smartparens with c/cpp-mode
2 parents 04dd4ee + 0e4fbca commit 7080e7f

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

smartparens-c.el

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;;; smartparens-c.el --- Additional configuration for C/C++ mode. -*- lexical-binding: t; -*-
2+
;;
3+
;; Author: Naoya Yamashita <[email protected]>
4+
;; Maintainer: Matus Goljer <[email protected]>
5+
;; Created: 23 June 2019
6+
;; Keywords: abbrev convenience editing
7+
;; URL: https://github.com/Fuco1/smartparens
8+
;;
9+
;; This file is not part of GNU Emacs.
10+
;;
11+
;;; License:
12+
;;
13+
;; This file is part of Smartparens.
14+
;;
15+
;; Smartparens is free software; you can redistribute it and/or modify
16+
;; it under the terms of the GNU General Public License as published by
17+
;; the Free Software Foundation, either version 3 of the License, or
18+
;; (at your option) any later version.
19+
;;
20+
;; Smartparens is distributed in the hope that it will be useful,
21+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
;; GNU General Public License for more details.
24+
;;
25+
;; You should have received a copy of the GNU General Public License
26+
;; along with Smartparens. If not, see <http://www.gnu.org/licenses/>.
27+
;;
28+
;;; Commentary:
29+
;;
30+
;; This file provides some additional configuration for C/C++ mode.
31+
;; To use it, simply add:
32+
;;
33+
;; (require 'smartparens-c)
34+
;;
35+
;; into your configuration. You can use this in conjunction with the
36+
;; default config or your own configuration.
37+
;;
38+
;;; Code:
39+
40+
(require 'smartparens)
41+
42+
;; remap electric delete functions to smartparens function
43+
(define-key smartparens-strict-mode-map [remap c-electric-delete-forward] 'sp-delete-char)
44+
(define-key smartparens-strict-mode-map [remap c-electric-backspace] 'sp-backward-delete-char)
45+
46+
(sp-with-modes sp-c-modes
47+
(sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET")))
48+
(sp-local-pair "/*" "*/" :post-handlers '((" | " "SPC")
49+
("* ||\n[i]" "RET"))))
50+
51+
(provide 'smartparens-c)
52+
;;; smartparens-c.el ends here

smartparens-config.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ ID, ACTION, CONTEXT."
101101
;; automatically. If you want to call sp-local-pair outside this
102102
;; macro, you MUST supply the major mode argument.
103103

104+
(--each sp-c-modes
105+
(eval-after-load it '(require 'smartparens-c)))
104106
(eval-after-load 'clojure-mode '(require 'smartparens-clojure))
105107
(eval-after-load 'crystal-mode '(require 'smartparens-crystal))
106108
(eval-after-load 'elixir-mode '(require 'smartparens-elixir))

smartparens.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,14 @@ Symbol is defined as a chunk of text recognized by
610610
:type '(repeat symbol)
611611
:group 'smartparens)
612612

613+
(defcustom sp-c-modes '(
614+
c-mode
615+
c++-mode
616+
)
617+
"List of C-related modes."
618+
:type '(repeat symbol)
619+
:group 'smartparens)
620+
613621
(defcustom sp-no-reindent-after-kill-modes '(
614622
python-mode
615623
coffee-mode

0 commit comments

Comments
 (0)