Function: calendar-show-more-months

calendar-show-more-months is an autoloaded, interactive and byte-compiled function defined in cal-move.el.gz.

Signature

(calendar-show-more-months &optional ARG)

Documentation

Show ARG more months on the right in the calendar.

The calendar shows at most 12 months and at least 3 months.

View in manual

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/cal-move.el.gz
;;;###cal-autoload
(defun calendar-show-more-months (&optional arg)
  "Show ARG more months on the right in the calendar.
The calendar shows at most 12 months and at least 3 months."
  (interactive "p" calendar-mode)
  (cond
   ((= arg 0) nil)
   ((> arg 0)
    (if (>= calendar-total-months 12)
        (error "The calendar shows at most 12 months."))
    (let ((avail (floor (/ (- (window-body-width) calendar-right-margin)
                           (+ calendar-month-width
                              calendar-intermonth-spacing)))))
      (if (< avail 1)
          (message "No space left to display more months.")
        (incf calendar-total-months (min avail arg))
        (calendar-recompute-layout-variables)
        (calendar-redraw))))
   (t
    (if (<= calendar-total-months 3)
        (error "The calendar shows at least 3 months."))
    (calendar-cursor-to-nearest-date)
    (let ((cursor-date (calendar-cursor-to-date t)))
      (setq calendar-total-months (max 3 (+ calendar-total-months arg)))
      (calendar-recompute-layout-variables)
      (pcase-let* ((`(,m1 ,y1 ,_ ,_) (calendar-get-month-range))
                   (offset (- (calendar-interval
                               m1 y1
                               (calendar-extract-month cursor-date)
                               (calendar-extract-year cursor-date))
                              calendar-total-months)))
        (if (< offset 0)
            (calendar-redraw)
          (calendar-increment-month m1 y1 (+ 2 offset))
          (calendar-generate-window m1 y1)
          (calendar-cursor-to-visible-date cursor-date)
          (calendar-update-mode-line)))))))