al-package-cmd.el 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;;; al-package-cmd.el --- Interactive commands related to Emacs package system
  2. ;; Copyright © 2013-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'cl-lib)
  15. (require 'package)
  16. (defvar al/package-archives
  17. '(("gnu" . "http://elpa.gnu.org/packages/")
  18. ("marmalade" . "https://marmalade-repo.org/packages/")
  19. ("melpa" . "http://melpa.org/packages/")
  20. ("melpa-stable" . "http://stable.melpa.org/packages/"))
  21. "Alist of package archives used by `al/add-package-archive'.
  22. This variable has the same form as `package-archives'.")
  23. ;;;###autoload
  24. (defun al/add-package-archive (name)
  25. "Add archive to the value of `package-archives'.
  26. NAME is an archive name from `al/package-archives'."
  27. (interactive
  28. (list (completing-read "Add package archive: "
  29. (mapcar #'car al/package-archives))))
  30. (let ((archive (assoc name al/package-archives)))
  31. (when archive
  32. (add-to-list 'package-archives archive)
  33. (pp-eval-expression 'package-archives))))
  34. ;;;###autoload
  35. (defun al/remove-package-archive (&optional name)
  36. "Remove archive to the value of `package-archives'.
  37. NAME is an archive name from `package-archives'.
  38. If NAME is nil (interactively, with \\[universal-argument]), \
  39. remove all archives (i.e., set it to nil)."
  40. (interactive
  41. (list (unless current-prefix-arg
  42. (completing-read "Remove package archive: "
  43. (mapcar #'car package-archives)))))
  44. (setq package-archives
  45. (and name
  46. (cl-remove-if (lambda (archive)
  47. (equal name (car archive)))
  48. package-archives)))
  49. (pp-eval-expression 'package-archives))
  50. (provide 'al-package-cmd)
  51. ;;; al-package-cmd.el ends here