11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++でプログラミングコンテストをする時用のflymakeの設定

Last updated at Posted at 2012-12-26

出来るようになること

  • タイプしている途中にエラーを表示してハイライトしてくれる(flymakeの機能)
  • flymakeに通常必要なMakefileを用意しなくて良くなる
  • next-error(\C-eにバインド), prev-error(\M-eにバインド)でミニバッファにエラーを表示
;;;flymake
(require 'flymake)

;;エラーメッセージをミニバッファで表示させる
(global-set-key "\C-e" 'flymake-goto-next-error)
(global-set-key "\M-e" 'flymake-goto-prev-error)

;; gotoした際にエラーメッセージをminibufferに表示する
(defun display-error-message ()
  (message (get-char-property (point) 'help-echo)))
(defadvice flymake-goto-prev-error (after flymake-goto-prev-error-display-message)
  (display-error-message))
(defadvice flymake-goto-next-error (after flymake-goto-next-error-display-message)
  (display-error-message))
(ad-activate 'flymake-goto-prev-error 'flymake-goto-prev-error-display-message)
(ad-activate 'flymake-goto-next-error 'flymake-goto-next-error-display-message)

;;c++のflymakeでmakefileを不要にする
(defun flymake-cc-init ()
  (let* ((temp-file   (flymake-init-create-temp-buffer-copy
		       'flymake-create-temp-inplace))
         (local-file  (file-relative-name
		       temp-file
		       (file-name-directory buffer-file-name))))
    (list "g++" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))

(push '("\\.cc$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.cpp$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.h$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.hpp$" flymake-cc-init) flymake-allowed-file-name-masks)

(add-hook 'c++-mode-hook '(lambda ()
  (flymake-mode t)
))

昔2箇所ぐらいからとってきて合体したんだけどソースがわからない。ごめんなさい。。。

おまけ

Flymake以外のC++の記述の際に関係する部分の設定

;;; 各種キーバインド
(global-unset-key "\C-l")
(global-set-key "\C-l" 'goto-line)  ;; \C-lは元来'recenter
(global-unset-key "\C-t")  ;; 文字のトグルは押し間違えしかないのでoffに
(global-set-key "\C-m" 'newline-and-indent)  ;; Returnキーを押したあとindentもするように

;;; 表示まわり
(transient-mark-mode t)
(show-paren-mode t)
(line-number-mode t)
(column-number-mode t)

;;; インデントポリシー
(setq c-default-style "stroustrup")
(setq-default indent-tabs-mode nil)  ;; タブを使わずにスペースを使う
(setq-default tab-width 2)

;;; 保存時の設定
(add-hook 'before-save-hook 'delete-trailing-whitespace)

;;; その他基本設定
(setq kill-whole-line t)  ;; 行頭でのC-kで行全体を削除
(setq backup-inhibited t)  ;; バックアップファイルを作らない
(setq delete-auto-save-files t)  ;; 終了時にオートセーブファイルを消す

;;; c-mode-common
(add-hook 'c-mode-common-hook
          '(lambda ()
             (progn
               (setq c-basic-offset 2)
             )))
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?