Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
157 lines (138 sloc) 6.13 KB
;;; maple-package.el --- package configuration. -*- lexical-binding: t -*-
;; Copyright (C) 2015-2019 lin.jiang
;; Author: lin.jiang <>
;; Version: 0.1.0
;; Package-Requires: ((emacs "25.1"))
;; URL:
;; This file is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <>.
;;; Commentary:
;; package configuration.
;;; Code:
(require 'package)
(defvar maple-package-autoload-file (expand-file-name "cache/autoloads.pkg.el" user-emacs-directory))
(defun maple-package-upgrade-alist(&optional filterp)
"Upgrade package alist with FILTERP."
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
(push (cadr (assq package package-archive-contents))
(if filterp
(let ((v (mapcar (lambda(name) (list (package-desc-full-name name) name)) upgrades)))
(cdr (assoc (completing-read "Upgrade package: " v) v)))
(defun maple-package-upgrade-by-name()
"Upgrade packages with SELECTED."
(maple-package-upgrade t))
(defun maple-package-upgrade (&optional filterp)
"Upgrade all packages automatically without showing *Packages* buffer with FILTERP."
(let ((upgrades (maple-package-upgrade-alist filterp)))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
(defun maple-package-reload-autoload ()
"Generate autoload file."
(with-temp-file maple-package-autoload-file
(insert ";; -*- lexical-binding:t -*-\n")
(prin1 `(setq load-path ',load-path
auto-mode-alist ',auto-mode-alist
package-activated-list ',package-activated-list)
(insert "\n\n")
(dolist (spec (maple-package-alist))
(let* ((desc (cdr spec))
(file (concat (package--autoloads-file-name desc) ".el")))
(when (file-exists-p file)
(insert "(let ((load-file-name " (prin1-to-string (abbreviate-file-name file)) "))\n")
(insert-file-contents file)
(while (re-search-forward "^\\(?:;;\\(.*\n\\)\\|\n\\|(provide '[^\n]+\\)" nil t)
(unless (nth 8 (syntax-ppss))
(replace-match "" t t)))
(unless (bolp) (insert "\n"))
(insert ")\n")))))
(while (re-search-forward "^\\s-*\\((\\(?:add-to-list\\|\\(?:when\\|if\\) (boundp\\)\\s-+'\\(?:load-path\\|auto-mode-alist\\)\\)" nil t)
(goto-char (match-beginning 1))
(defun maple-package-alist ()
"Return package alist."
(cl-loop for name in (mapcar #'car package-alist)
if (assq name package-alist)
nconc (cl-loop for dep in (package--get-deps name)
if (assq dep package-alist)
collect (cons dep (cadr it)))
and collect (cons name (cadr it)))
:key #'car
:from-end t))
(defun maple-package-byte-compile-file (file)
"Bytes compile FILE."
(let ((short-name (file-name-nondirectory file))
(byte-compile-dynamic-docstrings t))
(when (byte-compile-file file)
(load (byte-compile-dest-file file) nil t)
(unless noninteractive
(message "Finished compiling %s" short-name)))))
(defun maple-package-initialize-autoload()
"Initialize autoload file."
(when (not (file-exists-p maple-package-autoload-file))
(when (file-newer-than-file-p maple-package-autoload-file
(byte-compile-dest-file maple-package-autoload-file))
(maple-package-byte-compile-file maple-package-autoload-file))
(load (byte-compile-dest-file maple-package-autoload-file) nil t))
(defun maple-package-force-initialize()
"Force initialize package."
(when (file-exists-p maple-package-autoload-file)
(delete-file maple-package-autoload-file))
(defun maple-package-initialize(&optional no-activate)
"Package initialize with NO-ACTIVATE."
(if (not (file-exists-p maple-package-autoload-file))
(setq package-alist nil)
;; (package-read-all-archive-contents)
(unless no-activate
(dolist (elt package-alist)
(condition-case err
(package-activate (car elt))
(error (message "%s" (error-message-string err))))))
(setq package--initialized t)
(when no-activate (maple-package-initialize-autoload)))
(provide 'maple-package)
;;; maple-package.el ends here
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.