lang/ruby: keep mode-line indicator up-to-date
This commit is contained in:
parent
ad68f26477
commit
06aa16bbfb
1 changed files with 15 additions and 11 deletions
|
@ -1,9 +1,11 @@
|
||||||
;;; lang/ruby/config.el -*- lexical-binding: t; -*-
|
;;; lang/ruby/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defvar +ruby-mode-name-functions '(+ruby-version)
|
(defvar +ruby-mode-line-indicator
|
||||||
"A list of functions to retrieve a version or environment string from. The
|
'("Ruby" (+ruby-version (" " +ruby-version)))
|
||||||
first to return non-nil will have its result appended to the ruby-mode
|
"Format for the ruby version/env indicator in the mode-line.")
|
||||||
`mode-name' and displayed in the mode-line.")
|
|
||||||
|
(defvar-local +ruby-version nil
|
||||||
|
"The ruby version in the current buffer.")
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -23,13 +25,15 @@ first to return non-nil will have its result appended to the ruby-mode
|
||||||
;; so class and module pairs work
|
;; so class and module pairs work
|
||||||
(setq-hook! 'enh-ruby-mode-hook sp-max-pair-length 6)
|
(setq-hook! 'enh-ruby-mode-hook sp-max-pair-length 6)
|
||||||
|
|
||||||
(defun +ruby|add-version-to-modeline ()
|
;; Add ruby version string to the major mode in the modeline
|
||||||
"Add version string to the major mode in the modeline."
|
(defun +ruby|adjust-mode-line ()
|
||||||
(setq mode-name
|
(setq mode-name +ruby-mode-line-indicator))
|
||||||
(if-let* ((result (run-hook-with-args-until-success '+ruby-mode-name-functions)))
|
(add-hook 'enh-ruby-mode-hook #'+ruby|adjust-mode-line)
|
||||||
(format "Ruby %s" result)
|
|
||||||
"Ruby")))
|
(defun +ruby|update-version (&rest _)
|
||||||
(add-hook 'enh-ruby-mode-hook #'+ruby|add-version-to-modeline))
|
(setq +ruby-version (+ruby-version)))
|
||||||
|
(+ruby|update-version)
|
||||||
|
(add-hook 'enh-ruby-mode-hook #'+ruby|update-version))
|
||||||
|
|
||||||
|
|
||||||
(def-package! yard-mode :hook enh-ruby-mode)
|
(def-package! yard-mode :hook enh-ruby-mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue