doomemacs/core/core-editor.el

208 lines
6.5 KiB
EmacsLisp
Raw Normal View History

;;; core-editor.el -*- lexical-binding: t; -*-
2017-01-17 12:15:48 +08:00
(defvar doom-large-file-size 1
"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.")
(defvar doom-large-file-modes-list
'(archive-mode tar-mode jka-compr git-commit-mode image-mode
doc-view-mode doc-view-mode-maybe ebrowse-tree-mode pdf-view-mode)
"Major modes that `doom|check-large-file' will ignore.")
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
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
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-16 08:06:21 +08:00
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
(defun doom|check-large-file ()
"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-05-08 00:14:45 +08:00
(let ((size (nth 7 (file-attributes buffer-file-name))))
(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?")
2018-05-08 00:14:45 +08:00
(file-relative-name buffer-file-name))))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode))))
(add-hook 'find-file-hook #'doom|check-large-file)
2017-01-17 12:15:48 +08:00
;;
;; Built-in plugins
;;
(electric-indent-mode -1) ; enabled by default in Emacs 25+. No thanks.
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
;; revert buffers for changed files
(def-package! autorevert
:defer buffer
:config
(setq auto-revert-verbose nil)
(global-auto-revert-mode +1))
;; persist variables across sessions
(def-package! savehist
:defer (input . 1)
: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
:defer buffer
: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))
;; Keep track of recently opened files
(def-package! recentf
:defer (input . 1)
:commands recentf-open-files
:config
(setq recentf-save-file (concat doom-cache-dir "recentf")
recentf-auto-cleanup 60
recentf-max-menu-items 0
recentf-max-saved-items 300
recentf-filename-handlers '(file-truename)
recentf-exclude
(list #'file-remote-p "\\.\\(gz\\|gif\\|svg\\|png\\|jpe?g\\)$"
"^/tmp/" "^/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
"^/var/folders/.+$"
;; ignore private DOOM temp files (but not all of them)
(concat "^" (file-truename doom-local-dir))))
(recentf-mode +1))
(def-package! server
:when (display-graphic-p)
:defer 2
:config
(unless (server-running-p)
(server-start)))
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
;; Auto-close delimiters and blocks as you type
(def-package! smartparens
:defer (buffer . 2)
2017-07-27 00:49:08 +08:00
:config
(require 'smartparens-config)
(setq sp-highlight-pair-overlay nil
2017-01-17 12:15:48 +08:00
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
2018-05-12 02:22:05 +08:00
;; smartparens conflicts with evil-mode's replace state
(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")))
(smartparens-global-mode +1))
2016-03-23 23:59:06 +08:00
;; Branching undo
(def-package! undo-tree
:defer input
:config
(global-undo-tree-mode +1)
;; persistent undo history is known to cause undo history corruption, which
;; can be very destructive! So disable it!
(setq undo-tree-auto-save-history nil
2017-06-16 08:06:21 +08:00
undo-tree-history-directory-alist
(list (cons "." (concat doom-cache-dir "undo-tree-hist/")))))
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
(def-package! ace-link
2018-05-13 02:05:16 +08:00
:commands (ace-link-help ace-link-org ace-link-addr))
2017-01-17 12:15:48 +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
(def-package! command-log-mode
:commands (command-log-mode global-command-log-mode)
:config
(setq command-log-mode-auto-show t
command-log-mode-open-log-turns-on-mode t))
2016-06-09 09:08:19 +08:00
(def-package! expand-region
: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)
(advice-add #'doom/escape :before #'doom*quit-expand-region))
2015-06-06 18:40:33 +08:00
(def-package! helpful
:commands (helpful-callable helpful-function helpful-macro helpful-command
helpful-key helpful-variable helpful-at-point)
:init
(setq counsel-describe-function-function #'helpful-callable
counsel-describe-variable-function #'helpful-variable)
(global-set-key [remap describe-function] #'helpful-callable)
(global-set-key [remap describe-command] #'helpful-command)
(global-set-key [remap describe-variable] #'helpful-variable)
(global-set-key [remap describe-key] #'helpful-key)
(advice-add #'helpful--pretty-print :override #'doom*fix-helpful-prettyprint))
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
2015-06-05 06:23:21 +08:00
(provide 'core-editor)
;;; core-editor.el ends here