lang/cc: rewrite init of irony-mode & compiler options
This commit is contained in:
parent
2a7f1b20b9
commit
b288f34f4e
2 changed files with 47 additions and 26 deletions
|
@ -64,18 +64,19 @@
|
||||||
t))
|
t))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +cc|irony-add-include-paths ()
|
(defun +cc|irony-init-compile-options ()
|
||||||
"Seek out and add the nearest include/ folders to clang's options."
|
"Initialize compiler options for irony-mode. It searches for the nearest
|
||||||
(when-let (dir (locate-dominating-file buffer-file-name "include/"))
|
compilation database and initailizes it. If none was found, it uses
|
||||||
(cl-pushnew (concat "-I" (expand-file-name "include/" dir))
|
`+cc-c++-compiler-options'.
|
||||||
irony-additional-clang-options :test #'equal)))
|
|
||||||
|
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)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +cc|use-c++11 ()
|
|
||||||
"Enable C++11 support with clang (via irony)."
|
|
||||||
(cl-pushnew "-std=c++11" irony-additional-clang-options :test #'equal)
|
|
||||||
(when IS-MAC
|
|
||||||
;; NOTE beware: you'll get abi-inconsistencies when passing std-objects to
|
|
||||||
;; libraries linked with libstdc++ (e.g. if you use boost which wasn't
|
|
||||||
;; compiled with libc++)
|
|
||||||
(cl-pushnew "-stdlib=libc++" irony-additional-clang-options :test #'equal)))
|
|
||||||
|
|
|
@ -1,5 +1,30 @@
|
||||||
;;; lang/cc/config.el --- c, c++, and obj-c -*- lexical-binding: t; -*-
|
;;; lang/cc/config.el --- c, c++, and obj-c -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +cc-include-paths (list "include/")
|
||||||
|
"A list of paths, relative to a project root, to search for headers in
|
||||||
|
C/C++. Paths can be absolute.
|
||||||
|
|
||||||
|
The purpose of this variable is to ensure syntax checkers and code-completion
|
||||||
|
knows where to look for headers.")
|
||||||
|
|
||||||
|
(defvar +cc-compiler-options
|
||||||
|
`((c-mode . nil)
|
||||||
|
(c++-mode
|
||||||
|
. ,(list "-std=c++11" ; use C++11 by default
|
||||||
|
(when IS-MAC
|
||||||
|
;; NOTE beware: you'll get abi-inconsistencies when passing
|
||||||
|
;; std-objects to libraries linked with libstdc++ (e.g. if you use
|
||||||
|
;; boost which wasn't compiled with libc++)
|
||||||
|
(list "-stdlib=libc++"))))
|
||||||
|
(objc-mode . nil))
|
||||||
|
"A list of default compiler options for the C family. These are ignored if a
|
||||||
|
compilation database is present in the project.")
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Plugins
|
||||||
|
;;
|
||||||
|
|
||||||
(def-package! cc-mode
|
(def-package! cc-mode
|
||||||
:commands (c-mode c++-mode objc-mode java-mode)
|
:commands (c-mode c++-mode objc-mode java-mode)
|
||||||
:mode ("\\.mm" . objc-mode)
|
:mode ("\\.mm" . objc-mode)
|
||||||
|
@ -90,19 +115,14 @@
|
||||||
:preface
|
:preface
|
||||||
(setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
|
(setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
|
||||||
:init
|
:init
|
||||||
(defun +cc|init-irony-mode ()
|
(add-hook! (c-mode c++-mode objc-mode) #'irony-mode)
|
||||||
;; The major-mode check is necessary because some modes derive themselves
|
|
||||||
;; from a c base mode, like java-mode or php-mode.
|
|
||||||
(when (and (memq major-mode '(c-mode c++-mode objc-mode))
|
|
||||||
(file-directory-p irony-server-install-prefix))
|
|
||||||
(irony-mode +1)))
|
|
||||||
(add-hook 'c-mode-common-hook #'+cc|init-irony-mode)
|
|
||||||
:config
|
:config
|
||||||
(make-variable-buffer-local 'irony-additional-clang-options)
|
(unless (file-directory-p irony-server-install-prefix)
|
||||||
;; Add nearest include/ path to compiler options
|
(warn "irony-mode: server isn't installed; run M-x irony-install-server"))
|
||||||
(add-hook! '(c-mode-hook c++-mode-hook) #'+cc|irony-add-include-paths)
|
|
||||||
;; Use C++11/14 by default
|
;; Initialize compilation database, if present. Otherwise, fall back on
|
||||||
(add-hook 'c++-mode-hook #'+cc|use-c++11))
|
;; `+cc-compiler-options'.
|
||||||
|
(add-hook 'irony-mode-hook #'+cc|irony-init-compile-options))
|
||||||
|
|
||||||
(def-package! irony-eldoc
|
(def-package! irony-eldoc
|
||||||
:after irony
|
:after irony
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue