2012-03-03 42 views
7

Trong Emacs, khi bạn hiển thị lịch với M-x calendar, bạn sẽ có màn hình ba tháng - tháng trước, tháng này và tháng tiếp theo - trong cửa sổ mới chỉ cao 8 dòng.Lịch Emacs: hiển thị hơn 3 tháng?

Có thể tạo lịch mười hai tháng trong một cửa sổ kích thước đầy đủ không?

Trả lời

5

Dường như không phải là cách dễ dàng để thực hiện việc này. Tôi đã có thể gõ mã sau đây, sẽ hiển thị tất cả mười hai tháng, liên tiếp, trong một khung riêng biệt.

(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))) 

Bạn có thể cần tinh chỉnh nó một chút, tùy thuộc vào kích thước màn hình/phông chữ của bạn.

+0

Bạn dường như đã mã hóa cứng năm nay là năm 2012? Một cái gì đó như thế này có thể thích hợp hơn: '(string-to-number (định dạng-time-string"% Y "(current-time)))' – phils

+0

Vâng, hãy chỉnh sửa. –

4

12-THÁNG LỊCH - Scrolls THEO THÁNG (Tiền đạo/ngược)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;; 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)) 

Example http://www.lawlist.com/images/calendar_example.png

0

Nó không phải dễ dàng để làm được điều này, các mã để tạo lịch là:

(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))) 

Ở đây, (dotimes (i 3) ...) tạo 3 tháng liên tiếp.

Vì vậy, nếu bạn muốn tạo nhiều hơn 3 tháng trong hơn 1 hàng, bạn phải ghi đè calendar-generate chức năng của chính bạn, giống như @Luke nói.

+0

Trên thực tế, tạo ra hơn 3 tháng không phải là một phần khó khăn - khó bán là thuật toán để di chuyển điểm đến ngày và đặt lớp phủ cho các ngày lễ, sinh nhật và cuộc họp và cuộn về phía trước và ngược. Thuật toán cho lịch 12 tháng có tại đây http://stackoverflow.com/a/21709710/2112489 và tại đây http://stackoverflow.com/a/21834918/2112489. Tại thời điểm này, chỉ có các thuật toán có sẵn công khai để di chuyển con trỏ đến ngày trên lịch 3 tháng hoặc 12 tháng. Nếu bạn có khuynh hướng viết các thuật toán bổ sung, đó sẽ là một điều tuyệt vời :) – lawlist

Các vấn đề liên quan