Toggle http proxy in emacs-w3m
emacs-w3m is a browser which handles all my basic web surfing needs.
For some reason, I need switch my http proxy frequently.
The solution 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"
(interactive)
(let ((proxy "http://127.0.0.1:8000"))
(if (string= (getenv "http_proxy") proxy)
;; clear the proxy
(progn
(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))))