LoginSignup
5
5

More than 5 years have passed since last update.

spacemacsをproxy越しに使う方法

Posted at

spacemacsの動作で苦労しないためには

emacsを最低でも24.4にします。24.3とかだとエラーが発生します。linuxのディストリビューションのデフォルトのままだとemacsが古い場合、ソースからコンパイルして入れたほうが良いです。ついでに global (helm-gtagsで使う)とか使ってる場合、こいつも最新にしておいたほうが幸せになれます(5.xx系は避ける)。

proxyの設定方法

うちの会社のように腐れ外道なproxyの場合、.spacemacsファイルのspacemacs/init()にある

dotspacemacs-elpa-https t
dotspacemacs-elpa-timeout 5

dotspacemacs-elpa-https nil
dotspacemacs-elpa-timeout 20

とか値を変えておきます。proxy越しで毎回アップデート確認してほしくないときは、

dotspacemacs-check-for-update t

の値を nil に変えます。emacsの起動も早いし。

環境変数http_proxyの値をemacsに反映する方法

環境変数で統一的にproxyの値を書きたいので環境変数 http_proxy の値をemacsの設定に反映するためのemacs-lispを書きました。 いろんなところにproxyのパスワードがばらまかれて書かれてると変更があったときに反映に苦労します。一つでも減らしておきたいところです。
http://user:passwd@proxy_url:port の形式で書かれているのを前提にしています。

別にspacemacsでなくても普通のemacsのinit.elにも使えると思います。

dot.spacemacs
(defun set-proxy ()
  (when (getenv "http_proxy")
    (cl-flet (
           ;; get user:passwd entry from http_proxy environment var and base64-encode it.
           (get-passwd-encode-string ()
             (let* ((ev (getenv "http_proxy"))
                    (x (decode-coding-string (url-unhex-string ev) 'utf-8))
                    )
               (if (not (equal x ""))
                   (base64-encode-string
                    (substring x (+ 2 (string-match "//" x)) (string-match "@" x))
                    )
                 nil)))
           (get-proxy-url-string ()
             (let* ((ev (getenv "http_proxy"))
                    (x (decode-coding-string (url-unhex-string ev) 'utf-8))
                    )
               (if (not (equal x ""))
                   (substring x (+ 1 (string-match "@" x)))
               ""))) )
    ;; proxy service var
    (setq url-proxy-services `(("no_proxy" . "^\\(localhost \\| 10.*\\)")
                               ("http"  . ,(get-proxy-url-string))
                               ("https" . ,(get-proxy-url-string))
                               ))

こいつを.spacemacsの中に書き加え、.spacemacsのuser-initから呼び出されるように記載します。

dot.spacemacs
(defun dotspacemacs/user-init ()
  "Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
 This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."

  (set-proxy)    ;; プロキシ設定関数の呼び出し追加

  )
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5