真 もわ爛漫

しゃーら、しゃーらしゃーら

flymake, C, C++, Python

; flymake
; http://d.hatena.ne.jp/nyaasan/20071216/p1 (in Japanese)
; http://d.hatena.ne.jp/nushio/20071201 (in Japanese)
; http://www.emacswiki.org/cgi-bin/wiki/PythonMode
(require 'flymake)

(defun flymake-show-and-sit ()
  "Displays the error/warning for the current line in the minibuffer"
  (interactive)
  (progn
    (let* ( (line-no             (flymake-current-line-no) )
            (line-err-info-list  (nth 0 (flymake-find-err-info 
              d                          flymake-err-info line-no)))
            (count               (length line-err-info-list))
            )
      (while (> count 0)
        (when line-err-info-list
          (let* ((file       (flymake-ler-file (nth (1- count) 
                                                    line-err-info-list)))
                 (full-file  (flymake-ler-full-file (nth (1- count)
                                                         line-err-info-list)))
                 (text (flymake-ler-text (nth (1- count) line-err-info-list)))
                 (line       (flymake-ler-line (nth (1- count) 
                                                    line-err-info-list))))
            (message "[%s] %s" line text)
            )
          )
        (setq count (1- count)))))
  (sit-for 60.0)
  )
(global-set-key "\C-cd"
                'flymake-show-and-sit)

(defun flymake-c-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 "gcc" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))
(push '("\\.c$" flymake-c-init) flymake-allowed-file-name-masks)

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

(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)

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

; You must prepare epylint by hand
; See also http://www.emacswiki.org/cgi-bin/wiki/PythonMode
(defun flymake-pylint-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 "epylint" (list local-file))))
(push '("\\.py\\'" flymake-pylint-init) flymake-allowed-file-name-masks)

(add-hook 'python-mode-hook
          '(lambda ()
             (flymake-mode t)))

epylint

#!/usr/bin/env python
#
# pylint must be available. Please install by yourself.
import re
import sys
from subprocess import *
p = Popen("pylint -f parseable -r n --disable-msg-cat=C,R %s" %
          sys.argv[1], shell = True, stdout = PIPE).stdout

for line in p:
  match = re.search("\\[([WE])(, (.+?))?\\]", line)
  if match:
    kind = match.group(1)
    func = match.group(3)
    if kind == "W":
      msg = "Warning"
    else:
      msg = "Error"

    if func:
      line = re.sub("\\[([WE])(, (.+?))?\\]",
                      "%s (%s):" % (msg, func), line)
    else:
      line = re.sub("\\[([WE])?\\]", "%s:" % msg, line)
  print line,
p.close()

test

print datetime.datetme.today()
print "にぱー"
import datetime
print datetime.datetme.today()
print "にぱー"
# -*- encoding: utf-8 -*-
import datetime
print datetime.datetme.today()
print "にぱー"

注意: encoding 周りのWarningは一行目に出る("にぱー"の行に色はつかない)