Toggle http proxy in emacs-w3m

  |   Source

http proxy in emacs-w3m :emacs:proxy:http:en:

emacs-w3m is a browser embedded in Emacs. It can handle all my basic web surfing needs.

For some reason, I need switch my http proxy frequently when accessing the internet. So I need figure out a easy way doing this.

It turns out all I need to do is to set/unset the environment variable "http_proxy" in elisp code. Restarting the w3m session after change the environment variable is not needed at all.

Here is my code:

(defun toggle-env-http-proxy ()
  "set/unset the environment variable http_proxy which w3m uses"
  (let ((proxy ""))
    (if (string= (getenv "http_proxy") proxy)
        ;; clear the proxy
          (setenv "http_proxy" "")
          (message "env http_proxy is empty now"))
      ;; set the proxy
      (setenv "http_proxy" proxy)
      (message "env http_proxy is %s now" proxy))))
Comments powered by Disqus