(py|rb)env version in modeline + define-builder macro
This commit is contained in:
parent
979472385b
commit
c27dfd5540
10 changed files with 89 additions and 38 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
(when window-system
|
||||
(fringe-mode '(1 . 8))
|
||||
(set-frame-font narf-default-font)
|
||||
(setq frame-title-format '(buffer-file-name "%f" ("%b"))))
|
||||
|
||||
;; Highlight matching parens
|
||||
|
@ -17,6 +18,7 @@
|
|||
(size-indication-mode -1)
|
||||
|
||||
(setq-default
|
||||
line-spacing 1
|
||||
;; Multiple cursors across buffers cause a strange redraw delay for
|
||||
;; some things, like auto-complete or evil-mode's cursor color
|
||||
;; switching.
|
||||
|
@ -104,39 +106,47 @@
|
|||
(setq-default
|
||||
powerline-default-separator 'wave
|
||||
powerline-height 18)
|
||||
(require 'spaceline-segments)
|
||||
|
||||
;; Modeline caches
|
||||
;; Modeline cache
|
||||
(defvar narf--spaceline-file-path nil)
|
||||
(make-variable-buffer-local 'narf--spaceline-file-path)
|
||||
(add-hook! focus-in (setq narf--spaceline-file-path nil))
|
||||
|
||||
(defvar narf--spaceline-vc nil)
|
||||
(make-variable-buffer-local 'narf--spaceline-vc)
|
||||
(add-hook! before-save (setq narf--spaceline-vc nil))
|
||||
(defface mode-line-is-modified nil "Face for mode-line modified symbol")
|
||||
(defface mode-line-buffer-path nil "Face for mode-line buffer directory")
|
||||
|
||||
;; Custom modeline segments
|
||||
(spaceline-define-segment narf-buffer-path
|
||||
"Name of buffer."
|
||||
(concat (or narf--spaceline-file-path
|
||||
(setq narf--spaceline-file-path
|
||||
(let ((buffer-path (buffer-file-name)))
|
||||
(if (and buffer-path (file-exists-p buffer-path))
|
||||
(progn
|
||||
(let* ((max-length (/ (window-width) 2))
|
||||
(project-path (narf/project-root))
|
||||
(path (file-relative-name
|
||||
buffer-path (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)))))
|
||||
"Base filename of buffer."
|
||||
(concat (file-name-nondirectory buffer-file-name)
|
||||
(if (buffer-modified-p)
|
||||
(propertize "*" 'font-lock-face `(:inherit ,other-face :foreground "orange")))
|
||||
(propertize "*" 'face 'mode-line-is-modified))
|
||||
" ")
|
||||
: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))
|
||||
:tight-right t)
|
||||
|
||||
(spaceline-define-segment narf-buffer-encoding-abbrev
|
||||
|
@ -156,24 +166,40 @@
|
|||
|
||||
(spaceline-define-segment narf-vc
|
||||
"Version control info"
|
||||
(or narf--spaceline-vc
|
||||
(replace-regexp-in-string (regexp-quote (symbol-name (vc-deduce-backend)))
|
||||
"" (s-trim (powerline-vc)) t t))
|
||||
:when (powerline-vc))
|
||||
(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))
|
||||
|
||||
(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))))
|
||||
|
||||
;; Initialize modeline
|
||||
(spaceline-install
|
||||
;; Left side
|
||||
'(((narf-buffer-path :face other-face) remote-host)
|
||||
((flycheck-error flycheck-warning flycheck-info) :when active)
|
||||
(narf-vc :face other-face :when active))
|
||||
'((narf-buffer-dir :face other-face)
|
||||
(narf-buffer-path remote-host)
|
||||
(narf-vc)
|
||||
((flycheck-error flycheck-warning flycheck-info) :face other-face :when active))
|
||||
;; Right side
|
||||
'(selection-info
|
||||
narf-env-version
|
||||
narf-buffer-encoding-abbrev
|
||||
(major-mode (minor-modes :separator " ") process :when active)
|
||||
(global :when active)
|
||||
|
|
13
core/lib/defuns-spaceline.el
Normal file
13
core/lib/defuns-spaceline.el
Normal file
|
@ -0,0 +1,13 @@
|
|||
;;; defuns-spaceline.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf|spaceline-env-update ()
|
||||
(when narf--env-command
|
||||
(let* ((command (format "cd '%s' && %s" (narf/project-root) narf--env-command))
|
||||
(s (shell-command-to-string command)))
|
||||
(setq narf--env-version (if (string-match "[ \t\n\r]+\\'" s)
|
||||
(replace-match "" t t s)
|
||||
s)))))
|
||||
|
||||
(provide 'defuns-spaceline)
|
||||
;;; defuns-spaceline.el ends here
|
|
@ -1,7 +1,7 @@
|
|||
;;; macros-quickrun.el
|
||||
|
||||
;;;###autoload
|
||||
(defmacro build-for! (mode command &optional build-file)
|
||||
(defmacro define-builder! (mode command &optional build-file)
|
||||
"Register major/minor MODE with build COMMAND. If FILES are provided, do an
|
||||
additional check to make sure they exist in the project root."
|
||||
`(add-hook! ,mode
|
||||
|
|
10
core/lib/macros-spaceline.el
Normal file
10
core/lib/macros-spaceline.el
Normal file
|
@ -0,0 +1,10 @@
|
|||
;;; defuns-spaceline.el
|
||||
|
||||
;;;###autoload
|
||||
(defmacro define-env-command! (mode command)
|
||||
(add-hook! (focus-in find-file) 'narf|spaceline-env-update)
|
||||
`(add-hook ',(intern (format "%s-hook" (symbol-name mode)))
|
||||
(lambda () (setq narf--env-command ,command))))
|
||||
|
||||
(provide 'defuns-spaceline)
|
||||
;;; defuns-spaceline.el ends here
|
|
@ -5,8 +5,8 @@
|
|||
:interpreter "go"
|
||||
:init
|
||||
(add-hook! go-mode '(emr-initialize flycheck-mode))
|
||||
(build-for! go-mode "go build")
|
||||
:config
|
||||
(define-builder! go-mode "go build")
|
||||
(bind! :map go-mode-map
|
||||
:n "gd" 'godef-jump
|
||||
:n "gD" 'godef-describe
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
:keymap (make-sparse-keymap)
|
||||
(add-yas-minor-mode! 'love-mode))
|
||||
(associate! love-mode :files ("main.lua") :in (lua-mode))
|
||||
(build-for! love-mode "open -a love.app '%s'" "main.lua")
|
||||
(define-builder! love-mode "open -a love.app '%s'" "main.lua")
|
||||
|
||||
(provide 'module-lua)
|
||||
;;; module-lua.el ends here
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
python-environment-directory narf-temp-dir
|
||||
python-shell-interpreter "ipython")
|
||||
:config
|
||||
(define-env-command! python-mode "pyenv version | cut -d' ' -f1")
|
||||
(define-key python-mode-map (kbd "DEL") nil)) ; interferes with smartparens
|
||||
|
||||
(use-package nose
|
||||
|
@ -28,6 +29,7 @@
|
|||
:n "tV" 'nosetests-pdb-module)))
|
||||
|
||||
(use-package anaconda-mode
|
||||
:diminish anaconda-mode
|
||||
:defines (anaconda-mode-map anaconda-nav-mode-map)
|
||||
:functions (anaconda-mode-running-p)
|
||||
:init (add-hook! python-mode '(anaconda-mode eldoc-mode))
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
:interpreter "ruby"
|
||||
:init
|
||||
(add-hook! ruby-mode '(narf|enable-tab-width-2 flycheck-mode))
|
||||
(build-for! ruby-mode "rake %s" "Rakefile")
|
||||
:config
|
||||
(define-builder! ruby-mode "rake %s" "Rakefile")
|
||||
(define-env-command! ruby-mode "rbenv version | cut -d' ' -f1")
|
||||
;; Formatting
|
||||
(setq ruby-indent-level 2
|
||||
ruby-deep-indent-paren t)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
(use-package rust-mode
|
||||
:mode "\\.rs$"
|
||||
:config
|
||||
(build-for! rust-mode "cargo run" "Cargo.toml")
|
||||
(define-builder! rust-mode "cargo run" "Cargo.toml")
|
||||
(use-package flycheck-rust
|
||||
:config (add-hook! rust-mode 'flycheck-mode))
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
;;; module-vim.el
|
||||
|
||||
(use-package vimrc-mode
|
||||
:mode (("/\\.?g?vimrc$" . vimrc-mode)
|
||||
("\\.vim$" . vimrc-mode)))
|
||||
:mode ("/\\.?g?vimrc$" "\\.vim$" "/\\.vim/rc/.+$"))
|
||||
|
||||
(provide 'module-vim)
|
||||
;;; module-vim.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue