1

I'm using powerline for my modeline and I have placed a clock within the modeline. This clock is only updating when I'm within that buffer, if I have another buffer up the clock freezes until that buffer is activated.

;;Initalise powerline mode line theme. Used with moe-theme

(use-package powerline
  :defer 5
  :config
  ;; Time & Date
  (display-time-mode)
  (defpowerline display-time display-time-string)
  (setq display-time-format "%H:%M") 

  ;; Display battery
  (display-battery-mode)
  (defpowerline display-battery display-battery-string)
  (setq battery-mode-line-format "%L %b%p%%") ; "[%L %b%p%% %t]"

  (defvar lunaryorn-vc-mode-line
    '(" " (:propertize
           ;; Strip the backend name from the VC status information
           (:eval (let ((backend (symbol-name (vc-backend (buffer-file-name)))))
                    (substring vc-mode (+ (length backend) 2))))
           face font-lock-variable-name-face))
    "Mode line format for VC Mode.")
  (put 'lunaryorn-vc-mode-line 'risky-local-variable t)

  ;; Setup my mode line
  (setq-default mode-line-format
                (list "%e" ; print error message about full memory.
                      '(:eval (append
                               (list
                                (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)
                                (lunaryorn-vc-mode-line    'center     powerline-color2                 )

                                (powerline-pull-right (list 
                                                       (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-display-battery 'right nil)
                                                       (powerline-make-text       " "    nil)))
                                )))))


  ;; Remove the load
  (setq display-time-default-load-average nil)

  ;; Remove the mail
  (setq display-time-mail-string "")
  (setq display-time-use-mail-icon nil)

  ;; Turn buffer size off
  (setq size-indication-mode "")

  (setq visible-bell 1)

  (force-mode-line-update)
  )
map7
  • 503
  • 3
  • 15
  • Depending upon what is in the mode-line, updating all of them too often may be costly -- i.e., a noticeable slowdown in Emacs. You can call `(force-mode-line-update t)` using the optional argument for all windows at certain locations that make sense to you. E.g., create a function that wraps the aforementioned snippet and place it on a timer. If that is too much, then place it on an idle timer. If there are other triggers that make sense, then use that. I personally use timers very sparingly. Your function may look like this: `(defun map7-force-update () (force-mode-line-update t))` – lawlist Mar 04 '17 at 02:18
  • If I used a timer of 60 seconds would this slow down emacs much? – map7 Mar 05 '17 at 22:43
  • An idle timer is probably the safest bet, and 60 seconds sounds reasonable to me. If there are no time-consuming functions inside the `mode-line-format` or `header-line-format`, then you might not even notice the update if they are updated on a regular timer at a shorter duration. You can also fine-tune any time consuming functions if they exist -- e.g., use a pre-recorded value under some situations so that recalculation is not always needed. – lawlist Mar 05 '17 at 23:28
  • Should it be something like this? `(run-at-time "60 sec" 60 #'force-mode-line-update "Update clock.")` – map7 Mar 07 '17 at 10:59
  • You need the optional argument of `t` on `force-mode-line-update` -- see first comment for an example of `map7-force-update`. See also the documentation regarding avaialable arguments for `run-at-time`: https://www.gnu.org/software/emacs/manual/html_node/elisp/Timers.html The link to the following thread has some examples in the answer: http://emacs.stackexchange.com/questions/6029/is-it-possible-to-execute-a-function-or-command-at-a-specific-time – lawlist Mar 07 '17 at 17:15
  • Thanks it all works now with the line I wrote in the last comment. – map7 Mar 17 '17 at 02:29
  • For displaying time information a timer seems like the way to go. In my case I wanted to display information in the mode-line that was derived from the point. I achieved this by adding `force-mode-line-update` to the (buffer local) `post-command-hook`. This will cause latency issues if the function is tool expensive. – Att Righ May 24 '17 at 19:58

0 Answers0