2017-06-08 11:47:56 +02:00
|
|
|
;;; core-editor.el -*- lexical-binding: t; -*-
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-05-06 11:53:10 -04:00
|
|
|
(defvar doom-large-file-size 1
|
2017-05-06 22:55:10 +02:00
|
|
|
"Size (in MB) above which the user will be prompted to open the file literally
|
|
|
|
to avoid performance issues. Opening literally means that no major or minor
|
|
|
|
modes are active and the buffer is read-only.")
|
2017-05-06 11:53:10 -04:00
|
|
|
|
2017-05-06 22:55:10 +02:00
|
|
|
(defvar doom-large-file-modes-list
|
2018-05-26 03:06:22 +02:00
|
|
|
'(fundamental-mode special-mode archive-mode tar-mode jka-compr
|
|
|
|
git-commit-mode image-mode doc-view-mode doc-view-mode-maybe
|
|
|
|
ebrowse-tree-mode pdf-view-mode)
|
2017-05-06 22:55:10 +02:00
|
|
|
"Major modes that `doom|check-large-file' will ignore.")
|
2017-05-06 11:53:10 -04:00
|
|
|
|
2018-05-18 01:28:40 +02:00
|
|
|
(defvar-local doom-inhibit-indent-detection nil
|
|
|
|
"A buffer-local flag that indicates whether `dtrt-indent' should try to detect
|
|
|
|
indentation settings or not. This should be set by editorconfig if it
|
|
|
|
successfully sets indent_style/indent_size.")
|
|
|
|
|
2017-02-19 18:11:28 -05:00
|
|
|
(setq-default
|
2017-06-16 02:06:21 +02:00
|
|
|
vc-follow-symlinks t
|
2017-02-19 18:11:28 -05:00
|
|
|
;; Save clipboard contents into kill-ring before replacing them
|
|
|
|
save-interprogram-paste-before-kill t
|
|
|
|
;; Bookmarks
|
2017-11-04 22:34:55 +01:00
|
|
|
bookmark-default-file (concat doom-etc-dir "bookmarks")
|
2017-02-19 18:11:28 -05:00
|
|
|
bookmark-save-flag t
|
|
|
|
;; Formatting
|
|
|
|
delete-trailing-lines nil
|
|
|
|
fill-column 80
|
|
|
|
sentence-end-double-space nil
|
2017-06-05 23:00:50 +02:00
|
|
|
word-wrap t
|
2017-02-19 18:11:28 -05:00
|
|
|
;; Scrolling
|
|
|
|
hscroll-margin 1
|
|
|
|
hscroll-step 1
|
|
|
|
scroll-conservatively 1001
|
|
|
|
scroll-margin 0
|
2018-05-15 10:48:50 +02:00
|
|
|
hscroll-margin 2
|
2017-02-19 18:11:28 -05:00
|
|
|
scroll-preserve-screen-position t
|
|
|
|
;; Whitespace (see `editorconfig')
|
|
|
|
indent-tabs-mode nil
|
|
|
|
require-final-newline t
|
|
|
|
tab-always-indent t
|
|
|
|
tab-width 4
|
2017-06-16 02:06:21 +02:00
|
|
|
tabify-regexp "^\t* [ \t]+" ; for :retab
|
2017-02-19 18:11:28 -05:00
|
|
|
;; Wrapping
|
|
|
|
truncate-lines t
|
2018-05-08 23:21:17 +02:00
|
|
|
truncate-partial-width-windows 50)
|
2017-06-16 02:06:21 +02:00
|
|
|
|
2017-05-06 22:55:10 +02:00
|
|
|
(defun doom|check-large-file ()
|
2017-06-05 23:00:50 +02:00
|
|
|
"Check if the buffer's file is large (see `doom-large-file-size'). If so, ask
|
|
|
|
for confirmation to open it literally (read-only, disabled undo and in
|
|
|
|
fundamental-mode) for performance sake."
|
2018-06-14 19:51:11 +02:00
|
|
|
(when (and (not (memq major-mode doom-large-file-modes-list))
|
|
|
|
auto-mode-alist
|
2018-06-16 12:26:58 +02:00
|
|
|
(get-buffer-window))
|
2018-06-14 19:51:11 +02:00
|
|
|
(when-let* ((size (nth 7 (file-attributes buffer-file-name))))
|
|
|
|
(when (and (> size (* 1024 1024 doom-large-file-size))
|
|
|
|
(y-or-n-p
|
|
|
|
(format (concat "%s is a large file, open literally to "
|
|
|
|
"avoid performance issues?")
|
|
|
|
(file-relative-name buffer-file-name))))
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
(buffer-disable-undo)
|
|
|
|
(fundamental-mode)))))
|
2017-05-06 22:55:10 +02:00
|
|
|
(add-hook 'find-file-hook #'doom|check-large-file)
|
2017-05-06 11:53:10 -04:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-06-05 23:00:50 +02:00
|
|
|
;;
|
|
|
|
;; Built-in plugins
|
|
|
|
;;
|
|
|
|
|
2018-05-24 19:12:36 +02:00
|
|
|
(push '("/LICENSE\\'" . text-mode) auto-mode-alist)
|
2018-05-17 15:29:54 +02:00
|
|
|
|
2018-05-14 18:40:35 +02:00
|
|
|
(electric-indent-mode -1) ; enabled by default in Emacs 25+. No thanks.
|
|
|
|
|
2018-03-12 13:28:09 -04:00
|
|
|
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
|
|
|
|
|
2017-06-05 23:00:50 +02:00
|
|
|
;; revert buffers for changed files
|
2018-05-14 18:40:35 +02:00
|
|
|
(def-package! autorevert
|
2018-06-14 00:08:16 +02:00
|
|
|
:after-call after-find-file
|
2018-05-14 18:40:35 +02:00
|
|
|
:config
|
|
|
|
(setq auto-revert-verbose nil)
|
|
|
|
(global-auto-revert-mode +1))
|
|
|
|
|
|
|
|
;; persist variables across sessions
|
|
|
|
(def-package! savehist
|
2018-05-20 20:07:15 +02:00
|
|
|
:defer 1
|
|
|
|
:after-call post-command-hook
|
2018-05-14 18:40:35 +02:00
|
|
|
: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 location in buffers
|
|
|
|
(def-package! saveplace
|
2018-06-14 00:08:16 +02:00
|
|
|
:after-call (after-find-file dired-initial-position-hook)
|
2018-05-14 18:40:35 +02:00
|
|
|
:config
|
|
|
|
(setq save-place-file (concat doom-cache-dir "saveplace"))
|
|
|
|
(defun doom*recenter-on-load-saveplace (&rest _)
|
|
|
|
"Recenter on cursor when loading a saved place."
|
|
|
|
(if buffer-file-name (ignore-errors (recenter))))
|
|
|
|
(advice-add #'save-place-find-file-hook
|
|
|
|
:after-while #'doom*recenter-on-load-saveplace)
|
|
|
|
(save-place-mode +1))
|
2017-06-05 23:00:50 +02:00
|
|
|
|
|
|
|
;; Keep track of recently opened files
|
|
|
|
(def-package! recentf
|
2018-05-20 20:07:15 +02:00
|
|
|
:defer 1
|
2018-06-14 00:08:16 +02:00
|
|
|
:after-call after-find-file
|
2018-05-14 18:40:35 +02:00
|
|
|
:commands recentf-open-files
|
2017-06-05 23:00:50 +02:00
|
|
|
:config
|
2017-12-23 14:30:36 -05:00
|
|
|
(setq recentf-save-file (concat doom-cache-dir "recentf")
|
2018-05-20 20:07:46 +02:00
|
|
|
recentf-auto-cleanup 120
|
2017-06-05 23:00:50 +02:00
|
|
|
recentf-max-menu-items 0
|
2017-06-11 23:50:50 +02:00
|
|
|
recentf-max-saved-items 300
|
2017-12-22 15:22:42 -05:00
|
|
|
recentf-filename-handlers '(file-truename)
|
2017-06-11 23:50:50 +02:00
|
|
|
recentf-exclude
|
2018-05-20 20:07:46 +02:00
|
|
|
(list #'file-remote-p "\\.\\(?:gz\\|gif\\|svg\\|png\\|jpe?g\\)$"
|
2018-03-14 18:28:48 -04:00
|
|
|
"^/tmp/" "^/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
|
2017-06-11 23:50:50 +02:00
|
|
|
"^/var/folders/.+$"
|
|
|
|
;; ignore private DOOM temp files (but not all of them)
|
2018-05-20 20:07:46 +02:00
|
|
|
(lambda (file) (file-in-directory-p file doom-local-dir))))
|
2018-05-14 18:40:35 +02:00
|
|
|
(recentf-mode +1))
|
|
|
|
|
2018-06-15 21:44:44 +02:00
|
|
|
(def-package! server
|
|
|
|
:when (display-graphic-p)
|
|
|
|
:defer 1
|
|
|
|
:after-call (pre-command-hook after-find-file)
|
|
|
|
:config
|
|
|
|
(unless (server-running-p)
|
|
|
|
(server-start)))
|
|
|
|
|
2017-06-05 23:00:50 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-01-31 19:50:46 -05:00
|
|
|
;; Core Plugins
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
|
|
|
|
2017-01-31 19:50:46 -05:00
|
|
|
;; Auto-close delimiters and blocks as you type
|
2017-06-05 23:00:50 +02:00
|
|
|
(def-package! smartparens
|
2018-06-14 00:08:16 +02:00
|
|
|
:after-call (doom-before-switch-buffer-hook after-find-file)
|
2018-05-16 00:58:03 +02:00
|
|
|
:commands (sp-pair sp-local-pair sp-with-modes)
|
2017-07-26 18:49:08 +02:00
|
|
|
:config
|
2017-12-08 22:33:12 -05:00
|
|
|
(require 'smartparens-config)
|
2018-05-02 15:53:51 +02:00
|
|
|
(setq sp-highlight-pair-overlay nil
|
2018-06-17 02:12:14 +02:00
|
|
|
sp-highlight-wrap-overlay nil
|
|
|
|
sp-highlight-wrap-tag-overlay nil
|
|
|
|
sp-show-pair-from-inside t
|
2017-01-16 23:15:48 -05:00
|
|
|
sp-cancel-autoskip-on-backward-movement nil
|
2018-06-17 02:12:14 +02:00
|
|
|
sp-show-pair-delay 0.1
|
2017-01-16 23:15:48 -05:00
|
|
|
sp-max-pair-length 3)
|
2015-06-06 06:40:33 -04:00
|
|
|
|
2018-05-11 20:22:05 +02:00
|
|
|
;; smartparens conflicts with evil-mode's replace state
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook 'evil-replace-state-entry-hook #'turn-off-smartparens-mode)
|
|
|
|
(add-hook 'evil-replace-state-exit-hook #'turn-on-smartparens-mode)
|
2017-07-26 18:49:08 +02:00
|
|
|
|
2018-06-16 11:41:07 +02:00
|
|
|
(defun doom|init-smartparens-in-eval-expression ()
|
2018-06-16 12:40:57 +02:00
|
|
|
"Enable `smartparens-mode' in the minibuffer, during `eval-expression' or
|
|
|
|
`evil-ex'."
|
|
|
|
(when (memq this-command '(eval-expression evil-ex))
|
2018-06-16 11:41:07 +02:00
|
|
|
(smartparens-mode)))
|
|
|
|
(add-hook 'minibuffer-setup-hook #'doom|init-smartparens-in-eval-expression)
|
|
|
|
|
2018-06-16 12:40:57 +02:00
|
|
|
(sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil)
|
2017-06-16 02:06:21 +02:00
|
|
|
(sp-local-pair '(xml-mode nxml-mode php-mode) "<!--" "-->"
|
2018-05-14 18:40:35 +02:00
|
|
|
:post-handlers '(("| " "SPC")))
|
|
|
|
|
|
|
|
(smartparens-global-mode +1))
|
2016-03-23 11:59:06 -04:00
|
|
|
|
2017-06-23 17:28:32 +02:00
|
|
|
;; Branching undo
|
2017-06-05 03:15:21 +02:00
|
|
|
(def-package! undo-tree
|
2018-06-14 00:08:16 +02:00
|
|
|
:after-call (doom-before-switch-buffer-hook after-find-file)
|
2017-06-05 03:15:21 +02:00
|
|
|
:config
|
2017-06-23 17:28:32 +02:00
|
|
|
;; persistent undo history is known to cause undo history corruption, which
|
|
|
|
;; can be very destructive! So disable it!
|
2017-07-11 00:40:24 +02:00
|
|
|
(setq undo-tree-auto-save-history nil
|
2017-06-16 02:06:21 +02:00
|
|
|
undo-tree-history-directory-alist
|
2018-05-15 10:48:42 +02:00
|
|
|
(list (cons "." (concat doom-cache-dir "undo-tree-hist/"))))
|
|
|
|
(global-undo-tree-mode +1))
|
2017-06-05 03:15:21 +02:00
|
|
|
|
2016-03-03 15:04:14 -05:00
|
|
|
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
;; Autoloaded Plugins
|
2016-03-03 15:04:14 -05:00
|
|
|
;;
|
2015-06-06 06:40:33 -04:00
|
|
|
|
2018-06-14 00:38:44 +02:00
|
|
|
(setq command-log-mode-auto-show t
|
|
|
|
command-log-mode-open-log-turns-on-mode t)
|
2016-06-08 21:08:19 -04:00
|
|
|
|
2018-05-18 01:28:40 +02:00
|
|
|
(def-package! dtrt-indent
|
2018-06-14 00:38:44 +02:00
|
|
|
:unless noninteractive
|
|
|
|
:defer t
|
|
|
|
:init
|
2018-05-18 01:28:40 +02:00
|
|
|
(defun doom|detect-indentation ()
|
2018-05-26 03:06:45 +02:00
|
|
|
(unless (or doom-inhibit-indent-detection
|
2018-06-14 00:38:44 +02:00
|
|
|
buffer-read-only
|
|
|
|
(not (derived-mode-p 'prog-mode 'text-mode 'conf-mode)))
|
2018-05-18 01:28:40 +02:00
|
|
|
(dtrt-indent-mode +1)))
|
2018-06-14 00:38:44 +02:00
|
|
|
(add-hook! (prog-mode text-mode conf-mode)
|
|
|
|
#'doom|detect-indentation)
|
|
|
|
:config
|
|
|
|
(setq dtrt-indent-verbosity (if doom-debug-mode 2 0)))
|
2018-05-18 01:28:40 +02:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! expand-region
|
2018-06-14 00:38:44 +02:00
|
|
|
:commands (er/contract-region er/mark-symbol er/mark-word)
|
2018-01-02 13:50:35 -05:00
|
|
|
:config
|
|
|
|
(defun doom*quit-expand-region ()
|
|
|
|
(when (memq last-command '(er/expand-region er/contract-region))
|
|
|
|
(er/contract-region 0)))
|
2018-02-01 19:57:46 -05:00
|
|
|
(advice-add #'evil-escape :before #'doom*quit-expand-region)
|
|
|
|
(advice-add #'doom/escape :before #'doom*quit-expand-region))
|
2015-06-06 06:40:33 -04:00
|
|
|
|
2018-01-21 21:37:15 -05:00
|
|
|
(def-package! helpful
|
2018-06-14 00:38:44 +02:00
|
|
|
:defer t
|
2018-01-21 21:37:15 -05:00
|
|
|
:init
|
|
|
|
(setq counsel-describe-function-function #'helpful-callable
|
|
|
|
counsel-describe-variable-function #'helpful-variable)
|
|
|
|
|
2018-06-14 00:38:44 +02:00
|
|
|
(define-key! 'global
|
|
|
|
[remap describe-function] #'helpful-callable
|
|
|
|
[remap describe-command] #'helpful-command
|
|
|
|
[remap describe-variable] #'helpful-variable
|
|
|
|
[remap describe-key] #'helpful-key))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
(provide 'core-editor)
|
|
|
|
;;; core-editor.el ends here
|