lang/cc: fix smartparens not autopairing/skipping <>

Also removed +cc/autoclose->-maybe -- let smartparens handle this.
This commit is contained in:
Henrik Lissner 2018-02-14 05:06:26 -05:00
parent 11373e0128
commit b43743d565
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 12 additions and 17 deletions

View file

@ -32,21 +32,14 @@
0 ; no additional indent 0 ; no additional indent
(apply orig-fun args))) (apply orig-fun args)))
;;;###autoload
(defun +cc/autoclose->-maybe ()
"For some reason smartparens won't autoskip >'s, this hack does."
(interactive)
(if (save-excursion
(backward-char)
(looking-at-p "[^ \t]>"))
(forward-char)
(call-interactively #'self-insert-command)))
;;;###autoload ;;;###autoload
(defun +cc-sp-point-is-template-p (id action context) (defun +cc-sp-point-is-template-p (id action context)
"Return t if point is in the right place for C++ angle-brackets." "Return t if point is in the right place for C++ angle-brackets."
(and (sp-in-code-p id action context) (and (sp-in-code-p id action context)
(sp-point-after-word-p id action context))) (cond ((eq action 'insert)
(sp-point-after-word-p id action context))
((eq action 'autoskip)
(/= (char-before) 32)))))
;;;###autoload ;;;###autoload
(defun +cc-sp-point-after-include-p (id action context) (defun +cc-sp-point-after-include-p (id action context)

View file

@ -47,7 +47,8 @@ compilation database is present in the project.")
(push (cons #'+cc-objc-header-file-p 'objc-mode) magic-mode-alist) (push (cons #'+cc-objc-header-file-p 'objc-mode) magic-mode-alist)
:init :init
(setq-default c-basic-offset tab-width) (setq-default c-basic-offset tab-width
c-backspace-function #'delete-backward-char)
:config :config
(set! :electric '(c-mode c++-mode objc-mode java-mode) (set! :electric '(c-mode c++-mode objc-mode java-mode)
@ -84,18 +85,19 @@ compilation database is present in the project.")
;; custom bindings. We'll do this ourselves. ;; custom bindings. We'll do this ourselves.
(setq c-tab-always-indent nil (setq c-tab-always-indent nil
c-electric-flag nil) c-electric-flag nil)
(dolist (key '("#" "{" "}" "/" "*" ";" "," ":" "(" ")")) (dolist (key '("#" "{" "}" "/" "*" ";" "," ":" "(" ")" "\177"))
(define-key c-mode-base-map key nil)) (define-key c-mode-base-map key nil))
;; Smartparens and cc-mode both try to autoclose angle-brackets intelligently. ;; Smartparens and cc-mode both try to autoclose angle-brackets intelligently.
;; The result isn't very intelligent (causes redundant characters), so just do ;; The result isn't very intelligent (causes redundant characters), so just do
;; it ourselves. ;; it ourselves.
(map! :map c++-mode-map (map! :map c++-mode-map "<" nil ">" nil)
"<" nil
:i ">" #'+cc/autoclose->-maybe)
;; ...and leave it to smartparens ;; ...and leave it to smartparens
(sp-with-modes '(c++-mode objc-mode)
(sp-local-pair "<" ">"
:when '(+cc-sp-point-is-template-p +cc-sp-point-after-include-p)
:post-handlers '(("| " "SPC"))))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode) (sp-with-modes '(c-mode c++-mode objc-mode java-mode)
(sp-local-pair "<" ">" :when '(+cc-sp-point-is-template-p +cc-sp-point-after-include-p))
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC"))) (sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
;; Doxygen blocks ;; Doxygen blocks
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC"))) (sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))