apt-get install clang-tools-7 clang-format
export PATH=/usr/lib/llvm-7/bin:${PATH}
M-x package-install lsp-mode lsp-ui company-lsp dash-el elpa-f s-el elpa-markdown-mode dash-el
package name | package repository URI | remark |
---|---|---|
lsp-mode | http://github.com/emacs-lsp/lsp-mode.git | 各種LSPの言語モードを実装している。 C/C++ の設定もここに含まれる。 |
lsp-ui | https://github.com/emacs-lsp/lsp-ui.git | 補完を担うcompany-modeのLSP向け設定 |
company-lsp | https://github.com/tigersoldier/company-lsp.git | ドキュメントの表示など各種アクションを実装している。 |
elpa | https://git.savannah.gnu.org/git/emacs/elpa.git | elpa/packages/cl-generic 等を使用する為に取得する。サイズが大きいので注意。 |
ht | https://github.com/Wilfred/ht.el.git | debian9のパッケージには存在しない。lsp-mode の動作に必要 |
dash | https://github.com/magnars/dash.el | |
f | https://github.com/rejeep/f.el | |
s | https://github.com/magnars/s.el | |
markdown-mode | https://github.com/jrblevin/markdown-mode.git | |
clang-format | https://github.com/sonatard/clang-format.git | clang-format-<version> package に含まれる |
flycheck-mode | https://github.com/flycheck/flycheck | |
projectile | https://github.com/bbatsov/projectile |
package name | tag | remark |
---|---|---|
lsp-mode | refs/tags/7.0 | |
lsp-ui | refs/tags/7.0 | |
company-lsp | refs/tags/2.1.0 | |
elpa | (HEAD) | tagは試行中。動かなかったら検討する。 |
;;; ~/.emacs/init.el ;;; ~/.emacs.d/site-lisp 配下に各リポジトリを配置した場合の設定例 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/dash") load-path)) ; dash (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/elpa/packages/cl-generic") load-path)) ; cl-generic (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/ht") load-path)) ; ht.el (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/elpa/packages/hydra") load-path)) ; lv.el (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/elpa/packages/spinner") load-path)) ; spinner.el (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/elpa/packages/company") load-path)) ; company.el (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/markdown-mode") load-path)) ; markdown-mode (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/flycheck") load-path)) ; flycheck (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/projectile") load-path)) ; projectile (require 'projectile) (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/lsp-mode") load-path)) (require 'lsp-mode) (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/lsp-ui") load-path)) (require 'lsp-ui) (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/company-lsp") load-path)) (require 'company-lsp) (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/clang-format") load-path)) (require 'clang-format)
;;; .clang-firmat を読み込ませる関数を定義 ;; https://eklitzke.org/smarter-emacs-clang-format (defun clang-format-buffer-smart () "Reformat buffer if .clang-format exists in the projectile root." (interactive) (when (f-exists? (expand-file-name ".clang-format" (projectile-project-root))) (clang-format-buffer))) ;; https://eklitzke.org/smarter-emacs-clang-format ;(defun clang-format-buffer-smart-on-save () ; "Add auto-save hook for clang-format-buffer-smart." ; (add-hook 'before-save-hook 'clang-format-buffer-smart nil t)) ;;; hooks (add-hook 'c++-mode-hook 'company-mode) ; 補完用 (add-hook 'c-mode-hook 'company-mode) ; 補完用 (add-hook 'c++-mode-hook 'flycheck-mode) ; チェック用 (add-hook 'c-mode-hook 'flycheck-mode) ; チェック用 (add-hook 'c++-mode-hook #'lsp) (add-hook 'c-mode-hook #'lsp) ;;; key bindings ;;; 以下は clang-format の README.md の記載より転記した。 (global-set-key (kbd "C-c i") 'clang-format-region) (global-set-key (kbd "C-c u") 'clang-format-buffer-smart) ; (global-set-key (kbd "C-c i") 'clang-format-region) ; (global-set-key (kbd "C-c u") 'clang-format-buffer) ; (global-unset-key "\C-\M-q") ; (global-set-key (kbd "C-M q") 'clang-format-region)
debian9 の場合は、以下にある: $ locate clangd /usr/bin/clangd-7 # 下記の SymLink /usr/lib/llvm-7/bin/clangdこの場合、以下のように設定する:
;;; lsp-mode ;; https://qiita.com/false-git@github/items/3cb6ebd7f4d6f77acc54 (setq lsp-clients-clangd-executable "clangd-7") ; または ; (setq lsp-clients-clangd-executable "/usr/bin/clangd-7")
;;; ~/.emacs/init.el ;;; format-style (setq clang-format-style-option "llvm") ; llvm スタイルのフォーマットルールを利用する場合
$ clang-format -style=google -dump-config > .clang-format
package name | package repository URI | remark |
---|---|---|
clang-format+ | https://github.com/SavchenkoValeriy/emacs-clang-format-plus |