Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from shibayu36/master

which依存を基本的になくして、PATHやexec-pathも考慮するように
  • Loading branch information...
commit f7bc1df1b09e24f362e1b693843823b608cba614 2 parents 8131678 + a819c26
@kentaro authored
Showing with 65 additions and 7 deletions.
  1. +65 −7 perlbrew.el
View
72 perlbrew.el
@@ -3,6 +3,7 @@
;; Copyright (C) 2011 Kentaro Kuribayashi
;; Author: Kentaro Kuribayashi <kentarok@gmail.com>
+;; Version: 0.2
;; Keywords: Emacs, Perl
;; This program is free software; you can redistribute it and/or modify
@@ -20,12 +21,32 @@
;;; Commentary:
+;;; Initialize
;; (require 'perlbrew)
-;; (perlbrew-switch "perl-5.12.3") ;; initialize perl version to use
+;; (perlbrew-use "perl-5.12.3") ;; initialize perl version to use
+
+;;; Customizable Options:
+;;
+;; Below are customizable option list:
+;;
+;; `perlbrew-dir'
+;; your perlbrew directory
+;; default = ~/perl5/perlbrew
;;; Code:
-(defvar perlbrew-command-path "perlbrew")
+(defgroup perlbrew nil
+ "perlbrew"
+ :group 'perlbrew)
+
+(defcustom perlbrew-dir (concat (getenv "HOME") "/perl5/perlbrew")
+ "your perlbrew directory"
+ :group 'perlbrew)
+
+(defvar perlbrew-perls-dir nil)
+(defvar perlbrew-command-path nil)
+
+(defvar perlbrew-current-perl-dir nil)
(defvar perlbrew-current-perl-path nil)
(eval-when-compile
@@ -35,16 +56,28 @@
(interactive "M$ perlbrew ")
(let* ((command (perlbrew-command args))
(result (perlbrew-trim (shell-command-to-string command))))
- (if (interactive-p)
+ (if (called-interactively-p 'interactive)
(unless (string-match "^\\s*$" result) (message result))
result)))
+(defun perlbrew-use (version)
+ (interactive (list (completing-read "Version: " (perlbrew-list))))
+ (setq perlbrew-perls-dir (concat perlbrew-dir "/perls"))
+
+ (cond ((equal version "system")
+ (perlbrew-clean-exec-path)
+ (setq perlbrew-current-perl-path
+ (perlbrew-trim (shell-command-to-string "which perl"))))
+ (t
+ (perlbrew-set-current-perl-path version)
+ (perlbrew-set-current-exec-path))))
+
(defun perlbrew-switch (version)
(interactive (list (completing-read "Version: " (perlbrew-list))))
- (perlbrew (perlbrew-join (list "switch" version)))
- (perlbrew-set-current-perl-path))
+ (perlbrew-use version))
(defun perlbrew-command (args)
+ (setq perlbrew-command-path (concat perlbrew-dir "/bin/perlbrew"))
(perlbrew-join (list perlbrew-command-path args)))
(defun perlbrew-list ()
@@ -57,8 +90,27 @@
(defun perlbrew-get-current-perl-path ()
perlbrew-current-perl-path)
-(defun perlbrew-set-current-perl-path ()
- (setq perlbrew-current-perl-path (perlbrew-trim (shell-command-to-string "which perl"))))
+(defun perlbrew-set-current-perl-path (version)
+ (setq perlbrew-current-perl-dir (concat perlbrew-perls-dir "/" version))
+ (setq perlbrew-current-perl-path (concat perlbrew-current-perl-dir "/bin/perl")))
+
+(defun perlbrew-set-current-exec-path ()
+ (let* ((bin-dir (concat perlbrew-current-perl-dir "/bin")))
+ (perlbrew-clean-exec-path)
+
+ ;; setting for PATH
+ (setenv "PATH" (concat bin-dir ":" (getenv "PATH")))
+
+ ;; setting for exec-path
+ (add-to-list 'exec-path bin-dir)))
+
+(defun perlbrew-clean-exec-path ()
+ (setenv "PATH"
+ (mapconcat
+ 'identity
+ (perlbrew-remove-all-perl-path (split-string (getenv "PATH") ":"))
+ ":"))
+ (setq exec-path (perlbrew-remove-all-perl-path exec-path)))
(defun perlbrew-join (list)
(mapconcat 'identity list " "))
@@ -66,5 +118,11 @@
(defun perlbrew-trim (string)
(replace-regexp-in-string "\n+$" "" string))
+(defun perlbrew-remove-all-perl-path (path-list)
+ (remove-if
+ (lambda (i)
+ (string-match (concat "^" perlbrew-perls-dir) i))
+ path-list))
+
(provide 'perlbrew)
;;; perlbrew.el ends here
Please sign in to comment.
Something went wrong with that request. Please try again.