2012-03-03 13 views
7

In Emacs, quando si visualizza il calendario con M-x calendar, si ottiene un display di tre mesi - il mese scorso, questo mese e il mese successivo - in una nuova finestra alta solo 8 righe.Calendario Emacs: mostra più di 3 mesi?

È possibile generare un calendario di dodici mesi in una finestra a dimensione intera?

risposta

5

Non sembra essere un modo semplice per farlo. Sono stato in grado di abbattere il seguente codice, che mostrerà tutti i dodici mesi, in fila, in una cornice separata.

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

Potrebbe essere necessario modificarlo un po ', a seconda della dimensione del tuo schermo/carattere.

+0

Sembra che tu abbia codificato l'anno come 2012? Qualcosa di simile potrebbe essere preferibile: '(stringa-a-numero (formato-tempo-stringa"% Y "(corrente-tempo)))' – phils

+0

Sì, sentiti libero di modificare. –

4

12 MESI CALENDARIO - ROTOLI per mese (avanti/indietro)

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

Non è facile fare questo, il codice per generare calendario è:

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

Qui, (dotimes (i 3) ...) genera 3 mesi di seguito.

Quindi, se si desidera generare più di 3 mesi in più di 1 riga, è necessario sostituire da solo la funzione calendar-generate, come ha detto @Luke.

+0

In realtà, generare più di 3 mesi non è la parte più difficile - ciò che è semistrato sono gli algoritmi per spostare il punto alla data e posizionare gli overlay per le festività, i compleanni e le riunioni e scorrere avanti e indietro. L'algoritmo per il calendario di 12 mesi è qui http://stackoverflow.com/a/21709710/2112489 e qui http://stackoverflow.com/a/21834918/2112489. A questo punto, sono disponibili solo algoritmi disponibili pubblicamente per spostare il cursore sui calendari di 3 o 12 mesi. Se sei incline a scrivere algoritmi aggiuntivi, sarebbe fantastico :) – lawlist