| 1 | ;;; -*- coding: utf-8; mode:emacs-lisp -*- |
|---|
| 2 | ;;; set-perl5lib.el --- set path into PERL5LIB if its file path includes 'lib' directory |
|---|
| 3 | |
|---|
| 4 | ;; Copyright (C) 2008 Taiyoh Tanaka |
|---|
| 5 | ;; Author: Taiyoh Tanaka <sun.basix@gmail.com> |
|---|
| 6 | |
|---|
| 7 | ;; This file is free software; you can redistribute it and/or modify |
|---|
| 8 | ;; it under the terms of the GNU General Public License as published |
|---|
| 9 | ;; by the Free Software Foundation; either version 2, or (at your |
|---|
| 10 | ;; option) any later version. |
|---|
| 11 | |
|---|
| 12 | ;; This file is distributed in the hope that it will be useful, but |
|---|
| 13 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 | ;; General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | ;; You should have received a copy of the GNU General Public License |
|---|
| 18 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
|---|
| 19 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 20 | ;; Boston, MA 02111-1307, USA. |
|---|
| 21 | |
|---|
| 22 | ;;; Commentary: |
|---|
| 23 | |
|---|
| 24 | ;;; * set-perl5lib について |
|---|
| 25 | |
|---|
| 26 | ;;; ファイルのパスに"lib"というディレクトリが含まれていたら、 |
|---|
| 27 | ;;; そこまでのパスをPERL5LIBに登録します。 |
|---|
| 28 | ;;; |
|---|
| 29 | ;;; また、.emacsにて、 |
|---|
| 30 | ;;; (require 'set-perl5lib) |
|---|
| 31 | ;;; のあとで、Flymakeのflymake-perl-load関数をオーバーライドして |
|---|
| 32 | ;;; (set-perl5lib) |
|---|
| 33 | ;;; を関数内に追加すれば、自動的にパスを登録できます。 |
|---|
| 34 | ;;; |
|---|
| 35 | ;;; SeeAlso: http://d.hatena.ne.jp/sun-basix/20080117/1200528765 |
|---|
| 36 | |
|---|
| 37 | (defun perllib-check-path (lst lib-path) |
|---|
| 38 | (let ((dir (car lst)) |
|---|
| 39 | (set-lib-path (concat lib-path "/lib"))) |
|---|
| 40 | (if (setf stock-lst (cdr lst)) |
|---|
| 41 | (cond ((string= dir "lib") set-lib-path) |
|---|
| 42 | ((and (string= dir "t") |
|---|
| 43 | (file-readable-p set-lib-path)) set-lib-path) |
|---|
| 44 | (t (perllib-check-path stock-lst (concat lib-path "/" dir))))))) |
|---|
| 45 | |
|---|
| 46 | (defun set-perl5lib () |
|---|
| 47 | "Set path into PERL5LIB if its file path includes 'lib' directory" |
|---|
| 48 | (interactive) |
|---|
| 49 | (let* ((path-list (cdr (split-string |
|---|
| 50 | (if (string-match "^.:" buffer-file-name) |
|---|
| 51 | (concat (cygwin-mount-get-cygdrive-prefix) |
|---|
| 52 | (mapconcat 'identity (split-string buffer-file-name ":") "")) |
|---|
| 53 | (buffer-file-name) |
|---|
| 54 | ) |
|---|
| 55 | "/"))) |
|---|
| 56 | (lib-path (perllib-check-path path-list "")) |
|---|
| 57 | (current-perl5lib (getenv "PERL5LIB"))) |
|---|
| 58 | (when (or (and lib-path current-perl5lib |
|---|
| 59 | (not (string-match lib-path current-perl5lib))) |
|---|
| 60 | (not current-perl5lib)) |
|---|
| 61 | (setenv "PERL5LIB" (concat lib-path ":" current-perl5lib)) |
|---|
| 62 | (message "Added %s into PERL5LIB" lib-path)))) |
|---|
| 63 | |
|---|
| 64 | (provide 'set-perl5lib) |
|---|