dbordak / telephone-line

A new implementation of Powerline for Emacs
GNU General Public License v3.0
554 stars 51 forks source link

Make telephone-line look like doom modline #73

Closed thorstengrothe closed 6 years ago

thorstengrothe commented 6 years ago

Hi,

I would like to customize telephone-line so that it looks a bit like Doom modline. See the screenie here:

doom_modline

At the moment there are three things I like to customize:

  1. Show me the size of the file
  2. Show the abbreviated and colorized file path of the file
  3. Show me the correct file encoding UTF-8 and not only U:---

My current modline looks like this with ryo-modal mode here.

ryo_modline

My config is here

(setq telephone-line-lhs
          '((ryo    . (;; show ryo-modal mode on/off
                       telephone-line-ryo-modal-segment))
            (accent . (;; telephone-line-vc-segment
                       ;; telephone-line-erc-modified-channels-segment
                       ;; telephone-line-process-segment
                       ))
            (nil    . (;; show minor mode
                       ;; telephone-line-minor-mode-segment
                       ;; show encoding
                       telephone-line-buffer-segment
                       ))))
    (setq telephone-line-rhs
          '((nil    . (telephone-line-misc-info-segment
                       ))
            (accent . (;; show major mode
                       ;; telephone-line-major-mode-segment
                       ))
            (ryo    . (telephone-line-airline-position-segment))))

    (setq telephone-line-primary-left-separator 'telephone-line-gradient
          telephone-line-secondary-left-separator 'telephone-line-nil
          telephone-line-primary-right-separator 'telephone-line-gradient
          telephone-line-secondary-right-separator 'telephone-line-nil)
    (setq telephone-line-height 24
          telephone-line-evil-use-short-tag t)
    (telephone-line-mode t)

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

dbordak commented 6 years ago

You might be able to largely copy-paste the config from the doom modeline source; i'll look into this soon.

thorstengrothe commented 6 years ago

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

dbordak commented 6 years ago

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.

thorstengrothe commented 6 years ago

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!

dbordak commented 6 years ago

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.

thorstengrothe commented 6 years ago

Ok thanks for the response. I will have a look at projectile...

thorstengrothe commented 6 years ago

I set up projectile and the segment is working pretty fine now!

Thanks again!