[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Patches to calendar

From: Emilio C . Lopes
Subject: Re: Patches to calendar
Date: Tue, 21 Sep 2004 11:35:11 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Glenn Morris wrote:

> Emilio Lopes wrote:

>> Besides the new command `calendar-goto-iso-week' 
> I don't think it's worth adding a whole new function which duplicates
> practically the entire code from calendar-goto-iso-date, just for
> this.

It's a matter of convenience.  Of course one could also use
`calendar-forward-week' with an appropriate argument, but that's not
something you want to do when you're on the phone and somebody asks if
week 42 is ok.

Indeed, the original code I posted to gnu.emacs.sources asked the user
only for the ISO week _in the current year_ to jump to.  But for
consistence with other Calendar functions Ed Reingolg prefered to also
ask the user for the year, offering the current one as default.

But you are of course right; there's a lot of code duplication between
`calendar-goto-iso-date' and `calendar-goto-iso-week'.  I tried to
change this in the code at the end of this message.  Please let me
know if you find that better.

> Instead, I'm minded to just make calendar-goto-iso-date default to 1
> for the day of the week. The UI difference between that and
> `calendar-goto-iso-week' would just be a matter of pressing RET once
> more.

It depends on how often do you use the function.  Here in Germany
ISO weeks are *heavily* used, so any unnecessary keystroke is just
annoying.  That's why I wrote the code.

Some people who found the code useful have never known that
`calendar-goto-iso-date' asked for "our" calendar week.


> (defalias 'calendar-goto-iso-week 'calendar-goto-iso-date)

is the very least one should do.

Here is the "refactored" code:

(defun calendar-current-year ()
  "Return the current year."
  (extract-calendar-year (calendar-current-date)))

(defun calendar-weeks-in-year (year)
      (calendar-absolute-from-gregorian (list 1 4 (1+ year))))))))

(defun calendar-goto-iso-date (date &optional noecho)
  "Move cursor to ISO DATE; echo ISO date unless NOECHO is t."
   (let* ((year (calendar-read
                 "ISO calendar year (>0): "
                 (lambda (x) (> x 0))
                 (int-to-string (calendar-current-year))))
          (no-weeks (calendar-weeks-in-year year))
          (week (calendar-read
                 (format "ISO calendar week (1-%d): " no-weeks)
                 (lambda (x) (and (> x 0) (<= x no-weeks)))))
          (day (calendar-read
                "ISO day (1-7): "
                (lambda (x) (and (<= 1 x) (<= x 7))))))
     (list (list week day year))))
  (calendar-goto-date (calendar-gregorian-from-absolute
                       (calendar-absolute-from-iso date)))
  (unless noecho (calendar-print-iso-date)))

(defun calendar-goto-iso-week (week year &optional noecho)
  "Move cursor to start of ISO WEEK in YEAR; echo ISO date unless NOECHO is t."
   (let* ((year (calendar-read
                 "ISO calendar year (>0): "
                 (lambda (x) (> x 0))
                 (int-to-string (calendar-current-year))))
          (no-weeks (calendar-weeks-in-year year))
          (week (calendar-read
                 (format "ISO calendar week (1-%d): " no-weeks)
                 (lambda (x) (and (> x 0) (<= x no-weeks))))))
     (list week year)))
  (calendar-goto-iso-date (list week 1 year) noecho))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]