2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/cc/autoload.el -*- lexical-binding: t; -*-
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2017-08-04 22:48:06 +02:00
|
|
|
;;;###autoload
|
2017-09-17 22:01:04 +02:00
|
|
|
(defun +cc*align-lambda-arglist (orig-fun &rest args)
|
2017-08-04 22:48:06 +02:00
|
|
|
"Improve indentation of continued C++11 lambda function opened as argument."
|
|
|
|
(if (and (eq major-mode 'c++-mode)
|
|
|
|
(ignore-errors
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (c-langelem-pos langelem))
|
|
|
|
;; Detect "[...](" or "[...]{". preceded by "," or "(",
|
|
|
|
;; and with unclosed brace.
|
|
|
|
(looking-at-p ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
|
|
|
|
0 ; no additional indent
|
|
|
|
(apply orig-fun args)))
|
|
|
|
|
2017-02-19 18:57:16 -05:00
|
|
|
;;;###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)
|
2017-09-17 22:01:04 +02:00
|
|
|
(call-interactively #'self-insert-command)))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +cc-sp-point-is-template-p (id action context)
|
2017-09-17 22:01:04 +02:00
|
|
|
"Return t if point is in the right place for C++ angle-brackets."
|
2017-02-19 18:57:16 -05:00
|
|
|
(and (sp-in-code-p id action context)
|
|
|
|
(sp-point-after-word-p id action context)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +cc-sp-point-after-include-p (id action context)
|
2017-09-17 22:01:04 +02:00
|
|
|
"Return t if point is in an #include."
|
2017-02-19 18:57:16 -05:00
|
|
|
(and (sp-in-code-p id action context)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (line-beginning-position))
|
|
|
|
(looking-at-p "[ ]*#include[^<]+"))))
|
2017-09-17 22:01:04 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +cc-c-lineup-inclass (_langelem)
|
|
|
|
"Indent privacy keywords at same level as class properties."
|
|
|
|
(if (memq major-mode '(c-mode c++-mode))
|
|
|
|
(let ((inclass (assq 'inclass c-syntactic-context)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (c-langelem-pos inclass))
|
|
|
|
(if (or (looking-at "struct")
|
|
|
|
(looking-at "typedef struct"))
|
|
|
|
'+
|
|
|
|
'++)))
|
|
|
|
'+))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Hooks
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +cc|fontify-constants ()
|
|
|
|
"Better fontification for preprocessor constants"
|
|
|
|
(font-lock-add-keywords
|
|
|
|
nil '(("\\<[A-Z]*_[A-Z_]+\\>" . font-lock-constant-face)
|
|
|
|
("\\<[A-Z]\\{3,\\}\\>" . font-lock-constant-face))
|
|
|
|
t))
|
|
|
|
|
|
|
|
;;;###autoload
|
2017-09-19 05:06:50 +02:00
|
|
|
(defun +cc|irony-init-compile-options ()
|
|
|
|
"Initialize compiler options for irony-mode. It searches for the nearest
|
|
|
|
compilation database and initailizes it. If none was found, it uses
|
|
|
|
`+cc-c++-compiler-options'.
|
|
|
|
|
|
|
|
See https://github.com/Sarcasm/irony-mode#compilation-database for details on
|
|
|
|
compilation dbs."
|
|
|
|
(when (memq major-mode '(c-mode c++-mode objc-mode))
|
|
|
|
(require 'irony-cdb)
|
|
|
|
(unless (irony-cdb-autosetup-compile-options)
|
|
|
|
(irony-cdb--update-compile-options
|
|
|
|
(append (delq nil (cdr-safe (assq major-mode +cc-compiler-options)))
|
|
|
|
(cl-loop for path in +cc-include-paths
|
|
|
|
collect (format "-I %s" (shell-quote-argument path))))
|
|
|
|
(doom-project-root)))))
|
2017-09-17 22:01:04 +02:00
|
|
|
|