2017-01-16 23:15:48 -05:00
|
|
|
|
;;; core-editor.el --- filling the editor shaped hole in the Emacs OS
|
|
|
|
|
|
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
|
2017-05-06 11:53:10 -04: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-06 22:55:10 +02:00
|
|
|
|
"Major modes that `doom|check-large-file' will ignore.")
|
2017-05-06 11:53:10 -04:00
|
|
|
|
|
2017-02-19 18:11:28 -05:00
|
|
|
|
(setq-default
|
|
|
|
|
;; Save clipboard contents into kill-ring before replacing them
|
|
|
|
|
save-interprogram-paste-before-kill t
|
|
|
|
|
;; Bookmarks
|
2017-02-20 20:41:58 -05:00
|
|
|
|
bookmark-default-file (concat doom-cache-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
|
|
|
|
|
;; 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
|
|
|
|
|
tabify-regexp "^\t* [ \t]+" ; for :retab
|
|
|
|
|
whitespace-line-column fill-column
|
|
|
|
|
whitespace-style
|
|
|
|
|
'(face tabs tab-mark trailing lines-tail)
|
|
|
|
|
whitespace-display-mappings
|
|
|
|
|
'((tab-mark ?\t [?› ?\t]) (newline-mark 10 [36 10]))
|
|
|
|
|
;; Wrapping
|
|
|
|
|
truncate-lines t
|
|
|
|
|
truncate-partial-width-windows 50
|
|
|
|
|
visual-fill-column-center-text nil
|
2017-02-20 20:41:30 -05:00
|
|
|
|
word-wrap t
|
|
|
|
|
vc-follow-symlinks t)
|
2017-01-31 19:50:46 -05:00
|
|
|
|
|
2017-02-08 02:20:26 -05:00
|
|
|
|
;; Save point across sessions
|
|
|
|
|
(require 'saveplace)
|
2017-02-11 00:50:50 -05:00
|
|
|
|
(setq save-place-file (concat doom-cache-dir "saveplace"))
|
2017-02-21 00:47:34 -05:00
|
|
|
|
(save-place-mode +1)
|
2017-01-31 19:50:46 -05:00
|
|
|
|
|
2017-02-08 02:20:26 -05:00
|
|
|
|
;; Save history across sessions
|
|
|
|
|
(require 'savehist)
|
|
|
|
|
(setq savehist-file (concat doom-cache-dir "savehist")
|
|
|
|
|
savehist-save-minibuffer-history t
|
2017-02-20 00:40:38 -05:00
|
|
|
|
savehist-autosave-interval nil ; save on kill only
|
2017-02-08 02:20:26 -05:00
|
|
|
|
savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
|
|
|
|
|
(savehist-mode 1)
|
2017-01-31 19:50:46 -05:00
|
|
|
|
|
2017-02-08 02:20:26 -05:00
|
|
|
|
;; Keep track of recently opened files
|
|
|
|
|
(require 'recentf)
|
|
|
|
|
(setq recentf-save-file (concat doom-cache-dir "recentf")
|
2017-03-27 13:05:30 -04:00
|
|
|
|
recentf-exclude (list "/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
|
|
|
|
|
"^/var/folders/.+$" doom-local-dir)
|
2017-02-08 02:20:26 -05:00
|
|
|
|
recentf-max-menu-items 0
|
|
|
|
|
recentf-max-saved-items 250
|
|
|
|
|
recentf-filename-handlers '(abbreviate-file-name))
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(quiet! (recentf-mode 1))
|
2017-01-31 19:50:46 -05:00
|
|
|
|
|
2017-05-14 09:49:09 +02:00
|
|
|
|
;; Ediff: use existing frame instead of creating a new one
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(add-hook! ediff-load
|
2017-02-08 02:20:26 -05:00
|
|
|
|
(setq ediff-diff-options "-w"
|
2017-04-17 02:17:10 -04:00
|
|
|
|
ediff-split-window-function #'split-window-horizontally
|
|
|
|
|
ediff-window-setup-function #'ediff-setup-windows-plain)) ; no extra frames
|
2017-01-31 19:50:46 -05:00
|
|
|
|
|
2017-02-08 02:20:26 -05:00
|
|
|
|
;; revert buffers for changed files
|
|
|
|
|
(global-auto-revert-mode 1)
|
|
|
|
|
(setq auto-revert-verbose nil)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-20 19:43:57 -05:00
|
|
|
|
;; don't kill scratch buffers
|
|
|
|
|
(defun doom|dont-kill-scratch-buffer ()
|
2017-03-15 22:59:21 -04:00
|
|
|
|
(or (not (eq (buffer-name) "*scratch*"))
|
|
|
|
|
(ignore (bury-buffer))))
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(add-hook 'kill-buffer-query-functions #'doom|dont-kill-scratch-buffer)
|
2017-02-20 19:43:57 -05:00
|
|
|
|
|
2017-02-20 20:42:37 -05:00
|
|
|
|
;; enabled by default in Emacs 25+. No thanks.
|
|
|
|
|
(electric-indent-mode -1)
|
|
|
|
|
|
2017-03-22 00:33:39 -04:00
|
|
|
|
(defun doom*delete-trailing-whitespace (orig-fn &rest args)
|
|
|
|
|
"Don't affect trailing whitespace on current line."
|
|
|
|
|
(let ((spaces (1- (current-column)))
|
|
|
|
|
(linestr (buffer-substring-no-properties
|
|
|
|
|
(line-beginning-position)
|
|
|
|
|
(line-end-position))))
|
|
|
|
|
(apply orig-fn args)
|
|
|
|
|
(when (and (if (featurep 'evil) (evil-insert-state-p) t)
|
|
|
|
|
(string-match-p "^[\s\t]*$" linestr))
|
|
|
|
|
(insert linestr))))
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(advice-add #'delete-trailing-whitespace :around #'doom*delete-trailing-whitespace)
|
2017-03-22 00:33:39 -04:00
|
|
|
|
|
2017-05-06 22:55:10 +02:00
|
|
|
|
(defun doom|check-large-file ()
|
|
|
|
|
"Check if the buffer's file is large. If so, ask for confirmation to open it
|
|
|
|
|
literally (read-only, disabled undo and in fundamental-mode) for performance
|
|
|
|
|
sake."
|
|
|
|
|
(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 11:53:10 -04: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
|
|
|
|
;; Handles whitespace (tabs/spaces) settings externally. This way projects can
|
|
|
|
|
;; specify their own formatting rules.
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! editorconfig :demand t
|
2016-05-20 19:08:02 -04:00
|
|
|
|
:mode ("\\.?editorconfig$" . editorconfig-conf-mode)
|
2017-03-01 19:16:22 -05:00
|
|
|
|
:init
|
|
|
|
|
(def-setting! :editorconfig (action value)
|
|
|
|
|
`(after! editorconfig
|
|
|
|
|
,(cond ((eq action :add)
|
|
|
|
|
`(push ',value editorconfig-indentation-alist))
|
|
|
|
|
((eq action :remove)
|
|
|
|
|
(unless (symbolp value)
|
|
|
|
|
(error "%s is not a valid major-mode in editorconfig-indentation-alist" value))
|
|
|
|
|
`(setq editorconfig-indentation-alist
|
|
|
|
|
(delq (assq ',value editorconfig-indentation-alist)
|
|
|
|
|
editorconfig-indentation-alist)))
|
|
|
|
|
(t (error "%s is an invalid action for :editorconfig" action)))))
|
|
|
|
|
|
|
|
|
|
:config
|
|
|
|
|
(editorconfig-mode +1)
|
2016-05-20 19:08:02 -04:00
|
|
|
|
;; Show whitespace in tabs indentation mode
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(add-hook! 'editorconfig-custom-hooks
|
2016-05-12 22:11:43 -04:00
|
|
|
|
(if indent-tabs-mode (whitespace-mode +1))))
|
2016-04-23 22:08:46 -04:00
|
|
|
|
|
2017-01-31 19:50:46 -05:00
|
|
|
|
;; Auto-close delimiters and blocks as you type
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! smartparens :demand t
|
2017-01-16 23:15:48 -05:00
|
|
|
|
:init
|
2017-03-04 20:54:13 -05:00
|
|
|
|
(setq sp-autowrap-region nil ; let evil-surround handle this
|
2017-01-16 23:15:48 -05: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 06:40:33 -04:00
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
:config
|
|
|
|
|
(smartparens-global-mode 1)
|
|
|
|
|
(require 'smartparens-config)
|
|
|
|
|
;; Smartparens interferes with Replace mode
|
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-01-16 23:15:48 -05:00
|
|
|
|
;; Auto-close more conservatively
|
2017-03-04 20:51:35 -05:00
|
|
|
|
(sp-pair "'" nil :unless '(sp-point-before-word-p sp-point-after-word-p sp-point-before-same-p))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
(sp-pair "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p sp-point-before-same-p))
|
|
|
|
|
(sp-pair "{" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
|
|
|
|
|
:unless '(sp-point-before-word-p sp-point-before-same-p))
|
|
|
|
|
(sp-pair "(" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
|
|
|
|
|
:unless '(sp-point-before-word-p sp-point-before-same-p))
|
|
|
|
|
(sp-pair "[" nil :post-handlers '(("| " " "))
|
|
|
|
|
:unless '(sp-point-before-word-p sp-point-before-same-p))
|
2016-01-30 21:16:10 -05:00
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
(sp-local-pair
|
|
|
|
|
'css-mode "/*" "*/" :post-handlers '(("[d-3]||\n[i]" "RET") ("| " "SPC")))
|
|
|
|
|
(sp-local-pair '(sh-mode markdown-mode) "`" nil
|
|
|
|
|
:unless '(sp-point-before-word-p sp-point-before-same-p))
|
2017-02-06 00:12:44 -05:00
|
|
|
|
(sp-local-pair '(xml-mode nxml-mode php-mode)
|
|
|
|
|
"<!--" "-->" :post-handlers '(("| " "SPC"))))
|
2016-03-23 11:59:06 -04: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
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! ace-link
|
2017-02-19 18:11:28 -05:00
|
|
|
|
:commands (ace-link-help ace-link-org))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! ace-window
|
2017-04-07 01:30:13 -04:00
|
|
|
|
:commands (ace-window ace-swap-window ace-delete-window
|
2017-04-22 01:48:28 -04:00
|
|
|
|
ace-select-window ace-delete-other-windows)
|
2017-02-19 18:11:28 -05:00
|
|
|
|
:config
|
|
|
|
|
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
|
|
|
|
|
aw-scope 'frame
|
|
|
|
|
aw-background t))
|
2015-06-06 06:40:33 -04:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! avy
|
2016-04-16 21:27:59 -04:00
|
|
|
|
:commands (avy-goto-char-2 avy-goto-line)
|
2017-02-19 18:11:28 -05:00
|
|
|
|
:config
|
|
|
|
|
(setq avy-all-windows nil
|
|
|
|
|
avy-background t))
|
2016-04-16 21:27:59 -04:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! command-log-mode
|
2017-02-09 04:22:08 -05:00
|
|
|
|
:commands (command-log-mode global-command-log-mode)
|
|
|
|
|
:config
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(set! :popup "*command-log*" :size 40 :align 'right :noselect t)
|
2017-02-09 04:22:08 -05: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
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! expand-region
|
2017-02-19 18:11:28 -05:00
|
|
|
|
:commands (er/expand-region er/contract-region er/mark-symbol er/mark-word))
|
2015-06-06 06:40:33 -04:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! goto-last-change :commands goto-last-change)
|
2015-06-06 06:40:33 -04:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! help-fns+ ; Improved help commands
|
2016-10-02 23:21:47 +02:00
|
|
|
|
:commands (describe-buffer describe-command describe-file
|
|
|
|
|
describe-keymap describe-option describe-option-of-type))
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! imenu-anywhere
|
2017-01-16 23:15:48 -05:00
|
|
|
|
:commands (ido-imenu-anywhere ivy-imenu-anywhere helm-imenu-anywhere))
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! imenu-list :commands imenu-list-minor-mode)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! pcre2el :commands rxt-quote-pcre)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! smart-forward
|
2016-10-08 19:38:58 +02:00
|
|
|
|
:commands (smart-up smart-down smart-backward smart-forward))
|
2015-06-06 06:40:33 -04:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! wgrep
|
2016-06-13 02:11:33 -04:00
|
|
|
|
:commands (wgrep-setup wgrep-change-to-wgrep-mode)
|
|
|
|
|
:config
|
|
|
|
|
(setq wgrep-auto-save-buffer t)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(advice-add #'wgrep-abort-changes :after #'doom/popup-close)
|
|
|
|
|
(advice-add #'wgrep-finish-edit :after #'doom/popup-close))
|
2016-06-13 02:11:33 -04:00
|
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
|
(provide 'core-editor)
|
|
|
|
|
;;; core-editor.el ends here
|