2017-06-08 17:47:56 +08:00
|
|
|
|
;;; core-editor.el -*- lexical-binding: t; -*-
|
2017-01-17 12:15:48 +08:00
|
|
|
|
|
2017-05-06 23:53:10 +08:00
|
|
|
|
(defvar doom-large-file-size 1
|
2017-05-07 04:55:10 +08: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 23:53:10 +08:00
|
|
|
|
|
2017-05-07 04:55:10 +08:00
|
|
|
|
(defvar doom-large-file-modes-list
|
2017-05-06 23:53:10 +08:00
|
|
|
|
'(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-07 04:55:10 +08:00
|
|
|
|
"Major modes that `doom|check-large-file' will ignore.")
|
2017-05-06 23:53:10 +08:00
|
|
|
|
|
2017-02-20 07:11:28 +08:00
|
|
|
|
(setq-default
|
2017-06-16 08:06:21 +08:00
|
|
|
|
vc-follow-symlinks t
|
2017-02-20 07:11:28 +08:00
|
|
|
|
;; Save clipboard contents into kill-ring before replacing them
|
|
|
|
|
save-interprogram-paste-before-kill t
|
|
|
|
|
;; Bookmarks
|
2017-11-05 05:34:55 +08:00
|
|
|
|
bookmark-default-file (concat doom-etc-dir "bookmarks")
|
2017-02-20 07:11:28 +08:00
|
|
|
|
bookmark-save-flag t
|
|
|
|
|
;; Formatting
|
|
|
|
|
delete-trailing-lines nil
|
|
|
|
|
fill-column 80
|
|
|
|
|
sentence-end-double-space nil
|
2017-06-06 05:00:50 +08:00
|
|
|
|
word-wrap t
|
2017-02-20 07:11:28 +08:00
|
|
|
|
;; Scrolling
|
|
|
|
|
hscroll-margin 1
|
|
|
|
|
hscroll-step 1
|
|
|
|
|
scroll-conservatively 1001
|
|
|
|
|
scroll-margin 0
|
|
|
|
|
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 08:06:21 +08:00
|
|
|
|
tabify-regexp "^\t* [ \t]+" ; for :retab
|
2017-02-20 07:11:28 +08:00
|
|
|
|
;; Wrapping
|
|
|
|
|
truncate-lines t
|
|
|
|
|
truncate-partial-width-windows 50
|
2017-06-15 20:24:54 +08:00
|
|
|
|
;; whitespace-mode
|
|
|
|
|
whitespace-line-column fill-column
|
|
|
|
|
whitespace-style
|
|
|
|
|
'(face indentation tabs tab-mark spaces space-mark newline newline-mark
|
|
|
|
|
trailing lines-tail)
|
|
|
|
|
whitespace-display-mappings
|
|
|
|
|
'((tab-mark ?\t [?› ?\t])
|
2017-06-16 08:06:21 +08:00
|
|
|
|
(newline-mark ?\n [?¬ ?\n])
|
|
|
|
|
(space-mark ?\ [?·] [?.])))
|
|
|
|
|
|
2017-12-09 11:57:08 +08:00
|
|
|
|
;; ediff
|
|
|
|
|
(setq ediff-diff-options "-w"
|
|
|
|
|
ediff-split-window-function #'split-window-horizontally
|
|
|
|
|
ediff-window-setup-function #'ediff-setup-windows-plain)
|
2017-02-01 08:50:46 +08:00
|
|
|
|
|
2017-02-21 08:43:57 +08:00
|
|
|
|
(defun doom|dont-kill-scratch-buffer ()
|
2017-06-06 05:00:50 +08:00
|
|
|
|
"Don't kill the scratch buffer."
|
2017-05-21 14:27:42 +08:00
|
|
|
|
(or (not (string= (buffer-name) "*scratch*"))
|
2017-03-16 10:59:21 +08:00
|
|
|
|
(ignore (bury-buffer))))
|
2017-04-17 14:17:10 +08:00
|
|
|
|
(add-hook 'kill-buffer-query-functions #'doom|dont-kill-scratch-buffer)
|
2017-02-21 08:43:57 +08:00
|
|
|
|
|
2018-01-02 05:30:22 +08:00
|
|
|
|
;; temporary windows often have q bound to `quit-window', which only buries the
|
|
|
|
|
;; contained buffer. I rarely don't want that buffer killed, so...
|
|
|
|
|
(defun doom*quit-window (orig-fn &optional kill window)
|
|
|
|
|
(funcall orig-fn (not kill) window))
|
|
|
|
|
(advice-add #'quit-window :around #'doom*quit-window)
|
|
|
|
|
|
2017-05-07 04:55:10 +08:00
|
|
|
|
(defun doom|check-large-file ()
|
2017-06-06 05:00:50 +08: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."
|
2017-05-07 04:55:10 +08:00
|
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
|
(size (nth 7 (file-attributes filename))))
|
|
|
|
|
(when (and (not (memq major-mode doom-large-file-modes-list))
|
|
|
|
|
size (> 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 filename))))
|
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
|
(buffer-disable-undo)
|
|
|
|
|
(fundamental-mode))))
|
|
|
|
|
(add-hook 'find-file-hook #'doom|check-large-file)
|
2017-05-06 23:53:10 +08:00
|
|
|
|
|
2017-10-24 02:08:18 +08:00
|
|
|
|
(push '("/LICENSE$" . text-mode) auto-mode-alist)
|
|
|
|
|
|
2017-01-17 12:15:48 +08:00
|
|
|
|
|
2017-06-06 05:00:50 +08:00
|
|
|
|
;;
|
|
|
|
|
;; Built-in plugins
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
;; revert buffers for changed files
|
|
|
|
|
(global-auto-revert-mode 1)
|
|
|
|
|
(setq auto-revert-verbose nil)
|
|
|
|
|
|
|
|
|
|
;; enabled by default in Emacs 25+. No thanks.
|
|
|
|
|
(electric-indent-mode -1)
|
|
|
|
|
|
|
|
|
|
;; savehist / saveplace
|
|
|
|
|
(setq savehist-file (concat doom-cache-dir "savehist")
|
2017-09-13 21:24:37 +08:00
|
|
|
|
savehist-save-minibuffer-history t
|
2017-06-06 05:00:50 +08:00
|
|
|
|
savehist-autosave-interval nil ; save on kill only
|
|
|
|
|
savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
|
|
|
|
|
save-place-file (concat doom-cache-dir "saveplace"))
|
2017-06-12 06:20:30 +08:00
|
|
|
|
(add-hook! 'doom-init-hook #'(savehist-mode save-place-mode))
|
2017-06-06 05:00:50 +08:00
|
|
|
|
|
|
|
|
|
;; Keep track of recently opened files
|
|
|
|
|
(def-package! recentf
|
2017-12-09 11:33:12 +08:00
|
|
|
|
:hook (doom-init . recentf-mode)
|
2017-06-06 05:00:50 +08:00
|
|
|
|
:config
|
2017-12-24 03:30:36 +08:00
|
|
|
|
(setq recentf-save-file (concat doom-cache-dir "recentf")
|
2017-06-06 05:00:50 +08:00
|
|
|
|
recentf-max-menu-items 0
|
2017-06-12 05:50:50 +08:00
|
|
|
|
recentf-max-saved-items 300
|
2017-12-23 04:22:42 +08:00
|
|
|
|
recentf-filename-handlers '(file-truename)
|
2017-06-12 05:50:50 +08:00
|
|
|
|
recentf-exclude
|
|
|
|
|
(list "^/tmp/" "^/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
|
|
|
|
|
"^/var/folders/.+$"
|
|
|
|
|
;; ignore private DOOM temp files (but not all of them)
|
2017-12-24 05:15:29 +08:00
|
|
|
|
(concat "^" (file-truename doom-local-dir)))))
|
2017-06-06 05:00:50 +08:00
|
|
|
|
|
|
|
|
|
|
2017-01-17 12:15:48 +08:00
|
|
|
|
;;
|
2017-02-01 08:50:46 +08:00
|
|
|
|
;; Core Plugins
|
2017-01-17 12:15:48 +08:00
|
|
|
|
;;
|
|
|
|
|
|
2017-02-01 08:50:46 +08:00
|
|
|
|
;; Handles whitespace (tabs/spaces) settings externally. This way projects can
|
|
|
|
|
;; specify their own formatting rules.
|
2017-06-05 09:15:21 +08:00
|
|
|
|
(def-package! editorconfig
|
2017-03-02 08:16:22 +08:00
|
|
|
|
:config
|
2017-06-12 06:20:30 +08:00
|
|
|
|
(add-hook 'doom-init-hook #'editorconfig-mode)
|
2017-06-08 17:47:56 +08:00
|
|
|
|
|
2017-10-18 22:52:00 +08:00
|
|
|
|
;; editorconfig cannot procure the correct settings for extension-less files.
|
|
|
|
|
;; Executable scripts with a shebang line, for example. So why not use Emacs'
|
|
|
|
|
;; major mode to drop editorconfig a hint? This is accomplished by temporarily
|
|
|
|
|
;; appending an extension to `buffer-file-name' when we talk to editorconfig.
|
|
|
|
|
(defvar doom-editorconfig-mode-alist
|
|
|
|
|
'((sh-mode . "sh")
|
|
|
|
|
(python-mode . "py")
|
|
|
|
|
(ruby-mode . "rb")
|
|
|
|
|
(perl-mode . "pl")
|
|
|
|
|
(php-mode . "php"))
|
|
|
|
|
"An alist mapping major modes to extensions. Used by
|
|
|
|
|
`doom*editorconfig-smart-detection' to give editorconfig filetype hints.")
|
|
|
|
|
|
|
|
|
|
(defun doom*editorconfig-smart-detection (orig-fn &rest args)
|
|
|
|
|
"Retrieve the properties for the current file. If it doesn't have an
|
|
|
|
|
extension, try to guess one."
|
|
|
|
|
(let ((buffer-file-name
|
|
|
|
|
(if (file-name-extension buffer-file-name)
|
|
|
|
|
buffer-file-name
|
|
|
|
|
(format "%s%s" buffer-file-name
|
|
|
|
|
(let ((ext (cdr (assq major-mode doom-editorconfig-mode-alist))))
|
|
|
|
|
(or (and ext (concat "." ext))
|
|
|
|
|
""))))))
|
|
|
|
|
(apply orig-fn args)))
|
|
|
|
|
(advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection)
|
|
|
|
|
|
2017-12-09 11:38:49 +08:00
|
|
|
|
;; Editorconfig makes indentation too rigid in Lisp modes, so tell
|
|
|
|
|
;; editorconfig to ignore indentation. I prefer dynamic indentation support
|
|
|
|
|
;; built into Emacs.
|
|
|
|
|
(dolist (mode '(emacs-lisp-mode lisp-mode))
|
|
|
|
|
(setq editorconfig-indentation-alist
|
|
|
|
|
(assq-delete-all mode editorconfig-indentation-alist)))
|
2017-06-15 20:37:16 +08:00
|
|
|
|
|
2017-06-19 18:41:30 +08:00
|
|
|
|
(defvar whitespace-style)
|
2017-06-08 17:47:56 +08:00
|
|
|
|
(defun doom|editorconfig-whitespace-mode-maybe (&rest _)
|
|
|
|
|
"Show whitespace-mode when file uses TABS (ew)."
|
2017-06-15 20:24:54 +08:00
|
|
|
|
(when indent-tabs-mode
|
|
|
|
|
(let ((whitespace-style '(face tabs tab-mark trailing-lines tail)))
|
|
|
|
|
(whitespace-mode +1))))
|
2017-06-08 17:47:56 +08:00
|
|
|
|
(add-hook 'editorconfig-custom-hooks #'doom|editorconfig-whitespace-mode-maybe))
|
2016-04-24 10:08:46 +08:00
|
|
|
|
|
2017-10-03 01:57:46 +08:00
|
|
|
|
(def-package! editorconfig-conf-mode
|
|
|
|
|
:mode "\\.?editorconfig$")
|
|
|
|
|
|
2017-02-01 08:50:46 +08:00
|
|
|
|
;; Auto-close delimiters and blocks as you type
|
2017-06-06 05:00:50 +08:00
|
|
|
|
(def-package! smartparens
|
2018-01-01 12:18:07 +08:00
|
|
|
|
:hook (doom-init . smartparens-global-mode)
|
2017-07-27 00:49:08 +08:00
|
|
|
|
:config
|
2017-12-09 11:33:12 +08:00
|
|
|
|
(require 'smartparens-config)
|
|
|
|
|
|
2017-03-05 09:54:13 +08:00
|
|
|
|
(setq sp-autowrap-region nil ; let evil-surround handle this
|
2017-01-17 12:15:48 +08:00
|
|
|
|
sp-highlight-pair-overlay nil
|
|
|
|
|
sp-cancel-autoskip-on-backward-movement nil
|
|
|
|
|
sp-show-pair-delay 0
|
|
|
|
|
sp-max-pair-length 3)
|
2015-06-06 18:40:33 +08:00
|
|
|
|
|
2017-09-02 22:11:14 +08:00
|
|
|
|
;; disable smartparens in evil-mode's replace state (they conflict)
|
2017-04-17 14:17:10 +08: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-27 00:49:08 +08:00
|
|
|
|
|
2017-06-16 08:06:21 +08:00
|
|
|
|
(sp-local-pair '(xml-mode nxml-mode php-mode) "<!--" "-->"
|
|
|
|
|
:post-handlers '(("| " "SPC"))))
|
2016-03-23 23:59:06 +08:00
|
|
|
|
|
2017-06-23 23:28:32 +08:00
|
|
|
|
;; Branching undo
|
2017-06-05 09:15:21 +08:00
|
|
|
|
(def-package! undo-tree
|
|
|
|
|
:config
|
2017-12-09 11:33:12 +08:00
|
|
|
|
(add-hook 'doom-init-hook #'global-undo-tree-mode)
|
2017-06-23 23:28:32 +08:00
|
|
|
|
;; persistent undo history is known to cause undo history corruption, which
|
|
|
|
|
;; can be very destructive! So disable it!
|
2017-07-11 06:40:24 +08:00
|
|
|
|
(setq undo-tree-auto-save-history nil
|
2017-06-16 08:06:21 +08:00
|
|
|
|
undo-tree-history-directory-alist
|
2017-07-11 06:40:24 +08:00
|
|
|
|
(list (cons "." (concat doom-cache-dir "undo-tree-hist/")))))
|
2017-06-05 09:15:21 +08:00
|
|
|
|
|
2016-03-04 04:04:14 +08:00
|
|
|
|
|
|
|
|
|
;;
|
2017-01-17 12:15:48 +08:00
|
|
|
|
;; Autoloaded Plugins
|
2016-03-04 04:04:14 +08:00
|
|
|
|
;;
|
2015-06-06 18:40:33 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! ace-link
|
2017-02-20 07:11:28 +08:00
|
|
|
|
:commands (ace-link-help ace-link-org))
|
2017-01-17 12:15:48 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! avy
|
2016-04-17 09:27:59 +08:00
|
|
|
|
:commands (avy-goto-char-2 avy-goto-line)
|
2017-02-20 07:11:28 +08:00
|
|
|
|
:config
|
|
|
|
|
(setq avy-all-windows nil
|
|
|
|
|
avy-background t))
|
2016-04-17 09:27:59 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! command-log-mode
|
2017-02-09 17:22:08 +08:00
|
|
|
|
:commands (command-log-mode global-command-log-mode)
|
|
|
|
|
:config
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(set! :popup "*command-log*" :size 40 :align 'right :noselect t)
|
2017-02-09 17:22:08 +08:00
|
|
|
|
(setq command-log-mode-auto-show t
|
|
|
|
|
command-log-mode-open-log-turns-on-mode t))
|
2016-06-09 09:08:19 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! expand-region
|
2018-01-03 02:50:35 +08:00
|
|
|
|
:commands (er/expand-region er/contract-region er/mark-symbol er/mark-word)
|
|
|
|
|
:config
|
|
|
|
|
(defun doom*quit-expand-region ()
|
|
|
|
|
(when (memq last-command '(er/expand-region er/contract-region))
|
|
|
|
|
(er/contract-region 0)))
|
|
|
|
|
(advice-add #'evil-escape :before #'doom*quit-expand-region))
|
2015-06-06 18:40:33 +08:00
|
|
|
|
|
2017-12-11 00:48:58 +08:00
|
|
|
|
(def-package! help-fns+ ; Improved help commands
|
|
|
|
|
:commands (describe-buffer describe-command describe-file
|
|
|
|
|
describe-keymap describe-option describe-option-of-type))
|
2016-10-03 05:21:47 +08:00
|
|
|
|
|
2017-12-09 11:57:08 +08:00
|
|
|
|
(def-package! pcre2el
|
|
|
|
|
:commands rxt-quote-pcre)
|
2017-01-17 12:15:48 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! smart-forward
|
2016-10-09 01:38:58 +08:00
|
|
|
|
:commands (smart-up smart-down smart-backward smart-forward))
|
2015-06-06 18:40:33 +08:00
|
|
|
|
|
2017-02-23 13:06:12 +08:00
|
|
|
|
(def-package! wgrep
|
2016-06-13 14:11:33 +08:00
|
|
|
|
:commands (wgrep-setup wgrep-change-to-wgrep-mode)
|
2017-12-09 11:57:08 +08:00
|
|
|
|
:config (setq wgrep-auto-save-buffer t))
|
2016-06-13 14:11:33 +08:00
|
|
|
|
|
2015-06-05 06:23:21 +08:00
|
|
|
|
(provide 'core-editor)
|
|
|
|
|
;;; core-editor.el ends here
|