This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/c-c++/funcs.el
syl20bnr 7d215cb089 c-c++: move realgud config to c-c++ layer and delete debug layer
For now realug is used only to C and C++ so it makes more sense to add it to
the c-c++ layer for now.
Later if we can generalize the support of realgud for other languages and we
can start a debugger layer.
2017-05-14 13:20:10 -04:00

80 lines
3.1 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; funcs.el --- C/C++ Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs//clang-format-on-save ()
"Format buffers with ClangFormat when they get saved."
(when c-c++-enable-clang-format-on-save
(clang-format-buffer)))
(defun spacemacs/clang-format-on-save ()
"Add auto-save hook for ClangFormat."
(add-hook 'before-save-hook 'spacemacs//clang-format-on-save nil t))
(defun spacemacs/company-more-than-prefix-guesser ()
(spacemacs/c-c++-load-clang-args)
(company-clang-guess-prefix))
;; Based on the Sarcasm/irony-mode compilation database code.
(defun spacemacs/company-find-clang-complete-file ()
(when buffer-file-name
(let ((dir (locate-dominating-file buffer-file-name ".clang_complete")))
(when dir
(concat (file-name-as-directory dir) ".clang_complete")))))
;; Based on the Sarcasm/irony-mode compilation database code.
(defun spacemacs/company-load-clang-complete-file (cc-file)
"Load the flags from CC-FILE, one flag per line."
(let ((invocation-dir (expand-file-name (file-name-directory cc-file)))
(case-fold-search nil)
compile-flags)
(with-temp-buffer
(insert-file-contents cc-file)
;; Replace relative paths with absolute paths (by @trishume)
;; (goto-char (point-min))
(while (re-search-forward "\\(-I\\|-isystem\n\\)\\(\\S-+\\)" nil t)
(replace-match (format "%s%s" (match-string 1)
(expand-file-name (match-string 2)
invocation-dir))))
;; Turn lines into a list
(setq compile-flags
;; remove whitespaces at the end of each line, if any
(mapcar #'(lambda (line)
(if (string-match "[ \t]+$" line)
(replace-match "" t t line)
line))
(split-string (buffer-string) "\n" t))))
compile-flags))
(defun spacemacs/c-c++-load-clang-args ()
"Sets the arguments for company-clang, the system paths for company-c-headers
and the arguments for flyckeck-clang based on a project-specific text file."
(unless company-clang-arguments
(let* ((cc-file (spacemacs/company-find-clang-complete-file))
(flags (if cc-file
(spacemacs/company-load-clang-complete-file cc-file)
'()))
(dirs (mapcar (lambda (f) (substring f 2))
(remove-if-not (lambda (f) (string-prefix-p "-I" f))
flags))))
(setq-local company-clang-arguments flags)
(setq-local company-c-headers-path-system
(append '("/usr/include" "/usr/local/include")
dirs))
(setq-local flycheck-clang-args flags))))
;; realgud
(defun spacemacs//short-key-state (modeon)
"Set evil-evilified-state explicitly."
(if modeon
(evil-evilified-state)
(evil-normal-state)))