Closed thorstengrothe closed 6 years ago
You might be able to largely copy-paste the config from the doom modeline source; i'll look into this soon.
Sorry for my late response, I was very busy with my job.
I did my best to copy the relevant funcs from doom modline config. I think these funcs are responsive for displaying the truncated buffer file name:
(defvar doom-modeline-buffer-file-name-style 'truncate-upto-project
"Determines the style used by `doom-modeline-buffer-file-name'.
Given ~/Projects/FOSS/emacs/lisp/comint.el
truncate-upto-project => ~/P/F/emacs/lisp/comint.el
truncate-upto-root => ~/P/F/e/lisp/comint.el
truncate-all => ~/P/F/e/l/comint.el
relative-from-project => emacs/lisp/comint.el
relative-to-project => lisp/comint.el
file-name => comint.el")
(defun doom-modeline-buffer-file-name ()
"Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
(propertize
(pcase doom-modeline-buffer-file-name-style
(`truncate-upto-project (doom-modeline--buffer-file-name 'shrink))
(`truncate-upto-root (doom-modeline--buffer-file-name-truncate))
(`truncate-all (doom-modeline--buffer-file-name-truncate t))
(`relative-to-project (doom-modeline--buffer-file-name-relative))
(`relative-from-project (doom-modeline--buffer-file-name-relative 'include-project))
(`file-name (propertize (file-name-nondirectory buffer-file-name)
'face
(let ((face (or (and (buffer-modified-p)
'doom-modeline-buffer-modified)
(and (doom-modeline--active)
'doom-modeline-buffer-file))))
(when face `(:inherit ,face))))))
'help-echo buffer-file-truename))
(defun doom-modeline--buffer-file-name-truncate (&optional truncate-tail)
"Propertized variable `buffer-file-name' that truncates every dir along path.
If TRUNCATE-TAIL is t also truncate the parent directory of the file."
(let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename)))
(active (doom-modeline--active)))
(if (null dirs)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
(let ((dirname (car dirs))
(basename (cdr dirs))
(dir-faces (or modified-faces (if active 'doom-modeline-project-root-dir)))
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
(concat (propertize (concat dirname
(if truncate-tail (substring basename 0 1) basename)
"/")
'face (if dir-faces `(:inherit ,dir-faces)))
(propertize (file-name-nondirectory buffer-file-name)
'face (if file-faces `(:inherit ,file-faces)))))))))
(defun doom-modeline--buffer-file-name-relative (&optional include-project)
"Propertized variable `buffer-file-name' showing directories relative to project's root only."
(let ((root (doom-modeline-project-root))
(active (doom-modeline--active)))
(if (null root)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
(let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
(relative-dirs (file-relative-name (file-name-directory buffer-file-truename)
(if include-project (concat root "../") root)))
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
(if (equal "./" relative-dirs) (setq relative-dirs ""))
(concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces)))
(propertize (file-name-nondirectory buffer-file-truename)
'face (if file-faces `(:inherit ,file-faces))))))))
Not sure if this is everything. You can find the whole config here.
Thanks for your help!
Regards Thorsten
Hey, I just added a bunch of these. telephone-line-filesize-segment
, telephone-line-atom-eol-segment
, telephone-line-atom-encoding-segment
, and telephone-line-projectile-buffer-segment
. That last one is configurable; default is to display the filepath between the project root and the current file with every dir truncated.
I was on holiday and saw your post yesterday. Thanks for the new segments. Most of it is working fine now, that's great! Two small questions:
Is it possible to disable telephone-line-filesize-segment
for special buffers/views? For example in mu4e-main-mode
the same for the scratch buffer
.
Is it possible to use the new telephone-line-projectile-buffer-segment
without projectile, so that the filepath is shown for every file? I'm no yet using projectile and would like to have the truncated file-path for every file I'm editing...
Thanks for the great package!
You could make a similar segment without a projectile requirement, but it'd be kinda lame and always truncate the whole path from ~
.
I could write something up for you if you want, but honestly it'd probably be easier just to set up projectile.
Ok thanks for the response. I will have a look at projectile...
I set up projectile and the segment is working pretty fine now!
Thanks again!
Hi,
I would like to customize
telephone-line
so that it looks a bit like Doom modline. See the screenie here:At the moment there are three things I like to customize:
UTF-8
and not onlyU:---
My current modline looks like this with ryo-modal mode here.
My config is here
I know that the relevant segment for the file name and the encoding is
telephone-line-buffer-segment
. But I have no clue how to customize it, so that it shows the abrreveated file path and encoding (UTF-8).Has anyone an idea?
Thorsten