| 46 | | (defun set-perl5lib () |
| | 39 | ;;; * cygwin + Meadow 対応について |
| | 40 | |
| | 41 | ;;; cygwin 用の perl を Meadow から扱えるよう cygpath による |
| | 42 | ;;; パスの変換を加えました. |
| | 43 | ;;; |
| | 44 | ;;; また,幾つかの関数を分断し,コマンドについては引数を渡せるようにしました |
| | 45 | |
| | 46 | ;;; SeeAlso: http://d.hatena.ne.jp/lieutar/20080711/1215754040 |
| | 47 | |
| | 48 | (defvar perl5lib-under-cygwin-p nil |
| | 49 | "If it is not nil value , the perllib-check-path try to resolve by the command 'cygpath'") |
| | 50 | |
| | 51 | (defvar perl5lib-cygpath-cache nil) |
| | 52 | |
| | 53 | (defsubst perl5lib-apply-cygpath (path) |
| | 54 | (if perl5lib-under-cygwin-p |
| | 55 | (let ((associated (assoc path perl5lib-cygpath-cache))) |
| | 56 | (if associated |
| | 57 | (cdr associated) |
| | 58 | (let ((result |
| | 59 | (let ((result (shell-command-to-string |
| | 60 | (format "cygpath %s" path)))) |
| | 61 | (if (string-match "\\(\x0d\x0a\\|[\x0d\x0a]\\)" result) |
| | 62 | (substring result 0 (match-beginning 1)) |
| | 63 | result)))) |
| | 64 | (setq perl5lib-cygpath-cache |
| | 65 | (cons (cons path result) |
| | 66 | perl5lib-cygpath-cache))))) |
| | 67 | path)) |
| | 68 | |
| | 69 | (defun perllib-check-path (path) |
| | 70 | (let ((path (expand-file-name path)) |
| | 71 | (result (cond ((string-match "\\(/lib/\\)" path) |
| | 72 | (substring path 0 (match-end 1))) |
| | 73 | ((string-match "\\(/t/\\)" path) |
| | 74 | (format "%s/lib" (substring path 0 |
| | 75 | (match-beginning 1)))) |
| | 76 | (t nil)))) |
| | 77 | (when result |
| | 78 | (if perl5lib-under-cygwin-p |
| | 79 | (perl5lib-apply-cygpath result) |
| | 80 | result)))) |
| | 81 | |
| | 82 | (defun get-perl5lib (path) |
| | 83 | "Get path from the PATH if its file path includes 'lib' directory" |
| | 84 | (let* ((perl5lib-env (getenv "PERL5LIB")) |
| | 85 | (perl5lib (and perl5lib-env (split-string perl5lib-env ":")))) |
| | 86 | (append (let ((lib-path (perllib-check-path path))) |
| | 87 | (when (and lib-path |
| | 88 | (null (member lib-path perl5lib))) (list lib-path))) |
| | 89 | perl5lib))) |
| | 90 | |
| | 91 | (defun set-perl5lib (path) |
| 48 | | (interactive) |
| 49 | | (let* ((path-list (cdr (split-string buffer-file-name "/"))) |
| 50 | | (lib-path (perllib-check-path path-list "")) |
| 51 | | (current-perl5lib (getenv "PERL5LIB"))) |
| 52 | | (when (or (and lib-path current-perl5lib |
| 53 | | (not (string-match lib-path current-perl5lib))) |
| 54 | | (not current-perl5lib)) |
| 55 | | (setenv "PERL5LIB" (concat lib-path ":" current-perl5lib)) |
| 56 | | (message "Added %s into PERL5LIB" lib-path)))) |
| | 93 | (interactive (list buffer-file-name)) |
| | 94 | (let ((lib-path (mapconcat 'identity (get-perl5lib path) ":"))) |
| | 95 | (setenv "PERL5LIB" lib-path) |
| | 96 | (message "Added %s into PERL5LIB" lib-path))) |