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)
  )
  • 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 4 '17 at 2:18
  • If I used a timer of 60 seconds would this slow down emacs much? – map7 Mar 5 '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 5 '17 at 23:28
  • Should it be something like this? (run-at-time "60 sec" 60 #'force-mode-line-update "Update clock.") – map7 Mar 7 '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: gnu.org/software/emacs/manual/html_node/elisp/Timers.html The link to the following thread has some examples in the answer: emacs.stackexchange.com/questions/6029/… – lawlist Mar 7 '17 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.