From 668b9f88f921f0b1bb4b6e1ab5e2f320c7b9d092 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 16 Nov 2014 22:36:07 -0500 Subject: [PATCH 1/4] Move contribsys package.el initialization in a function --- core/contribsys.el | 32 +++++++++++++++++--------------- init.el | 3 ++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/contribsys.el b/core/contribsys.el index 0fdf73c36..23d7387bd 100644 --- a/core/contribsys.el +++ b/core/contribsys.el @@ -1,19 +1,4 @@ ;; Spacemacs Contribution System -(require 'package) -(setq package-archives '(("ELPA" . "http://tromey.com/elpa/") - ("gnu" . "http://elpa.gnu.org/packages/") - ("melpa" . "http://melpa.org/packages/"))) -(package-initialize) -(setq warning-minimum-level :error) - -;; Emacs 24.3 and above ships with python.el but in some Emacs 24.3.1 packages -;; for Ubuntu, python.el seems to be missing. -;; This hack adds marmalade repository for this case only. -(unless (or (package-installed-p 'python) (version< emacs-version "24.3")) - (add-to-list 'package-archives - '("marmalade" . "http://marmalade-repo.org/packages/"))) - -(load (concat spacemacs-core-directory "ht.el")) (defconst spacemacs-dotspacemacs-version "1.0" "Minimum Version exepected for ~/.spacemacs file.") @@ -78,6 +63,23 @@ NOT USED FOR NOW :-)" (defvar dotspacemacs-excluded-packages '() "A list of packages and/or extensions that will not be install and loaded.") +(defun contribsys/package.el-initialize () + "Initialize package.el" + (require 'package) + (unless package--initialized + (load (concat spacemacs-core-directory "ht.el")) + (setq package-archives '(("ELPA" . "http://tromey.com/elpa/") + ("gnu" . "http://elpa.gnu.org/packages/") + ("melpa" . "http://melpa.org/packages/"))) + (package-initialize) + ;; Emacs 24.3 and above ships with python.el but in some Emacs 24.3.1 packages + ;; for Ubuntu, python.el seems to be missing. + ;; This hack adds marmalade repository for this case only. + (unless (or (package-installed-p 'python) (version< emacs-version "24.3")) + (add-to-list 'package-archives + '("marmalade" . "http://marmalade-repo.org/packages/"))) + (setq warning-minimum-level :error))) + (defun contribsys/dotfile-location () "Return the absolute path to the spacemacs dotfile." (concat user-home-directory ".spacemacs")) diff --git a/init.el b/init.el index 8638bbb19..e9cc656fa 100644 --- a/init.el +++ b/init.el @@ -2,6 +2,7 @@ (defconst spacemacs-core-directory (expand-file-name (concat user-emacs-directory "core/")) "Spacemacs core directory.") +(load (concat spacemacs-core-directory "contribsys.el")) (load (concat spacemacs-core-directory "spacemacs-mode.el")) (spacemacs/buffer) @@ -31,7 +32,7 @@ "Dropbox directory.") ;; if you have a dropbox, then ~/Dropbox/emacs is added to load path (add-to-list 'load-path (concat user-dropbox-directory "emacs/")) - (load (concat spacemacs-core-directory "contribsys.el")) + (contribsys/package.el-initialize) ;; User configuration file for Spacemacs: ~/.spacemacs (contribsys/load-dotfile) (contribsys/call-dotfile-func dotspacemacs/init) From 4b46e83172af7f1aeb7cf6e4e96098f253ce2f5f Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 16 Nov 2014 22:39:03 -0500 Subject: [PATCH 2/4] Move theme and UI elements config to spacemacs-mode --- core/spacemacs-mode.el | 94 +++++++++++++++++++++++++++++++++--------- spacemacs/config.el | 24 ----------- 2 files changed, 75 insertions(+), 43 deletions(-) diff --git a/core/spacemacs-mode.el b/core/spacemacs-mode.el index 691f584b9..b8e7bffc8 100644 --- a/core/spacemacs-mode.el +++ b/core/spacemacs-mode.el @@ -4,25 +4,6 @@ (defvar spacemacs-min-version "24.3" "Mininal required version of Emacs.") -(define-derived-mode spacemacs-mode special-mode "spacemacs-mode" - "Spacemacs major mode for startup screen." - :syntax-table nil - :abbrev-table nil - (setq truncate-lines t) - (setq cursor-type nil) - ;; no welcome buffer - (setq inhibit-startup-screen t) - ;; motion state since this is a special mode - (eval-after-load 'evil - '(add-to-list 'evil-motion-state-modes 'spacemacs-mode))) - -(defun spacemacs/emacs-version-ok () - (not (version< emacs-version spacemacs-min-version))) - -(defun display-startup-echo-area-message () - "Change the default welcome message of minibuffer to another one." - (message "Spacemacs is ready.")) - (defvar spacemacs-title-length 70) (defvar spacemacs-loading-counter 0) (defvar spacemacs-loading-text "Loading") @@ -35,6 +16,81 @@ (defvar spacemacs-loading-dots-chunk-size (/ spacemacs-loading-dots-count spacemacs-loading-dots-chunk-count)) (defvar spacemacs-loading-dots-chunk-threshold 0) +(defvar spacemacs-solarized-dark-createdp nil) + +(define-derived-mode spacemacs-mode special-mode "spacemacs-mode" + "Spacemacs major mode for startup screen." + :syntax-table nil + :abbrev-table nil + (setq truncate-lines t) + (setq cursor-type nil) + ;; no welcome buffer + (setq inhibit-startup-screen t) + ;; load the default theme manually to give a smooth startup experience + (spacemacs/load-or-install-package 'dash) + (add-to-list 'load-path "~/.emacs.d/spacemacs/extensions/solarized-theme/") + (require 'solarized) + (deftheme solarized-dark "The dark variant of the Solarized colour theme") + (deftheme solarized-light "The light variant of the Solarized colour theme") + (create-solarized-theme 'light 'solarized-light) + ;; font + ;; Dynamic font size depending on the system + (let ((font "Source Code Pro")) + (when (member font (font-family-list)) + (pcase window-system + (`x (spacemacs/set-font font 10)) + (`mac (spacemacs/set-font font 12)) + (`w32 (spacemacs/set-font font 9)) + (other (spacemacs/set-font font 10))))) + ;; edit area full screen + (tool-bar-mode -1) + (when (not (eq window-system 'mac)) + (menu-bar-mode -1)) + (scroll-bar-mode -1) + ;; motion state since this is a special mode + (eval-after-load 'evil + '(add-to-list 'evil-motion-state-modes 'spacemacs-mode))) + +(defun spacemacs/load-or-install-package (pkg) + "Load PKG package. PKG will be installed if it is not already +installed." + (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) + (let* ((elpa-dir (concat user-emacs-directory "elpa/")) + (pkg-elpa-dir + (if (file-exists-p elpa-dir) + (reduce (lambda (x y) (if x x y)) + (mapcar (lambda (x) + (if (string-match (symbol-name pkg) x) x)) + (directory-files elpa-dir)) + :initial-value nil)))) + (if pkg-elpa-dir + (add-to-list 'load-path (concat user-emacs-directory "elpa/" + pkg-elpa-dir)) + ;; install the package + (contribsys/package.el-initialize) + (package-refresh-contents) + (package-install pkg)) + (require pkg))))) + +(defun spacemacs/emacs-version-ok () + (not (version< emacs-version spacemacs-min-version))) + +(defun display-startup-echo-area-message () + "Change the default welcome message of minibuffer to another one." + (message "Spacemacs is ready.")) + +(defun spacemacs/set-font (font size &optional options) + (let* ((fontstr (if options + (format "%s-%s:%s" font size options) + (format "%s-%s" font size)))) + (message (format "Set default font: %s" fontstr)) + (add-to-list 'default-frame-alist (cons 'font fontstr)) + (set-default-font fontstr))) (defun spacemacs/buffer () "Create and initialize the spacemacs startup buffer." diff --git a/spacemacs/config.el b/spacemacs/config.el index 1e538b69b..b0ed05564 100644 --- a/spacemacs/config.el +++ b/spacemacs/config.el @@ -22,17 +22,9 @@ ;; Edit ;; --------------------------------------------------------------------------- -;; set the 2 keys sequence to return to normal state -;; default is "fd" -(defvar spacemacs-normal-state-sequence '(?f . ?d) - "Two keys sequence to return to normal state.") -(defvar spacemacs-normal-state-sequence-delay 0.2 - "Maximum delay between the two keys to trigger the normal state.") ;; start scratch in text mode (usefull to get a faster Emacs load time ;; because it avoids autoloads of elisp modes) (setq initial-major-mode 'text-mode) -;; font size -;;(set-face-attribute 'default nil :height 110) ;; whitespace-mode (setq-default show-trailing-whitespace nil) ;; When point is on paranthesis, highlight the matching one @@ -52,11 +44,6 @@ (lambda () (setq mode-name "Elisp"))) ;; important for golden-ratio to better work (setq window-combination-resize t) -;; edit area full screen -(tool-bar-mode -1) -(when (not (eq window-system 'mac)) - (menu-bar-mode -1)) -(scroll-bar-mode -1) ;; fringes (setq-default fringe-indicator-alist '((truncation . nil) (continuation . nil))) @@ -73,16 +60,6 @@ (setq tooltip-use-echo-area t) ;; When emacs asks for "yes" or "no", let "y" or "n" sufficide (fset 'yes-or-no-p 'y-or-n-p) -;; font -;; (set-default-font "DejaVu Sans Mono-10") -;; Dynamic font size depending on the system -(let ((font "Source Code Pro")) - (when (member font (font-family-list)) - (pcase window-system - (`x (spacemacs/set-font font 10)) - (`mac (spacemacs/set-font font 12)) - (`w32 (spacemacs/set-font font 9)) - (other (spacemacs/set-font font 10))))) ;; draw underline lower (setq x-underline-at-descent-line t) ;; setup right and left margins @@ -239,4 +216,3 @@ (defun server-remove-kill-buffer-hook () (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)) (add-hook 'server-visit-hook 'server-remove-kill-buffer-hook) - From 39f4dbdab1383f927635fe4dfb1744e5f20eb125 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 16 Nov 2014 22:39:37 -0500 Subject: [PATCH 3/4] Update load-theme advice to lazy create solarized-dark --- spacemacs/funcs.el | 86 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/spacemacs/funcs.el b/spacemacs/funcs.el index e0f03294c..faf1cc893 100644 --- a/spacemacs/funcs.el +++ b/spacemacs/funcs.el @@ -51,6 +51,49 @@ (interactive) (string-equal system-type "windows-nt")) +;; From http://stackoverflow.com/a/18796138 +;; Cycle through this set of themes +(defvar spacemacs-themes '(solarized-light + solarized-dark + monokai + zenburn) + "Themes officially supported by spacemacs.") +(defvar spacemacs-cur-theme (pop spacemacs-themes) + "Current spacemacs theme.") + +(defun spacemacs/cycle-spacemacs-theme () + "Cycle through themes defined in spacemacs-themes." + (interactive) + (when spacemacs-cur-theme + (disable-theme spacemacs-cur-theme) + (setq spacemacs-themes (append spacemacs-themes + (list spacemacs-cur-theme)))) + (setq spacemacs-cur-theme (pop spacemacs-themes)) + (message "Loading theme %s..." spacemacs-cur-theme) + (load-theme spacemacs-cur-theme t)) + +(defadvice load-theme (around spacemacs/load-theme-adv activate) + "Perform post load processing." + (let ((theme (ad-get-arg 0))) + (if (and spacemacs-solarized-dark-createdp + (eq 'solarized-dark theme)) + (create-solarized-theme 'dark 'solarized-dark)) + ad-do-it + (setq spacemacs-cur-theme theme) + (spacemacs/post-theme-init theme))) + +(defun spacemacs/post-theme-init (theme) + " Some processing that needs to be done when the current theme has been +changed to THEME." + (interactive) + ;; Define a face for each state + (if (fboundp 'spacemacs/set-state-faces) + (spacemacs/set-state-faces)) + (if (fboundp 'spacemacs/set-flycheck-mode-line-faces) + (spacemacs/set-flycheck-mode-line-faces)) + (if (fboundp 'powerline-reset) + (powerline-reset))) + ;; insert one or several line below without changing current evil state (defun evil-insert-line-below (count) "Insert one of several lines below the current point's line without changing @@ -302,41 +345,6 @@ argument takes the kindows rotate backwards." "Edit the `file' in the spacemacs base directory, in the current window." (ido-find-file-in-dir spacemacs-contrib-config-directory)) -;; From http://stackoverflow.com/a/18796138 -;; Cycle through this set of themes -(setq spacemacs-themes '(solarized-light - solarized-dark - monokai - zenburn)) -(defvar spacemacs-cur-theme (pop spacemacs-themes)) -(defun spacemacs/cycle-spacemacs-theme () - "Cycle through themes defined in spacemacs-themes." - (interactive) - (when spacemacs-cur-theme - (disable-theme spacemacs-cur-theme) - (setq spacemacs-themes (append spacemacs-themes - (list spacemacs-cur-theme)))) - (setq spacemacs-cur-theme (pop spacemacs-themes)) - (message "Loading theme %s..." spacemacs-cur-theme) - (load-theme spacemacs-cur-theme t)) - -(defadvice load-theme (after spacemacs/load-theme-adv activate) - "Perform post load processing." - (setq spacemacs-cur-theme (ad-get-arg 0)) - (spacemacs/post-theme-init spacemacs-cur-theme)) - -(defun spacemacs/post-theme-init (theme) - " Some processing that needs to be done when the current theme has been -changed to THEME." - (interactive) - ;; Define a face for each state - (if (fboundp 'spacemacs/set-state-faces) - (spacemacs/set-state-faces)) - (if (fboundp 'spacemacs/set-flycheck-mode-line-faces) - (spacemacs/set-flycheck-mode-line-faces)) - (if (fboundp 'powerline-reset) - (powerline-reset))) - ;; From http://xugx2007.blogspot.ca/2007/06/benjamin-rutts-emacs-c-development-tips.html (setq compilation-finish-function (lambda (buf str) @@ -548,14 +556,6 @@ kill internal buffers too." (when (not (frame-parameter nil 'fullscreen)) 'fullscreen))) )) -(defun spacemacs/set-font (font size &optional options) - (let* ((fontstr (if options - (format "%s-%s:%s" font size options) - (format "%s-%s" font size)))) - (message (format "Set default font: %s" fontstr)) - (add-to-list 'default-frame-alist (cons 'font fontstr)) - (set-default-font fontstr))) - (defun spacemacs/scale-font-size-overlay-map () "Set a temporary overlay map to easily change the font size." (set-temporary-overlay-map From 37e57f2659bb4694e24502f7c89351b79d4843d8 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 16 Nov 2014 22:40:21 -0500 Subject: [PATCH 4/4] Remove solarized theme init from spacemacs/extensions.el --- spacemacs/extensions.el | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spacemacs/extensions.el b/spacemacs/extensions.el index 62fb7812b..cb7ef9502 100644 --- a/spacemacs/extensions.el +++ b/spacemacs/extensions.el @@ -4,7 +4,6 @@ (defvar spacemacs-pre-extensions '( use-package - solarized-theme )) ;; Post extensions are loaded *after* the packages @@ -99,20 +98,3 @@ (spray-quit) (set-default-evil-insert-state-cursor) (evil-normal-state)))))) - -;; solarized theme dependencies -(unless (package-installed-p 'dash) - (package-refresh-contents) - (package-install 'dash)) -(defun spacemacs/init-solarized-theme () - ;; different method used than the documented one in order to speed up the - ;; loading of emacs - (use-package solarized - :init - (progn - (deftheme solarized-dark "The dark variant of the Solarized colour theme") - (create-solarized-theme 'dark 'solarized-dark) - (deftheme solarized-light "The light variant of the Solarized colour theme") - (create-solarized-theme 'light 'solarized-light) - (spacemacs/post-theme-init 'solarized-light) - (redisplay))))