2015-03-02 03:12:09 +00:00
|
|
|
;;; core-spacemacs.el --- Spacemacs Core File
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
2014-09-24 00:47:20 +00:00
|
|
|
(setq message-log-max 16384)
|
|
|
|
(defconst emacs-start-time (current-time))
|
|
|
|
|
2015-01-03 03:21:35 +00:00
|
|
|
(require 'subr-x nil 'noerror)
|
2015-01-27 03:51:47 +00:00
|
|
|
(require 'core-emacs-backports)
|
2015-06-07 03:26:14 +00:00
|
|
|
(require 'core-release-management)
|
2015-04-11 19:10:21 +00:00
|
|
|
(require 'core-auto-completion)
|
2015-01-27 03:51:47 +00:00
|
|
|
(require 'core-themes-support)
|
|
|
|
(require 'core-fonts-support)
|
|
|
|
(require 'core-spacemacs-buffer)
|
2015-03-01 04:33:57 +00:00
|
|
|
(require 'core-toggle)
|
|
|
|
(require 'core-micro-state)
|
2015-06-26 03:49:53 +00:00
|
|
|
(require 'core-evilify-keymap)
|
2015-05-20 03:39:03 +00:00
|
|
|
(require 'core-use-package-ext)
|
2015-01-02 05:50:21 +00:00
|
|
|
|
2015-01-08 05:34:23 +00:00
|
|
|
(defgroup spacemacs nil
|
|
|
|
"Spacemacs customizations."
|
|
|
|
:group 'starter-kit
|
|
|
|
:prefix 'spacemacs-)
|
|
|
|
|
2015-01-05 05:20:38 +00:00
|
|
|
;; loading progress bar variables
|
2015-03-12 03:46:37 +00:00
|
|
|
(defvar spacemacs-loading-char ?█)
|
|
|
|
(defvar spacemacs-loading-string "")
|
2014-11-17 03:39:03 +00:00
|
|
|
(defvar spacemacs-loading-counter 0)
|
2015-03-12 03:46:37 +00:00
|
|
|
;; (defvar spacemacs-loading-text "Loading")
|
|
|
|
;; (defvar spacemacs-loading-done-text "Ready!")
|
2014-11-17 03:39:03 +00:00
|
|
|
(defvar spacemacs-loading-dots-chunk-count 3)
|
2015-03-12 03:46:37 +00:00
|
|
|
(defvar spacemacs-loading-dots-count (window-total-size nil 'width))
|
2014-11-17 03:39:03 +00:00
|
|
|
(defvar spacemacs-loading-dots-chunk-size
|
|
|
|
(/ spacemacs-loading-dots-count spacemacs-loading-dots-chunk-count))
|
|
|
|
(defvar spacemacs-loading-dots-chunk-threshold 0)
|
|
|
|
|
2015-06-23 04:00:51 +00:00
|
|
|
(defvar spacemacs-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [tab] 'widget-forward)
|
|
|
|
(define-key map (kbd "C-i") 'widget-forward)
|
|
|
|
(define-key map [backtab] 'widget-backward)
|
|
|
|
(define-key map [return] 'widget-button-press)
|
|
|
|
(define-key map [down-mouse-1] 'widget-button-click)
|
|
|
|
map)
|
|
|
|
"Keymap for spacemacs mode.")
|
|
|
|
|
2015-01-28 03:06:59 +00:00
|
|
|
(define-derived-mode spacemacs-mode special-mode "Spacemacs"
|
2015-06-23 04:00:51 +00:00
|
|
|
"Spacemacs major mode for startup screen.
|
|
|
|
|
|
|
|
\\<spacemacs-mode-map>
|
|
|
|
"
|
2015-03-01 17:49:39 +00:00
|
|
|
:group 'spacemacs
|
2014-09-10 03:12:31 +00:00
|
|
|
:syntax-table nil
|
|
|
|
:abbrev-table nil
|
|
|
|
(setq truncate-lines t)
|
2015-06-23 04:00:51 +00:00
|
|
|
;; needed to make tab work correctly in terminal
|
|
|
|
(evil-define-key 'motion spacemacs-mode-map (kbd "C-i") 'widget-forward)
|
2015-02-16 01:13:43 +00:00
|
|
|
;; motion state since this is a special mode
|
|
|
|
(add-to-list 'evil-motion-state-modes 'spacemacs-mode))
|
|
|
|
|
2015-03-01 04:33:57 +00:00
|
|
|
(defun spacemacs/init ()
|
2015-02-16 01:13:43 +00:00
|
|
|
"Create the special buffer for `spacemacs-mode' and perform startup
|
|
|
|
initialization."
|
2015-04-13 01:27:07 +00:00
|
|
|
;; explicitly set the prefered coding systems to avoid annoying prompt
|
|
|
|
;; from emacs (especially on Microsoft Windows)
|
|
|
|
(prefer-coding-system 'utf-8)
|
2015-03-02 03:12:09 +00:00
|
|
|
;; dotfile init
|
|
|
|
(dotspacemacs/load-file)
|
|
|
|
(dotspacemacs|call-func dotspacemacs/init "Calling dotfile init...")
|
|
|
|
;; spacemacs init
|
2015-02-16 01:13:43 +00:00
|
|
|
(switch-to-buffer (get-buffer-create spacemacs-buffer-name))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/set-mode-line "")
|
2014-10-24 03:11:18 +00:00
|
|
|
;; no welcome buffer
|
2014-11-04 03:37:25 +00:00
|
|
|
(setq inhibit-startup-screen t)
|
2015-01-24 03:02:08 +00:00
|
|
|
;; default theme
|
|
|
|
(let ((default-theme (car dotspacemacs-themes)))
|
|
|
|
(spacemacs/load-theme default-theme)
|
2015-04-14 19:50:29 +00:00
|
|
|
;; used to prevent automatic deletion of used packages
|
|
|
|
(setq spacemacs-used-theme-packages
|
|
|
|
(delq nil (mapcar 'spacemacs//get-theme-package
|
|
|
|
dotspacemacs-themes)))
|
2015-01-24 03:02:08 +00:00
|
|
|
(setq-default spacemacs--cur-theme default-theme)
|
|
|
|
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
|
2015-03-13 04:29:30 +00:00
|
|
|
;; removes the GUI elements
|
2015-03-18 04:09:24 +00:00
|
|
|
(when (and (fboundp 'tool-bar-mode) (not (eq tool-bar-mode -1)))
|
2015-03-13 04:29:30 +00:00
|
|
|
(tool-bar-mode -1))
|
2015-03-18 04:09:24 +00:00
|
|
|
(when (and (fboundp 'scroll-bar-mode) (not (eq scroll-bar-mode -1)))
|
2015-03-13 04:29:30 +00:00
|
|
|
(scroll-bar-mode -1))
|
|
|
|
;; tooltips in echo-aera
|
2015-03-18 04:09:24 +00:00
|
|
|
(when (and (fboundp 'tooltip-mode) (not (eq tooltip-mode -1)))
|
2015-03-13 04:29:30 +00:00
|
|
|
(tooltip-mode -1))
|
|
|
|
(setq tooltip-use-echo-area t)
|
2015-03-17 03:39:19 +00:00
|
|
|
(unless (eq window-system 'mac)
|
2015-03-18 04:09:24 +00:00
|
|
|
(when (and (fboundp 'menu-bar-mode) (not (eq menu-bar-mode -1)))
|
2015-03-17 03:39:19 +00:00
|
|
|
(menu-bar-mode -1)))
|
2015-01-07 05:04:47 +00:00
|
|
|
;; for convenience and user support
|
2015-03-18 04:09:24 +00:00
|
|
|
(unless (fboundp 'tool-bar-mode)
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/message (concat "No graphical support detected, you won't be"
|
2015-01-07 05:04:47 +00:00
|
|
|
"able to launch a graphical instance of Emacs"
|
|
|
|
"with this build.")))
|
2014-11-28 05:07:29 +00:00
|
|
|
;; font
|
2015-01-30 02:19:37 +00:00
|
|
|
(if (find-font (font-spec :name (car dotspacemacs-default-font)))
|
|
|
|
(spacemacs/set-default-font dotspacemacs-default-font)
|
2015-04-12 16:25:53 +00:00
|
|
|
(spacemacs-buffer/warning "Cannot find font \"%s\"!"
|
|
|
|
(car dotspacemacs-default-font)))
|
2014-12-12 16:53:19 +00:00
|
|
|
;; banner
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/insert-banner-and-buttons)
|
2015-02-16 01:13:43 +00:00
|
|
|
(setq-default evil-want-C-u-scroll t)
|
|
|
|
;; Initializing configuration from ~/.spacemacs
|
|
|
|
(dotspacemacs|call-func dotspacemacs/init "Executing user init...")
|
2015-07-24 04:08:43 +00:00
|
|
|
;; mandatory dependencies
|
2015-02-06 04:20:14 +00:00
|
|
|
;; dash is required to prevent a package.el bug with f on 24.3.1
|
|
|
|
(spacemacs/load-or-install-package 'dash t)
|
2015-07-24 04:08:43 +00:00
|
|
|
(spacemacs/load-or-install-package 's t)
|
2014-12-18 00:02:34 +00:00
|
|
|
;; bind-key is required by use-package
|
|
|
|
(spacemacs/load-or-install-package 'bind-key t)
|
|
|
|
(spacemacs/load-or-install-package 'use-package t)
|
2015-06-03 02:07:55 +00:00
|
|
|
(setq use-package-verbose dotspacemacs-verbose-loading)
|
2015-05-20 03:39:03 +00:00
|
|
|
;; inject use-package hooks for easy customization of
|
|
|
|
;; stock package configuration
|
2015-05-21 02:39:14 +00:00
|
|
|
(setq use-package-inject-hooks t)
|
2015-07-24 04:08:43 +00:00
|
|
|
;; which-key
|
|
|
|
(spacemacs/load-or-install-package 'which-key t)
|
2015-04-08 03:50:22 +00:00
|
|
|
;; evil and evil-leader must be installed at the beginning of the
|
|
|
|
;; boot sequence.
|
|
|
|
;; Use C-u as scroll-up (must be set before actually loading evil)
|
2014-12-12 16:53:19 +00:00
|
|
|
(spacemacs/load-or-install-package 'evil t)
|
|
|
|
(spacemacs/load-or-install-package 'evil-leader t)
|
2015-01-08 05:34:23 +00:00
|
|
|
;; check for new version
|
|
|
|
(if dotspacemacs-mode-line-unicode-symbols
|
2015-01-09 05:22:17 +00:00
|
|
|
(setq-default spacemacs-version-check-lighter "[⇪]"))
|
2015-01-08 05:34:23 +00:00
|
|
|
(spacemacs/set-new-version-lighter-mode-line-faces)
|
2015-04-12 04:24:03 +00:00
|
|
|
(add-hook 'after-init-hook 'spacemacs-buffer/goto-link-line)
|
2015-02-16 01:13:43 +00:00
|
|
|
(spacemacs-mode))
|
2014-12-14 18:53:06 +00:00
|
|
|
|
2015-01-01 07:07:13 +00:00
|
|
|
(defun spacemacs//get-package-directory (pkg)
|
|
|
|
"Return the directory of PKG. Return nil if not found."
|
|
|
|
(let ((elpa-dir (concat user-emacs-directory "elpa/")))
|
|
|
|
(when (file-exists-p elpa-dir)
|
|
|
|
(let ((dir (reduce (lambda (x y) (if x x y))
|
|
|
|
(mapcar (lambda (x)
|
2015-01-05 05:23:02 +00:00
|
|
|
(if (string-match
|
2015-04-08 03:50:22 +00:00
|
|
|
(concat "/"
|
|
|
|
(symbol-name pkg)
|
|
|
|
"-[0-9]+") x) x))
|
2015-01-01 07:07:13 +00:00
|
|
|
(directory-files elpa-dir 'full))
|
|
|
|
:initial-value nil)))
|
|
|
|
(if dir (file-name-as-directory dir))))))
|
|
|
|
|
|
|
|
(defun spacemacs/load-or-install-package (pkg &optional log file-to-load)
|
2014-12-12 16:53:19 +00:00
|
|
|
"Load PKG package. PKG will be installed if it is not already installed.
|
2015-01-01 07:07:13 +00:00
|
|
|
Whenever the initial require fails the absolute path to the package
|
|
|
|
directory is returned.
|
|
|
|
If LOG is non-nil a message is displayed in spacemacs-mode buffer.
|
|
|
|
FILE-TO-LOAD is an explicit file to load after the installation."
|
2014-11-17 03:39:03 +00:00
|
|
|
(condition-case nil
|
|
|
|
(require pkg)
|
|
|
|
(error
|
|
|
|
;; not installed, we try to initialize package.el only if required to
|
|
|
|
;; precious seconds during boot time
|
|
|
|
(require 'cl)
|
2015-01-01 07:07:13 +00:00
|
|
|
(let ((pkg-elpa-dir (spacemacs//get-package-directory pkg)))
|
2014-11-17 03:39:03 +00:00
|
|
|
(if pkg-elpa-dir
|
2015-01-05 05:23:02 +00:00
|
|
|
(add-to-list 'load-path pkg-elpa-dir)
|
2014-11-17 03:39:03 +00:00
|
|
|
;; install the package
|
2014-12-12 16:53:19 +00:00
|
|
|
(when log
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2014-12-12 16:53:19 +00:00
|
|
|
(format "(Bootstrap) Installing %s...\n" pkg))
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay))
|
2014-11-17 03:39:03 +00:00
|
|
|
(package-refresh-contents)
|
2015-01-01 07:07:13 +00:00
|
|
|
(package-install pkg)
|
|
|
|
(setq pkg-elpa-dir (spacemacs//get-package-directory pkg)))
|
|
|
|
(require pkg nil 'noerror)
|
|
|
|
(when file-to-load
|
|
|
|
(load-file (concat pkg-elpa-dir file-to-load)))
|
|
|
|
pkg-elpa-dir))))
|
2014-11-17 03:39:03 +00:00
|
|
|
|
2015-03-31 03:16:33 +00:00
|
|
|
(defun spacemacs/maybe-install-dotfile ()
|
|
|
|
"Install the dotfile if it does not exist."
|
|
|
|
(unless (file-exists-p dotspacemacs-filepath)
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/set-mode-line "Dotfile wizard installer")
|
2015-03-31 03:16:33 +00:00
|
|
|
(spacemacs//redisplay)
|
|
|
|
(when (dotspacemacs/install 'with-wizard)
|
|
|
|
(dotspacemacs/sync-configuration-layers)
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-04-17 15:05:54 +00:00
|
|
|
"The dotfile has been installed.\n"))))
|
2015-03-31 03:16:33 +00:00
|
|
|
|
2015-01-01 04:53:38 +00:00
|
|
|
(defun spacemacs/display-and-copy-version ()
|
|
|
|
"Echo the current spacemacs version and copy it."
|
|
|
|
(interactive)
|
|
|
|
(let ((msg (format "Spacemacs v.%s" spacemacs-version)))
|
|
|
|
(message msg) (kill-new msg)))
|
|
|
|
|
2014-09-30 02:43:25 +00:00
|
|
|
(defun display-startup-echo-area-message ()
|
|
|
|
"Change the default welcome message of minibuffer to another one."
|
|
|
|
(message "Spacemacs is ready."))
|
|
|
|
|
2015-03-02 03:12:09 +00:00
|
|
|
(defun spacemacs/setup-after-init-hook ()
|
|
|
|
"Add post init processing."
|
|
|
|
(add-hook
|
|
|
|
'after-init-hook
|
|
|
|
(lambda ()
|
|
|
|
;; Ultimate configuration decisions are given to the user who can defined
|
|
|
|
;; them in his/her ~/.spacemacs file
|
|
|
|
(dotspacemacs|call-func dotspacemacs/config "Calling dotfile config...")
|
|
|
|
;; from jwiegley
|
|
|
|
;; https://github.com/jwiegley/dot-emacs/blob/master/init.el
|
|
|
|
(let ((elapsed (float-time
|
|
|
|
(time-subtract (current-time) emacs-start-time))))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-04-13 06:17:48 +00:00
|
|
|
(format "\n[%s packages loaded in %.3fs]\n"
|
2015-03-02 03:12:09 +00:00
|
|
|
(configuration-layer//initialized-packages-count)
|
|
|
|
elapsed)))
|
2015-04-02 04:32:38 +00:00
|
|
|
;; Display useful lists of items
|
|
|
|
(when dotspacemacs-startup-lists
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/insert-startupify-lists))
|
2015-03-16 05:28:21 +00:00
|
|
|
(when configuration-layer-error-count
|
|
|
|
;; ("%e" mode-line-front-space mode-line-mule-info mode-line-client mode-line-modified mode-line-remote mode-line-frame-identification mode-line-buffer-identification " " mode-line-position evil-mode-line-tag
|
|
|
|
;; (vc-mode vc-mode)
|
|
|
|
;; " " mode-line-modes mode-line-misc-info mode-line-end-spaces
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/set-mode-line
|
2015-04-03 02:23:16 +00:00
|
|
|
(format (concat "%s error(s) at startup! "
|
2015-03-16 05:28:21 +00:00
|
|
|
"Spacemacs may not be able to operate properly.")
|
|
|
|
configuration-layer-error-count))
|
|
|
|
(force-mode-line-update))
|
2015-03-02 03:12:09 +00:00
|
|
|
(spacemacs/check-for-new-version spacemacs-version-check-interval))))
|
|
|
|
|
|
|
|
(provide 'core-spacemacs)
|