With this package you can easily enable/disable proxies per protocol in you Emacs. You could also use this package to provide proxy settings for a group of s-expressions. This package respects your $HTTP_PROXY, $HTTPS_PROXY and $NO_PROXY shell environment variables.
If you don't have ELPA package in your Emacs, clone this repository and load file.
git clone https://github.com/rayw000/use-proxy.git(load-file "/path/to/use-proxy/use-proxy.el")
(require 'use-proxy)Globally enable use-proxy-mode.
(use-proxy-mode)You can bind keys to function use-proxy-toggle-proto-proxy and use-proxy-toggle-proxies-global, for example
(global-set-key (kbd "C-c C-p") 'use-proxy-toggle-proto-proxy)
(global-set-key (kbd "C-c C-g") 'use-proxy-toggle-proxies-global)This package provides these following variables you could customize:
-
use-proxy-http-proxyHTTP proxy you could use. If not set, the value of
$HTTP_PROXYin your environment will be used. -
use-proxy-https-proxyHTTPS proxy you could use. If not set, the value of
$HTTPS_PROXYin your environment will be used. -
use-proxy-no-proxyA regular expression matches hosts you don't want to connect through proxy. If not set, the value of
$NO_PROXYin your environment will be used. -
use-proxy-display-in-global-mode-stringBoolean indicates whether display proxy states in
global-mode-string. If non-nil, proxy states will also be added intoglobal-mode-string. In which case even if you turn off minor mode list or work withdiminish, proxy states would still be visible in your mode line if you enable%Msubstitution.
NOTICE: Do not forget to load your custom-file if you customized these variables.
- Toggle specified proxy by protocol.
(use-proxy-toggle-proto-proxy)Running this command will prompt you available protocols to choose to enable the corresponding proxy. Enabled proxies will be shown in the minor mode lighter.
- Toggle proxies global or not (respect
no_proxysettings or not).
(use-proxy-toggle-proxies-global)If using proxies globally, a g will be appended to lighter.
- Temporarily enable proxy for a batch of s-expressions. You are only required to provide a protocol list which you want to enable proxies for. This macro will read corresponding proxy settings from your customization variables.
(use-proxy-with-custom-proxies '("http" "https")
(browse-url-emacs "https://www.google.com"))- Toggle all proxies on/off
(use-proxy-toggle-all-proxies)- Temporarily enable proxy for a batch of s-expression. You are required to provide a proxy setting association list.
(use-proxy-with-specified-proxies '(("http" . "localhost:8080")
("https" . "localhost:8081"))
(browse-url-emacs "https://www.google.com"))All use-proxy does is manipulating your url-proxy-services variable. Every time you toggle proxies, url-proxy-services will be saved into your custom.el file. When use-proxy-mode is on, this variable will be loaded.