doomemacs/core/core-ui.el

316 lines
11 KiB
EmacsLisp
Raw Normal View History

2015-06-06 06:40:33 -04:00
;;; core-ui.el --- interface settings
2015-06-15 09:05:52 +02:00
;; see lib/ui-defuns.el
(if window-system
(progn
(fringe-mode '(3 . 6))
(setq frame-title-format '(buffer-file-name "%f" ("%b")))
(setq initial-frame-alist '((width . 120) (height . 80)))
2015-11-09 20:49:33 -05:00
(set-frame-font narf-default-font)
(set-face-attribute 'default t :font narf-default-font)
(define-fringe-bitmap 'tilde [0 0 0 113 219 142 0 0] nil nil 'center)
(setcdr (assq 'empty-line fringe-indicator-alist) 'tilde)
(set-fringe-bitmap-face 'tilde 'font-lock-comment-face))
2015-10-26 01:29:38 -04:00
(menu-bar-mode -1))
2015-06-06 06:40:33 -04:00
2015-06-04 18:23:21 -04:00
(setq-default
2015-10-08 01:46:19 -04:00
blink-matching-paren nil
2015-11-09 15:52:42 -05:00
show-paren-delay 0.075
2015-10-26 01:29:38 -04:00
2015-07-28 13:13:20 +02:00
;; Multiple cursors across buffers cause a strange redraw delay for
;; some things, like auto-complete or evil-mode's cursor color
;; switching.
2015-06-04 18:23:21 -04:00
cursor-in-non-selected-windows nil
2015-11-09 15:52:42 -05:00
highlight-nonselected-windows nil
2015-07-28 13:13:20 +02:00
2015-10-12 04:31:55 -04:00
uniquify-buffer-name-style nil
2015-11-10 18:01:57 -05:00
visible-bell nil ; silence of the bells
use-dialog-box nil ; always avoid GUI
2015-11-09 15:52:42 -05:00
redisplay-dont-pause t
2015-06-04 18:23:21 -04:00
indicate-buffer-boundaries nil
2015-11-10 18:01:57 -05:00
indicate-empty-lines t
fringes-outside-margins t
hl-line-sticky-flag nil
2015-10-26 01:29:38 -04:00
jit-lock-defer-time 0
2015-11-09 15:52:42 -05:00
jit-lock-stealth-time 1
resize-mini-windows t)
2015-11-10 18:01:57 -05:00
(blink-cursor-mode 1) ; do blink cursor
(tooltip-mode -1) ; show tooltips in echo area
;; Highlight line
(add-hook! (prog-mode puml-mode markdown-mode) 'hl-line-mode)
;; Disable line highlight in visual mode
(defvar narf--hl-line-mode nil)
(make-variable-buffer-local 'narf--hl-line-mode)
(defun narf|hl-line-on ()
(when narf--hl-line-mode (hl-line-mode +1)))
(defun narf|hl-line-off ()
(when narf--hl-line-mode (hl-line-mode -1)))
(add-hook! hl-line-mode (if hl-line-mode (setq narf--hl-line-mode t)))
(add-hook! evil-visual-state-entry 'narf|hl-line-off)
(add-hook! evil-visual-state-exit 'narf|hl-line-on)
;; Hide modeline in help windows ;;;;;;;
(add-hook! help-mode (setq-local mode-line-format nil))
2015-11-10 18:01:57 -05:00
;; Highlight TODO/FIXME/NOTE tags ;;;;;;
2015-11-07 20:16:31 -05:00
(defface narf-todo-face '((t (:inherit font-lock-warning-face))) "Face for TODOs")
(defface narf-fixme-face '((t (:inherit font-lock-warning-face))) "Face for FIXMEs")
(defface narf-note-face '((t (:inherit font-lock-warning-face))) "Face for NOTEs")
(add-hook! (prog-mode emacs-lisp-mode)
(font-lock-add-keywords nil '(("\\<\\(TODO\\((.+)\\)?:?\\)" 1 'narf-todo-face prepend)))
(font-lock-add-keywords nil '(("\\<\\(FIXME\\((.+)\\)?:?\\)" 1 'narf-fixme-face prepend)))
(font-lock-add-keywords nil '(("\\<\\(NOTE\\((.+)\\)?:?\\)" 1 'narf-note-face prepend))))
2015-06-04 18:23:21 -04:00
2015-07-28 13:13:20 +02:00
2015-11-07 20:16:31 -05:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-11-09 20:49:33 -05:00
(use-package writeroom-mode
:defer t
:config
(setq-default
writeroom-restore-window-config t
writeroom-fullscreen-effect nil
writeroom-width 110))
(use-package hideshow
:commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p)
:diminish hs-minor-mode
:init
(after! evil
(defun narf-load-hs-minor-mode ()
(advice-remove 'evil-toggle-fold 'narf-load-hs-minor-mode)
(hs-minor-mode 1))
(advice-add 'evil-toggle-fold :before 'narf-load-hs-minor-mode)))
(use-package rainbow-delimiters
:commands rainbow-delimiters-mode
:init (add-hook! (emacs-lisp-mode js2-mode scss-mode) 'rainbow-delimiters-mode)
2015-11-09 15:52:42 -05:00
:config (setq rainbow-delimiters-max-face-count 4))
2015-11-09 15:52:42 -05:00
(use-package rainbow-mode :defer t
:init (add-hook! rainbow-mode (hl-line-mode (if rainbow-mode -1 1))))
2015-10-08 01:49:13 -04:00
(use-package popwin
:config
2015-11-09 15:52:42 -05:00
(setq popwin:popup-window-height 20)
2015-10-08 01:49:13 -04:00
(mapc (lambda (rule) (push rule popwin:special-display-config))
2015-11-09 15:52:42 -05:00
'(("*eshell*" :position left :width 80 :stick t :dedicated t)
("*scratch*" :position bottom :height 20 :stick t :dedicated t)
("*Apropos*" :position bottom :height 40 :stick t :dedicated t)
("*quickrun*" :position bottom :height 10 :stick t)
("*helm-ag-edit*" :position bottom :height 20 :stick t)
(help-mode :position bottom :height 15 :stick t)
("*Backtrace*" :position bottom :height 15 :stick t)
("^\\*[Hh]elm.*?\\*\\'" :regexp t :position bottom :height 15)
("^\\*Org-Babel.*\\*$" :regexp t :position bottom :height 15)
("^\\*Org .*\\*$" :regexp t :position bottom :height 15)
("^\\*CPU-Profiler-Report .+\\*$" :regexp t :position bottom :height 0.35)
2015-10-28 03:31:51 -04:00
))
2015-10-08 01:49:13 -04:00
(popwin-mode 1))
(use-package volatile-highlights
:diminish volatile-highlights-mode
:config
(vhl/define-extension 'my-undo-tree-highlights
2015-10-26 01:29:38 -04:00
'undo-tree-undo 'undo-tree-redo)
(vhl/install-extension 'my-undo-tree-highlights)
(volatile-highlights-mode t))
2015-10-26 01:29:38 -04:00
(use-package nlinum
2015-10-28 03:31:51 -04:00
:commands nlinum-mode
2015-06-06 06:40:33 -04:00
:preface
(defvar narf--hl-nlinum-overlay nil)
2015-11-09 15:52:42 -05:00
(defvar narf--hl-nlinum-line nil)
2015-11-10 18:01:57 -05:00
(defvar nlinum-format " %4d ")
2015-10-03 04:56:33 -04:00
(defface linum-highlight-face '((t (:inherit linum))) "Face for line highlights")
2015-11-09 15:52:42 -05:00
:init
2015-10-03 04:56:33 -04:00
(defun narf|nlinum-enable ()
(nlinum-mode +1)
2015-11-09 15:52:42 -05:00
(add-hook 'post-command-hook 'narf|nlinum-hl-line))
2015-10-21 05:16:32 -04:00
2015-10-03 04:56:33 -04:00
(defun narf|nlinum-disable ()
(nlinum-mode -1)
(remove-hook 'post-command-hook 'narf|nlinum-hl-line)
(narf|nlinum-unhl-line))
2015-11-10 18:01:57 -05:00
(add-hook!
(markdown-mode prog-mode scss-mode web-mode)
'narf|nlinum-enable)
2015-10-03 04:56:33 -04:00
:config
2015-06-06 06:40:33 -04:00
(defun narf|nlinum-unhl-line ()
2015-09-30 13:47:57 -04:00
"Highlight line number"
2015-06-06 06:40:33 -04:00
(when narf--hl-nlinum-overlay
(let* ((ov narf--hl-nlinum-overlay)
(disp (get-text-property 0 'display (overlay-get ov 'before-string)))
(str (nth 1 disp)))
(put-text-property 0 (length str) 'face 'linum str)
(setq narf--hl-nlinum-overlay nil
2015-06-15 09:05:52 +02:00
narf--hl-nlinum-line nil))))
2015-06-06 06:40:33 -04:00
(defun narf|nlinum-hl-line (&optional line)
2015-09-30 13:47:57 -04:00
"Unhighlight line number"
2015-06-06 06:40:33 -04:00
(let ((line-no (or line (line-number-at-pos (point)))))
(when (and nlinum-mode (not (eq line-no narf--hl-nlinum-line)))
(let* ((pbol (if line (save-excursion (goto-char (point-min))
(forward-line line-no)
(point-at-bol))
(point-at-bol)))
(peol (1+ pbol)))
;; Handle EOF case
2015-10-28 03:31:51 -04:00
(let ((max (point-max)))
(when (>= peol max)
(setq peol max)))
2015-06-06 06:40:33 -04:00
(jit-lock-fontify-now pbol peol)
(let* ((overlays (overlays-in pbol peol))
(ov (-first (lambda (item) (overlay-get item 'nlinum)) overlays)))
(when ov
(narf|nlinum-unhl-line)
2015-11-09 15:52:42 -05:00
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
2015-06-06 06:40:33 -04:00
(put-text-property 0 (length str) 'face 'linum-highlight-face str)
(setq narf--hl-nlinum-overlay ov
narf--hl-nlinum-line line-no))))))))
2015-06-15 09:05:52 +02:00
(add-hook! nlinum-mode
2015-10-26 01:29:38 -04:00
(setq nlinum--width
(length (int-to-string (count-lines (point-min) (point-max)))))))
2015-06-06 06:40:33 -04:00
2015-09-27 23:36:09 -04:00
;; Mode-line ;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-06-06 06:40:33 -04:00
2015-09-28 15:55:25 -04:00
(use-package spaceline-segments
2015-11-07 00:20:04 -05:00
:init
(defvar narf--env-version nil)
(defvar narf--env-command nil)
(make-variable-buffer-local 'narf--env-version)
(make-variable-buffer-local 'narf--env-command)
2015-09-30 13:47:57 -04:00
:config
2015-09-28 15:55:25 -04:00
(setq-default
powerline-default-separator nil
2015-11-09 15:52:42 -05:00
powerline-height 18)
2015-09-28 15:55:25 -04:00
(defface mode-line-is-modified nil "Face for mode-line modified symbol")
2015-10-13 00:46:17 -04:00
(defface mode-line-buffer-file nil "Face for mode-line buffer file path")
2015-09-30 13:47:57 -04:00
;; Custom modeline segments
2015-09-28 15:55:25 -04:00
(spaceline-define-segment narf-buffer-path
2015-10-26 01:29:50 -04:00
(if buffer-file-name
(let* ((project-path (let (projectile-require-project-root) (projectile-project-root)))
(buffer-path (file-relative-name buffer-file-name project-path))
(max-length (/ (window-width) 2))
(path-len (length buffer-path)))
(concat (file-name-nondirectory (directory-file-name project-path))
"/"
(if (> path-len max-length)
(concat "" (replace-regexp-in-string
"^.*?/" "/"
(substring buffer-path (- path-len max-length) path-len)))
buffer-path)))
"%b")
:face (if active 'mode-line-buffer-file 'mode-line-inactive)
2015-11-07 00:20:04 -05:00
:tight t)
2015-10-26 01:29:50 -04:00
(spaceline-define-segment narf-buffer-modified
(concat
2015-10-28 17:27:37 -04:00
(when buffer-file-name
(concat
(when (buffer-modified-p) "[+]")
(unless (file-exists-p buffer-file-name) "[!]")))
(if buffer-read-only "[RO]"))
2015-10-26 01:29:50 -04:00
:face mode-line-is-modified
2015-10-28 17:27:37 -04:00
:when (not (string-prefix-p "*" (buffer-name)))
2015-11-09 15:52:42 -05:00
:skip-alternate t
2015-10-26 01:29:50 -04:00
:tight t)
2015-10-13 00:46:17 -04:00
2015-09-28 15:55:25 -04:00
(spaceline-define-segment narf-buffer-encoding-abbrev
"The line ending convention used in the buffer."
2015-10-28 17:27:37 -04:00
(symbol-name buffer-file-coding-system)
2015-11-04 01:45:11 -05:00
:when (not (string-match-p "\\(utf-8\\|undecided\\)" (symbol-name buffer-file-coding-system))))
2015-09-28 15:55:25 -04:00
(spaceline-define-segment narf-buffer-position
"A more vim-like buffer position."
2015-11-07 20:17:35 -05:00
(let ((start (window-start))
(end (window-end))
(pend (point-max)))
(if (and (eq start 1)
(eq end pend))
":All"
(let ((perc (/ end 0.01 pend)))
(cond ((eq start 1) ":Top")
((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc))))))
2015-10-26 01:29:50 -04:00
:tight-right t)
2015-09-28 15:55:25 -04:00
(spaceline-define-segment narf-vc
"Version control info"
(let ((vc (vc-working-revision buffer-file-name)))
(when vc
2015-10-26 01:29:50 -04:00
(format "%s%s" vc (case (vc-state buffer-file-name)
('edited "+")
('conflict "!!!")
(t "")))))
2015-11-09 15:52:42 -05:00
:face other-face
2015-10-26 01:29:50 -04:00
:when (and active vc-mode))
2015-09-28 15:55:25 -04:00
(spaceline-define-segment narf-env-version
"A HUD that shows which part of the buffer is currently visible."
2015-10-06 05:47:24 -04:00
(when (and narf--env-command (not narf--env-version))
(narf|spaceline-env-update))
narf--env-version
:when (and narf--env-version (memq major-mode '(ruby-mode enh-ruby-mode python-mode))))
2015-10-06 05:47:24 -04:00
(spaceline-define-segment narf-hud
"A HUD that shows which part of the buffer is currently visible."
(powerline-hud highlight-face default-face 1)
2015-10-26 01:29:50 -04:00
:tight-right t)
2015-10-06 05:47:24 -04:00
(spaceline-define-segment narf-anzu
"Show the current match number and the total number of matches. Requires anzu
to be enabled."
(let ((here anzu--current-position)
(total anzu--total-matched))
(when anzu--state
2015-11-07 00:20:04 -05:00
(concat
(propertize
(cl-case anzu--state
(search (format " %s/%d%s "
(anzu--format-here-position here total)
total (if anzu--overflow-p "+" "")))
(replace-query (format " %d replace " total))
(replace (format " %d/%d " here total)))
'face highlight-face)
" ")))
2015-10-26 01:29:50 -04:00
:when (and active (bound-and-true-p anzu--state))
:tight t)
2015-10-08 01:49:13 -04:00
2015-09-30 13:47:57 -04:00
;; Initialize modeline
2015-09-28 15:55:25 -04:00
(spaceline-install
;; Left side
2015-10-26 01:29:50 -04:00
'(narf-anzu
(narf-buffer-path remote-host)
2015-10-26 01:29:50 -04:00
narf-buffer-modified
2015-10-03 04:56:52 -04:00
narf-vc
((flycheck-error flycheck-warning flycheck-info) :when active))
2015-09-28 15:55:25 -04:00
;; Right side
'((selection-info :face highlight-face)
narf-env-version
2015-09-28 15:55:25 -04:00
narf-buffer-encoding-abbrev
2015-11-09 15:52:42 -05:00
((major-mode :tight-right t)
2015-11-04 01:45:11 -05:00
(minor-modes :tight t :separator "")
2015-10-03 04:56:52 -04:00
process :when active)
2015-09-28 15:55:25 -04:00
(global :when active)
2015-11-07 00:20:04 -05:00
("%l·%c" narf-buffer-position)
2015-11-09 15:52:42 -05:00
narf-hud
2015-10-06 05:47:24 -04:00
)))
2015-06-04 18:23:21 -04:00
(provide 'core-ui)
;;; core-ui.el ends here