doomemacs/core/core-ui.el

272 lines
10 KiB
EmacsLisp
Raw Normal View History

2017-01-16 23:15:48 -05:00
;; core-ui.el --- draw me like one of your French editors
2015-06-15 09:05:52 +02:00
2017-01-28 02:03:35 -05:00
(defvar doom-ui-fringe-size '3 "Default fringe width")
2017-01-16 23:15:48 -05:00
2017-01-31 19:48:16 -05:00
(defvar doom-ui-default-background "#333333"
"The default frame background color.")
(defvar doom-ui-default-foreground "#CCCCCC"
"The default frame foreground color.")
2017-01-16 23:15:48 -05:00
(setq bidi-display-reordering nil ; disable bidirectional text for tiny performance boost
2017-01-28 02:03:35 -05:00
blink-matching-paren nil ; don't blink--too distracting
cursor-in-non-selected-windows nil ; hide cursors in other windows
2017-01-16 23:15:48 -05:00
frame-inhibit-implied-resize t
;; remove continuation arrow on right fringe
fringe-indicator-alist (delq (assq 'continuation fringe-indicator-alist)
fringe-indicator-alist)
highlight-nonselected-window nil
image-animate-loop t
indicate-buffer-boundaries nil
indicate-empty-lines nil
max-mini-window-height 0.3
mode-line-default-help-echo nil ; disable mode-line mouseovers
resize-mini-windows 'grow-only ; Minibuffer resizing
show-help-function nil ; hide :help-echo text
show-paren-delay 0.075
show-paren-highlight-openparen t
show-paren-when-point-inside-paren t
split-width-threshold nil ; favor horizontal splits
uniquify-buffer-name-style nil
use-dialog-box nil ; always avoid GUI
visible-cursor nil
2017-01-28 02:03:35 -05:00
x-stretch-cursor t
;; no beeping or blinking please
ring-bell-function 'ignore
visible-bell nil
;; Ask for confirmation on quit only if real buffers exist
confirm-kill-emacs (lambda (_) (if (doom-real-buffers-list) (y-or-n-p " Quit?") t)))
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
;; auto-enabled in Emacs 25+; I'd rather enable it manually
(global-eldoc-mode -1)
2017-01-31 04:31:47 -05:00
;; show typed keystrokes in minibuffer
(setq echo-keystrokes 0.02)
;; ...but hide them while isearch is active
(@add-hook isearch-mode (setq echo-keystrokes 0))
(@add-hook isearch-mode-end (setq echo-keystrokes 0.02))
2017-01-31 04:31:47 -05:00
2017-01-28 02:03:35 -05:00
;; A minor mode for toggling the mode-line
(defvar doom--hidden-modeline-format nil
"The modeline format to use when `doom-hide-modeline-mode' is active. Don't
set this directly. Bind it in `let' instead.")
(defvar-local doom--old-modeline-format nil
"The old modeline format, so `doom-hide-modeline-mode' can revert when it's
disabled.")
(define-minor-mode doom-hide-modeline-mode
"Minor mode to hide the mode-line in the current buffer."
:init-value nil
:global nil
(if doom-hide-modeline-mode
(setq doom--old-modeline-format mode-line-format
mode-line-format doom--hidden-modeline-format)
(setq mode-line-format doom--old-modeline-format
doom--mode-line nil))
(force-mode-line-update))
;; Ensure major-mode or theme changes don't overwrite these variables
(put 'doom--old-modeline 'permanent-local t)
(put 'doom-hide-modeline-mode 'permanent-local t)
2017-01-16 23:15:48 -05:00
;;
2017-01-16 23:15:48 -05:00
;; Bootstrap
;;
2016-05-23 17:13:59 -04:00
2017-01-16 23:15:48 -05:00
(tooltip-mode -1) ; relegate tooltips to echo area only
(menu-bar-mode -1)
2017-02-03 08:04:19 -05:00
(when (display-graphic-p)
2017-01-16 23:15:48 -05:00
(scroll-bar-mode -1)
(tool-bar-mode -1)
2017-01-28 02:03:35 -05:00
;; buffer name in frame title
(setq-default frame-title-format '("%b"))
2017-01-16 23:15:48 -05:00
;; standardize fringe width
(fringe-mode doom-ui-fringe-size)
2017-01-31 19:48:16 -05:00
(setq default-frame-alist
(append `((left-fringe . ,doom-ui-fringe-size)
(right-fringe . ,doom-ui-fringe-size)
(background-color . ,doom-ui-default-background)
(foreground-color . ,doom-ui-default-foreground))
default-frame-alist))
2017-01-16 23:15:48 -05:00
;; no fringe in the minibuffer
(@add-hook (emacs-startup minibuffer-setup)
2017-01-28 02:03:35 -05:00
(set-window-fringes (minibuffer-window) 0 0 nil)))
2016-09-22 13:38:09 +02:00
2016-03-03 15:04:14 -05:00
;;
;; Plugins
;;
2017-01-28 02:03:35 -05:00
;; I modified the built-in `hideshow' package to enable itself when needed. A
;; better, more vim-like code-folding plugin would be the `origami' plugin, but
;; until certain breaking bugs are fixed in it, I won't switch over.
2017-02-11 00:46:42 -05:00
(@def-package hideshow ; built-in
2017-01-16 23:15:48 -05:00
:commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p)
:init
2017-01-28 02:03:35 -05:00
(defun doom*autoload-hideshow ()
(unless (bound-and-true-p hs-minor-mode)
(hs-minor-mode 1)))
(advice-add 'evil-toggle-fold :before 'doom*autoload-hideshow))
2017-01-16 23:15:48 -05:00
2017-01-28 02:03:35 -05:00
;; Show uninterrupted indentation markers with some whitespace voodoo.
2017-02-11 00:46:42 -05:00
(@def-package highlight-indent-guides
2017-01-16 23:15:48 -05:00
:commands highlight-indent-guides-mode
:config
(setq highlight-indent-guides-method 'character)
2017-02-01 00:31:58 -05:00
(defun doom|inject-trailing-whitespace (&optional start end)
2017-01-28 02:03:35 -05:00
"The opposite of `delete-trailing-whitespace'. Injects whitespace into
buffer so that `highlight-indent-guides-mode' will display uninterrupted indent
markers. This whitespace is stripped out on save, as not to affect the resulting
file."
2017-01-16 23:15:48 -05:00
(interactive (progn (barf-if-buffer-read-only)
(if (use-region-p)
(list (region-beginning) (region-end))
(list nil nil))))
(unless indent-tabs-mode
(save-match-data
(save-excursion
(let ((end-marker (copy-marker (or end (point-max))))
(start (or start (point-min))))
(goto-char start)
(while (and (re-search-forward "^$" end-marker t) (not (>= (point) end-marker)))
(let (line-start line-end next-start next-end)
(save-excursion
;; Check previous line indent
(forward-line -1)
(setq line-start (point)
line-end (save-excursion (back-to-indentation) (point)))
;; Check next line indent
(forward-line 2)
(setq next-start (point)
next-end (save-excursion (back-to-indentation) (point)))
;; Back to origin
(forward-line -1)
;; Adjust indent
(let* ((line-indent (- line-end line-start))
(next-indent (- next-end next-start))
(indent (min line-indent next-indent)))
(insert (make-string (if (zerop indent) 0 (1+ indent)) ? )))))
(forward-line 1)))))
(set-buffer-modified-p nil))
nil)
(@add-hook highlight-indent-guides-mode
2017-01-16 23:15:48 -05:00
(if highlight-indent-guides-mode
(progn
2017-02-01 00:31:58 -05:00
(doom|inject-trailing-whitespace)
2017-01-28 02:03:35 -05:00
(add-hook 'after-save-hook 'doom|adjust-indent-guides nil t))
(remove-hook 'after-save-hook 'doom|adjust-indent-guides t)
(delete-trailing-whitespace))))
2017-01-16 23:15:48 -05:00
;; Some modes don't adequately highlight numbers, therefore...
2017-02-11 00:46:42 -05:00
(@def-package highlight-numbers :commands highlight-numbers-mode)
2017-01-16 23:15:48 -05:00
2017-01-28 02:03:35 -05:00
;; Line highlighting
2017-02-11 00:46:42 -05:00
(@def-package hl-line ; built-in
:init
2016-10-07 00:26:03 +02:00
;; stickiness doesn't play nice with emacs 25+
2016-06-08 14:43:40 -04:00
(setq hl-line-sticky-flag nil
2017-01-28 02:03:35 -05:00
global-hl-line-sticky-flag nil))
2016-05-01 01:05:25 -04:00
2017-01-28 02:03:35 -05:00
;; Line number column. A faster (or equivalent, in the worst case) line number
;; plugin than the built-in `linum'.
2017-02-11 00:46:42 -05:00
(@def-package nlinum
2015-10-28 03:31:51 -04:00
:commands nlinum-mode
2017-01-16 23:15:48 -05:00
:preface (defvar nlinum-format "%4d ")
2015-11-09 15:52:42 -05:00
:init
(@add-hook
(markdown-mode prog-mode scss-mode web-mode conf-mode groovy-mode
nxml-mode snippet-mode php-mode)
2016-04-30 23:13:39 -04:00
'nlinum-mode)
2017-01-16 23:15:48 -05:00
2015-10-03 04:56:33 -04:00
:config
2017-01-16 23:15:48 -05:00
;; Optimization: calculate line number column width beforehand
(@add-hook nlinum-mode
2016-05-23 17:13:59 -04:00
(setq nlinum--width (length (save-excursion (goto-char (point-max))
2016-05-24 22:50:39 -04:00
(format-mode-line "%l")))))
2016-08-28 22:54:48 +02:00
2017-02-01 00:31:58 -05:00
;; Disable nlinum explicitly before making a frame, otherwise nlinum throws
;; linum face errors that prevent the frame from spawning.
(@add-hook '(before-make-frame-hook after-make-frame-functions)
2017-01-28 02:03:35 -05:00
(nlinum-mode -1)))
2015-10-26 01:29:38 -04:00
2017-01-28 02:03:35 -05:00
;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk
;; languages like Lisp.
2017-02-11 00:46:42 -05:00
(@def-package rainbow-delimiters
2016-08-28 22:54:48 +02:00
:commands rainbow-delimiters-mode
:config (setq rainbow-delimiters-max-face-count 3)
:init
(@add-hook (emacs-lisp-mode lisp-mode js-mode css-mode c-mode-common)
2016-08-28 22:54:48 +02:00
'rainbow-delimiters-mode))
;;
;; Modeline
;;
(defvar doom-modeline-segments '()
"An alist of mode-line segments. Use `@def-modeline-segment' to define them.")
(defvar doom-modeline-formats '()
"An alist of mode-line formats. Use `@def-modeline' to define them and
`doom-modeline' to retrieve them.")
;; TODO Improve docstrings
(defmacro @def-modeline-segment (name &rest forms)
"Defines a modeline segment function and byte compiles it."
(declare (indent defun) (doc-string 2))
(let ((sym (intern (format "doom-modeline-segment--%s" name))))
(prog1
`(progn
(defun ,sym () ,@forms)
(push (cons ',name ',sym) doom-modeline-segments))
(let (byte-compile-warnings)
(byte-compile ',sym)))))
(defsubst doom--prepare-modeline-segments (segments)
(-non-nil
(--map (if (stringp it)
it
(list (cdr (assq it doom-modeline-segments))))
segments)))
(defmacro @def-modeline (name lhs &optional rhs)
"Defines a modeline format and byte-compiles it.
Example:
(@def-modeline minimal
(bar matches \" \" buffer-info)
(media-info major-mode))
(setq-default mode-line-format (doom-modeline 'minimal))"
(let ((sym (intern (format "doom-modeline--%s" name)))
(lhs-forms (doom--prepare-modeline-segments lhs))
(rhs-forms (doom--prepare-modeline-segments rhs)))
(prog1
`(progn
(defun ,sym ()
(let ((lhs (list ,@lhs-forms))
(rhs (list ,@rhs-forms)))
(list lhs
(propertize
" " 'display
`((space :align-to (- (+ right right-fringe right-margin)
,(+ 1 (string-width (format-mode-line rhs)))))))
rhs)))
(push (cons ',name ',sym) doom-modeline-formats))
(let (byte-compile-warnings)
(byte-compile ',sym)))))
(defun doom-modeline (key)
"Fetch the forms for the mode line format named KEY from
`doom-modeline-formats'. KEY is a symbol, and should be the name of a mode line
defined with `@def-modeline'."
(let ((modeline (assq key doom-modeline-formats)))
(unless modeline
(error "Modeline format doesn't exist: %s" key))
`(:eval (,(cdr modeline)))))
2015-06-04 18:23:21 -04:00
(provide 'core-ui)
;;; core-ui.el ends here