jonathanchu / emacs-powerline

Powerline for Emacs
497 stars 37 forks source link

How do I display the time in the mode line? #27

Closed brabalan closed 9 years ago

brabalan commented 10 years ago

I see this is also mentioned in #4 but I could not find an answer there: is there a way to display the date and time in the mode line? This is what I tried (just to get the hours and minutes), but the space on the right is not sufficient. How can I reserve more space?

(defpowerline display-time display-time-string)

(setq display-time-format "%H:%M")

(setq-default mode-line-format
              (list "%e"
                    '(:eval (concat
                             (powerline-lcl            'left   nil  )
                             (powerline-rmw            'left   nil  )
                             (powerline-buffer-id      'left   nil  powerline-color1  )
                             (powerline-major-mode     'left        powerline-color1  )
                             (powerline-minor-modes    'left        powerline-color1  )
                             (powerline-narrow         'left        powerline-color1  powerline-color2  )
                             (powerline-vc             'center                        powerline-color2  )
                             (powerline-make-fill                                     powerline-color2  )
                             (powerline-row            'right       powerline-color1  powerline-color2  )
                             (powerline-make-text      ":"          powerline-color1  )
                             (powerline-column         'right       powerline-color1  )
                             (powerline-percent        'right  nil  powerline-color1  )
                             (powerline-display-time   'right  nil)
                             (powerline-make-text      "  "    nil  )))))
zarkone commented 10 years ago

You mean you do not see all the text? It's because powerline-make-fill leaves only 24 symbols for right arrow block. Quick workaround is to remove this line from mode-line-format... I will think about better solution.

zarkone commented 10 years ago

Or you can change 24 to greater value to fit your string.. I'm newbie at Lisp and Emacs, I don't know how to pre-count symbols in modeline.

zarkone commented 10 years ago

Actually, there is a way to count symbols in mode line: http://www.gnu.org/software/emacs/manual/html_node/elisp/Emulating-Mode-Line.html#Emulating-Mode-Line

brabalan commented 10 years ago

Yes, the problem is that there is not enough space. I could hack another value directly in the code, but this is not a very portable solution.

zarkone commented 10 years ago

You're right. I'll try to improve powerline-make-fill. As for me, I prefer not to use this "filler" and align all to left: http://pasteboard.co/QGzxmzD.png There's also hard-coded staff of my experiments >..< I promise, my improved code will not be like that.

brabalan commented 10 years ago

That would be great, thanks!

This is what I had in my emacs configuration before (when I was not using powerline), if it's helpful:

#+BEGIN_SRC emacs-lisp
  (setq global-mode-string (remove 'display-time-string global-mode-string))
  (setq mode-line-end-spaces
        (list (propertize " " 'display '(space :align-to (- right 15)))
              'display-time-string))
#+END_SRC
jonathanchu commented 9 years ago

@brabalan Merged in @zarkone's solution. This worked well for me and I think it should be a good solution to help account for most situations. Cheers! :beers: