読者です 読者をやめる 読者になる 読者になる

*iroi*

mechairoi の Blog

perlのflymakeの設定

emacs
  • buffer localにしたかったのでPERL5LIBにsetenvせず起動オプションで -Mlib glob.
  • 常にgitを使うのでgitプロジェクトの一番上を起点にしている.
;; -- flymake
(add-to-list 'flymake-allowed-file-name-masks
             '("\\.t$" flymake-perl-init)) ; pm, pl は設定されてる.

(defconst my-flymake-perl-lib-suffix-list
  '("lib" "t/lib" "modules/*/lib" "modules/*/t/lib"))

(defun my-flymake-perl-options ()
  (when my-current-git-root
    (mapcar (lambda (suffix)
              (format "-Mlib glob qw(%s%s) " my-current-git-root suffix))
            my-flymake-perl-lib-suffix-list)))

;; override (flymake.el)
(defun flymake-perl-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 "perl" (append '("-wc ") (my-flymake-perl-options) (list local-file)))))

;; -- hook

(add-hook 'cperl-mode-hook 'my-cperl-mode-init)
(defun my-cperl-mode-init ()
  (let ((root (my-git-root)))
    (set (make-local-variable 'my-current-git-root) root)
    (when root (my-make-tags-if-need root t)))
  (flymake-mode t))

;; -- my-git

(defun my-git-root ()
  (flet ((iter (path)
               (let ((p (and path (vc-git-root path))))
                 (or (and p (iter (my-parent-directory p))) p))))
    (iter (if (buffer-file-name)
              (file-name-directory (buffer-file-name))
            default-directory))))

(defun my-parent-directory (path)
  (file-name-directory (directory-file-name (file-name-directory path))))