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
|
|
|
|
|
2015-06-24 15:36:05 +02:00
|
|
|
(when window-system
|
2015-10-06 05:47:24 -04:00
|
|
|
(fringe-mode '(2 . 4))
|
2015-10-01 03:40:09 -04:00
|
|
|
(set-frame-font narf-default-font)
|
2015-08-11 15:10:37 +02:00
|
|
|
(setq frame-title-format '(buffer-file-name "%f" ("%b"))))
|
2015-06-06 06:40:33 -04:00
|
|
|
|
2015-09-30 13:47:57 -04:00
|
|
|
;; Highlight matching parens
|
2015-10-03 04:57:24 -04:00
|
|
|
(setq show-paren-delay 0.075)
|
2015-09-30 13:47:57 -04:00
|
|
|
(show-paren-mode 1)
|
2015-06-04 18:23:21 -04:00
|
|
|
|
2015-09-30 13:47:57 -04: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-04 18:23:21 -04:00
|
|
|
|
|
|
|
(setq-default
|
2015-10-08 01:46:19 -04:00
|
|
|
blink-matching-paren nil
|
2015-10-01 03:40:09 -04:00
|
|
|
line-spacing 1
|
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-07-28 13:13:20 +02:00
|
|
|
|
2015-06-04 18:23:21 -04:00
|
|
|
visible-bell nil ; silence of the bells
|
2015-06-06 06:40:33 -04:00
|
|
|
use-dialog-box nil ; avoid GUI
|
2015-06-04 18:23:21 -04:00
|
|
|
redisplay-dont-pause t
|
|
|
|
indicate-buffer-boundaries nil
|
|
|
|
indicate-empty-lines nil
|
2015-06-06 06:40:33 -04:00
|
|
|
fringes-outside-margins t) ; fringes on the other side of line numbers
|
2015-06-04 18:23:21 -04:00
|
|
|
|
2015-07-28 13:13:20 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2015-10-06 05:47:24 -04:00
|
|
|
(use-package yascroll
|
|
|
|
:config
|
|
|
|
(defun yascroll:compute-thumb-size (window-lines buffer-lines)
|
|
|
|
"Return the proper size (height) of scroll bar thumb."
|
|
|
|
(let ((window-lines (* window-lines 0.91)))
|
|
|
|
(if (zerop buffer-lines)
|
|
|
|
1
|
|
|
|
(max 1 (floor (min (* (/ (float window-lines) buffer-lines) window-lines) buffer-lines))))))
|
|
|
|
|
|
|
|
(setq yascroll:scroll-bar 'right-fringe
|
|
|
|
yascroll:delay-to-hide nil)
|
|
|
|
(add-to-list 'yascroll:enabled-window-systems 'mac)
|
|
|
|
(defadvice yascroll:before-change (around always-show-bar activate) ())
|
|
|
|
(global-yascroll-bar-mode 1))
|
|
|
|
|
2015-09-29 11:36:06 -04: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 09:05:52 +02:00
|
|
|
(use-package nlinum ; line numbers
|
2015-06-06 06:40:33 -04:00
|
|
|
:preface
|
|
|
|
(defvar narf--hl-nlinum-overlay nil)
|
|
|
|
(defvar narf--hl-nlinum-line nil)
|
2015-08-06 12:46:39 +02:00
|
|
|
(defvar nlinum-format " %3d ")
|
2015-06-06 06:40:33 -04:00
|
|
|
:init
|
2015-10-03 04:56:33 -04:00
|
|
|
(defface linum-highlight-face '((t (:inherit linum))) "Face for line highlights")
|
|
|
|
(defun narf|nlinum-enable ()
|
|
|
|
(nlinum-mode +1)
|
|
|
|
(add-hook! post-command 'narf|nlinum-hl-line))
|
|
|
|
(defun narf|nlinum-disable ()
|
|
|
|
(nlinum-mode -1)
|
|
|
|
(remove-hook 'post-command-hook 'narf|nlinum-hl-line)
|
|
|
|
(narf|nlinum-unhl-line))
|
|
|
|
|
|
|
|
;; Preset width nlinum
|
|
|
|
(add-hook! (text-mode prog-mode scss-mode web-mode) 'narf|nlinum-enable)
|
|
|
|
(add-hook! org-mode 'narf|nlinum-disable)
|
|
|
|
: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
|
|
|
|
(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))))))))
|
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
(add-hook! nlinum-mode
|
2015-06-06 06:40:33 -04:00
|
|
|
(setq nlinum--width (length (number-to-string (count-lines (point-min) (point-max)))))))
|
|
|
|
|
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-09-30 13:47:57 -04:00
|
|
|
:config
|
2015-09-28 15:55:25 -04:00
|
|
|
(setq-default
|
|
|
|
powerline-default-separator 'wave
|
|
|
|
powerline-height 18)
|
|
|
|
|
2015-10-01 03:40:09 -04:00
|
|
|
;; Modeline cache
|
2015-09-30 13:47:57 -04:00
|
|
|
(defvar narf--spaceline-file-path nil)
|
|
|
|
(make-variable-buffer-local 'narf--spaceline-file-path)
|
2015-10-01 03:40:09 -04:00
|
|
|
(add-hook! focus-in (setq narf--spaceline-file-path nil))
|
2015-09-30 13:47:57 -04:00
|
|
|
|
2015-10-01 03:40:09 -04: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-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-01 03:40:09 -04:00
|
|
|
"Base filename of buffer."
|
2015-10-03 04:21:24 -04:00
|
|
|
(if buffer-file-name
|
|
|
|
(concat (file-name-nondirectory buffer-file-name)
|
|
|
|
(if (buffer-modified-p)
|
|
|
|
(propertize "*" 'face 'mode-line-is-modified))
|
|
|
|
" ")
|
2015-10-03 19:40:24 -04:00
|
|
|
(format " %s " (powerline-buffer-id)))
|
2015-10-01 03:40:09 -04:00
|
|
|
:tight t)
|
|
|
|
|
|
|
|
(spaceline-define-segment narf-buffer-dir
|
|
|
|
"Buffer file directory."
|
|
|
|
(propertize
|
|
|
|
(or narf--spaceline-file-path
|
|
|
|
(setq narf--spaceline-file-path
|
2015-10-03 04:21:24 -04:00
|
|
|
(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)))))
|
|
|
|
(path-len (length path)))
|
|
|
|
(if (> path-len max-length)
|
|
|
|
(concat "…" (replace-regexp-in-string
|
|
|
|
"^.*?/" "/"
|
|
|
|
(substring path (- path-len max-length) path-len)))
|
|
|
|
path))))
|
2015-10-01 03:40:09 -04:00
|
|
|
'face (if (powerline-selected-window-active)
|
|
|
|
'mode-line-buffer-path
|
|
|
|
'mode-line-inactive))
|
2015-10-03 04:21:24 -04:00
|
|
|
:when buffer-file-name
|
2015-09-28 15:55:25 -04:00
|
|
|
:tight-right t)
|
|
|
|
|
|
|
|
(spaceline-define-segment narf-buffer-encoding-abbrev
|
|
|
|
"The line ending convention used in the buffer."
|
2015-09-30 13:47:57 -04:00
|
|
|
(let ((buf-coding (symbol-name buffer-file-coding-system)))
|
2015-09-28 15:55:25 -04:00
|
|
|
(if (string-match "\\(dos\\|unix\\|mac\\)" buf-coding)
|
|
|
|
(match-string 1 buf-coding)
|
|
|
|
buf-coding))
|
2015-09-30 13:47:57 -04:00
|
|
|
:when (not (string-match-p "unix" (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."
|
|
|
|
(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"
|
2015-10-01 03:40:09 -04:00
|
|
|
(let ((vc (vc-working-revision buffer-file-name)))
|
|
|
|
(when vc
|
2015-10-03 04:56:52 -04:00
|
|
|
(format " %s %s%s " (char-to-string #xe0a0) vc
|
2015-10-01 03:40:09 -04:00
|
|
|
(case (vc-state buffer-file-name) ('edited "+") ('conflict "!!!") (t "")))))
|
2015-10-03 04:56:52 -04:00
|
|
|
:when (and active vc-mode)
|
|
|
|
:tight t)
|
2015-09-28 15:55:25 -04:00
|
|
|
|
2015-09-28 19:51:16 -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)
|
|
|
|
:tight t)
|
|
|
|
|
2015-10-01 03:40:09 -04:00
|
|
|
;; 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."
|
2015-10-06 05:47:24 -04:00
|
|
|
(when (and narf--env-command (not narf--env-version))
|
2015-10-01 03:40:09 -04:00
|
|
|
(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)
|
|
|
|
:tight t)
|
|
|
|
|
2015-09-30 13:47:57 -04:00
|
|
|
;; Initialize modeline
|
2015-09-28 15:55:25 -04:00
|
|
|
(spaceline-install
|
|
|
|
;; Left side
|
2015-10-01 03:40:09 -04:00
|
|
|
'((narf-buffer-dir :face other-face)
|
|
|
|
(narf-buffer-path remote-host)
|
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
|
2015-09-28 19:51:16 -04:00
|
|
|
'(selection-info
|
2015-10-01 03:40:09 -04:00
|
|
|
narf-env-version
|
2015-09-28 15:55:25 -04:00
|
|
|
narf-buffer-encoding-abbrev
|
2015-10-03 04:56:52 -04:00
|
|
|
((" " :tight t)
|
|
|
|
major-mode
|
|
|
|
(minor-modes :separator " ")
|
|
|
|
process :when active)
|
2015-09-28 15:55:25 -04:00
|
|
|
(global :when active)
|
2015-09-30 13:47:57 -04:00
|
|
|
narf-buffer-position
|
2015-10-06 05:47:24 -04:00
|
|
|
narf-hud
|
|
|
|
)))
|
2015-06-04 18:23:21 -04:00
|
|
|
|
|
|
|
(provide 'core-ui)
|
|
|
|
;;; core-ui.el ends here
|