Day 3

A modern emacs configuration

Spliting the spacemacs/init

(defun dotspacemacs/init ()
 "Instantiate Spacemacs core settings."
 (dotspacemacs/init/coding)
 (dotspacemacs/init/display)
 (dotspacemacs/init/evil)
 (dotspacemacs/init/keys)
 (dotspacemacs/init/layouts)
 (dotspacemacs/init/misc)
 (dotspacemacs/init/packages)
 (dotspacemacs/init/startup))

Spliting the spacemacs/config

(defun dotspacemacs/user-config ()
 "Configuration that cannot be delegated to layers."
 (dotspacemacs/user-config/toggles)
 (dotspacemacs/user-config/development)
 (dotspacemacs/user-config/experiments))

Spliting the spacemacs/layers

(defun dotspacemacs/layers ()
 "Instantiate Spacemacs layers declarations and package configurations."
 (dotspacemacs/layers/config)
 (dotspacemacs/layers/packages))

Source Code


(defvar XING-ONLY? nil
 "If cloning, set to nil, enable non-layer personal configuration.")

(defvar linux? (eq system-type 'gnu/linux)
 "Are we on a gnu/linux machine?")

(defvar desktop? (= 1440 (display-pixel-height))
 "Am I on my desktop? For determining font size.")

(defun os-path (path)
 "Prepend drive label to PATH if on windows machine."
 (if linux?
     path
   (expand-file-name path "c:")))

(setq x-smart-package-archives
'(
	 ("org"       . "https://orgmode.org/elpa/")
	 ("gnu"       . "https://elpa.gnu.org/packages/")
	 ("melpa"     . "https://melpa.org/packages/")
	 ("milkbox"   . "https://melpa.milkbox.net/packages/")
	 ("elpy"      . "https://jorgenschaefer.github.io/packages/")
	 ("marmalade" . "https://marmalade-repo.org/packages/")
	 )
)

(setq x-local-package-archives
'(
	 ("org" . "http://localhost/static/elpa/org/")
	 ("gnu" . "http://localhost/static/elpa/gnu/")
	 ("melpa" . "http://localhost/static/elpa/melpa/")
	 ("stable-melpa" . "http://localhost/static/elpa/stable-melpa/")
	 )
)

(defun x/refresh-packages ()
(interactive)
 (when (>= emacs-major-version 24)
   (require 'package)
   (setq package-archives x-smart-package-archives)
   (package-initialize)))


;;; Spacemacs/

(defun dotspacemacs/init ()
 "Instantiate Spacemacs core settings."
 (dotspacemacs/init/coding)
 (dotspacemacs/init/display)
 (dotspacemacs/init/evil)
 (dotspacemacs/init/keys)
 (dotspacemacs/init/layouts)
 (dotspacemacs/init/misc)
 (dotspacemacs/init/packages)
 (dotspacemacs/init/startup))

(defun dotspacemacs/layers ()
 "Instantiate Spacemacs layers declarations and package configurations."
 (dotspacemacs/layers/config)
 (dotspacemacs/layers/packages))

(defun dotspacemacs/user-init ()
 "Package independent settings to run before `dotspacemacs/user-config'."

 (setq tramp-ssh-controlmaster-options
	"-o ControlMaster=auto -o ControlPath='tramp.%%C' -o ControlPersist=no")
 (setq evil-shift-round nil)
 (setq byte-compile-warnings '(not obsolete))
 (setq warning-minimum-level :error)
 (setq exec-path-from-shell-check-startup-files nil)
 (setq purpose-mode nil)
 (setq-default git-magit-status-fullscreen t)
 (setq custom-file (expand-file-name "custom.el" dotspacemacs-directory)))

(defun dotspacemacs/user-config ()
 "Configuration that cannot be delegated to layers."
 (dotspacemacs/user-config/toggles)
 (dotspacemacs/user-config/development)
 (dotspacemacs/user-config/experiments))

;;; Spacemacs/Layers

;;;; Local

(defvar dotspacemacs/layers/local
 '((macros :location local)    ; All local layers inherit these macros

	 (config :location local)    ; Org, Avy, Evil, Misc... config
	 (display :location local)   ; Pretty-eshell/code/outlines... pkgs
	 (langs :location local)     ; Language config
	 (personal :location local)  ; Personal pkgs
	 )
 "Local layers housed in `~/.spacemacs.d/layers'.")

;;;; Core

(defvar dotspacemacs/layers/core
 '(better-defaults
	 git
	 syntax-checking

	 (auto-completion :variables
		 auto-completion-return-key-behavior 'complete
		 auto-completion-tab-key-behavior 'complete
		 auto-completion-enable-snippets-in-popup t)

	 (ivy :variables
		 ivy-extra-directories nil)

	 (org :variables
		 org-projectile-file "TODO.org"
		 org-enable-org-journal-support t
		 org-enable-hugo-support t
		 org-enable-reveal-js-support t
		 org-enable-github-support t
		 org-want-todo-bindings t)

	 (shell :variables
		 shell-default-shell 'eshell)

	 (version-control :variables
		 version-control-global-margin t
		 version-control-diff-tool 'git-gutter+)
	 )
 "Layers I consider core to Spacemacs.")

;;;; Langs

(defvar dotspacemacs/layers/langs
 '(c-c++
   emacs-lisp
   (javascript :variables node-add-modules-path t)
   (typescript :variables typescript-fmt-on-save t)
   rust

   csv
   html
   markdown

   (clojure :variables
            clojure-enable-fancify-symbols t)
   ;; haskell
   (haskell :variables
            haskell-completion-backend 'intero)
   (python :variables
           python-sort-imports-on-save t
           python-test-runner 'pytest
           :packages
           (not hy-mode)  ; I maintain `hy-mode', using local branch
           )
   )
 "Programming and markup language layers.")

;;;; Extra

(defvar dotspacemacs/layers/extra
 '(gnus
	 graphviz
	 pdf-tools
	 ranger
	 treemacs
	 docker

	 (ibuffer :variables
		 ibuffer-group-buffers-by 'projects)

	 )
 "Miscellaneous layers.")

;;;; Xingwenju

(defvar dotspacemacs/layers/xingwenju
 '(
	 xingwenju
	 )
 "Xing Wenju layers.")

;;;; Layers/config

(defun dotspacemacs/layers/config ()
 (setq-default

  dotspacemacs-distribution
  'spacemacs

  dotspacemacs-enable-lazy-installation
  'unused

  dotspacemacs-ask-for-lazy-installation
  t

  dotspacemacs-configuration-layer-path
  (list (os-path "~/.spacemacs.d/layers/"))

  dotspacemacs-configuration-layers
	(
		append
   dotspacemacs/layers/local
   dotspacemacs/layers/core
   dotspacemacs/layers/langs
   dotspacemacs/layers/extra
   dotspacemacs/layers/xingwenju
   )
  ))

;;;; Layers/packages

(defun dotspacemacs/layers/packages ()
 (setq-default

	dotspacemacs-additional-packages
	'(
		 solarized-theme
		 nord-theme
		 github-modern-theme
		 atom-dark-theme
		 org-journal
		 ox-reveal
		 ox-hugo
		 w3m
		 etags-select
		 nodejs-repl
		 )

	dotspacemacs-excluded-packages
	'(
		 fringe
		 hy-mode
		 )

	dotspacemacs-frozen-packages
	'()

	dotspacemacs-install-packages
	'used-but-keep-unused
	))

;;; Spacemacs/Init
;;;; Coding

(defun dotspacemacs/init/coding ()
 (setq-default
  dotspacemacs-search-tools
  '("ag" "rg" "pt" "ack" "grep")

  dotspacemacs-smooth-scrolling
  t

  dotspacemacs-folding-method
  'evil

  dotspacemacs-smartparens-strict-mode
  nil

  dotspacemacs-smart-closing-parenthesis
  nil

  dotspacemacs-highlight-delimiters
  'all

  dotspacemacs-line-numbers
  nil

  dotspacemacs-whitespace-cleanup
  'trailing
  ))

;;;; Display

(defun dotspacemacs/init/display ()
 (setq-default

	dotspacemacs-themes
	'(
		 zenburn
		 solarized-light
		 solarized-dark
		 github-modern
		 nord  ; Minimal theme modifications for nord
		 tango
		 )

	dotspacemacs-default-font
	`(
		 "Fira Code"
		 :size ,(cond ((not linux?) 16)
							(desktop? 16)
							(t 16))
		 :weight normal
		 :width normal
		 :powerline-scale 1.5
		 )

	dotspacemacs-fullscreen-at-startup
	t

	dotspacemacs-fullscreen-use-non-native
	nil

	dotspacemacs-maximized-at-startup
	nil

	dotspacemacs-active-transparency
	70

	dotspacemacs-inactive-transparency
	50

	dotspacemacs-mode-line-theme
	'all-the-icons

	dotspacemacs-mode-line-unicode-symbols
	t

	dotspacemacs-zone-out-when-idle
	nil

	dotspacemacs-frame-title-format
	"%I@%S"

	dotspacemacs-icon-title-format
	nil
	))

;;;; Evil

(defun dotspacemacs/init/evil ()
 (setq-default

  dotspacemacs-editing-style
  'vim

  dotspacemacs-colorize-cursor-according-to-state
  t

  dotspacemacs-remap-Y-to-y$
  t

  dotspacemacs-retain-visual-state-on-shift
  t

  dotspacemacs-visual-line-move-text
  nil

  dotspacemacs-ex-substitute-global
  nil

  dotspacemacs-enable-paste-transient-state
  nil

  dotspacemacs-show-transient-state-title
  t

  dotspacemacs-show-transient-state-color-guide
  t
  ))

;;;; Keys

(defun dotspacemacs/init/keys ()
 (setq-default

  dotspacemacs-leader-key
  "SPC"

  dotspacemacs-emacs-command-key
  "SPC"

  dotspacemacs-ex-command-key
  ":"

  dotspacemacs-emacs-leader-key
  "M-m"

  dotspacemacs-major-mode-leader-key
  ","

  dotspacemacs-major-mode-emacs-leader-key
  "C-M-m"

  dotspacemacs-which-key-delay
  0.4

  dotspacemacs-which-key-position
  'bottom

  dotspacemacs-distinguish-gui-tab
  nil
  ))

;;;; Layouts

(defun dotspacemacs/init/layouts ()
 (setq-default

	dotspacemacs-scratch-mode
	'org-mode

	dotspacemacs-default-layout-name
	"Default"

	dotspacemacs-display-default-layout
	t

	dotspacemacs-auto-resume-layouts
	t

	dotspacemacs-auto-generate-layout-names
	t

	dotspacemacs-switch-to-buffer-prefers-purpose
	nil
	))

;;;; Misc

(defun dotspacemacs/init/misc ()
 (setq-default

  dotspacemacs-large-file-size
  5

  dotspacemacs-auto-save-file-location
  'cache

  dotspacemacs-max-rollback-slots
  5

  dotspacemacs-persistent-server
  nil

  dotspacemacs-helm-resize
  nil

  dotspacemacs-helm-no-header
  nil

  dotspacemacs-helm-position
  'bottom
  ))

;;;; Packages

(defun dotspacemacs/init/packages ()
 (setq-default

  dotspacemacs-default-package-repository
  nil

  dotspacemacs-elpa-https
  t

  dotspacemacs-elpa-timeout
  5

  dotspacemacs-check-for-update
  nil

  dotspacemacs-elpa-subdirectory
  nil
	)
;; x/refresh-packages

)

;;;; Startup

(defun dotspacemacs/init/startup ()
 (setq-default

	dotspacemacs-verbose-loading
	nil

	dotspacemacs-startup-banner
	'official

	dotspacemacs-startup-lists
	'(
		 (recents . 3)
		 (projects . 3)
		 (agenda . 3)
		 (todos . 3)
		 (bookmarks . 3)
		 )

	dotspacemacs-startup-buffer-responsive
	t

	dotspacemacs-loading-progress-bar
	t
	))

;;; Spacemacs/User-Config
;;;; Toggles

(defun dotspacemacs/user-config/toggles ()
 "Spacemacs toggles not intended to be put into layers."
 (spacemacs/toggle-highlight-long-lines-globally-on)
 (spacemacs/toggle-mode-line-minor-modes-off)
 (spacemacs/toggle-aggressive-indent-globally-on)
 (global-highlight-parentheses-mode 1)
(golden-ratio-mode 1)
(global-company-mode 1)
 (rainbow-delimiters-mode-enable)
 (fringe-mode '(0 . 8)))

;;;; Development
(defun dotspacemacs/user-config/development ()
 "Setting development Environment."
;; Tags
(setq tags-add-tables nil)
(setq tags-file-name nil)
 (setq tags-table-list
	'("~/.spacemacs.d/TAGS"
		 "~/workspace/wechaty-master/TAGS"
		 "~/workspace/cp-work-ts-vue/TAGS"))
;; Org
(setq spaceline-org-clock-p t)
(with-eval-after-load 'org-agenda
(require 'org-projectile)
(push (org-projectile-todo-files) org-agenda-files))
)

;;;; Experiments

(defun dotspacemacs/user-config/experiments ()
 "Space for trying out configuration updates."
 (setq nord-comment-brightness 15)
 (setq nord-uniform-mode-lines t)

 (when XING-ONLY?
   (load-file (os-path "~/.spacemacs.d/elisp/init.el"))
   (require 'hy-mode)
   (require 'spacemacs-hy)
   (require 'hy-personal)
   ))

To be Continued…