2012-03-03 15 views
7

W Emacs, gdy wyświetlasz kalendarz z M-x calendar, otrzymujesz trzymiesięczny wyświetlacz - ostatni miesiąc, miesiąc i następny miesiąc - w nowym oknie, który ma tylko 8 linii wysokości.Kalendarz Emacs: pokaż więcej niż 3 miesiące?

Czy można wygenerować kalendarz dwunastomiesięczny w oknie pełnowymiarowym?

Odpowiedz

5

Wydaje się, że nie ma na to łatwego sposobu. Udało mi się odtworzyć poniższy kod, który będzie wyświetlany przez wszystkie dwanaście miesięcy, w osobnej ramce.

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

Może być konieczne zmodyfikowanie go w zależności od rozmiaru ekranu/czcionki.

+0

Wygląda na to, że rok był zakodowany na stałe jako rok 2012? Coś takiego może być lepsze: '(string-to-number (format-string-string"% Y "(current-time)))' – phils

+0

Tak, możesz edytować. –

4

12-miesiąca kalendarzowego - przewija za miesiąc (do przodu/do tyłu)

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

Niełatwo to zrobić, kod, aby wygenerować kalendarz jest:

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

Tutaj, (dotimes (i 3) ...) generowanie 3 miesiące z rzędu.

Jeśli chcesz wygenerować więcej niż 3 miesiące w więcej niż jednym wierszu, musisz zastąpić funkcję calendar-generate samodzielnie, tak samo jak @Luke powiedział.

+0

Właściwie generowanie ponad 3 miesięcy nie jest trudną częścią - co jest pół-trudne to algorytmy przesuwania punktu do daty i umieszczania nakładek na święta, urodziny i spotkania oraz przewijanie do przodu i do tyłu. Algorytm 12-miesięcznego kalendarza znajduje się tutaj http://stackoverflow.com/a/21709710/2112489 i tutaj http://stackoverflow.com/a/21834918/2112489. W tym momencie dostępne są tylko ogólnodostępne algorytmy przesuwania kursora do daty w kalendarzach 3-miesięcznych lub 12-miesięcznych. Jeśli jesteś skłonny napisać dodatkowe algorytmy, byłoby świetnie :) – lawlist

Powiązane problemy