Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-08 Thread Alf-Ivar Holm
[EMAIL PROTECTED] (Edward M. Reingold) writes:

 [EMAIL PROTECTED] (Edward M. Reingold) writes:
 How do you know that the holidays are correct when the calendar
 has more than 3 months? Do you have a way to check, say, the dates
 of lunar phases, Easter, Chinese New Year, Yom Kippur, Islamic New
 Year, solstices/equinoxes?  You will see SOME holidays (or diary
 entries) but not all that apply to the months displayed.

I now see that I misread this question: I read it as it was about the
hack as it is implemented now and how I know that the hack works with
non-fixed holidays, not about my comment about the non-implemented
dynamically sized calendar.

The answer to the question above is: I don't know, and that is why I
wrote that I had to specifically test for it if it were implemented,
for instance in the way that RMS wrote in
[EMAIL PROTECTED].

[...]
 if the window is 5 months wide, they could be visible and the
 command to list or highlight all holidays will miss them.

 Almost all of the non-trivial holidays/diary entries would suffer in
 the same way, so rewriting the code properly to display a wider
 window means modifying almost every holiday/diary function in some
 (usually non-obvious) way.

That supports the point I was trying to make.  Since this feature is
not implemented I do not have to bother with it in the modified code -
as the current calendar is static.

Affi
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-08 Thread Ed Reingold
 It sounds like we should systematically replace such code with
 something more robust.  It could use two variables,
 calendar-first-visible-month and calendar-last-visible-month, to indicate
 the range that is visible.

Yes, something like that; but it is not always that simple; I used that 
example because it came from code that the poster has modifed for his use.



___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22

2006-12-07 Thread Alf-Ivar Holm
[EMAIL PROTECTED] writes:

 Alf-Ivar Holm [EMAIL PROTECTED] writes:

 Could you give me _one_ function that would break?  The displayed
 calendar is quite static, e.g. it does not support dynamic display of
 months when changing the width of the window (I could easily fit 5
 months, included week numbers, on my screen if I do a horizontal
 maximization of my calendar window), a functionality I would have had
 to specifically test for if it were present.  When it comes to
 calculating a date I can't see why the visual representation of the
 calendar matters, e.g. the date structures is luckily not dependent of
 what is displayed in the buffer.

 Code that will break: all the holiday determination for non-trivial holidays.

Ok, I'l discuss that in the other (sub) thread.

 This is the same thing I told you years ago: To determine the which diary
 entries or holidays are in the visible range, the 3-month size of the window
 is assumed; thus if you write the (trivial) loops to get, say, a 5-month
 calendar window, the holidays will not be properly determined or highlighted.
 The same is true for diary entries.

What I was trying to say with the 5-month comment was that IF such
functionality existed there would probably more work on my part (as
well).  With the calendar being static, it is quite easy to add visual
stuff, like the week display hack.

 Also, when you ask for information about a date under the cursor
 (holidays, diary entries, other calendars, sunset, etc, etc), the
 code needs to translate the physical cursor position to a date.

Ok, but the postion of the dates are not changed by the addition of
the week numbers, which is display in the 5 character empty space to
the right of each month.  

This is why the need for a seperate face is needed (which again
prompted this update) as the calendar gets a bit cramped with the week
numbers added.  There is another 5 characters on the left that would
be nice to use to put some air between the week number of one month
and the dates of the next, but *that* would change the positions of
the dates and therefore need tweeking of the date calculation.  (This
is left as an exercise to someone else.)

 That translation process assumes a rigid form to the calendar
 window--adding the ISO week or stretching the calendar to 5 months,
 say, screws up that translation process.

I agree that adding the stretching is a major rewrite (that I admit
that I would have liked to see implemented.)

 The problem with redoing the calendar code to include extraneous information
 (like ISO weeks) or changing the number of months displayed is that the
 assumptions about the window's contents are intrinsic to many parts of the
 code and very hard to ferret out.  It is very easy to make such changes so
 that work with YOUR PARTICULAR calendar usage, but it would require a MAJOR
 rewriting of the code to make it work generally.

Ok, I might have been a bit hasty in my comment about the visual
representation, but if the code only refers to positions, and not
content, the hack would still work as the date placements are not
changed.

 Sorry, but when the heart of the code was written in the mid 1980s,
 all that was generally available were 80-column aasci screens.

I still use 80 columns in my emacs windows, but as I display my
calendar in a separat window I could sometimes stretch it sideways
if I wanted to plan something which stretch over more than 3 months -
that's the idea I had about the 5 month comment.

Affi
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-07 Thread Alf-Ivar Holm
[EMAIL PROTECTED] (Edward M. Reingold) writes:

 AH == Alf-Ivar Holm [EMAIL PROTECTED] writes:

 AH I should point out as this is titled a hack and I do not have have a
 AH test suite I will not guarantee that it works in all environments, BUT
 AH I have used it with extensive diary usage, and with the use of
 AH Norwegian names, holidays, and calendar set up without any problems
 AH (except for eventual changes in functions/variables when a new emacs
 AH arrived, e.g. v. 22) for 10 years.  Despite what the calendar author

 How do you know that the holidays are correct when the calendar has
 more than 3 months?  Do you have a way to check, say, the dates of
 lunar phases, Easter, Chinese New Year, Yom Kippur, Islamic New
 Year, solstices/equinoxes?  You will see SOME holidays (or diary
 entries) but not all that apply to the months displayed.

I admit that I don't use many of those, but I have got Easter, which I
had to modify to fit to the Norwegian Easter celebration¹.  I have got
this in the sitestart.el, again based on your code:

(defun local-holiday-easter-etc ()
  List of dates related to Easter in Norway, as visible in calendar window.
 (if (and ( displayed-month 5))
 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
   (let* ((century (1+ (/ displayed-year 100)))
  (shifted-epact;; Age of moon for April 5...
   (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
 (-   ;; ...corrected for the Gregorian century rule
  (/ (* 3 century) 4))
 (/;; ...corrected for Metonic cycle inaccuracy.
  (+ 5 (* 8 century)) 25)
 (* 30 century));;  Keeps value positive.
  30))
  (adjusted-epact   ;;  Adjust for 29.5 day month.
   (if (or (= shifted-epact 0)
   (and (= shifted-epact 1) ( 10 (% displayed-year 19
   (1+ shifted-epact)
 shifted-epact))
  (paschal-moon   ;; Day after the full moon on or after March 21.
   (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
  adjusted-epact))
  (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
  (mandatory
   (list
(list (calendar-gregorian-from-absolute (- abs-easter 7))
  Palmesøndag)
(list (calendar-gregorian-from-absolute (- abs-easter 3))
  Skjærtorsdag)
(list (calendar-gregorian-from-absolute (- abs-easter 2))
  Langfredag)
(list (calendar-gregorian-from-absolute abs-easter)
  1. påskedag)
(list (calendar-gregorian-from-absolute (+ abs-easter 1))
  2. påskedag)
(list (calendar-gregorian-from-absolute (+ abs-easter 39))
  Himmelspretten)
(list (calendar-gregorian-from-absolute (+ abs-easter 49))
  1. pinsedag)
(list (calendar-gregorian-from-absolute (+ abs-easter 50))
  2. pinsedag)))
  (output-list
   (filter-visible-calendar-holidays mandatory)))
 (if all-christian-calendar-holidays
 (setq output-list
   (append 
(filter-visible-calendar-holidays optional)
output-list)))
 output-list)))

(eval-after-load holidays
  '(fset 'holiday-easter-etc 'local-holiday-easter-etc))

And this works as expected (by me), e.g. the Easter of 2007 is shown
here, with the cursor on Easter Sunday (1. påskedag):

http://pogostick.net/~affi/Screendump-Calendar-Easter2007.png

 The code won't generally die ungracefully, but the the output will
 NOT be right.

Yes, that is of course harder to debug.

Affi

¹) We only got 2 and half work day each Easter, with the day off on
the day after Easter Sunday as well.  We basically don't work at all
at Easter.
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-07 Thread Edward M. Reingold
 AH == Alf-Ivar Holm [EMAIL PROTECTED] writes:

AH (defun local-holiday-easter-etc () List of dates related to Easter in
AH Norway, as visible in calendar window.  (if (and ( displayed-month
AH 5)) nil;; Ash Wednesday, Good Friday, and Easter are not visible.

This a good example of why the wider window can cause erroneous results.
The test

   (if ( displayed-month 5)

checks if the center of the 3 month window is beyond May, in which case (as
the comment from my code says!) Ash Wednesday, Good Friday, and Easter cannot
be visibible because they occur in Feb/Mar/Apr.  But if the window is 5 months
wide, they could be visible and the command to list or highlight all holidays
will miss them.

Almost all of the non-trivial holidays/diary entries would suffer in the same
way, so rewriting the code properly to display a wider window means modifying
almost every holiday/diary function in some (usually non-obvious) way.
-- 

Professor Edward M. ReingoldEmail: [EMAIL PROTECTED]
Department of Computer Science  Voice: (312) 567-3309
Illinois Institute of TechnologyAssistant: (312) 567-5152
Stuart Building Fax:   (312) 567-5067
10 West 31st Street, Suite 236
Chicago, IL  60616-3729  U.S.A.
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-07 Thread Richard Stallman
How do you know that the holidays are correct when the calendar has more 
than
3 months?  Do you have a way to check, say, the dates of lunar phases, 
Easter,
Chinese New Year, Yom Kippur, Islamic New Year, solstices/equinoxes?  You 
will
see SOME holidays (or diary entries) but not all that apply to the months
displayed.

One easy way to check is to run the standard calendar code (without
this customization) and see if it indicates the same holidays.


___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22, the real update

2006-12-07 Thread Richard Stallman
The test

   (if ( displayed-month 5)

checks if the center of the 3 month window is beyond May, in which case (as
the comment from my code says!) Ash Wednesday, Good Friday, and Easter 
cannot
be visibible because they occur in Feb/Mar/Apr.

It sounds like we should systematically replace such code with
something more robust.  It could use two variables,
calendar-first-visible-month and calendar-last-visible-month, to indicate
the range that is visible.

If someone wants to work on this now, that would be useful.  But we
should not install such changes until after Emacs 22 is released.


___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22

2006-12-06 Thread Alf-Ivar Holm
[EMAIL PROTECTED] (Edward M. Reingold) writes:

 This kind of modification of the shape of the calendar window will
 break many things in the determination of holidays and diary
 entries.  It is not recommended!

Yes, you told me 10 years ago, but as you have not yet provided me
with any proof and I have not seen any of these functions break, I
post it in case anyone else would like to have it.

 It is trivial to generate that look, but many, many functions would
 need to be modified to do the necessary interpretation of teh
 modified calendar buffer.

Could you give me _one_ function that would break?  The displayed
calendar is quite static, e.g. it does not support dynamic display of
months when changing the width of the window (I could easily fit 5
months, included week numbers, on my screen if I do a horizontal
maximization of my calendar window), a functionality I would have had
to specifically test for if it were present.  When it comes to
calculating a date I can't see why the visual representation of the
calendar matters, e.g. the date structures is luckily not dependent of
what is displayed in the buffer.

Affi
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: Calendar hack: Displaying ISO weeks, update for emacs 22

2006-12-04 Thread Kevin Rodgers

Richard Stallman wrote:

We took out `facemenu-unlisted-faces' because it was a no-op,
it did nothing.  We were not sure it was worth reimplementing the
functionality.  But now I see that we should.


Why?  The only way Affi's calendar-hack.el uses it is:

  (add-to-list 'facemenu-unlisted-faces 'calendar-week-face)
  (add-to-list 'facemenu-unlisted-faces 'calendar-header-face)
  (add-to-list 'facemenu-unlisted-faces 'calendar-sunday-face)

Simply commenting that out -- or for older Emacs versions, protecting it
inside (with (boundp 'facemenu-unlisted-faces) ...) -- should be enough.
In any case, the face won't be added to facemenu-listed-faces, which
achieves the desired result.

--
Kevin



___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources