c/c++: clean up config

This commit is contained in:
Henrik Lissner 2016-04-19 02:42:07 -04:00
parent c2ced47f13
commit 637bbb98c3

View file

@ -23,12 +23,13 @@
(associate! objc-mode :match "\\.mm$") (associate! objc-mode :match "\\.mm$")
(add-hook 'c-initialization-hook 'narf|init-c/c++-settings) (add-hook 'c-initialization-hook 'narf|init-c/c++-settings)
(add-hook 'c++-mode-hook 'highlight-numbers-mode) (add-hook 'c++-mode-hook 'highlight-numbers-mode)
(add-hook 'c++-mode-hook 'narf|init-c++-C11-highlights)
:config :config
(setq c-tab-always-indent nil (setq c-tab-always-indent nil
c-electric-flag nil) c-electric-flag nil)
(map! (:map c-mode-base-map (map! :map c-mode-base-map
(:localleader :nv ";" 'narf/append-semicolon))) (:localleader :nv ";" 'narf/append-semicolon))
(define-text-object! "<" "<" ">") (define-text-object! "<" "<" ">")
(sp-local-pair '(c-mode c++-mode) "<" ">" :when '(narf/sp-point-is-template-p narf/sp-point-after-include-p)) (sp-local-pair '(c-mode c++-mode) "<" ">" :when '(narf/sp-point-is-template-p narf/sp-point-after-include-p))
@ -38,39 +39,37 @@
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC"))) (sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))
(sp-local-pair "/*!" "*/" :post-handlers '(("||\n[i]" "RET") ("[d-1]< | " "SPC")))) (sp-local-pair "/*!" "*/" :post-handlers '(("||\n[i]" "RET") ("[d-1]< | " "SPC"))))
(progn ;; C/C++ (add-hook! (c-mode c++-mode objc-mode)
(add-hook 'c++-mode-hook 'narf|init-c++-C11-highlights) (electric-indent-local-mode +1)
(add-hook! (c-mode c++-mode) (setq electric-indent-chars '(?\n ?})))
(electric-indent-local-mode +1)
(setq electric-indent-chars '(?\n ?})))
;; Fix enum and C++11 lambda indentation ;; C/C++
(defadvice c-lineup-arglist (around c-lineup-arglist-indent-fix activate) (advice-add 'c-lineup-arglist :around 'narf/c-lineup-arglist)
"Improve indentation of continued C++11 lambda function opened as argument." (defun narf/c-lineup-arglist (orig-fun &rest args)
(setq ad-return-value "Improve indentation of continued C++11 lambda function opened as argument."
(if (and (eq major-mode 'c++-mode) (if (and (eq major-mode 'c++-mode)
(ignore-errors (ignore-errors
(save-excursion (save-excursion
(goto-char (c-langelem-pos langelem)) (goto-char (c-langelem-pos langelem))
;; Detect "[...](" or "[...]{". preceded by "," or "(", ;; Detect "[...](" or "[...]{". preceded by "," or "(",
;; and with unclosed brace. ;; and with unclosed brace.
(looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$")))) (looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
0 ; no additional indent 0 ; no additional indent
ad-do-it)))) (apply orig-fun args)))
(progn ;; Obj-C ;; C++ header files
(push `(,(lambda () (push `(,(lambda () (and (f-ext? buffer-file-name "h")
(and (f-ext? buffer-file-name "h") (or (f-exists? (f-swap-ext buffer-file-name "cpp"))
(re-search-forward "@\\<interface\\>" (awhen (car-safe (projectile-get-other-files (buffer-file-name) (projectile-current-project-files)))
magic-mode-regexp-match-limit t))) (f-ext? it "cpp")))))
. objc-mode) . c++-mode)
magic-mode-alist) magic-mode-alist)
(push `(,(lambda () ;; Obj-C
(and (f-ext? buffer-file-name "h") (push `(,(lambda () (and (f-ext? buffer-file-name "h")
(f-exists? (f-swap-ext buffer-file-name "cpp")))) (re-search-forward "@\\<interface\\>" magic-mode-regexp-match-limit t)))
. c++-mode) . objc-mode)
magic-mode-alist)) magic-mode-alist)
(use-package irony (use-package irony
:config :config