Guest User

Untitled

a guest
May 25th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. ;; -*- coding: utf-8 -*-
  2.  
  3. (when (locate-library "flymake")
  4. (require 'flymake)
  5.  
  6. ;;シンタックスチェックは次のコマンドが呼ばれる
  7. ;;make -s -C . CHK_SOURCES=hoge.cpp SYNTAX_CHECK_MODE=1 check-syntax
  8. ;;
  9. ;; Makefile があれば、次のルールを追加
  10. ;;PHONY: check-syntax
  11. ;;#check-syntax:
  12. ;;# $(CC) -Wall -Wextra -pedantic -fsyntax-only $(CHK_SOURCES)
  13. ;;
  14. ;;CHECKSYNTAX.c = $(CC) $(CFLAGS) $(CPPFLAGS) -Wall -Wextra -pedantic -fsyntax-only
  15. ;;CHECKSYNTAX.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -Wall -Wextra -pedantic -fsyntax-only
  16. ;;
  17. ;;check-syntax: $(addsuffix -check-syntax,$(CHK_SOURCES))
  18. ;;%.c-check-syntax: ; $(CHECKSYNTAX.c) $*.c
  19. ;;%.cc-check-syntax: ; $(CHECKSYNTAX.cc) $*.cc
  20.  
  21.  
  22. ;; GUIの警告は表示しない
  23. (setq flymake-gui-warnings-enabled nil)
  24.  
  25. ;; 全てのファイルで flymakeを有効化
  26. (add-hook 'find-file-hook 'flymake-find-file-hook)
  27.  
  28. ;; flymake を使えない場合をチェック
  29. (defadvice flymake-can-syntax-check-file
  30. (after my-flymake-can-syntax-check-file activate)
  31. (cond
  32. ((not ad-return-value))
  33. ;; tramp 経由であれば、無効
  34. ((and (fboundp 'tramp-list-remote-buffers)
  35. (memq (current-buffer) (tramp-list-remote-buffers)))
  36. (setq ad-return-value nil))
  37. ;; 書き込み不可ならば、flymakeは無効
  38. ((not (file-writable-p buffer-file-name))
  39. (setq ad-return-value nil))
  40. ;; flymake で使われるコマンドが無ければ無効
  41. ((let ((cmd (nth 0 (prog1
  42. (funcall (flymake-get-init-function buffer-file-name))
  43. (funcall (flymake-get-cleanup-function buffer-file-name))))))
  44. (and cmd (not (executable-find cmd))))
  45. (setq ad-return-value nil))
  46. ))
  47.  
  48. ;; M-p/M-n で警告/エラー行の移動
  49. (global-set-key "\M-p" 'flymake-goto-prev-error)
  50. (global-set-key "\M-n" 'flymake-goto-next-error)
  51.  
  52. ;; 警告エラー行の表示
  53. ;;(global-set-key "\C-cd" 'flymake-display-err-menu-for-current-line)
  54. (global-set-key "\C-cd"
  55. '(lambda ()
  56. (interactive)
  57. ;;(my-flymake-display-err-minibuf-for-current-line)
  58. (my-flymake-display-err-popup.el-for-current-line)
  59. ))
  60.  
  61. ;; Minibuf に出力
  62. (defun my-flymake-display-err-minibuf-for-current-line ()
  63. "Displays the error/warning for the current line in the minibuffer"
  64. (interactive)
  65. (let* ((line-no (flymake-current-line-no))
  66. (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no)))
  67. (count (length line-err-info-list)))
  68. (while (> count 0)
  69. (when line-err-info-list
  70. (let* ((text (flymake-ler-text (nth (1- count) line-err-info-list)))
  71. (line (flymake-ler-line (nth (1- count) line-err-info-list))))
  72. (message "[%s] %s" line text)))
  73. (setq count (1- count)))))
  74.  
  75. ;; popup.el を使って tip として表示
  76. (defun my-flymake-display-err-popup.el-for-current-line ()
  77. "Display a menu with errors/warnings for current line if it has errors and/or warnings."
  78. (interactive)
  79. (let* ((line-no (flymake-current-line-no))
  80. (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no)))
  81. (menu-data (flymake-make-err-menu-data line-no line-err-info-list)))
  82. (if menu-data
  83. (popup-tip (mapconcat '(lambda (e) (nth 0 e))
  84. (nth 1 menu-data)
  85. "\n")))
  86. ))
  87.  
  88. (defun flymake-simple-generic-init (cmd &optional opts)
  89. (let* ((temp-file (flymake-init-create-temp-buffer-copy
  90. 'flymake-create-temp-inplace))
  91. (local-file (file-relative-name
  92. temp-file
  93. (file-name-directory buffer-file-name))))
  94. (list cmd (append opts (list local-file)))))
  95.  
  96. ;; Makefile が無くてもC/C++のチェック
  97. (defun flymake-simple-make-or-generic-init (cmd &optional opts)
  98. (if (file-exists-p "Makefile")
  99. (flymake-simple-make-init)
  100. (flymake-simple-generic-init cmd opts)))
  101.  
  102. (defun flymake-c-init ()
  103. (flymake-simple-make-or-generic-init
  104. "gcc" '("-Wall" "-Wextra" "-pedantic" "-fsyntax-only")))
  105.  
  106. (defun flymake-cc-init ()
  107. (flymake-simple-make-or-generic-init
  108. "g++" '("-Wall" "-Wextra" "-pedantic" "-fsyntax-only")))
  109.  
  110. (push '("\\.[cCmM]\\'" flymake-c-init) flymake-allowed-file-name-masks)
  111. (push '("\\.\\(?:cc\|cpp\|CC\|CPP\\)\\'" flymake-cc-init) flymake-allowed-file-name-masks)
  112.  
  113. ;; Invoke ruby with '-c' to get syntax checking
  114. (when (executable-find "ruby")
  115. (defun flymake-ruby-init ()
  116. (flymake-simple-generic-init
  117. "ruby" '("-c")))
  118.  
  119. (push '(".+\\.rb\\'" flymake-ruby-init) flymake-allowed-file-name-masks)
  120. (push '("Rakefile\\'" flymake-ruby-init) flymake-allowed-file-name-masks)
  121.  
  122. (push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3) flymake-err-line-patterns)
  123. )
  124.  
  125. ;; bash チェック
  126. (defvar flymake-shell-of-choice
  127. "bash"
  128. "Path of shell.")
  129.  
  130. (defvar flymake-shell-arguments
  131. (list "-n")
  132. "Shell arguments to invoke syntax checking.")
  133.  
  134. (defun flymake-shell-init ()
  135. (flymake-simple-generic-init
  136. flymake-shell-of-choice flymake-shell-arguments))
  137.  
  138. (push '(".+\\.sh\\'" flymake-shell-init) flymake-allowed-file-name-masks)
  139. (push '("^\\(.+\\): line \\([0-9]+\\): \\(.+\\)$" 1 2 nil 3) flymake-err-line-patterns)
  140.  
  141. ;;;; HTML
  142. ;;(when (executable-find "tidy")
  143. ;; (defun flymake-html-init ()
  144. ;; (let* ((coding (coding-system-base buffer-file-coding-system))
  145. ;; (opt (cdr (assq coding
  146. ;; '((utf-8 . "-utf8")
  147. ;; (iso-2022-jp . "-iso2022")
  148. ;; (japanese-shift-jis . "-shiftjis"))))))
  149. ;; (flymake-simple-generic-init
  150. ;; "tidy" (list "-e" opt))))
  151. ;;
  152. ;; (push '("\\.html\\'\\|\\.ctp" flymake-html-init) flymake-allowed-file-name-masks)
  153. ;; (push '("line \\([0-9]+\\) column \\([0-9]+\\) - \\(Warning\\|Error\\): \\(.*\\)" nil 1 2 4) flymake-err-line-patterns)
  154. ;; )
  155.  
  156. ;;;; XSL
  157. ;;(push '(".+\\.xsl\\'" flymake-xml-init) flymake-allowed-file-name-masks)
  158.  
  159. ;;;; Python
  160. ;;(defun flymake-pep8-init ()
  161. ;; (flymake-simple-generic-init
  162. ;; "pep8"))
  163. ;;
  164. ;;(defun flymake-pylint-init ()
  165. ;; (flymake-simple-generic-init
  166. ;; "epylint"))
  167. ;;
  168. ;;(push '("\\.py\\'" flymake-pylint-init) flymake-allowed-file-name-masks)
  169. ;;(push '("\\.py\\'" flymake-pep8-init) flymake-allowed-file-name-masks)
  170.  
  171. ;;;; Javascript
  172. ;;(defun flymake-js-init ()
  173. ;; (flymake-simple-generic-init
  174. ;; "js" '("-s")))
  175. ;;
  176. ;;(push '(".+\\.json\\'" flymake-js-init) flymake-allowed-file-name-masks)
  177. ;;(push '(".+\\.js\\'" flymake-js-init) flymake-allowed-file-name-masks)
  178. ;;
  179. ;;(push '("^\\(.+\\)\:\\([0-9]+\\)\: \\(strict warning: trailing comma.+\\)\:$" 1 2 nil 3)
  180. ;; flymake-err-line-patterns)
  181.  
  182. )
Add Comment
Please, Sign In to add comment