(defun package--ensure-init-file ()
"Ensure that the user's init file has `package-initialize'.
`package-initialize' doesn't have to be called, as long as it is
present somewhere in the file, even as a comment. If it is not,
add a call to it along with some explanatory comments."
(when (and (stringp user-init-file)
(let* ((buffer (find-buffer-visiting user-init-file))
(re-search-forward "(package-initialize\\_>" nil 'noerror))))
(re-search-forward "(package-initialize\\_>" nil 'noerror)))))
(with-current-buffer (or buffer
(let ((delay-mode-hooks t)
(setq buffer-name (buffer-file-name))
(set-visited-file-name (file-chase-links user-init-file)))
(while (and (looking-at-p "[[:blank:]]*\\(;\\|$\\)")
";; Added by Package.el. This must come before configurations of\n"
";; installed packages. Don't delete this line. If you don't want it,\n"
";; just comment it out by adding a semicolon to the start of the line.\n"
";; You may delete these explanatory comments.\n"
(unless (looking-at-p "$")
(let ((file-precious-flag t))
(setq package--init-file-ensured t))
Created: 2018-12-14 Fri 21:04