2017-06-09 00:19:44 +02:00
|
|
|
|
;;; core-ui.el -*- lexical-binding: t; -*-
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(defvar doom-fringe-size '4
|
|
|
|
|
"Default fringe width.")
|
|
|
|
|
|
|
|
|
|
(defvar doom-theme nil
|
|
|
|
|
"A symbol representing the color theme to load.")
|
|
|
|
|
|
2017-07-04 19:53:39 +02:00
|
|
|
|
(defvar doom-font nil
|
2017-12-08 22:40:31 -05:00
|
|
|
|
"The default font to use. Expects a `font-spec'.")
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
2017-07-04 19:52:21 +02:00
|
|
|
|
(defvar doom-big-font nil
|
2017-12-08 22:40:31 -05:00
|
|
|
|
"The default large font to use when `doom-big-font-mode' is enabled. Expects a
|
|
|
|
|
`font-spec'.")
|
2017-07-04 19:52:21 +02:00
|
|
|
|
|
2017-07-04 19:53:39 +02:00
|
|
|
|
(defvar doom-variable-pitch-font nil
|
2017-12-08 22:40:31 -05:00
|
|
|
|
"The default font to use for variable-pitch text. Expects a `font-spec'.")
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
2017-07-04 19:53:39 +02:00
|
|
|
|
(defvar doom-unicode-font nil
|
2017-12-08 22:40:31 -05:00
|
|
|
|
"Fallback font for unicode glyphs. Is ignored if :feature unicode is active.
|
|
|
|
|
Expects a `font-spec'.")
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
|
|
|
|
(defvar doom-major-mode-names
|
|
|
|
|
'((sh-mode . "sh")
|
|
|
|
|
(emacs-lisp-mode . "Elisp"))
|
|
|
|
|
"An alist mapping major modes symbols to strings (or functions that will
|
|
|
|
|
return a string). This changes the 'long' name of a major-mode, allowing for
|
|
|
|
|
shorter major mode name in the mode-line. See `doom|set-mode-name'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Hook(s)
|
|
|
|
|
(defvar doom-init-ui-hook nil
|
|
|
|
|
"List of hooks to run when the theme and font is initialized (or reloaded with
|
2017-11-05 01:23:36 +01:00
|
|
|
|
`doom//reload-theme').")
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-19 18:11:28 -05:00
|
|
|
|
(setq-default
|
|
|
|
|
bidi-display-reordering nil ; disable bidirectional text for tiny performance boost
|
|
|
|
|
blink-matching-paren nil ; don't blink--too distracting
|
|
|
|
|
cursor-in-non-selected-windows nil ; hide cursors in other windows
|
2017-07-18 22:07:13 +02:00
|
|
|
|
display-line-numbers-width 3
|
2017-02-19 18:11:28 -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)
|
2017-03-03 12:22:06 +01:00
|
|
|
|
highlight-nonselected-windows nil
|
2017-02-19 18:11:28 -05:00
|
|
|
|
image-animate-loop t
|
|
|
|
|
indicate-buffer-boundaries nil
|
|
|
|
|
indicate-empty-lines nil
|
|
|
|
|
max-mini-window-height 0.3
|
2017-06-05 00:47:56 +02:00
|
|
|
|
mode-line-default-help-echo nil ; disable mode-line mouseovers
|
|
|
|
|
mouse-yank-at-point t ; middle-click paste at point, not at click
|
2018-01-01 16:59:59 -05:00
|
|
|
|
ibuffer-use-other-window t
|
2017-06-05 00:47:56 +02:00
|
|
|
|
resize-mini-windows 'grow-only ; Minibuffer resizing
|
|
|
|
|
show-help-function nil ; hide :help-echo text
|
2017-07-02 16:55:39 +02:00
|
|
|
|
split-width-threshold 160 ; favor horizontal splits
|
2017-05-14 09:44:22 +02:00
|
|
|
|
uniquify-buffer-name-style 'forward
|
2017-06-05 00:47:56 +02:00
|
|
|
|
use-dialog-box nil ; always avoid GUI
|
2017-02-19 18:11:28 -05:00
|
|
|
|
visible-cursor nil
|
2017-03-09 00:47:35 -05:00
|
|
|
|
x-stretch-cursor nil
|
2017-06-05 00:47:56 +02:00
|
|
|
|
;; defer jit font locking slightly to [try to] improve Emacs performance
|
|
|
|
|
jit-lock-defer-time nil
|
|
|
|
|
jit-lock-stealth-nice 0.1
|
|
|
|
|
jit-lock-stealth-time 0.2
|
|
|
|
|
jit-lock-stealth-verbose nil
|
2017-05-16 22:21:55 +02:00
|
|
|
|
;; `pos-tip' defaults
|
|
|
|
|
pos-tip-internal-border-width 6
|
|
|
|
|
pos-tip-border-width 1
|
2017-02-19 18:11:28 -05:00
|
|
|
|
;; no beeping or blinking please
|
2017-04-17 02:17:10 -04:00
|
|
|
|
ring-bell-function #'ignore
|
2017-06-11 14:05:14 +02:00
|
|
|
|
visible-bell nil)
|
2017-01-28 02:03:35 -05:00
|
|
|
|
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(fset #'yes-or-no-p #'y-or-n-p) ; y/n instead of yes/no
|
2017-01-28 02:03:35 -05:00
|
|
|
|
|
2017-06-11 14:05:14 +02:00
|
|
|
|
(defun doom-quit-p (&optional prompt)
|
2017-06-28 16:18:22 +02:00
|
|
|
|
"Return t if this session should be killed. Prompts the user for
|
|
|
|
|
confirmation."
|
2017-06-27 01:49:04 +02:00
|
|
|
|
(if (ignore-errors (doom-real-buffer-list))
|
2017-06-11 14:05:14 +02:00
|
|
|
|
(or (yes-or-no-p (format "››› %s" (or prompt "Quit Emacs?")))
|
|
|
|
|
(ignore (message "Aborted")))
|
|
|
|
|
t))
|
|
|
|
|
(setq confirm-kill-emacs nil)
|
|
|
|
|
(add-hook 'kill-emacs-query-functions #'doom-quit-p)
|
|
|
|
|
|
2017-01-31 04:31:47 -05:00
|
|
|
|
;; show typed keystrokes in minibuffer
|
2017-06-12 00:54:57 +02:00
|
|
|
|
(defun doom|enable-ui-keystrokes () (setq echo-keystrokes 0.02))
|
|
|
|
|
(defun doom|disable-ui-keystrokes () (setq echo-keystrokes 0))
|
|
|
|
|
(doom|enable-ui-keystrokes)
|
2017-01-31 04:31:47 -05:00
|
|
|
|
;; ...but hide them while isearch is active
|
2017-06-12 00:54:57 +02:00
|
|
|
|
(add-hook 'isearch-mode-hook #'doom|disable-ui-keystrokes)
|
|
|
|
|
(add-hook 'isearch-mode-end-hook #'doom|enable-ui-keystrokes)
|
2017-01-31 04:31:47 -05:00
|
|
|
|
|
2017-01-28 02:03:35 -05:00
|
|
|
|
;; A minor mode for toggling the mode-line
|
2017-04-25 22:55:57 -04:00
|
|
|
|
(defvar-local doom--modeline-format nil
|
2017-01-28 02:03:35 -05:00
|
|
|
|
"The modeline format to use when `doom-hide-modeline-mode' is active. Don't
|
2017-06-14 21:03:20 +02:00
|
|
|
|
set this directly. Let-bind it instead.")
|
2017-01-28 02:03:35 -05:00
|
|
|
|
(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
|
2017-04-18 05:00:54 -04:00
|
|
|
|
mode-line-format doom--modeline-format)
|
2017-01-28 02:03:35 -05:00
|
|
|
|
(setq mode-line-format doom--old-modeline-format
|
2017-04-18 05:00:54 -04:00
|
|
|
|
doom--old-modeline-format nil))
|
2017-01-28 02:03:35 -05:00
|
|
|
|
(force-mode-line-update))
|
|
|
|
|
;; Ensure major-mode or theme changes don't overwrite these variables
|
2017-04-25 22:55:57 -04:00
|
|
|
|
(put 'doom--modeline-format 'permanent-local t)
|
2017-02-19 18:11:28 -05:00
|
|
|
|
(put 'doom--old-modeline-format 'permanent-local t)
|
2017-01-28 02:03:35 -05:00
|
|
|
|
(put 'doom-hide-modeline-mode 'permanent-local t)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-04-18 05:00:54 -04:00
|
|
|
|
(defun doom|hide-modeline-mode-reset ()
|
|
|
|
|
"Sometimes, a major-mode is activated after `doom-hide-modeline-mode' is
|
|
|
|
|
activated, thus disabling it (because changing major modes invokes
|
|
|
|
|
`kill-all-local-variables' and specifically seems to kill `mode-line-format's
|
|
|
|
|
local value, whether or not it's permanent-local. Therefore, we cycle
|
|
|
|
|
`doom-hide-modeline-mode' to fix this."
|
|
|
|
|
(when doom-hide-modeline-mode
|
|
|
|
|
(doom-hide-modeline-mode -1)
|
|
|
|
|
(doom-hide-modeline-mode +1)))
|
2017-05-13 22:37:37 +02:00
|
|
|
|
(add-hook 'after-change-major-mode-hook #'doom|hide-modeline-mode-reset)
|
|
|
|
|
|
|
|
|
|
;; no modeline in completion popups
|
|
|
|
|
(add-hook 'completion-list-mode-hook #'doom-hide-modeline-mode)
|
2017-04-18 05:00:54 -04:00
|
|
|
|
|
2017-03-04 20:54:13 -05:00
|
|
|
|
;; undo/redo changes to Emacs' window layout
|
|
|
|
|
(defvar winner-dont-bind-my-keys t) ; I'll bind keys myself
|
2017-06-12 00:20:30 +02:00
|
|
|
|
(autoload 'winner-mode "winner" nil t)
|
2017-08-06 16:30:53 +02:00
|
|
|
|
(add-hook 'doom-init-ui-hook #'winner-mode)
|
2017-02-19 19:01:12 -05:00
|
|
|
|
|
2017-05-15 13:52:22 +02:00
|
|
|
|
;; highlight matching delimiters
|
2017-05-16 00:49:42 +02:00
|
|
|
|
(setq show-paren-delay 0.1
|
2017-05-15 13:52:22 +02:00
|
|
|
|
show-paren-highlight-openparen t
|
|
|
|
|
show-paren-when-point-inside-paren t)
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(add-hook 'doom-init-ui-hook #'show-paren-mode)
|
2017-05-15 13:52:22 +02:00
|
|
|
|
|
2017-06-05 00:52:52 +02:00
|
|
|
|
;;; More reliable inter-window border
|
|
|
|
|
;; The native border "consumes" a pixel of the fringe on righter-most splits,
|
|
|
|
|
;; `window-divider' does not. Available since Emacs 25.1.
|
|
|
|
|
(setq-default window-divider-default-places t
|
2017-06-28 16:18:22 +02:00
|
|
|
|
window-divider-default-bottom-width 0
|
2017-06-05 00:52:52 +02:00
|
|
|
|
window-divider-default-right-width 1)
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(add-hook 'doom-init-ui-hook #'window-divider-mode)
|
2017-06-05 00:52:52 +02:00
|
|
|
|
|
2017-05-28 16:12:28 +02:00
|
|
|
|
;; like diminish, but for major-modes. [pedantry intensifies]
|
|
|
|
|
(defun doom|set-mode-name ()
|
2017-06-28 16:18:22 +02:00
|
|
|
|
"Set the major mode's `mode-name', as dictated by `doom-major-mode-names'."
|
2017-12-10 14:49:52 -05:00
|
|
|
|
(when-let* ((name (cdr (assq major-mode doom-major-mode-names))))
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(setq mode-name
|
2017-09-24 20:49:36 +02:00
|
|
|
|
(cond ((functionp name) (funcall name))
|
|
|
|
|
((stringp name) name)
|
|
|
|
|
(t (error "'%s' isn't a valid name for %s" name major-mode))))))
|
2017-05-28 16:12:28 +02:00
|
|
|
|
(add-hook 'after-change-major-mode-hook #'doom|set-mode-name)
|
|
|
|
|
|
2016-10-04 22:52:43 +02:00
|
|
|
|
|
|
|
|
|
;;
|
2017-06-28 16:18:22 +02:00
|
|
|
|
;; Themes & fonts
|
2016-10-04 22:52:43 +02:00
|
|
|
|
;;
|
2016-05-23 17:13:59 -04:00
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
|
;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and
|
|
|
|
|
;; daemon Emacs is hairy.
|
|
|
|
|
;;
|
2017-08-06 16:30:53 +02:00
|
|
|
|
;; + Running `doom|init-ui' directly sorts out the initial GUI frame.
|
2017-06-28 16:18:22 +02:00
|
|
|
|
;; + Attaching it to `after-make-frame-functions' sorts out daemon Emacs.
|
|
|
|
|
;; + Waiting for 0.1s in `doom|reload-ui-in-daemon' fixes daemon Emacs started
|
|
|
|
|
;; with `server-start' in an interactive session of Emacs AND in tty Emacs.
|
|
|
|
|
(defun doom|init-ui (&optional frame)
|
|
|
|
|
"Set the theme and load the font, in that order."
|
|
|
|
|
(when doom-theme
|
|
|
|
|
(load-theme doom-theme t))
|
2017-07-28 19:54:23 +02:00
|
|
|
|
(condition-case-unless-debug ex
|
|
|
|
|
(when (display-graphic-p)
|
|
|
|
|
(when (fontp doom-font)
|
|
|
|
|
(set-frame-font doom-font nil (if frame (list frame) t))
|
|
|
|
|
(set-face-attribute 'fixed-pitch frame :font doom-font))
|
|
|
|
|
;; Fallback to `doom-unicode-font' for Unicode characters
|
|
|
|
|
(when (fontp doom-unicode-font)
|
|
|
|
|
(set-fontset-font t 'unicode doom-unicode-font frame))
|
|
|
|
|
;; ...and for variable-pitch-mode:
|
|
|
|
|
(when (fontp doom-variable-pitch-font)
|
|
|
|
|
(set-face-attribute 'variable-pitch frame :font doom-variable-pitch-font)))
|
|
|
|
|
('error
|
2017-12-22 17:10:13 -05:00
|
|
|
|
(if (string-prefix-p "Font not available: " (error-message-string ex))
|
|
|
|
|
(lwarn 'doom-ui :warning
|
|
|
|
|
"Could not find the '%s' font on your system, falling back to system font"
|
|
|
|
|
(font-get (caddr ex) :family))
|
|
|
|
|
(lwarn 'doom-ui :error
|
|
|
|
|
"Unexpected error while initializing fonts: %s"
|
|
|
|
|
(error-message-string ex)))))
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(run-hooks 'doom-init-ui-hook))
|
|
|
|
|
|
|
|
|
|
(defun doom|reload-ui-in-daemon (frame)
|
|
|
|
|
"Reload the theme (and font) in an daemon frame."
|
|
|
|
|
(when (or (daemonp) (not (display-graphic-p)))
|
|
|
|
|
(with-selected-frame frame
|
|
|
|
|
(run-with-timer 0.1 nil #'doom|init-ui))))
|
|
|
|
|
|
|
|
|
|
;; register UI init hooks
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(add-hook 'doom-post-init-hook #'doom|init-ui)
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(add-hook! 'after-make-frame-functions #'(doom|init-ui doom|reload-ui-in-daemon))
|
2017-06-16 02:31:37 +02:00
|
|
|
|
|
2017-06-11 14:05:14 +02:00
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
|
;;
|
|
|
|
|
;; Bootstrap
|
|
|
|
|
;;
|
2017-06-08 11:47:56 +02:00
|
|
|
|
|
2017-06-28 16:18:22 +02:00
|
|
|
|
;; prompts the user for confirmation when deleting a non-empty frame
|
|
|
|
|
(define-key global-map [remap delete-frame] #'doom/delete-frame)
|
2017-09-24 20:49:36 +02:00
|
|
|
|
;; simple name in frame title
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(setq-default frame-title-format '("DOOM Emacs"))
|
|
|
|
|
;; auto-enabled in Emacs 25+; I'll do it myself
|
|
|
|
|
(global-eldoc-mode -1)
|
|
|
|
|
;; a good indicator that Emacs isn't frozen
|
|
|
|
|
(add-hook 'doom-post-init-hook #'blink-cursor-mode)
|
|
|
|
|
;; standardize default fringe width
|
2017-06-28 18:05:11 +02:00
|
|
|
|
(if (fboundp 'fringe-mode) (fringe-mode doom-fringe-size))
|
2017-06-08 11:47:56 +02:00
|
|
|
|
;; draw me like one of your French editors
|
2017-01-16 23:15:48 -05:00
|
|
|
|
(tooltip-mode -1) ; relegate tooltips to echo area only
|
|
|
|
|
(menu-bar-mode -1)
|
2017-06-14 21:03:20 +02:00
|
|
|
|
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
|
|
|
|
|
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
|
2017-06-12 00:20:30 +02:00
|
|
|
|
|
|
|
|
|
(defun doom|no-fringes-in-minibuffer ()
|
2017-06-28 16:18:22 +02:00
|
|
|
|
"Disable fringes in the minibuffer window."
|
2017-06-12 00:20:30 +02:00
|
|
|
|
(set-window-fringes (minibuffer-window) 0 0 nil))
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(add-hook! '(doom-post-init-hook minibuffer-setup-hook)
|
2017-06-12 00:20:30 +02:00
|
|
|
|
#'doom|no-fringes-in-minibuffer)
|
2016-09-22 13:38:09 +02:00
|
|
|
|
|
2017-12-28 21:43:48 -05:00
|
|
|
|
(defun doom|protect-visible-buffers ()
|
|
|
|
|
"Don't kill the current buffer if it is visible in another window (bury it
|
|
|
|
|
instead)."
|
2017-12-30 00:53:51 -05:00
|
|
|
|
(not (delq (selected-window)
|
|
|
|
|
(get-buffer-window-list nil nil t))))
|
2017-12-30 01:30:41 -05:00
|
|
|
|
(add-hook! doom-post-init
|
|
|
|
|
(add-hook 'kill-buffer-query-functions #'doom|protect-visible-buffers))
|
2017-12-28 21:43:48 -05:00
|
|
|
|
|
2016-03-03 15:04:14 -05:00
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Plugins
|
|
|
|
|
;;
|
|
|
|
|
|
2017-06-09 00:19:44 +02:00
|
|
|
|
(def-package! all-the-icons
|
|
|
|
|
:commands (all-the-icons-octicon all-the-icons-faicon all-the-icons-fileicon
|
2017-06-15 23:56:22 +02:00
|
|
|
|
all-the-icons-wicon all-the-icons-material all-the-icons-alltheicon
|
2017-06-09 00:19:44 +02:00
|
|
|
|
all-the-icons-install-fonts)
|
|
|
|
|
:init
|
|
|
|
|
(defun doom*disable-all-the-icons-in-tty (orig-fn &rest args)
|
|
|
|
|
(when (display-graphic-p)
|
|
|
|
|
(apply orig-fn args)))
|
|
|
|
|
;; all-the-icons doesn't work in the terminal, so we "disable" it.
|
2017-12-29 01:46:20 -05:00
|
|
|
|
(dolist (fn '(all-the-icons-octicon all-the-icons-material
|
|
|
|
|
all-the-icons-faicon all-the-icons-fileicon
|
|
|
|
|
all-the-icons-wicon all-the-icons-alltheicon))
|
|
|
|
|
(advice-add fn :around #'doom*disable-all-the-icons-in-tty)))
|
2017-06-09 00:19:44 +02:00
|
|
|
|
|
2017-06-07 14:32:34 +02:00
|
|
|
|
(def-package! fringe-helper
|
2017-06-09 00:32:49 +02:00
|
|
|
|
:commands (fringe-helper-define fringe-helper-convert)
|
|
|
|
|
:init
|
|
|
|
|
(unless (fboundp 'define-fringe-bitmap)
|
2017-09-15 14:35:18 +02:00
|
|
|
|
;; doesn't exist in terminal Emacs; define it to prevent errors
|
2017-06-28 16:18:22 +02:00
|
|
|
|
(defun define-fringe-bitmap (&rest _))))
|
2017-06-07 14:32:34 +02:00
|
|
|
|
|
2017-02-23 00:06:12 -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)
|
2017-12-23 22:13:48 -05:00
|
|
|
|
:config (setq hs-hide-comments-when-hiding-all nil))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-03-25 03:15:37 -04:00
|
|
|
|
(def-package! highlight-indentation
|
2017-06-23 17:55:19 +02:00
|
|
|
|
:commands (highlight-indentation-mode highlight-indentation-current-column-mode))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-07-18 22:12:50 +02:00
|
|
|
|
;; For modes with sub-par number fontification
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! highlight-numbers :commands highlight-numbers-mode)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-07-18 22:12:50 +02:00
|
|
|
|
;; Highlights the current line
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! hl-line ; built-in
|
2017-12-08 22:33:12 -05:00
|
|
|
|
:hook ((prog-mode text-mode conf-mode) . hl-line-mode)
|
2017-02-19 18:11:28 -05:00
|
|
|
|
:config
|
2017-06-05 00:47:56 +02:00
|
|
|
|
;; I don't need hl-line showing in other windows. This also offers a small
|
|
|
|
|
;; speed boost when buffer is displayed in multiple windows.
|
2016-06-08 14:43:40 -04:00
|
|
|
|
(setq hl-line-sticky-flag nil
|
2017-05-14 00:19:45 +02:00
|
|
|
|
global-hl-line-sticky-flag nil)
|
|
|
|
|
|
2017-12-11 13:46:09 -05:00
|
|
|
|
;; On Emacs 26+, when point is on the last line, hl-line highlights bleed into
|
|
|
|
|
;; the rest of the window after eob. This is the fix.
|
|
|
|
|
(when (boundp 'display-line-numbers)
|
|
|
|
|
(defun doom--line-range ()
|
|
|
|
|
(cons (line-beginning-position)
|
2017-12-11 15:23:42 -05:00
|
|
|
|
(cond ((save-excursion
|
|
|
|
|
(goto-char (line-end-position))
|
|
|
|
|
(and (eobp) (not (bolp))))
|
|
|
|
|
(1- (line-end-position)))
|
|
|
|
|
((or (eobp) (save-excursion (forward-line) (eobp)))
|
|
|
|
|
(line-end-position))
|
|
|
|
|
(t
|
|
|
|
|
(line-beginning-position 2)))))
|
2017-12-11 13:46:09 -05:00
|
|
|
|
(setq hl-line-range-function #'doom--line-range))
|
|
|
|
|
|
2017-05-14 00:19:45 +02:00
|
|
|
|
(after! evil
|
2017-11-30 20:22:51 -05:00
|
|
|
|
(defvar-local doom-buffer-hl-line-mode nil)
|
|
|
|
|
|
2017-06-28 16:16:03 +02:00
|
|
|
|
;; Disable `hl-line' in evil-visual mode (temporarily). `hl-line' can make
|
|
|
|
|
;; the selection region harder to see while in evil visual mode.
|
2017-11-30 20:22:51 -05:00
|
|
|
|
(defun doom|disable-hl-line ()
|
|
|
|
|
(when hl-line-mode
|
|
|
|
|
(setq doom-buffer-hl-line-mode t)
|
|
|
|
|
(hl-line-mode -1)))
|
|
|
|
|
(defun doom|enable-hl-line-maybe ()
|
|
|
|
|
(if doom-buffer-hl-line-mode (hl-line-mode +1)))
|
2017-06-19 00:04:20 +02:00
|
|
|
|
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(add-hook 'evil-visual-state-entry-hook #'doom|disable-hl-line)
|
2017-11-30 20:22:51 -05:00
|
|
|
|
(add-hook 'evil-visual-state-exit-hook #'doom|enable-hl-line-maybe)))
|
2016-05-01 01:05:25 -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-23 00:06:12 -05:00
|
|
|
|
(def-package! rainbow-delimiters
|
2017-12-23 22:13:48 -05:00
|
|
|
|
:hook (lisp-mode . rainbow-delimiters-mode)
|
|
|
|
|
:config (setq rainbow-delimiters-max-face-count 3))
|
2016-08-28 22:54:48 +02:00
|
|
|
|
|
2017-03-06 19:06:59 -05:00
|
|
|
|
;; For a distractions-free-like UI, that dynamically resizes margets and can
|
|
|
|
|
;; center a buffer.
|
|
|
|
|
(def-package! visual-fill-column
|
2017-05-14 00:25:04 +02:00
|
|
|
|
:commands visual-fill-column-mode
|
2017-03-06 19:06:59 -05:00
|
|
|
|
:config
|
2017-12-27 18:20:58 -05:00
|
|
|
|
(setq-default
|
|
|
|
|
visual-fill-column-center-text t
|
|
|
|
|
visual-fill-column-width
|
|
|
|
|
;; take Emacs 26 line numbers into account
|
|
|
|
|
(+ (if (boundp 'display-line-numbers) 6 0)
|
|
|
|
|
fill-column)))
|
2017-03-06 19:06:59 -05:00
|
|
|
|
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
2017-07-18 22:07:13 +02:00
|
|
|
|
;;
|
|
|
|
|
;; Line numbers
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
(defvar doom-line-numbers-style t
|
|
|
|
|
"The style to use for the line number display.
|
|
|
|
|
|
|
|
|
|
Accepts the same arguments as `display-line-numbers', which are:
|
|
|
|
|
|
|
|
|
|
nil No line numbers
|
|
|
|
|
t Ordinary line numbers
|
|
|
|
|
'relative Relative line numbers")
|
|
|
|
|
|
|
|
|
|
(defun doom|enable-line-numbers (&optional arg)
|
|
|
|
|
"Enables the display of line numbers, using `display-line-numbers' (in Emacs
|
|
|
|
|
26+) or `nlinum-mode'.
|
|
|
|
|
|
|
|
|
|
See `doom-line-numbers-style' to control the style of line numbers to display."
|
|
|
|
|
(cond ((boundp 'display-line-numbers)
|
|
|
|
|
(setq display-line-numbers
|
|
|
|
|
(pcase arg
|
|
|
|
|
(+1 doom-line-numbers-style)
|
|
|
|
|
(-1 nil)
|
|
|
|
|
(_ doom-line-numbers-style))))
|
|
|
|
|
((eq doom-line-numbers-style 'relative)
|
|
|
|
|
(if (= arg -1)
|
|
|
|
|
(nlinum-relative-off)
|
|
|
|
|
(nlinum-relative-on)))
|
|
|
|
|
((not (null doom-line-numbers-style))
|
|
|
|
|
(nlinum-mode (or arg +1)))))
|
|
|
|
|
|
|
|
|
|
(defun doom|disable-line-numbers ()
|
|
|
|
|
"Disable the display of line numbers."
|
|
|
|
|
(doom|enable-line-numbers -1))
|
|
|
|
|
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(add-hook! (prog-mode text-mode conf-mode) #'doom|enable-line-numbers)
|
2017-07-18 22:07:13 +02:00
|
|
|
|
|
|
|
|
|
;; Emacs 26+ has native line number support.
|
2017-12-10 14:50:43 -05:00
|
|
|
|
;; Line number column. A faster (or equivalent, in the worst case) line number
|
|
|
|
|
;; plugin than `linum-mode'.
|
|
|
|
|
(def-package! nlinum
|
|
|
|
|
:unless (boundp 'display-line-numbers)
|
|
|
|
|
:commands nlinum-mode
|
|
|
|
|
:init
|
|
|
|
|
(defvar doom-line-number-lpad 4
|
|
|
|
|
"How much padding to place before line numbers.")
|
|
|
|
|
(defvar doom-line-number-rpad 1
|
|
|
|
|
"How much padding to place after line numbers.")
|
|
|
|
|
(defvar doom-line-number-pad-char 32
|
|
|
|
|
"Character to use for padding line numbers.
|
2017-07-18 22:07:13 +02:00
|
|
|
|
|
|
|
|
|
By default, this is a space character. If you use `whitespace-mode' with
|
|
|
|
|
`space-mark', the whitespace in line numbers will be affected (this can look
|
|
|
|
|
ugly). In this case, you can change this to ?\u2002, which is a unicode
|
|
|
|
|
character that looks like a space that `whitespace-mode' won't affect.")
|
2017-12-10 14:50:43 -05:00
|
|
|
|
:config
|
|
|
|
|
(setq nlinum-highlight-current-line t)
|
2017-07-18 22:07:13 +02:00
|
|
|
|
|
2017-12-10 14:50:43 -05:00
|
|
|
|
;; Fix lingering hl-line overlays (caused by nlinum)
|
|
|
|
|
(add-hook! 'hl-line-mode-hook
|
|
|
|
|
(remove-overlays (point-min) (point-max) 'face 'hl-line))
|
2017-07-18 22:07:13 +02:00
|
|
|
|
|
2017-12-10 14:50:43 -05:00
|
|
|
|
(defun doom-nlinum-format-fn (line _width)
|
|
|
|
|
"A more customizable `nlinum-format-function'. See `doom-line-number-lpad',
|
2017-07-18 22:07:13 +02:00
|
|
|
|
`doom-line-number-rpad' and `doom-line-number-pad-char'. Allows a fix for
|
|
|
|
|
`whitespace-mode' space-marks appearing inside the line number."
|
2017-12-10 14:50:43 -05:00
|
|
|
|
(let ((str (number-to-string line)))
|
|
|
|
|
(setq str (concat (make-string (max 0 (- doom-line-number-lpad (length str)))
|
|
|
|
|
doom-line-number-pad-char)
|
|
|
|
|
str
|
|
|
|
|
(make-string doom-line-number-rpad doom-line-number-pad-char)))
|
|
|
|
|
(put-text-property 0 (length str) 'face
|
|
|
|
|
(if (and nlinum-highlight-current-line
|
|
|
|
|
(= line nlinum--current-line))
|
|
|
|
|
'nlinum-current-line
|
|
|
|
|
'linum)
|
|
|
|
|
str)
|
|
|
|
|
str))
|
|
|
|
|
(setq nlinum-format-function #'doom-nlinum-format-fn)
|
|
|
|
|
|
|
|
|
|
(defun doom|init-nlinum-width ()
|
|
|
|
|
"Calculate line number column width beforehand (optimization)."
|
|
|
|
|
(setq nlinum--width
|
|
|
|
|
(length (save-excursion (goto-char (point-max))
|
|
|
|
|
(format-mode-line "%l")))))
|
|
|
|
|
(add-hook 'nlinum-mode-hook #'doom|init-nlinum-width))
|
|
|
|
|
|
|
|
|
|
;; Fixes disappearing line numbers in nlinum and other quirks
|
|
|
|
|
(def-package! nlinum-hl
|
|
|
|
|
:unless (boundp 'display-line-numbers)
|
|
|
|
|
:after nlinum
|
|
|
|
|
:config
|
|
|
|
|
;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode',
|
|
|
|
|
;; line numbers tend to vanish next to code blocks.
|
|
|
|
|
(advice-add #'markdown-fontify-code-block-natively
|
|
|
|
|
:after #'nlinum-hl-do-markdown-fontify-region)
|
|
|
|
|
;; When using `web-mode's code-folding an entire range of line numbers will
|
|
|
|
|
;; vanish in the affected area.
|
|
|
|
|
(advice-add #'web-mode-fold-or-unfold :after #'nlinum-hl-do-generic-flush)
|
|
|
|
|
;; Changing fonts can leave nlinum line numbers in their original size; this
|
|
|
|
|
;; forces them to resize.
|
|
|
|
|
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
|
|
|
|
|
|
|
|
|
|
(def-package! nlinum-relative
|
|
|
|
|
:unless (boundp 'display-line-numbers)
|
|
|
|
|
:commands nlinum-relative-mode
|
|
|
|
|
:config
|
|
|
|
|
(after! evil (nlinum-relative-setup-evil)))
|
2017-07-18 22:07:13 +02:00
|
|
|
|
|
|
|
|
|
|
2017-02-11 06:02:46 -05:00
|
|
|
|
;;
|
|
|
|
|
;; Modeline
|
|
|
|
|
;;
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(defmacro def-modeline-segment! (name &rest forms)
|
2017-03-04 00:28:16 -05:00
|
|
|
|
"Defines a modeline segment and byte compiles it."
|
2017-02-11 06:02:46 -05:00
|
|
|
|
(declare (indent defun) (doc-string 2))
|
2017-03-04 00:28:16 -05:00
|
|
|
|
(let ((sym (intern (format "doom-modeline-segment--%s" name))))
|
|
|
|
|
`(progn
|
|
|
|
|
(defun ,sym () ,@forms)
|
|
|
|
|
,(unless (bound-and-true-p byte-compile-current-file)
|
|
|
|
|
`(let (byte-compile-warnings)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(byte-compile #',sym))))))
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
|
|
|
|
(defsubst doom--prepare-modeline-segments (segments)
|
2017-06-08 11:47:56 +02:00
|
|
|
|
(cl-loop for seg in segments
|
|
|
|
|
if (stringp seg)
|
|
|
|
|
collect seg
|
|
|
|
|
else
|
|
|
|
|
collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg))))))
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(defmacro def-modeline! (name lhs &optional rhs)
|
2017-03-04 00:28:16 -05:00
|
|
|
|
"Defines a modeline format and byte-compiles it. NAME is a symbol to identify
|
|
|
|
|
it (used by `doom-modeline' for retrieval). LHS and RHS are lists of symbols of
|
|
|
|
|
modeline segments defined with `def-modeline-segment!'.
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
|
|
|
|
Example:
|
2017-03-04 00:28:16 -05:00
|
|
|
|
(def-modeline! minimal
|
|
|
|
|
(bar matches \" \" buffer-info)
|
|
|
|
|
(media-info major-mode))
|
2017-04-25 18:25:54 -04:00
|
|
|
|
(doom-set-modeline 'minimal t)"
|
2017-02-13 04:52:44 -05:00
|
|
|
|
(let ((sym (intern (format "doom-modeline-format--%s" name)))
|
2017-02-11 06:02:46 -05:00
|
|
|
|
(lhs-forms (doom--prepare-modeline-segments lhs))
|
|
|
|
|
(rhs-forms (doom--prepare-modeline-segments rhs)))
|
2017-03-04 00:28:16 -05:00
|
|
|
|
`(progn
|
|
|
|
|
(defun ,sym ()
|
|
|
|
|
(let ((lhs (list ,@lhs-forms))
|
|
|
|
|
(rhs (list ,@rhs-forms)))
|
2017-06-17 11:40:21 +02:00
|
|
|
|
(let ((rhs-str (format-mode-line rhs)))
|
|
|
|
|
(list lhs
|
|
|
|
|
(propertize
|
|
|
|
|
" " 'display
|
|
|
|
|
`((space :align-to (- (+ right right-fringe right-margin)
|
|
|
|
|
,(+ 1 (string-width rhs-str))))))
|
|
|
|
|
rhs-str))))
|
2017-03-04 00:28:16 -05:00
|
|
|
|
,(unless (bound-and-true-p byte-compile-current-file)
|
|
|
|
|
`(let (byte-compile-warnings)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(byte-compile #',sym))))))
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
|
|
|
|
(defun doom-modeline (key)
|
2017-03-04 00:28:16 -05:00
|
|
|
|
"Returns a mode-line configuration associated with KEY (a symbol). Throws an
|
|
|
|
|
error if it doesn't exist."
|
2017-02-13 04:52:44 -05:00
|
|
|
|
(let ((fn (intern (format "doom-modeline-format--%s" key))))
|
2017-04-25 18:25:54 -04:00
|
|
|
|
(when (functionp fn)
|
|
|
|
|
`(:eval (,fn)))))
|
|
|
|
|
|
|
|
|
|
(defun doom-set-modeline (key &optional default)
|
|
|
|
|
"Set the modeline format. Does nothing if the modeline KEY doesn't exist. If
|
|
|
|
|
DEFAULT is non-nil, set the default mode-line for all buffers."
|
2017-12-10 14:49:52 -05:00
|
|
|
|
(when-let* ((modeline (doom-modeline key)))
|
2017-07-18 22:12:50 +02:00
|
|
|
|
(setf (if default
|
|
|
|
|
(default-value 'mode-line-format)
|
|
|
|
|
(buffer-local-value 'mode-line-format (current-buffer)))
|
|
|
|
|
modeline)))
|
2017-02-11 06:02:46 -05:00
|
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
|
(provide 'core-ui)
|
|
|
|
|
;;; core-ui.el ends here
|