summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2019-05-13 00:12:32 +0800
committerSteve Lee <me@xiangyangli.com>2019-05-13 00:12:32 +0800
commite49e90668a6e24046329461bb598d180cee18a00 (patch)
treebaf5710e6731833da3ba252e501b76053a9126af
parent2bb475c91d90e6258a0c279713251d7dbf35b3cd (diff)
downloaddotfiles-e49e90668a6e24046329461bb598d180cee18a00.tar.xz
dotfiles-e49e90668a6e24046329461bb598d180cee18a00.zip
update emacs.d
-rw-r--r--.emacs.d/.gitignore3
-rw-r--r--.emacs.d/lisp/init-company.el1
-rw-r--r--.emacs.d/lisp/init-elpa.el112
-rw-r--r--.emacs.d/lisp/init-evil.el3
-rw-r--r--.emacs.d/lisp/init-expand-region.el2
-rw-r--r--.emacs.d/lisp/init-flycheck.el2
-rw-r--r--.emacs.d/lisp/init-helm.el1
-rw-r--r--.emacs.d/lisp/init-neotree.el2
-rw-r--r--.emacs.d/lisp/init-slime.el2
-rw-r--r--.emacs.d/lisp/init-window-numbering.el2
10 files changed, 119 insertions, 11 deletions
diff --git a/.emacs.d/.gitignore b/.emacs.d/.gitignore
index 95bc89c..9029749 100644
--- a/.emacs.d/.gitignore
+++ b/.emacs.d/.gitignore
@@ -1 +1,4 @@
+custom.el
+*~
elpa/
+elpa*
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)