doomemacs/core/core.el

272 lines
12 KiB
EmacsLisp
Raw Normal View History

2015-06-06 06:40:33 -04:00
;;; core.el --- The heart of the beast
2015-06-04 18:23:21 -04:00
;;
2015-06-06 06:40:33 -04:00
;;; Naming conventions:
2015-06-04 18:23:21 -04:00
;;
2016-05-20 22:37:30 -04:00
;; doom-... A public variable/constant or function
;; doom--... An internal variable or function (non-interactive)
;; doom/... An autoloaded interactive function
;; doom:... An ex command
;; doom|... A hook
;; doom*... An advising function
;; doom.... Custom prefix commands
;; ...! Macro or shortcut alias
2015-06-04 18:23:21 -04:00
;;
;; Autoloaded functions are in {core,modules}/defuns/defuns-*.el
2016-03-03 15:04:14 -05:00
;;
2015-09-30 13:47:57 -04:00
;;;
2015-06-04 18:23:21 -04:00
2015-12-11 22:43:55 -05:00
(setq-default
2016-04-21 00:31:54 -04:00
;; stop package.el from being annoying. I rely solely on Cask.
package--init-file-ensured t
package-enable-at-startup nil
package-archives
2016-05-20 22:37:30 -04:00
'(("gnu" . "http://elpa.gnu.org/packages/")
2016-04-21 00:31:54 -04:00
("melpa" . "http://melpa.org/packages/")
2016-05-20 22:37:30 -04:00
("org" . "http://orgmode.org/elpa/"))
2016-04-21 00:31:54 -04:00
2015-10-01 13:48:48 -04:00
ad-redefinition-action 'accept ; silence the advised function warnings
2015-11-17 21:48:21 -05:00
compilation-always-kill t ; kill compilation process before spawning another
compilation-ask-about-save nil ; save all buffers before compiling
compilation-scroll-output t ; scroll with output while compiling
2016-04-08 16:15:37 -04:00
delete-by-moving-to-trash t
echo-keystrokes 0.02 ; show me what I type
2015-06-06 06:40:33 -04:00
ediff-diff-options "-w"
ediff-split-window-function 'split-window-horizontally ; side-by-side diffs
ediff-window-setup-function 'ediff-setup-windows-plain ; no extra frames
2016-04-08 16:15:37 -04:00
enable-recursive-minibuffers nil ; no minibufferception
idle-update-delay 2 ; update a little less often
2015-09-30 13:47:57 -04:00
inhibit-startup-echo-area-message "hlissner" ; username shuts up emacs
major-mode 'text-mode
2016-04-08 16:15:37 -04:00
ring-bell-function 'ignore ; silence of the bells!
save-interprogram-paste-before-kill nil
sentence-end-double-space nil
2016-05-20 22:37:30 -04:00
confirm-nonexistent-file-or-buffer t
2015-06-06 06:40:33 -04:00
2016-04-08 16:15:37 -04:00
;; http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
minibuffer-prompt-properties
'(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
2015-06-06 06:40:33 -04:00
bookmark-save-flag t
2016-05-20 22:37:30 -04:00
bookmark-default-file (concat doom-temp-dir "/bookmarks")
2015-11-17 21:48:21 -05:00
;; Disable all backups (that's what git/dropbox are for)
2016-04-26 02:00:19 -04:00
history-length 1000
vc-make-backup-files nil
2015-06-06 06:40:33 -04:00
auto-save-default nil
2016-05-20 22:37:30 -04:00
auto-save-list-file-name (concat doom-temp-dir "/autosave")
2015-06-06 06:40:33 -04:00
make-backup-files nil
create-lockfiles nil
2016-05-20 22:37:30 -04:00
backup-directory-alist `((".*" . ,(concat doom-temp-dir "/backup/")))
2015-06-06 06:40:33 -04:00
;; Remember undo history
undo-tree-auto-save-history nil
2016-05-20 22:37:30 -04:00
undo-tree-history-directory-alist `(("." . ,(concat doom-temp-dir "/undo/"))))
2015-06-04 18:23:21 -04:00
2016-03-03 15:04:14 -05:00
;; UTF-8 please
2015-09-30 13:47:57 -04:00
(setq locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
2016-03-10 23:54:56 -05:00
(set-charset-priority 'unicode)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
2015-09-30 13:47:57 -04:00
2016-04-05 23:58:32 -04:00
;;
;; Variables
;;
2016-05-20 22:37:30 -04:00
(defvar doom-unreal-buffers '("^ ?\\*.+\\*"
2016-04-05 23:58:32 -04:00
image-mode
dired-mode
reb-mode
messages-buffer-mode)
"A list of regexps or modes whose buffers are considered unreal, and will be
2016-05-20 22:37:30 -04:00
ignored when using `doom:next-real-buffer' and `doom:previous-real-buffer' (or
killed by `doom/kill-unreal-buffers', or after `doom/kill-real-buffer').")
2016-04-05 23:58:32 -04:00
2016-05-20 22:37:30 -04:00
(defvar doom-ignore-buffers '("*Completions*" "*Compile-Log*" "*inferior-lisp*"
2016-04-05 23:58:32 -04:00
"*Fuzzy Completions*" "*Apropos*" "*Help*" "*cvs*"
"*Buffer List*" "*Ibuffer*" "*NeoTree*" "
*NeoTree*" "*esh command on file*" "*WoMan-Log*"
"*compilation*" "*use-package*" "*quickrun*"
"*eclim: problems*" "*Flycheck errors*"
"*popwin-dummy*"
2016-04-05 23:58:32 -04:00
;; Helm
"*helm*" "*helm recentf*" "*helm projectile*"
"*helm imenu*" "*helm company*" "*helm buffers*"
"*Helm Css SCSS*" "*helm-ag*" "*helm-ag-edit*"
"*Helm Swoop*" "*helm M-x*" "*helm mini*"
"*Helm Completions*" "*Helm Find Files*"
"*helm mu*" "*helm mu contacts*"
"*helm-mode-describe-variable*"
"*helm-mode-describe-function*"
2016-04-05 23:58:32 -04:00
;; Org
"*Org todo*" "*Org Links*" "*Agenda Commands*")
"List of buffer names to ignore when using `winner-undo', or `winner-redo'")
2016-05-20 22:37:30 -04:00
(defvar doom-cleanup-processes-alist '(("pry" . ruby-mode)
2016-04-05 23:58:32 -04:00
("irb" . ruby-mode)
("ipython" . python-mode))
2016-05-20 22:37:30 -04:00
"An alist of (process-name . major-mode), that `doom:cleanup-processes' checks
2016-04-05 23:58:32 -04:00
before killing processes. If there are no buffers with matching major-modes, it
gets killed.")
2016-05-20 22:37:30 -04:00
(defvar doom-project-root-files
2016-04-05 23:58:32 -04:00
'(".git" ".hg" ".svn" ".project" "local.properties" "project.properties"
"rebar.config" "project.clj" "SConstruct" "pom.xml" "build.sbt"
"build.gradle" "Gemfile" "requirements.txt" "tox.ini" "package.json"
"gulpfile.js" "Gruntfile.js" "bower.json" "composer.json" "Cargo.toml"
"mix.exs")
"A list of files that count as 'project files', which determine whether a
folder is the root of a project or not.")
2016-04-05 23:58:32 -04:00
2016-03-03 15:04:14 -05:00
;;
2016-05-20 09:23:46 -04:00
;; Libraries
2016-03-03 15:04:14 -05:00
;;
2015-09-30 13:47:57 -04:00
2016-05-11 05:36:49 -04:00
(require 'f)
2016-05-20 22:37:30 -04:00
(require 'dash)
(require 's)
2015-09-30 13:47:57 -04:00
(require 'core-defuns)
2016-05-20 22:37:30 -04:00
(unless (require 'autoloads nil t)
(doom-reload-autoloads)
(unless (require 'autoloads nil t)
(error "Autoloads couldn't be loaded or generated!")))
2015-09-30 13:47:57 -04:00
2016-05-20 09:23:46 -04:00
(autoload 'use-package "use-package" "" nil 'macro)
2016-05-18 16:58:07 -04:00
(use-package anaphora
:commands (awhen aif acond awhile))
(use-package persistent-soft
:commands (persistent-soft-store
persistent-soft-fetch
persistent-soft-exists-p
persistent-soft-flush
persistent-soft-location-readable
2015-11-17 02:18:56 -05:00
persistent-soft-location-destroy)
2016-05-20 22:37:30 -04:00
:init (defvar pcache-directory (concat doom-temp-dir "/pcache/")))
(use-package async
:commands (async-start
async-start-process
async-get
async-wait
async-inject-variables))
2016-05-19 03:17:59 -04:00
(use-package json
:commands (json-read-from-string json-encode json-read-file))
(use-package help-fns+ ; Improved help commands
:commands (describe-buffer describe-command describe-file
describe-keymap describe-option describe-option-of-type))
;;
;; Automatic minor modes
;;
2016-05-20 22:37:30 -04:00
(defvar doom-auto-minor-mode-alist '()
2016-05-19 03:17:59 -04:00
"Alist of filename patterns vs corresponding minor mode functions, see
`auto-mode-alist'. All elements of this alist are checked, meaning you can
enable multiple minor modes for the same regexp.")
2016-05-20 22:37:30 -04:00
(defun doom|enable-minor-mode-maybe ()
"Check file name against `doom-auto-minor-mode-alist'."
2016-05-19 03:17:59 -04:00
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
2016-05-20 22:37:30 -04:00
(alist doom-auto-minor-mode-alist))
2016-05-19 03:17:59 -04:00
;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions name))
;; Remove remote file name identification.
(when (and (stringp remote-id)
(string-match-p (regexp-quote remote-id) name))
(setq name (substring name (match-end 0))))
(while (and alist (caar alist) (cdar alist))
(if (string-match (caar alist) name)
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
2016-05-20 22:37:30 -04:00
(add-hook 'find-file-hook 'doom|enable-minor-mode-maybe)
2016-05-19 03:17:59 -04:00
2016-03-03 15:04:14 -05:00
;;
(setq initial-major-mode 'doom-mode
initial-scratch-message nil
inhibit-startup-screen t) ; don't show emacs start screen
(defvar doom-buffer-name "*doom*" "")
(defvar doom-buffer nil "")
(define-derived-mode doom-mode text-mode "DOOM"
"Major mode for special DOOM buffers.")
(add-hook 'after-init-hook 'doom-mode-init)
(defun doom-mode-init (&optional auto-detect-frame)
(let ((old-scratch (get-buffer "*scratch*")))
(when old-scratch
(with-current-buffer old-scratch
(rename-buffer doom-buffer-name)
(setq doom-buffer old-scratch))))
(unless doom-buffer
(setq doom-buffer (get-buffer-create doom-buffer-name)))
(with-current-buffer doom-buffer
(doom-mode)
(erase-buffer)
(insert
(let* ((width (- (if auto-detect-frame (window-width) (cdr (assq 'width default-frame-alist))) 3))
(lead (make-string (truncate (/ (- width 78) 2)) ? )))
(concat
(propertize
(concat
(make-string (min 3 (/ (if auto-detect-frame (window-height) (cdr (assq 'height default-frame-alist))) 5)) ?\n)
lead "================= =============== =============== ======== ========\n"
lead "\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //\n"
lead "||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||\n"
lead "|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||\n"
lead "||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||\n"
lead "|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||\n"
lead "||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||\n"
lead "|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||\n"
lead "||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||\n"
lead "|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||\n"
lead "|| `' || || `' || || `' || || | \\ / | ||\n"
lead "|| .===' `===. .==='.`===. .===' /==. | \\/ | ||\n"
lead "|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||\n"
lead "|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||\n"
lead "|| .==' _-' '-__\\._-' '-_./__-' `' |. /| | ||\n"
lead "||.==' _-' `' | /==.||\n"
lead "==' _-' E M A C S \\/ `==\n"
lead "\\ _-' `-_ /\n"
lead " `'' ``'")
'face 'font-lock-comment-face)
"\n\n"
(propertize
(s-center (1- width) (format "Press `,m` to open recent files, or `,E` to access emacs.d"
emacs-end-time))
'face 'font-lock-keyword-face)
(if emacs-end-time
(concat
"\n\n"
2016-05-20 22:55:53 -04:00
(s-trim-right (s-center (- width 2) (format "Loaded in %.3fs" emacs-end-time))))
""))))
(doom|update-scratch-buffer-cwd)))
(add-hook! after-init
2016-05-20 09:23:46 -04:00
;; We add this to `after-init-hook' to allow errors to stop it
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs."
(cl-flet ((process-list ())) ad-do-it))
2016-05-20 09:23:46 -04:00
;; Prevent any auto-displayed text...
(advice-add 'display-startup-echo-area-message :override 'ignore)
2016-05-20 09:23:46 -04:00
;; ...so we can display our own
2016-05-20 22:37:30 -04:00
(setq emacs-end-time (float-time (time-subtract (current-time) emacs-start-time)))
(message ":: Loaded in %.3fs" emacs-end-time))
2015-06-04 18:23:21 -04:00
(provide 'core)
;;; core.el ends here