mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-24 03:00:10 +00:00
Fix #42: refactor doom-modeline-project-root to avoid errors.
This commit is contained in:
parent
f0e882dbe6
commit
813adefbfa
1 changed files with 13 additions and 13 deletions
|
@ -331,18 +331,18 @@ active.")
|
||||||
(defun doom-modeline-project-root ()
|
(defun doom-modeline-project-root ()
|
||||||
"Get the path to the root of your project.
|
"Get the path to the root of your project.
|
||||||
|
|
||||||
If STRICT-P, return nil if no project was found, otherwise return
|
Return `default-directory' if no project was found."
|
||||||
`default-directory'."
|
|
||||||
(if (local-variable-p 'doom-modeline-project-root)
|
(if (local-variable-p 'doom-modeline-project-root)
|
||||||
doom-modeline-project-root
|
doom-modeline-project-root
|
||||||
(or
|
(setq doom-modeline-project-root
|
||||||
(when (featurep 'projectile)
|
(or
|
||||||
(let ((projectile-require-project-root nil))
|
(when (featurep 'projectile) (projectile-project-root))
|
||||||
(setq doom-modeline-project-root
|
(when (featurep 'project)
|
||||||
(projectile-ensure-project (projectile-project-root)))))
|
(when-let ((project (project-current)))
|
||||||
(when (featurep 'project)
|
(car (project-roots project))))
|
||||||
(when-let ((project (project-current)))
|
default-directory))))
|
||||||
(car (project-roots project)))))))
|
|
||||||
|
(project-roots (project-current))
|
||||||
|
|
||||||
;; Disable projectile mode-line segment
|
;; Disable projectile mode-line segment
|
||||||
(setq projectile-dynamic-mode-line nil)
|
(setq projectile-dynamic-mode-line nil)
|
||||||
|
@ -439,7 +439,7 @@ active.")
|
||||||
(defun doom-modeline-update-env ()
|
(defun doom-modeline-update-env ()
|
||||||
"Update environment info on mode-line."
|
"Update environment info on mode-line."
|
||||||
(when doom-modeline-env-command
|
(when doom-modeline-env-command
|
||||||
(let ((default-directory (or (doom-modeline-project-root) ""))
|
(let ((default-directory (doom-modeline-project-root))
|
||||||
(s (shell-command-to-string doom-modeline-env-command)))
|
(s (shell-command-to-string doom-modeline-env-command)))
|
||||||
(setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
(setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
||||||
(replace-match "" t t s)
|
(replace-match "" t t s)
|
||||||
|
@ -494,7 +494,7 @@ active.")
|
||||||
if (= d 0) collect (string-to-char " ")
|
if (= d 0) collect (string-to-char " ")
|
||||||
else collect (string-to-char "."))
|
else collect (string-to-char "."))
|
||||||
(if (eq idx len) "\"};" "\",\n")))))
|
(if (eq idx len) "\"};" "\",\n")))))
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center)))))
|
||||||
|
|
||||||
(defun doom-modeline-buffer-file-name ()
|
(defun doom-modeline-buffer-file-name ()
|
||||||
"Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
|
"Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
|
||||||
|
@ -567,7 +567,7 @@ fish-shell style.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el"
|
~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el"
|
||||||
(let* ((project-root (or (doom-modeline-project-root) ""))
|
(let* ((project-root (doom-modeline-project-root))
|
||||||
(file-name-split (shrink-path-file-mixed project-root
|
(file-name-split (shrink-path-file-mixed project-root
|
||||||
(or (file-name-directory file-path) "./")
|
(or (file-name-directory file-path) "./")
|
||||||
file-path))
|
file-path))
|
||||||
|
|
Loading…
Reference in a new issue