Changeset 15693 for lang/elisp

Show
Ignore:
Timestamp:
07/12/08 13:33:58 (4 months ago)
Author:
lieutar
Message:

modified the emacs lisp file for cygwin + Meadow

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/set-perl5lib/branch/cygwin/set-perl5lib.el

    r15690 r15693  
    3333;;; を関数内に追加すれば、自動的にパスを登録できます。 
    3434;;; 
     35 
    3536;;; SeeAlso: http://d.hatena.ne.jp/sun-basix/20080117/1200528765 
    3637 
    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))))))) 
    4538 
    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) 
    4792  "Set path into PERL5LIB if its file path includes 'lib' directory" 
    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))) 
    5797 
    5898(provide 'set-perl5lib)