Subject: Fwd: bug#14509: Centerd calendar buffer

From: E Sabof <[email-masked]>
Date: Fri, 31 May 2013 19:27:37 +0100

A better version:

(defun es-calendar-recenter (&optional all-frames)
  (let (( calendar-width
          (+ (* 7 3 3)
             (* 2 calendar-intermonth-spacing)
             -1)))
    (save-excursion
      (goto-char (point-min))
      (while (search-forward-regexp "^ +" nil t)
        (put-text-property
         (match-beginning 0)
         (match-end 0)
         'display
         `(space :align-to (+ center (,(/ calendar-width -2)
                                      . width))))))))
(defadvice calendar-generate (after center-calendar activate)
  (es-calendar-recenter t))

(eval-after-load 'calendar
  '(defun calendar-update-mode-line ()
     "Update the calendar mode line with the current date and date style."
     (if (bufferp (get-buffer calendar-buffer))
         (with-current-buffer calendar-buffer
           (let* ((start (- calendar-left-margin 2))
                  (date (condition-case nil
                            (calendar-cursor-to-nearest-date)
                          (error (calendar-current-date))))
                  (content-string (calendar-string-spread
                                   (mapcar 'eval calendar-mode-line-format)
                                   ?\s (- calendar-right-margin (1-
start)))))
             (setq mode-line-format
                   (concat (propertize
                            " "
                            'display
                            `(space :align-to (+ center (,(/ (length
content-string) -2) . width))))
                           content-string)))
           (force-mode-line-update)))))