unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* calendar problem: week number
@ 2008-08-07  9:15 Werner LEMBERG
  2008-08-07  9:38 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Werner LEMBERG @ 2008-08-07  9:15 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: Text/Plain, Size: 312 bytes --]


Companies in German are used to refer to the `Kalenderwoche' (the
current number of the week counted from the beginning of the year).
For example, this week is the 32nd week.  Can I configure `calendar'
to make it display, eg., like in the attached image?  I haven't found
a hint in the info file.


    Werner

[-- Attachment #2: calendar-week.png --]
[-- Type: Image/Png, Size: 10128 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07  9:15 calendar problem: week number Werner LEMBERG
@ 2008-08-07  9:38 ` Tassilo Horn
  2008-08-07 14:49   ` Ed Reingold
  2008-08-08 14:43   ` Werner LEMBERG
  2008-08-07 10:03 ` tomas
  2008-08-07 11:40 ` Lawrence Mitchell
  2 siblings, 2 replies; 11+ messages in thread
From: Tassilo Horn @ 2008-08-07  9:38 UTC (permalink / raw)
  To: emacs-devel

On Thursday 07 August 2008 11:15:11 Werner LEMBERG wrote:

Hi Werner,

> Companies in German are used to refer to the `Kalenderwoche' (the
> current number of the week counted from the beginning of the year).
> For example, this week is the 32nd week.  Can I configure `calendar'
> to make it display, eg., like in the attached image?  I haven't found
> a hint in the info file.

I use this custom code to do that:

--8<---------------cut here---------------start------------->8---
(add-to-list 'calendar-mode-line-format
             '(let ((day (nth 1 date))
                    (month (nth 0 date))
                    (year (nth 2 date)))
                (format-time-string "Week of year: %V"
                                    (encode-time 1 1 1 day month 
year))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07  9:15 calendar problem: week number Werner LEMBERG
  2008-08-07  9:38 ` Tassilo Horn
@ 2008-08-07 10:03 ` tomas
  2008-08-07 10:34   ` Werner LEMBERG
  2008-08-07 11:40 ` Lawrence Mitchell
  2 siblings, 1 reply; 11+ messages in thread
From: tomas @ 2008-08-07 10:03 UTC (permalink / raw)
  To: Werner LEMBERG; +Cc: emacs-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Aug 07, 2008 at 11:15:11AM +0200, Werner LEMBERG wrote:
> 
> Companies in German are used to refer to the `Kalenderwoche' (the
> current number of the week counted from the beginning of the year).
> For example, this week is the 32nd week.  Can I configure `calendar'
> to make it display, eg., like in the attached image?  I haven't found
> a hint in the info file.

Typing 'p c' shows you the ISO date, with week number, which should be
the same as the German 'Kalenderwoche' (AFAIK it's all ISO 8601).

I don't think you can customize the calendar to show week numbers next
to the rows (that's what you are looking for, right?

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFImshYBcgs9XrR2kYRAhuSAJ4z8PKQWTILkBm17wmAxxgusdO38ACbBnjI
kP3pkAsTajTFs40QMNb3ffg=
=YiSt
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07 10:03 ` tomas
@ 2008-08-07 10:34   ` Werner LEMBERG
  0 siblings, 0 replies; 11+ messages in thread
From: Werner LEMBERG @ 2008-08-07 10:34 UTC (permalink / raw)
  To: tomas; +Cc: emacs-devel


> Typing 'p c' shows you the ISO date, with week number, which should
> be the same as the German 'Kalenderwoche' (AFAIK it's all ISO 8601).

Ah, thanks.

> I don't think you can customize the calendar to show week numbers
> next to the rows (that's what you are looking for, right?

Yep.


    Werner




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07  9:15 calendar problem: week number Werner LEMBERG
  2008-08-07  9:38 ` Tassilo Horn
  2008-08-07 10:03 ` tomas
@ 2008-08-07 11:40 ` Lawrence Mitchell
  2008-08-07 11:58   ` Ed Reingold
  2 siblings, 1 reply; 11+ messages in thread
From: Lawrence Mitchell @ 2008-08-07 11:40 UTC (permalink / raw)
  To: emacs-devel

Werner LEMBERG wrote:


> Companies in German are used to refer to the `Kalenderwoche' (the
> current number of the week counted from the beginning of the year).
> For example, this week is the 32nd week.  Can I configure `calendar'
> to make it display, eg., like in the attached image?  I haven't found
> a hint in the info file.

The following patch seems to do the right thing, although it only
works correctly if calendar-week-start-day is 1 (monday).  I don't think
it breaks any of the movement commands.

Cheers,

Lawrence

diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index dc2f8ce..9989b22 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1409,7 +1409,13 @@ line."
           (substring string 0 calendar-day-header-width)))
       (make-string (- calendar-column-width calendar-day-header-width) ?\s)))
    (calendar-ensure-newline)
-   (calendar-insert-at-column indent calendar-intermonth-text trunc)
+   (calendar-insert-at-column (- indent 3) calendar-intermonth-text trunc)
+   (insert (propertize (format "%2d " (car (calendar-iso-from-absolute
+                                            (calendar-dayname-on-or-before
+                                             1 (calendar-absolute-from-gregorian
+                                                (list month 1
+                                                      year))))))
+                       'font-lock-face 'font-lock-comment-face))
    ;; Add blank days before the first of the month.
    (insert (make-string (* blank-days calendar-column-width) ?\s))
    ;; Put in the days of the month.
@@ -1429,7 +1435,18 @@ line."
                 (/= day last))
        (calendar-ensure-newline)
        (setq day (1+ day))              ; first day of next week
-       (calendar-insert-at-column indent calendar-intermonth-text trunc)))))
+       (calendar-insert-at-column (- indent 3) calendar-intermonth-text trunc)
+       (insert (propertize
+                (format "%2d " (car (calendar-iso-from-absolute
+                                     (calendar-dayname-on-or-before
+                                      1
+                                      (calendar-absolute-from-gregorian
+                                       (list month
+                                             (+ i
+                                                (- 7
+                                                   calendar-week-start-day))
+                                            year))))))
+                'font-lock-face 'font-lock-comment-face))))))
 
 (defun calendar-redraw ()
   "Redraw the calendar display, if `calendar-buffer' is live."

-- 
Lawrence Mitchell <wence@gmx.li>





^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07 11:40 ` Lawrence Mitchell
@ 2008-08-07 11:58   ` Ed Reingold
  2008-08-07 12:59     ` Lawrence Mitchell
  0 siblings, 1 reply; 11+ messages in thread
From: Ed Reingold @ 2008-08-07 11:58 UTC (permalink / raw)
  To: emacs-devel

The "fix" below will break many, many things--holidays, diary entries, 
conversions to other calendars, etc.  The exact shape of the calendar window 
cannot be changed.


> Werner LEMBERG wrote:
> 
> 
> > Companies in German are used to refer to the `Kalenderwoche' (the
> > current number of the week counted from the beginning of the year).
> > For example, this week is the 32nd week.  Can I configure `calendar'
> > to make it display, eg., like in the attached image?  I haven't found
> > a hint in the info file.
> 
> The following patch seems to do the right thing, although it only
> works correctly if calendar-week-start-day is 1 (monday).  I don't think
> it breaks any of the movement commands.
> 
> Cheers,
> 
> Lawrence
> 
> diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
> index dc2f8ce..9989b22 100644
> --- a/lisp/calendar/calendar.el
> +++ b/lisp/calendar/calendar.el
> @@ -1409,7 +1409,13 @@ line."
>            (substring string 0 calendar-day-header-width)))
>        (make-string (- calendar-column-width calendar-day-header-width) ?\s)))
>     (calendar-ensure-newline)
> -   (calendar-insert-at-column indent calendar-intermonth-text trunc)
> +   (calendar-insert-at-column (- indent 3) calendar-intermonth-text trunc)
> +   (insert (propertize (format "%2d " (car (calendar-iso-from-absolute
> +                                            (calendar-dayname-on-or-before
> +                                             1 (calendar-absolute-from-gregorian
> +                                                (list month 1
> +                                                      year))))))
> +                       'font-lock-face 'font-lock-comment-face))
>     ;; Add blank days before the first of the month.
>     (insert (make-string (* blank-days calendar-column-width) ?\s))
>     ;; Put in the days of the month.
> @@ -1429,7 +1435,18 @@ line."
>                  (/= day last))
>         (calendar-ensure-newline)
>         (setq day (1+ day))              ; first day of next week
> -       (calendar-insert-at-column indent calendar-intermonth-text trunc)))))
> +       (calendar-insert-at-column (- indent 3) calendar-intermonth-text trunc)
> +       (insert (propertize
> +                (format "%2d " (car (calendar-iso-from-absolute
> +                                     (calendar-dayname-on-or-before
> +                                      1
> +                                      (calendar-absolute-from-gregorian
> +                                       (list month
> +                                             (+ i
> +                                                (- 7
> +                                                   calendar-week-start-day))
> +                                            year))))))
> +                'font-lock-face 'font-lock-comment-face))))))
>  
>  (defun calendar-redraw ()
>    "Redraw the calendar display, if `calendar-buffer' is live."
> 
> -- 
> Lawrence Mitchell <wence@gmx.li>
> 
> 






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07 11:58   ` Ed Reingold
@ 2008-08-07 12:59     ` Lawrence Mitchell
  0 siblings, 0 replies; 11+ messages in thread
From: Lawrence Mitchell @ 2008-08-07 12:59 UTC (permalink / raw)
  To: emacs-devel

Ed Reingold wrote:
> The "fix" below will break many, many things--holidays, diary entries,
> conversions to other calendars, etc.  The exact shape of the calendar window
> cannot be changed.

I made sure not to change the shape of the calendar window: the
extra week numbers are placed in the space between months without
changing the column layout.  Will this nonetheless affect things?

[...]

Cheers,
Lawrence
-- 
Lawrence Mitchell <wence@gmx.li>





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07  9:38 ` Tassilo Horn
@ 2008-08-07 14:49   ` Ed Reingold
  2008-08-08 14:43   ` Werner LEMBERG
  1 sibling, 0 replies; 11+ messages in thread
From: Ed Reingold @ 2008-08-07 14:49 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

> (add-to-list 'calendar-mode-line-format
>              '(let ((day (nth 1 date))
>                     (month (nth 0 date))
>                     (year (nth 2 date)))
>                 (format-time-string "Week of year: %V"
>                                     (encode-time 1 1 1 day month 
> year))))

That should not cause any problems.  Note that you can also use the calendar 
code functions for the week number; see cal-iso.el








^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-07  9:38 ` Tassilo Horn
  2008-08-07 14:49   ` Ed Reingold
@ 2008-08-08 14:43   ` Werner LEMBERG
  2008-08-08 14:54     ` Werner LEMBERG
  2008-08-08 15:17     ` Lawrence Mitchell
  1 sibling, 2 replies; 11+ messages in thread
From: Werner LEMBERG @ 2008-08-08 14:43 UTC (permalink / raw)
  To: horn; +Cc: emacs-devel


> > Companies in German are used to refer to the `Kalenderwoche' (the
> > current number of the week counted from the beginning of the
> > year).  For example, this week is the 32nd week.  Can I configure
> > `calendar' to make it display, eg., like in the attached image?  I
> > haven't found a hint in the info file.
> 
> I use this custom code to do that: [...]

Thanks, but helps a bit but it is not what I really want -- in most
cases you don't need the current week number but a values of a
completely different week number.

Maybe this can be added somehow to calendar.


    Werner




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-08 14:43   ` Werner LEMBERG
@ 2008-08-08 14:54     ` Werner LEMBERG
  2008-08-08 15:17     ` Lawrence Mitchell
  1 sibling, 0 replies; 11+ messages in thread
From: Werner LEMBERG @ 2008-08-08 14:54 UTC (permalink / raw)
  To: horn; +Cc: emacs-devel


> Thanks, but helps a bit but it is not what I really want [...]

Oops.  I shouldn't watch the opening of the Olympic Games :-)


    Werner




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: calendar problem: week number
  2008-08-08 14:43   ` Werner LEMBERG
  2008-08-08 14:54     ` Werner LEMBERG
@ 2008-08-08 15:17     ` Lawrence Mitchell
  1 sibling, 0 replies; 11+ messages in thread
From: Lawrence Mitchell @ 2008-08-08 15:17 UTC (permalink / raw)
  To: emacs-devel

Werner LEMBERG wrote:
>>> Companies in German are used to refer to the `Kalenderwoche' (the
>>> current number of the week counted from the beginning of the
>>> year).  For example, this week is the 32nd week.  Can I configure
>>> `calendar' to make it display, eg., like in the attached image?  I
>>> haven't found a hint in the info file.

>> I use this custom code to do that: [...]

> Thanks, but helps a bit but it is not what I really want -- in most
> cases you don't need the current week number but a values of a
> completely different week number.

> Maybe this can be added somehow to calendar.

It turns out it is, after Ed pointed out that my idea of adding
something to calendar-generate-month may not work, I had another
look to see if I had in fact broken things.  It turns out Glenn
Morris has recently (Jun 26th) implemented more flexible calendar
printing: removing magic numbers and the like.

Anyway, to get iso week numbers in the calendar view, just modify
`calendar-intermonth-text' as suggested in its docstring.  This
is in NEWS, but not yet in the info file, I believe.

Cheers,
Lawrence
-- 
Lawrence Mitchell <wence@gmx.li>





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-08-08 15:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-07  9:15 calendar problem: week number Werner LEMBERG
2008-08-07  9:38 ` Tassilo Horn
2008-08-07 14:49   ` Ed Reingold
2008-08-08 14:43   ` Werner LEMBERG
2008-08-08 14:54     ` Werner LEMBERG
2008-08-08 15:17     ` Lawrence Mitchell
2008-08-07 10:03 ` tomas
2008-08-07 10:34   ` Werner LEMBERG
2008-08-07 11:40 ` Lawrence Mitchell
2008-08-07 11:58   ` Ed Reingold
2008-08-07 12:59     ` Lawrence Mitchell

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).