dbordak / telephone-line

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

Feature request (and sample solution): Evil-like indicator for buffer modified state #105

Open sebasmonia opened 5 years ago

sebasmonia commented 5 years ago

My current implementation shows a red (not too bright) background when the buffer is modified, else the inactive face.

I guess if the face was part of the core package then it could be customized like the ones for the evil indicator, which is what I used to come up with my config. Probably would need a better name, though :)

(use-package telephone-line
  :config
  (progn
    (defface telephone-line-extra-accent-active
      '((t (:foreground "white" :background "dark slate blue" :inherit mode-line)))
      "Extra accent face for my telephone-line."
      :group 'telephone-line)

    (defface telephone-line-extra-accent-inactive
      '((t (:foreground "white" :background "grey14" :inherit mode-line-inactive)))
      "Extra accent face for my telephone-line."
      :group 'telephone-line)

    (defface telephone-line-buffer-modified-face
      '((t (:foreground "white" :background "firebrick1" :inherit mode-line)))
      "Face for buffer modified segment."
      :group 'telephone-line)

    (defun telephone-line-buffer-mod-color-segment-face (active)
      "Determine the color for the buffer modified segment."
      (if (and active (not buffer-read-only) (buffer-modified-p))
          'telephone-line-buffer-modified-face
        'telephone-line-accent-inactive))

    (telephone-line-defsegment* telephone-line-buffer-mod-segment ()
      (cond
       (buffer-read-only "·")
       ((buffer-modified-p) "!")
       (t "-")))

    (setq telephone-line-faces
          '((extra-accent . (telephone-line-extra-accent-active . telephone-line-extra-accent-inactive))
            (accent . (telephone-line-accent-active . telephone-line-accent-inactive))
            (nil . (mode-line . mode-line-inactive))
            (buffer-state . telephone-line-buffer-mod-color-segment-face)))

    (setq telephone-line-primary-left-separator 'telephone-line-abs-left
          telephone-line-secondary-left-separator 'telephone-line-abs-left)
    (setq telephone-line-primary-right-separator 'telephone-line-abs-right
          telephone-line-secondary-right-separator 'telephone-line-abs-right)
    (setq telephone-line-lhs
          '((buffer-state . (telephone-line-buffer-mod-segment))
            (extra-accent . (telephone-line-buffer-shortname-segment))
            (accent       . (telephone-line-projectile-segment))
            (nil          . (telephone-line-position+region-segment
                             telephone-line-narrow-segment))))
    (setq telephone-line-rhs
          '((nil          . (telephone-line-process-segment
                             telephone-line-misc-info-segment))
            (extra-accent . (telephone-line-vc-nobackend-segment))
            (accent       . (telephone-line-minions-mode-segment))))
    (telephone-line-mode t)))
sebasmonia commented 5 years ago

I've thought about this some more, and we either include a ton of segments OR provide more samples like the org file. Maybe in the repo's wiki?