在Emacs中,當您使用M-x calendar
顯示日曆時,您會在上個月,本月和下個月獲得三個月的顯示 - 在只有8行高的新窗口中顯示。Emacs日曆:顯示超過3個月?
是否可以在全尺寸窗口中生成12個月的日曆?
在Emacs中,當您使用M-x calendar
顯示日曆時,您會在上個月,本月和下個月獲得三個月的顯示 - 在只有8行高的新窗口中顯示。Emacs日曆:顯示超過3個月?
是否可以在全尺寸窗口中生成12個月的日曆?
似乎沒有一種簡單的方法來做到這一點。我能夠敲出下面的代碼,它將在一個單獨的框架中連續顯示12個月。
(require 'cl)
(require 'calendar)
(defun twelve-month-calendar()
(interactive)
(let ((calendar-buffer (get-buffer-create "12-month calendar"))
(month 12)
(year 2012))
(set-buffer calendar-buffer)
(setq calendar-frame (make-frame))
(make-variable-buffer-local 'font-lock-face)
(set-face-attribute 'default calendar-frame :height 70)
(set-frame-width calendar-frame 300)
(erase-buffer)
(dotimes (i 12)
(calendar-generate-month month year 0)
(calendar-increment-month month year -1))
(calendar-mode)))
根據您的屏幕/字體大小,您可能需要稍微調整一下。
12個月的日曆 - 滾動BY MONTH(向前/向後)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Scroll a yearly calendar by month -- in a forwards or backwards direction. ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(eval-after-load "calendar" '(progn
(define-key calendar-mode-map "<" 'lawlist-scroll-year-calendar-backward)
(define-key calendar-mode-map ">" 'lawlist-scroll-year-calendar-forward)))
(defun year-calendar (&optional month year)
"Generate a one (1) year calendar that can be scrolled by month in each direction.
This is a modification of: http://homepage3.nifty.com/oatu/emacs/calendar.html
See also: http://ivan.kanis.fr/caly.el"
(interactive)
(require 'calendar)
(let* (
(current-year (number-to-string (nth 5 (decode-time (current-time)))))
(month (if month month
(string-to-number
(read-string "Please enter a month number (e.g., 1): " nil nil "1"))))
(year (if year year
(string-to-number
(read-string "Please enter a year (e.g., 2014): "
nil nil current-year)))))
(switch-to-buffer (get-buffer-create calendar-buffer))
(when (not (eq major-mode 'calendar-mode))
(calendar-mode))
(setq displayed-month month)
(setq displayed-year year)
(setq buffer-read-only nil)
(erase-buffer)
;; horizontal rows
(calendar-for-loop j from 0 to 3 do
;; vertical columns
(calendar-for-loop i from 0 to 2 do
(calendar-generate-month
;; month
(cond
((> (+ (* j 3) i month) 12)
(- (+ (* j 3) i month) 12))
(t
(+ (* j 3) i month)))
;; year
(cond
((> (+ (* j 3) i month) 12)
(+ year 1))
(t
year))
;; indentation/spacing between months
(+ 5 (* 25 i))))
(goto-char (point-max))
(insert (make-string (- 10 (count-lines (point-min) (point-max))) ?\n))
(widen)
(goto-char (point-max))
(narrow-to-region (point-max) (point-max)))
(widen)
(goto-char (point-min))
(setq buffer-read-only t)))
(defun lawlist-scroll-year-calendar-forward (&optional arg event)
"Scroll the yearly calendar by month in a forward direction."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(unless arg (setq arg 1))
(save-selected-window
(if (setq event (event-start event)) (select-window (posn-window event)))
(unless (zerop arg)
(let* (
(month displayed-month)
(year displayed-year))
(calendar-increment-month month year arg)
(year-calendar month year)))
(goto-char (point-min))
(run-hooks 'calendar-move-hook)))
(defun lawlist-scroll-year-calendar-backward (&optional arg event)
"Scroll the yearly calendar by month in a backward direction."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(lawlist-scroll-year-calendar-forward (- (or arg 1)) event))
這並不容易做到這一點,以產生日程的代碼是:
(defun calendar-generate (month year)
"Generate a three-month Gregorian calendar centered around MONTH, YEAR."
;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
;; Note that while calendars for years BC could be displayed as it
;; stands, almost all other calendar functions (eg holidays) would
;; at best have unpredictable results for such dates.
(if (< (+ month (* 12 (1- year))) 2)
(error "Months before January, 1 AD cannot be displayed"))
(setq displayed-month month
displayed-year year)
(erase-buffer)
(calendar-increment-month month year -1)
(dotimes (i 3)
(calendar-generate-month month year
(+ calendar-left-margin
(* calendar-month-width i)))
(calendar-increment-month month year 1)))
在這裏,(dotimes (i 3) ...)
連續產生3個月。
因此,如果您想要在超過1行中生成超過3個月,則必須自行覆蓋calendar-generate
函數,與@Luke所說的相同。
實際上,生成超過3個月不是困難的部分 - 算法將點移動到日期併爲節假日,生日和會議放置覆蓋,並向前和向後滾動。 12個月的日曆的算法在這裏http://stackoverflow.com/a/21709710/2112489和這裏http://stackoverflow.com/a/21834918/2112489。目前,只有公開的算法才能在3個月或12個月的日曆上移動光標。如果你傾向於編寫額外的算法,那將是一個偉大的:) – lawlist 2015-06-29 06:03:58
您似乎已將2012年的年份硬編碼?像這樣的可能是更好的:'(字符串到數字(格式 - 時間字符串「%Y」(當前時間)))' – phils 2012-03-04 01:50:09
是的,隨意編輯。 – 2012-03-04 13:54:01