When I open Emacs, it evaluates my init file, which includes refreshing my package archives via internet connection. This is problematic when I don't have an internet connection, thus I need to prevent execution of that code when starting Emacs without an internet connection. To solve this issue, I wonder if there is there a way to have Emacs ignore the package refresh code when I don't have an internet connection?
Here are the first few lines of my init.el
:
;; Requisites: Emacs >= 24
(require 'package)
(package-initialize)
;; PACKAGE MANAGEMENT
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-refresh-contents)
I imagine that I can add code to load my Emacs file as follows:
;; Requisites: Emacs >= 24
(when (connected-to-internet-p) ; I need this predicate function
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-refresh-contents))
Is there a (connected-to-internet)
function, or similar approach, to resolve this issue?