doomemacs/core/core-ui.el

211 lines
7.9 KiB
EmacsLisp
Raw Normal View History

2015-06-06 18:40:33 +08:00
;;; core-ui.el --- interface settings
2015-06-15 15:05:52 +08:00
;; see lib/ui-defuns.el
2015-06-24 21:36:05 +08:00
(when window-system
(fringe-mode '(1 . 8))
(set-frame-font narf-default-font)
2015-08-11 21:10:37 +08:00
(setq frame-title-format '(buffer-file-name "%f" ("%b"))))
2015-06-06 18:40:33 +08:00
2015-10-01 01:47:57 +08:00
;; Highlight matching parens
(setq show-paren-delay 0.05)
(show-paren-mode 1)
2015-06-05 06:23:21 +08:00
2015-10-01 01:47:57 +08:00
(global-hl-line-mode 1) ; do highlight line
(blink-cursor-mode 1) ; do blink cursor
(line-number-mode 1) ; do show line no in modeline
(column-number-mode 1) ; do show col no in modeline
(tooltip-mode -1) ; don't show tooltips
(size-indication-mode -1)
2015-06-05 06:23:21 +08:00
(setq-default
line-spacing 1
2015-07-28 19:13:20 +08: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-05 06:23:21 +08:00
cursor-in-non-selected-windows nil
2015-07-28 19:13:20 +08:00
2015-06-05 06:23:21 +08:00
visible-bell nil ; silence of the bells
2015-06-06 18:40:33 +08:00
use-dialog-box nil ; avoid GUI
2015-06-05 06:23:21 +08:00
redisplay-dont-pause t
indicate-buffer-boundaries nil
indicate-empty-lines nil
2015-06-06 18:40:33 +08:00
fringes-outside-margins t) ; fringes on the other side of line numbers
2015-06-05 06:23:21 +08:00
2015-07-28 19:13:20 +08:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package fill-column-indicator
:config
(setq fci-rule-color "#2b303f")
(setq-default fill-column 80)
(add-hook! text-mode 'fci-mode))
2015-06-15 15:05:52 +08:00
(use-package nlinum ; line numbers
:defer t
2015-06-06 18:40:33 +08:00
:defines nlinum--width
:preface
(defface linum '((t (:inherit default)))
"Face for line numbers" :group 'nlinum-mode)
(defface linum-highlight-face '((t (:inherit linum)))
"Face for line highlights" :group 'nlinum-mode)
(defvar narf--hl-nlinum-overlay nil)
(defvar narf--hl-nlinum-line nil)
2015-08-06 18:46:39 +08:00
(defvar nlinum-format " %3d ")
2015-06-06 18:40:33 +08:00
:init
(defun narf|nlinum-unhl-line ()
2015-10-01 01:47:57 +08:00
"Highlight line number"
2015-06-06 18:40:33 +08: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 15:05:52 +08:00
narf--hl-nlinum-line nil))))
2015-06-06 18:40:33 +08:00
(defun narf|nlinum-hl-line (&optional line)
2015-10-01 01:47:57 +08:00
"Unhighlight line number"
2015-06-06 18:40:33 +08: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
(when (>= peol (point-max))
(setq peol (point-max)))
(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)
(let* ((disp (get-text-property 0 'display (overlay-get ov 'before-string)))
(str (nth 1 disp)))
(put-text-property 0 (length str) 'face 'linum-highlight-face str)
(put-text-property 0 (length str) 'face 'linum-highlight-face str)
(setq narf--hl-nlinum-overlay ov
narf--hl-nlinum-line line-no))))))))
(defun narf|nlinum-enable ()
(nlinum-mode +1)
2015-10-01 01:47:57 +08:00
(add-hook! post-command 'narf|nlinum-hl-line))
2015-06-06 18:40:33 +08:00
(defun narf|nlinum-disable ()
(nlinum-mode -1)
(remove-hook 'post-command-hook 'narf|nlinum-hl-line)
(narf|nlinum-unhl-line))
;; Preset width nlinum
2015-07-24 19:04:46 +08:00
(add-hook! (text-mode prog-mode scss-mode web-mode) 'narf|nlinum-enable)
(add-hook! org-mode 'narf|nlinum-disable)
2015-06-15 15:05:52 +08:00
(add-hook! nlinum-mode
2015-06-06 18:40:33 +08:00
(setq nlinum--width (length (number-to-string (count-lines (point-min) (point-max)))))))
2015-09-28 11:36:09 +08:00
;; Mode-line ;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-06-06 18:40:33 +08:00
2015-09-29 03:55:25 +08:00
(use-package spaceline-segments
2015-10-01 01:47:57 +08:00
:config
2015-09-29 03:55:25 +08:00
(setq-default
powerline-default-separator 'wave
powerline-height 18)
;; Modeline cache
2015-10-01 01:47:57 +08:00
(defvar narf--spaceline-file-path nil)
(make-variable-buffer-local 'narf--spaceline-file-path)
(add-hook! focus-in (setq narf--spaceline-file-path nil))
2015-10-01 01:47:57 +08:00
(defface mode-line-is-modified nil "Face for mode-line modified symbol")
(defface mode-line-buffer-path nil "Face for mode-line buffer directory")
2015-10-01 01:47:57 +08:00
;; Custom modeline segments
2015-09-29 03:55:25 +08:00
(spaceline-define-segment narf-buffer-path
"Base filename of buffer."
(concat (file-name-nondirectory buffer-file-name)
(if (buffer-modified-p)
(propertize "*" 'face 'mode-line-is-modified))
2015-09-29 03:55:25 +08:00
" ")
:tight t)
(spaceline-define-segment narf-buffer-dir
"Buffer file directory."
(propertize
(or narf--spaceline-file-path
(setq narf--spaceline-file-path
(if (and buffer-file-name (file-exists-p buffer-file-name))
(progn
(let* ((max-length (/ (window-width) 2))
(project-path (narf/project-root))
(path (file-name-directory
(file-relative-name buffer-file-name
(file-name-directory (if (string-match "/+\\'" project-path)
(replace-match "" t t project-path)
project-path))))))
(if (> (length path) max-length)
(concat "" (replace-regexp-in-string
"^.*?/" "/"
(let ((l (length path))) (substring path (- l max-length) l))))
path)))
(powerline-buffer-id))))
'face (if (powerline-selected-window-active)
'mode-line-buffer-path
'mode-line-inactive))
2015-09-29 03:55:25 +08:00
:tight-right t)
(spaceline-define-segment narf-buffer-encoding-abbrev
"The line ending convention used in the buffer."
2015-10-01 01:47:57 +08:00
(let ((buf-coding (symbol-name buffer-file-coding-system)))
2015-09-29 03:55:25 +08:00
(if (string-match "\\(dos\\|unix\\|mac\\)" buf-coding)
(match-string 1 buf-coding)
buf-coding))
2015-10-01 01:47:57 +08:00
:when (not (string-match-p "unix" (symbol-name buffer-file-coding-system))))
2015-09-29 03:55:25 +08:00
(spaceline-define-segment narf-buffer-position
"A more vim-like buffer position."
(let ((perc (/ (window-end) 0.01 (point-max))))
(cond ((eq (window-start) 1) ":Top")
((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc)))))
(spaceline-define-segment narf-vc
"Version control info"
(let ((vc (vc-working-revision buffer-file-name)))
(when vc
(format "%s %s%s" (char-to-string #xe0a0) vc
(case (vc-state buffer-file-name) ('edited "+") ('conflict "!!!") (t "")))))
:when (and active vc-mode))
2015-09-29 03:55:25 +08:00
(spaceline-define-segment narf-hud
"A HUD that shows which part of the buffer is currently visible."
(powerline-hud highlight-face default-face)
:tight t)
;; Display version string
(defvar narf--env-version nil)
(defvar narf--env-command nil)
(make-variable-buffer-local 'narf--env-version)
(make-variable-buffer-local 'narf--env-command)
(spaceline-define-segment narf-env-version
"A HUD that shows which part of the buffer is currently visible."
(unless 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-01 01:47:57 +08:00
;; Initialize modeline
2015-09-29 03:55:25 +08:00
(spaceline-install
;; Left side
'((narf-buffer-dir :face other-face)
(narf-buffer-path remote-host)
(narf-vc)
((flycheck-error flycheck-warning flycheck-info) :face other-face :when active))
2015-09-29 03:55:25 +08:00
;; Right side
'(selection-info
narf-env-version
2015-09-29 03:55:25 +08:00
narf-buffer-encoding-abbrev
2015-10-01 01:47:57 +08:00
(major-mode (minor-modes :separator " ") process :when active)
2015-09-29 03:55:25 +08:00
(global :when active)
2015-10-01 01:47:57 +08:00
narf-buffer-position
narf-hud)))
2015-06-05 06:23:21 +08:00
(provide 'core-ui)
;;; core-ui.el ends here