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-05-13 11:59:52 +02:00
|
|
|
|
(defvar doom-ui-fringe-size '4 "Default fringe width")
|
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
|
|
|
|
|
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
|
|
|
|
|
resize-mini-windows 'grow-only ; Minibuffer resizing
|
|
|
|
|
show-help-function nil ; hide :help-echo text
|
|
|
|
|
split-width-threshold nil ; 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-02-19 18:11:28 -05:00
|
|
|
|
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)))
|
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
|
|
|
|
|
|
|
|
|
;; 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
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(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
|
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
|
|
|
|
|
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
|
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-02-19 19:01:12 -05:00
|
|
|
|
(require 'winner)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(add-hook 'window-setup-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)
|
|
|
|
|
(show-paren-mode +1)
|
|
|
|
|
|
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
|
|
|
|
|
window-divider-default-bottom-width 1
|
|
|
|
|
window-divider-default-right-width 1)
|
|
|
|
|
(window-divider-mode +1)
|
|
|
|
|
|
2017-05-28 16:12:28 +02:00
|
|
|
|
;; like diminish, but for major-modes. [pedantry intensifies]
|
|
|
|
|
(defvar doom-ui-mode-names
|
|
|
|
|
'((sh-mode . "sh")
|
|
|
|
|
(emacs-lisp-mode "Elisp"))
|
|
|
|
|
"An alist mapping major modes to alternative names, which will be set when the
|
|
|
|
|
mode is detected.")
|
|
|
|
|
|
|
|
|
|
(defun doom|set-mode-name ()
|
|
|
|
|
"Set the major mode's `mode-name', as dictated by `doom-ui-mode-names'."
|
|
|
|
|
(let ((name (assq major-mode doom-ui-mode-names)))
|
|
|
|
|
(if name (setq mode-name (cdr name)))))
|
|
|
|
|
(add-hook 'after-change-major-mode-hook #'doom|set-mode-name)
|
|
|
|
|
|
2016-10-04 22:52:43 +02:00
|
|
|
|
|
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
;; Bootstrap
|
2016-10-04 22:52:43 +02:00
|
|
|
|
;;
|
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-06-04 21:28:19 +02:00
|
|
|
|
(when (fboundp 'tool-bar-mode)
|
|
|
|
|
(tool-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)
|
2017-01-28 02:03:35 -05:00
|
|
|
|
;; buffer name in frame title
|
2017-02-19 18:11:28 -05:00
|
|
|
|
(setq-default frame-title-format '("DOOM Emacs"))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
;; standardize fringe width
|
2017-02-21 16:04:35 -05:00
|
|
|
|
(push (cons 'left-fringe doom-ui-fringe-size) default-frame-alist)
|
|
|
|
|
(push (cons 'right-fringe doom-ui-fringe-size) default-frame-alist)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
;; no fringe in the minibuffer
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(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-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-02-19 19:01:33 -05:00
|
|
|
|
:config
|
|
|
|
|
(setq hs-hide-comments-when-hiding-all nil))
|
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-03-25 03:15:37 -04:00
|
|
|
|
(def-package! highlight-indentation
|
|
|
|
|
:commands (highlight-indentation-mode highlight-indentation-current-column-mode)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
:config
|
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
|
2017-03-25 03:15:37 -04:00
|
|
|
|
buffer so that `highlight-indentation-mode' will display uninterrupted indent
|
2017-01-28 02:03:35 -05:00
|
|
|
|
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)
|
2017-03-25 03:15:37 -04:00
|
|
|
|
(while (and (re-search-forward "^$" end-marker t) (< (point) end-marker))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
(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)
|
|
|
|
|
|
2017-03-25 03:15:37 -04:00
|
|
|
|
(add-hook! (highlight-indentation-mode highlight-indentation-current-column-mode)
|
2017-04-21 15:56:50 -04:00
|
|
|
|
(if (or highlight-indentation-mode highlight-indentation-current-column-mode)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
(progn
|
2017-02-01 00:31:58 -05:00
|
|
|
|
(doom|inject-trailing-whitespace)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
|
|
|
|
|
(add-hook 'after-save-hook #'doom|inject-trailing-whitespace nil t))
|
|
|
|
|
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)
|
|
|
|
|
(remove-hook 'after-save-hook #'doom|inject-trailing-whitespace t)
|
2017-01-28 02:03:35 -05:00
|
|
|
|
(delete-trailing-whitespace))))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2017-02-19 18:11:28 -05:00
|
|
|
|
;; For modes that don't adequately highlight numbers
|
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-01-28 02:03:35 -05:00
|
|
|
|
;; Line highlighting
|
2017-02-23 00:06:12 -05:00
|
|
|
|
(def-package! hl-line ; built-in
|
2017-05-13 22:39:50 +02:00
|
|
|
|
:init
|
|
|
|
|
(add-hook! (linum-mode nlinum-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-06-05 03:12:06 +02:00
|
|
|
|
;; Fix lingering hl-line overlays
|
|
|
|
|
(add-hook! 'hl-line-mode-hook
|
|
|
|
|
(remove-overlays (point-min) (point-max) 'face 'hl-line))
|
|
|
|
|
|
2017-06-05 00:47:56 +02:00
|
|
|
|
;; Acts & looks weird with evil visual mode, so disable it temporarily
|
2017-05-14 00:19:45 +02:00
|
|
|
|
(defun doom|hl-line-off () (hl-line-mode -1))
|
|
|
|
|
(after! evil
|
|
|
|
|
(add-hook! 'hl-line-mode-hook
|
|
|
|
|
(when hl-line-mode
|
|
|
|
|
(add-hook 'evil-visual-state-entry-hook #'doom|hl-line-off nil t)
|
|
|
|
|
(add-hook 'evil-visual-state-exit-hook #'hl-line-mode nil t)))))
|
2016-05-01 01:05:25 -04:00
|
|
|
|
|
2017-05-27 14:33:59 +02:00
|
|
|
|
;; Line number column. A faster (or equivalent, in the worst case) line number
|
|
|
|
|
;; plugin than the built-in `linum'.
|
|
|
|
|
(def-package! nlinum
|
|
|
|
|
:commands nlinum-mode
|
|
|
|
|
:preface
|
|
|
|
|
(defvar linum-format "%3d ")
|
|
|
|
|
(defvar nlinum-format "%4d ")
|
2015-11-09 15:52:42 -05:00
|
|
|
|
:init
|
2017-05-13 22:39:50 +02:00
|
|
|
|
(add-hook! (prog-mode text-mode)
|
|
|
|
|
(unless (eq major-mode 'org-mode)
|
2017-05-27 14:33:59 +02:00
|
|
|
|
(nlinum-mode +1)))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
2015-10-03 04:56:33 -04:00
|
|
|
|
:config
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(defun doom-nlinum-flush-window (&optional window)
|
|
|
|
|
(let ((window (or window (selected-window)))
|
|
|
|
|
(orig-win (selected-window)))
|
|
|
|
|
(with-selected-window window
|
|
|
|
|
(when nlinum-mode
|
|
|
|
|
(if (not (eq window orig-win))
|
|
|
|
|
(nlinum--flush)
|
|
|
|
|
;; done in two steps to leave current line number highlighting alone
|
|
|
|
|
(nlinum--region (point-min) (max 1 (1- (line-beginning-position))))
|
|
|
|
|
(nlinum--region (min (point-max) (1+ (line-end-position))) (point-max)))))))
|
|
|
|
|
|
|
|
|
|
;; nlinum has a tendency to lose line numbers over time; a known issue. These
|
|
|
|
|
;; hooks/advisors attempt to stave off these glitches.
|
2017-05-27 14:33:59 +02:00
|
|
|
|
(defun doom*nlinum-flush-all-windows (&rest _)
|
|
|
|
|
"Fix nlinum margins after major UI changes (like a change of font)."
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(mapc #'doom-nlinum-flush-window (doom-visible-windows))
|
|
|
|
|
nil)
|
2017-05-27 14:33:59 +02:00
|
|
|
|
(advice-add #'set-frame-font :after #'doom*nlinum-flush-all-windows)
|
|
|
|
|
|
|
|
|
|
(defun doom*nlinum-flush (&optional _ norecord)
|
|
|
|
|
;; norecord check is necessary to prevent infinite recursion in
|
|
|
|
|
;; `select-window'
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(when (not norecord) (doom-nlinum-flush-window)))
|
2017-05-27 14:33:59 +02:00
|
|
|
|
(advice-add #'select-window :before #'doom*nlinum-flush)
|
|
|
|
|
(advice-add #'select-window :after #'doom*nlinum-flush)
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(add-hook '+evil-esc-hook #'doom*nlinum-flush-all-windows t)
|
|
|
|
|
(add-hook 'focus-in-hook #'doom*nlinum-flush-all-windows)
|
|
|
|
|
(add-hook 'focus-out-hook #'doom*nlinum-flush-all-windows)
|
2017-05-27 14:33:59 +02:00
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
(after! web-mode
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(advice-add #'web-mode-fold-or-unfold :after #'doom*nlinum-flush))
|
2017-05-27 14:33:59 +02:00
|
|
|
|
|
|
|
|
|
;; Optimization: calculate line number column width beforehand
|
|
|
|
|
(add-hook! nlinum-mode
|
2017-05-28 15:33:05 +02:00
|
|
|
|
(setq nlinum--width
|
|
|
|
|
(length (save-excursion (goto-char (point-max))
|
|
|
|
|
(format-mode-line "%l"))))))
|
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-23 00:06:12 -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)
|
2017-04-17 02:17:10 -04:00
|
|
|
|
:init (add-hook 'lisp-mode-hook #'rainbow-delimiters-mode))
|
2016-08-28 22:54:48 +02:00
|
|
|
|
|
2017-05-14 00:20:00 +02:00
|
|
|
|
;; indicators for empty lines past EOF
|
2017-05-14 11:54:18 +02:00
|
|
|
|
(def-package! vi-tilde-fringe
|
|
|
|
|
:when (display-graphic-p)
|
|
|
|
|
:demand t
|
2017-05-14 00:20:00 +02:00
|
|
|
|
:config (global-vi-tilde-fringe-mode t))
|
|
|
|
|
|
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-04-08 01:30:05 -04:00
|
|
|
|
(setq-default visual-fill-column-center-text nil
|
2017-03-08 14:41:49 -05:00
|
|
|
|
visual-fill-column-width fill-column))
|
2017-03-06 19:06:59 -05: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-03-04 00:28:16 -05:00
|
|
|
|
(let (segs)
|
|
|
|
|
(dolist (seg segments (nreverse segs))
|
|
|
|
|
(push (if (stringp seg)
|
|
|
|
|
seg
|
|
|
|
|
(list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))
|
|
|
|
|
segs))))
|
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)))
|
|
|
|
|
(list lhs
|
|
|
|
|
(propertize
|
|
|
|
|
" " 'display
|
|
|
|
|
`((space :align-to (- (+ right right-fringe right-margin)
|
|
|
|
|
,(+ 1 (string-width (format-mode-line rhs)))))))
|
|
|
|
|
rhs)))
|
|
|
|
|
,(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."
|
|
|
|
|
(let ((modeline (doom-modeline key)))
|
|
|
|
|
(when modeline
|
|
|
|
|
(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
|