From e49e90668a6e24046329461bb598d180cee18a00 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 13 May 2019 00:12:32 +0800 Subject: update emacs.d --- .emacs.d/lisp/init-company.el | 1 + .emacs.d/lisp/init-elpa.el | 112 ++++++++++++++++++++++++++++++--- .emacs.d/lisp/init-evil.el | 3 +- .emacs.d/lisp/init-expand-region.el | 2 +- .emacs.d/lisp/init-flycheck.el | 2 +- .emacs.d/lisp/init-helm.el | 1 + .emacs.d/lisp/init-neotree.el | 2 + .emacs.d/lisp/init-slime.el | 2 +- .emacs.d/lisp/init-window-numbering.el | 2 + 9 files changed, 116 insertions(+), 11 deletions(-) (limited to '.emacs.d/lisp') diff --git a/.emacs.d/lisp/init-company.el b/.emacs.d/lisp/init-company.el index c6579b4..df6dc5e 100644 --- a/.emacs.d/lisp/init-company.el +++ b/.emacs.d/lisp/init-company.el @@ -4,6 +4,7 @@ ;;; Code: +(package-install 'company) (global-company-mode) (provide 'init-company) diff --git a/.emacs.d/lisp/init-elpa.el b/.emacs.d/lisp/init-elpa.el index 1430955..a6ee481 100644 --- a/.emacs.d/lisp/init-elpa.el +++ b/.emacs.d/lisp/init-elpa.el @@ -1,15 +1,113 @@ +;;; init-elpa.el --- Settings and helpers for package.el -*- lexical-binding: t -*- +;;; Commentary: +;;; Code: -;;; elpa +(require 'package) -;;; + +;;; Install into separate package dirs for each Emacs version, to prevent bytecode incompatibility +(let ((versioned-package-dir + (expand-file-name (format "elpa-%s.%s" emacs-major-version emacs-minor-version) + user-emacs-directory))) + (setq package-user-dir versioned-package-dir)) -;;; -(require 'package) -(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/")) + +;;; Standard package repositories + +(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) + (not (gnutls-available-p)))) + (proto (if no-ssl "http" "https"))) + (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t) + ;; Official MELPA Mirror, in case necessary. + ;;(add-to-list 'package-archives (cons "melpa-mirror" (concat proto "://www.mirrorservice.org/sites/melpa.org/packages/")) t) + (if (< emacs-major-version 24) + ;; For important compatibility libraries like cl-lib + (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/"))) + (unless no-ssl + ;; Force SSL for GNU ELPA + (setcdr (assoc "gnu" package-archives) "https://elpa.gnu.org/packages/")))) + + +;;; On-demand installation of packages + +(require 'cl-lib) + +(defun require-package (package &optional min-version no-refresh) + "Install given PACKAGE, optionally requiring MIN-VERSION. +If NO-REFRESH is non-nil, the available package lists will not be +re-downloaded in order to locate PACKAGE." + (or (package-installed-p package min-version) + (let* ((known (cdr (assoc package package-archive-contents))) + (versions (mapcar #'package-desc-version known))) + (if (cl-find-if (lambda (v) (version-list-<= min-version v)) versions) + (package-install package) + (if no-refresh + (error "No version of %s >= %S is available" package min-version) + (package-refresh-contents) + (require-package package min-version t)))))) + +(defun maybe-require-package (package &optional min-version no-refresh) + "Try to install PACKAGE, and return non-nil if successful. +In the event of failure, return nil and print a warning message. +Optionally require MIN-VERSION. If NO-REFRESH is non-nil, the +available package lists will not be re-downloaded in order to +locate PACKAGE." + (condition-case err + (require-package package min-version no-refresh) + (error + (message "Couldn't install optional package `%s': %S" package err) + nil))) + + +;;; Fire up package.el + +(setq package-enable-at-startup nil) (package-initialize) -(provide 'init-elpa) -;;; init-elpa.el ends here + +;; package.el updates the saved version of package-selected-packages correctly only +;; after custom-file has been loaded, which is a bug. We work around this by adding +;; the required packages to package-selected-packages after startup is complete. +(defvar sanityinc/required-packages nil) +(defun sanityinc/note-selected-package (oldfun package &rest args) + "If OLDFUN reports PACKAGE was successfully installed, note it in `sanityinc/required-packages'." + (let ((available (apply oldfun package args))) + (prog1 available + (when (and available (boundp 'package-selected-packages)) + (add-to-list 'sanityinc/required-packages package))))) + +(advice-add 'require-package :around 'sanityinc/note-selected-package) + +(when (fboundp 'package--save-selected-packages) + (require-package 'seq) + (add-hook 'after-init-hook + (lambda () (package--save-selected-packages + (seq-uniq (append sanityinc/required-packages package-selected-packages)))))) + + +(require-package 'fullframe) +(fullframe list-packages quit-window) + + +(defun sanityinc/set-tabulated-list-column-width (col-name width) + "Set any column with name COL-NAME to the given WIDTH." + (when (> width (length col-name)) + (cl-loop for column across tabulated-list-format + when (string= col-name (car column)) + do (setf (elt column 1) width)))) + +(defun sanityinc/maybe-widen-package-menu-columns () + "Widen some columns of the package menu table to avoid truncation." + (when (boundp 'tabulated-list-format) + (sanityinc/set-tabulated-list-column-width "Version" 13) + (let ((longest-archive-name (apply 'max (mapcar 'length (mapcar 'car package-archives))))) + (sanityinc/set-tabulated-list-column-width "Archive" longest-archive-name)))) + +(add-hook 'package-menu-mode-hook 'sanityinc/maybe-widen-package-menu-columns) + + +(provide 'init-elpa) +;;; init-elpa.el ends here diff --git a/.emacs.d/lisp/init-evil.el b/.emacs.d/lisp/init-evil.el index 7463dd0..cd57a7e 100644 --- a/.emacs.d/lisp/init-evil.el +++ b/.emacs.d/lisp/init-evil.el @@ -4,7 +4,8 @@ ;;; Code: -(package-install 'evil) +(require-package 'evil) +(require-package 'evil-leader) ;; Evil leader, more evil (global-evil-leader-mode) (require 'evil) diff --git a/.emacs.d/lisp/init-expand-region.el b/.emacs.d/lisp/init-expand-region.el index 05b3ac0..19064d2 100644 --- a/.emacs.d/lisp/init-expand-region.el +++ b/.emacs.d/lisp/init-expand-region.el @@ -4,7 +4,7 @@ ;;; Code: -(require 'expand-region) +(require-package 'expand-region) (provide 'init-expand-region) ;;; init-expand-region ends here diff --git a/.emacs.d/lisp/init-flycheck.el b/.emacs.d/lisp/init-flycheck.el index d124711..8a7f546 100644 --- a/.emacs.d/lisp/init-flycheck.el +++ b/.emacs.d/lisp/init-flycheck.el @@ -4,7 +4,7 @@ ;;; Code: -(package-install 'flycheck) +(require-package 'flycheck) (global-flycheck-mode) (setq flycheck-check-syntax-automatically '(mode-enabled save)) diff --git a/.emacs.d/lisp/init-helm.el b/.emacs.d/lisp/init-helm.el index 52708c1..0280565 100644 --- a/.emacs.d/lisp/init-helm.el +++ b/.emacs.d/lisp/init-helm.el @@ -4,6 +4,7 @@ ;;; Code: +(require-package 'helm) (require 'helm-config) (global-set-key (kbd "M-x") 'helm-M-x) diff --git a/.emacs.d/lisp/init-neotree.el b/.emacs.d/lisp/init-neotree.el index d25e13f..a1ca271 100644 --- a/.emacs.d/lisp/init-neotree.el +++ b/.emacs.d/lisp/init-neotree.el @@ -4,6 +4,8 @@ ;;; Code: +(require-package 'neotree) + (global-unset-key (kbd "C-e")) (global-set-key (kbd "C-x x") 'neotree-toggle) diff --git a/.emacs.d/lisp/init-slime.el b/.emacs.d/lisp/init-slime.el index 157f0ee..96c863a 100644 --- a/.emacs.d/lisp/init-slime.el +++ b/.emacs.d/lisp/init-slime.el @@ -4,7 +4,7 @@ ;;; Code: -(package-install 'slime) +(require-package 'slime) (setq inferior-lisp-program "/usr/bin/sbcl") (setq slime-contribs '(slime-fancy)) diff --git a/.emacs.d/lisp/init-window-numbering.el b/.emacs.d/lisp/init-window-numbering.el index c8425ff..3fd48e0 100644 --- a/.emacs.d/lisp/init-window-numbering.el +++ b/.emacs.d/lisp/init-window-numbering.el @@ -4,6 +4,8 @@ ;;; Code: +(require-package 'window-numbering) + (window-numbering-mode) (provide 'init-window-numbering) -- cgit v1.2.3