From b43743d565faefd8556ae2843b3eb016da720a3d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 14 Feb 2018 05:06:26 -0500 Subject: [PATCH] lang/cc: fix smartparens not autopairing/skipping <> Also removed +cc/autoclose->-maybe -- let smartparens handle this. --- modules/lang/cc/autoload.el | 15 ++++----------- modules/lang/cc/config.el | 14 ++++++++------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modules/lang/cc/autoload.el b/modules/lang/cc/autoload.el index 896d61377..929d5af02 100644 --- a/modules/lang/cc/autoload.el +++ b/modules/lang/cc/autoload.el @@ -32,21 +32,14 @@ 0 ; no additional indent (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 (defun +cc-sp-point-is-template-p (id action context) "Return t if point is in the right place for C++ angle-brackets." (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 (defun +cc-sp-point-after-include-p (id action context) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index c47de2917..0160b8794 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -47,7 +47,8 @@ compilation database is present in the project.") (push (cons #'+cc-objc-header-file-p 'objc-mode) magic-mode-alist) :init - (setq-default c-basic-offset tab-width) + (setq-default c-basic-offset tab-width + c-backspace-function #'delete-backward-char) :config (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. (setq c-tab-always-indent nil c-electric-flag nil) - (dolist (key '("#" "{" "}" "/" "*" ";" "," ":" "(" ")")) + (dolist (key '("#" "{" "}" "/" "*" ";" "," ":" "(" ")" "\177")) (define-key c-mode-base-map key nil)) ;; Smartparens and cc-mode both try to autoclose angle-brackets intelligently. ;; The result isn't very intelligent (causes redundant characters), so just do ;; it ourselves. - (map! :map c++-mode-map - "<" nil - :i ">" #'+cc/autoclose->-maybe) + (map! :map c++-mode-map "<" nil ">" nil) ;; ...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-local-pair "<" ">" :when '(+cc-sp-point-is-template-p +cc-sp-point-after-include-p)) (sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC"))) ;; Doxygen blocks (sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))