Defer editorconfig, savehist, saveplace, undo-tree & recentf

This commit is contained in:
Henrik Lissner 2017-06-05 03:15:21 +02:00
parent a5325f6a2a
commit 0150f78e87

View file

@ -44,34 +44,6 @@ modes are active and the buffer is read-only.")
word-wrap t word-wrap t
vc-follow-symlinks t) vc-follow-symlinks t)
;; Save point across sessions
(require 'saveplace)
(setq save-place-file (concat doom-cache-dir "saveplace"))
(save-place-mode +1)
;; Save history across sessions
(require 'savehist)
(setq savehist-file (concat doom-cache-dir "savehist")
savehist-save-minibuffer-history t
savehist-autosave-interval nil ; save on kill only
savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
(savehist-mode 1)
;; Branching & persistent undo
(require 'undo-tree)
(setq undo-tree-auto-save-history t
undo-tree-history-directory-alist (list (cons "." (concat doom-cache-dir "undo-tree-hist/"))))
;; Keep track of recently opened files
(require 'recentf)
(setq recentf-save-file (concat doom-cache-dir "recentf")
recentf-exclude (list "/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
"^/var/folders/.+$" doom-local-dir)
recentf-max-menu-items 0
recentf-max-saved-items 250
recentf-filename-handlers '(abbreviate-file-name))
(quiet! (recentf-mode 1))
;; Ediff: use existing frame instead of creating a new one ;; Ediff: use existing frame instead of creating a new one
(add-hook! ediff-load (add-hook! ediff-load
(setq ediff-diff-options "-w" (setq ediff-diff-options "-w"
@ -127,10 +99,15 @@ sake."
;; Handles whitespace (tabs/spaces) settings externally. This way projects can ;; Handles whitespace (tabs/spaces) settings externally. This way projects can
;; specify their own formatting rules. ;; specify their own formatting rules.
(def-package! editorconfig :demand t (def-package! editorconfig
:mode ("\\.?editorconfig$" . editorconfig-conf-mode) :mode ("\\.?editorconfig$" . editorconfig-conf-mode)
:init :init
;; deferred loading, the clumsy way
(add-transient-hook! 'find-file-hook (require 'editorconfig))
(add-transient-hook! 'after-change-major-mode-hook (require 'editorconfig))
(def-setting! :editorconfig (action value) (def-setting! :editorconfig (action value)
":add or :remove an entry in `editorconfig-indentation-alist'."
`(after! editorconfig `(after! editorconfig
,(cond ((eq action :add) ,(cond ((eq action :add)
`(push ',value editorconfig-indentation-alist)) `(push ',value editorconfig-indentation-alist))
@ -148,6 +125,35 @@ sake."
(add-hook! 'editorconfig-custom-hooks (add-hook! 'editorconfig-custom-hooks
(if indent-tabs-mode (whitespace-mode +1)))) (if indent-tabs-mode (whitespace-mode +1))))
;; NOTE I've extracted some of savehist/saveplace's init code into def-package
;; blocks so that they can benefit from deferred loading.
;; persistent history
(def-package! savehist
:commands (savehist-minibuffer-hook savehist-autosave)
:init
(add-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook)
(add-hook 'kill-emacs-hook #'savehist-autosave)
:config
(setq savehist-file (concat doom-cache-dir "savehist")
savehist-save-minibuffer-history t
savehist-autosave-interval nil ; save on kill only
savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
(savehist-mode 1))
;; persistent point
(def-package! saveplace
:commands (save-place-find-file-hook save-place-dired-hook save-place-kill-emacs-hook save-place-to-alist)
:init
(add-hook 'find-file-hook #'save-place-find-file-hook t)
(add-hook 'dired-initial-position-hook #'save-place-dired-hook)
(add-hook 'kill-buffer-hook #'save-place-to-alist)
(unless noninteractive
(add-hook 'kill-emacs-hook #'save-place-kill-emacs-hook))
:config
(setq save-place-file (concat doom-cache-dir "saveplace"))
(save-place-mode +1))
;; Auto-close delimiters and blocks as you type ;; Auto-close delimiters and blocks as you type
(def-package! smartparens :demand t (def-package! smartparens :demand t
:init :init
@ -180,6 +186,31 @@ sake."
(sp-local-pair '(xml-mode nxml-mode php-mode) (sp-local-pair '(xml-mode nxml-mode php-mode)
"<!--" "-->" :post-handlers '(("| " "SPC")))) "<!--" "-->" :post-handlers '(("| " "SPC"))))
;; Branching & persistent undo
(def-package! undo-tree
:init
(add-transient-hook! 'find-file-hook (require 'undo-tree))
:config
(setq undo-tree-auto-save-history t
undo-tree-history-directory-alist (list (cons "." (concat doom-cache-dir "undo-tree-hist/"))))
(defun doom*silent-undo-tree-load-history-hook (orig-fn &rest args)
"Silence undo-tree load errors."
(quiet! (apply orig-fn args)))
(advice-add #'undo-tree-load-history-hook :around #'doom*silent-undo-tree-load-history-hook))
;; Keep track of recently opened files
(def-package! recentf
:defer 1
:config
(setq recentf-save-file (concat doom-cache-dir "recentf")
recentf-exclude (list "/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
"^/var/folders/.+$" doom-local-dir)
recentf-max-menu-items 0
recentf-max-saved-items 250
recentf-filename-handlers '(abbreviate-file-name))
(quiet! (recentf-mode 1)))
;; ;;
;; Autoloaded Plugins ;; Autoloaded Plugins