* [PATCH] org-agenda: rework ndays and span handling
@ 2010-11-29 10:49 Julien Danjou
2010-11-29 11:14 ` Carsten Dominik
2010-11-30 23:53 ` Carsten Dominik
0 siblings, 2 replies; 17+ messages in thread
From: Julien Danjou @ 2010-11-29 10:49 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Julien Danjou
* org-agenda.el (org-agenda-custom-commands-local-options):
Allow org-agenda-span to be a symbol.
(org-agenda-ndays): Make obsolete.
(org-agenda-span): New variable superseding org-agenda-ndays.
(org-agenda-menu): Use org-agenda-current-span.
(org-agenda-current-span): New local variable storing current
span.
(org-agenda-list): Take a span instead of ndays as argument.
This function is now responsible for computing the ndays based
on span.
(org-agenda-ndays-to-span): Return span only if number of days
really matches.
(org-agenda-span-to-ndays): New function.
(org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
(org-agenda-goto-today): Use org-agenda-compute-starting-span.
(org-agenda-later): Do not give compute a new span, use the
current one.
(org-agenda-day-view, org-agenda-week-view)
(org-agenda-month-view, org-agenda-year-view): Stop touching
org-agenda-ndays.
(org-agenda-change-time-span): Only compute starting-span.
(org-agenda-compute-starting-span): New function derived from
the old org-agenda-compute-time-span.
(org-agenda-set-mode-name): Compute mode based on
org-agenda-current-span.
(org-agenda-span-name): New function.
* org-mouse.el: Replace Replace org-agenda-ndays by
org-agenda-current-span.
* org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
Hi,
This patch is pretty huge, so I'll give a bit of context about it.
I'm weird, but I used org-agenda-ndays set to 14. Unfortunately, this
settings was interpreted as a month view. Pressing 'f' key to see later,
would show me the next month, which was not at all what I wanted.
On the same idea, day view or week view would change my org-agenda-ndays
settings, which I think is not a good idea. Changing user setting is *bad*.
:-)
So I rewrote the things this way:
- Rename org-agenda-span to org-agenda-current-span
Which has the same meaning has before, except it can be numeric.
- Rename org-agenda-ndays to org-agenda-span
I think the name is better choosen. You can set it to a symbol instead of
only a numeric value. That means you can set it to 'month and it will show
you the number of days of the current month in your agenda. Better than
30. But you can still set it to 30, or 31, or whatever you want.
- Do not change org-agenda-span. Never.
- Use org-agenda-current-span for navigation.
That means if you press 'f', it will shows you really the next
org-agenda-current-span ndays, and not something based on "I think you
want a weekly view".
Tested, no bug found so far. :-)
doc/org.texi | 14 ++--
doc/orgguide.texi | 6 +-
lisp/org-agenda.el | 188 +++++++++++++++++++++++++++++----------------------
lisp/org-mouse.el | 4 +-
4 files changed, 119 insertions(+), 93 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index e2e9af5..b5b70c9 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the current week or day.
@table @kbd
@cindex org-agenda, command
@orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
+@vindex org-agenda-span
Compile an agenda for the current week from a list of Org files. The agenda
shows the entries for each day. With a numeric prefix@footnote{For backward
compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
listed before the agenda. This feature is deprecated, use the dedicated TODO
list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+variable @code{org-agenda-span})
@end table
Remote editing from the agenda buffer means, for example, that you can
@@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
be mapped to the interval 1938-2037.
@c
@orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+@vindex org-agenda-span
+Go forward in time to display the following @code{org-agenda-current-span} days.
For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
@c
@orgcmd{b,org-agenda-earlier}
Go backward in time to display earlier dates.
@@ -8369,7 +8369,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
system you use, please check the FAQ for examples.}
@example
emacs -eval '(org-batch-store-agenda-views \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
@@ -14033,7 +14033,7 @@ You may also modify parameters on the fly like this:
@example
emacs -batch -l ~/.emacs \
-eval '(org-batch-agenda "a" \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
| lpr
diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index b67f7f1..690111b 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -1931,9 +1931,9 @@ Delete other windows.
Switch to day/week view.
@c
@item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days. For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days. For example, if the display covers a
+week, switch to the following/previous week.
@c
@item .
Go to today.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 48856c9..c44595d 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
(const org-agenda-prefix-format :value " %-12:c%?-12t% s")
(string))
(list :tag "Number of days in agenda"
- (const org-agenda-ndays)
- (integer :value 1))
+ (const org-agenda-span)
+ (choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(list :tag "Fixed starting date"
(const org-agenda-start-day)
(string :value "2007-11-01"))
@@ -888,12 +892,25 @@ option will be ignored."
:group 'org-agenda-windows
:type 'boolean)
-(defcustom org-agenda-ndays 7
- "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+ "Number of days to include in overview display.
Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+ :group 'org-agenda-daily/weekly
+ :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+ "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
Custom commands can set this variable in the options section."
:group 'org-agenda-daily/weekly
- :type 'integer)
+ :type '(choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(defcustom org-agenda-start-on-weekday 1
"Non-nil means start the overview always on the specified weekday.
@@ -1825,19 +1842,19 @@ The following commands are available:
("View"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)
+ :style radio :selected (eq org-agenda-current-span 'day)
:keys "v d (or just d)"]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)
+ :style radio :selected (eq org-agenda-current-span 'week)
:keys "v w (or just w)"]
["Month View" org-agenda-month-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+ :style radio :selected (eq org-agenda-current-span 'month)
:keys "v m"]
["Year View" org-agenda-year-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(365 366))
+ :style radio :selected (eq org-agenda-current-span 'year)
:keys "v y"]
"--"
["Include Diary" org-agenda-toggle-diary
@@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
(defvar org-agenda-last-arguments nil
"The arguments of the previous call to `org-agenda'.")
(defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+ "The current span used in the agenda view.") ; local variable in the agenda buffer
(defvar org-include-all-loc nil) ; local variable
(defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
the daily/weekly agenda, see `org-agenda-skip-function'.")
;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
"Produce a daily/weekly view from all files in variable `org-agenda-files'.
The view will be for the current day or week, but from the overview buffer
you will be able to go to other days/weeks.
@@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
agenda instead.
With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
-the number of days. NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
+the number of days. SPAN defaults to `org-agenda-span'.
START-DAY defaults to TODAY, or to the most recent match for the weekday
given in `org-agenda-start-on-weekday'."
(interactive "P")
(if (and (integerp include-all) (> include-all 0))
- (setq ndays include-all include-all nil))
- (setq ndays (or ndays org-agenda-ndays)
- start-day (or start-day org-agenda-start-day))
+ (setq span include-all include-all nil))
+ (setq start-day (or start-day org-agenda-start-day))
(if org-agenda-overriding-arguments
(setq include-all (car org-agenda-overriding-arguments)
start-day (nth 1 org-agenda-overriding-arguments)
- ndays (nth 2 org-agenda-overriding-arguments)))
+ span (nth 2 org-agenda-overriding-arguments)))
(if (stringp start-day)
;; Convert to an absolute day number
(setq start-day (time-to-days (org-read-date nil t start-day))))
- (setq org-agenda-last-arguments (list include-all start-day ndays))
+ (setq org-agenda-last-arguments (list include-all start-day span))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
- (let* ((org-agenda-start-on-weekday
- (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
- org-agenda-start-on-weekday nil))
- (thefiles (org-agenda-files nil 'ifmode))
- (files thefiles)
+ (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
(today (org-agenda-today))
(sd (or start-day today))
+ (ndays (org-agenda-span-to-ndays span sd))
+ (org-agenda-start-on-weekday
+ (if (eq ndays 7)
+ org-agenda-start-on-weekday))
+ (thefiles (org-agenda-files nil 'ifmode))
+ (files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
- (< org-agenda-ndays 7))
+ (< ndays 7))
sd
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
@@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
(day-numbers (list start))
(day-cnt 0)
(inhibit-redisplay (not debug-on-error))
- s e rtn rtnall file date d start-pos end-pos todayp nd
+ s e rtn rtnall file date d start-pos end-pos todayp
clocktable-start clocktable-end filter)
(setq org-agenda-redo-command
- (list 'org-agenda-list (list 'quote include-all) start-day ndays))
- ;; Make the list of days
- (setq ndays (or ndays org-agenda-ndays)
- nd ndays)
- (while (> ndays 1)
- (push (1+ (car day-numbers)) day-numbers)
- (setq ndays (1- ndays)))
+ (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+ (dotimes (n (1- ndays))
+ (push (1+ (car day-numbers)) day-numbers))
(setq day-numbers (nreverse day-numbers))
(setq clocktable-start (car day-numbers)
clocktable-end (1+ (or (org-last day-numbers) 0)))
(org-prepare-agenda "Day/Week")
(org-set-local 'org-starting-day (car day-numbers))
(org-set-local 'org-include-all-loc include-all)
- (org-set-local 'org-agenda-span
- (org-agenda-ndays-to-span nd))
+ (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
(when (and (or include-all org-agenda-include-all-todo)
(member today day-numbers))
(setq files thefiles
@@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
(if org-agenda-overriding-header
(insert (org-add-props (copy-sequence org-agenda-overriding-header)
nil 'face 'org-agenda-structure) "\n")
- (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+ (insert (org-agenda-span-name span)
"-agenda"
(if (< (- d2 d1) 350)
(if (= w1 w2)
@@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
(if rtnall (insert
(org-finalize-agenda-entries
(org-agenda-add-time-grid-maybe
- rtnall nd todayp))
+ rtnall ndays todayp))
"\n"))
(put-text-property s (1- (point)) 'day d)
(put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
(message "")))
(defun org-agenda-ndays-to-span (n)
- (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+ "Return a span symbol for a span of N days, or N if none matches."
+ (cond ((symbolp n) n)
+ ((= n 1) 'day)
+ ((= n 7) 'week)
+ (t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+ "Return ndays from SPAN starting at START-DAY."
+ (cond ((numberp span) span)
+ ((eq span 'day) 1)
+ ((eq span 'week) 7)
+ ((eq span 'month)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (calendar-last-day-of-month (car date) (caddr date))))
+ ((eq span 'year)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+ "Return a SPAN name."
+ (if (null span)
+ ""
+ (if (symbolp span)
+ (capitalize (symbol-name span))
+ (format "%d days" span))))
;;; Agenda word search
@@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
(cond
(tdpos (goto-char tdpos))
((eq org-agenda-type 'agenda)
- (let* ((sd (org-agenda-today))
- (comp (org-agenda-compute-time-span sd org-agenda-span))
+ (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
(org-agenda-overriding-arguments org-agenda-last-arguments))
- (setf (nth 1 org-agenda-overriding-arguments) (car comp))
- (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+ (setf (nth 1 org-agenda-overriding-arguments) sd)
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda)))
(t (error "Cannot find today")))))
@@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
With prefix ARG, go forward that many times the current span."
(interactive "p")
(org-agenda-check-type t 'agenda)
- (let* ((span org-agenda-span)
+ (let* ((span org-agenda-current-span)
(sd org-starting-day)
(greg (calendar-gregorian-from-absolute sd))
(cnt (org-get-at-bol 'org-day-cnt))
- greg2 nd)
+ greg2)
(cond
((eq span 'day)
- (setq sd (+ arg sd) nd 1))
+ (setq sd (+ arg sd)))
((eq span 'week)
- (setq sd (+ (* 7 arg) sd) nd 7))
+ (setq sd (+ (* 7 arg) sd)))
((eq span 'month)
(setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
sd (calendar-absolute-from-gregorian greg2))
- (setcar greg2 (1+ (car greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+ (setcar greg2 (1+ (car greg2))))
((eq span 'year)
(setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
sd (calendar-absolute-from-gregorian greg2))
- (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+ (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+ (t
+ (setq sd (+ (* span arg) sd))))
(let ((org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments) sd nd t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda cnt))))
@@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
"Switch to daily view for agenda.
With argument DAY-OF-YEAR, switch to that day of the year."
(interactive "P")
- (setq org-agenda-ndays 1)
(org-agenda-change-time-span 'day day-of-year))
(defun org-agenda-week-view (&optional iso-week)
"Switch to daily view for agenda.
@@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
week 12 of year 2007. Years in the range 1938-2037 can also be
written as 2-digit years."
(interactive "P")
- (setq org-agenda-ndays 7)
(org-agenda-change-time-span 'week iso-week))
(defun org-agenda-month-view (&optional month)
"Switch to monthly view for agenda.
@@ -6120,70 +6154,61 @@ written as 2-digit years."
"Change the agenda view to SPAN.
SPAN may be `day', `week', `month', `year'."
(org-agenda-check-type t 'agenda)
- (if (and (not n) (equal org-agenda-span span))
+ (if (and (not n) (equal org-agenda-current-span span))
(error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
org-starting-day))
- (computed (org-agenda-compute-time-span sd span n))
+ (sd (org-agenda-compute-starting-span sd span n))
(org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments)
- (car computed) (cdr computed) t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda))
(org-agenda-set-mode-name)
(message "Switched to %s view" span))
-(defun org-agenda-compute-time-span (sd span &optional n)
- "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+ "Compute starting date for agenda.
SPAN may be `day', `week', `month', `year'. The return value
is a cons cell with the starting date and the number of days,
so that the date SD will be in that range."
(let* ((greg (calendar-gregorian-from-absolute sd))
(dg (nth 1 greg))
(mg (car greg))
- (yg (nth 2 greg))
- nd w1 y1 m1 thisweek)
+ (yg (nth 2 greg)))
(cond
((eq span 'day)
(when n
(setq sd (+ (calendar-absolute-from-gregorian
(list mg 1 yg))
- n -1)))
- (setq nd 1))
+ n -1))))
((eq span 'week)
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
(d (if org-agenda-start-on-weekday
(- nt org-agenda-start-on-weekday)
- 0)))
+ 0))
+ y1)
(setq sd (- sd (+ (if (< d 0) 7 0) d)))
(when n
(require 'cal-iso)
- (setq thisweek (car (calendar-iso-from-absolute sd)))
(when (> n 99)
(setq y1 (org-small-year-to-year (/ n 100))
n (mod n 100)))
(setq sd
(calendar-absolute-from-iso
(list n 1
- (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
- (setq nd 7)))
+ (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
((eq span 'month)
- (when (and n (> n 99))
- (setq y1 (org-small-year-to-year (/ n 100))
- n (mod n 100)))
- (setq sd (calendar-absolute-from-gregorian
- (list (or n mg) 1 (or y1 yg)))
- nd (- (calendar-absolute-from-gregorian
- (list (1+ (or n mg)) 1 (or y1 yg)))
- sd)))
+ (let (y1)
+ (when (and n (> n 99))
+ (setq y1 (org-small-year-to-year (/ n 100))
+ n (mod n 100)))
+ (setq sd (calendar-absolute-from-gregorian
+ (list (or n mg) 1 (or y1 yg))))))
((eq span 'year)
(setq sd (calendar-absolute-from-gregorian
- (list 1 1 (or n yg)))
- nd (- (calendar-absolute-from-gregorian
- (list 1 1 (1+ (or n yg))))
- sd))))
- (cons sd nd)))
+ (list 1 1 (or n yg))))))
+ sd))
(defun org-agenda-next-date-line (&optional arg)
"Jump to the next line indicating a date in agenda buffer."
@@ -6338,8 +6363,9 @@ When called with a prefix argument, include all archive files as well."
(setq mode-name
(concat "Org-Agenda"
(if (get 'org-agenda-files 'org-restrict) " []" "")
- (if (equal org-agenda-ndays 1) " Day" "")
- (if (equal org-agenda-ndays 7) " Week" "")
+ " " (org-agenda-span-name (or org-agenda-current-span
+ org-agenda-ndays
+ org-agenda-span))
(if org-agenda-follow-mode " Follow" "")
(if org-agenda-entry-text-mode " ETxt" "")
(if org-agenda-include-diary " Diary" "")
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index e16c977..d18a12d 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
"--"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)]
+ :style radio :selected (eq org-agenda-current-span 'day)]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)]
+ :style radio :selected (eq org-agenda-current-span 'week)]
"--"
["Show Logbook entries" org-agenda-log-mode
:style toggle :selected org-agenda-show-log
--
1.7.2.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-11-29 10:49 [PATCH] org-agenda: rework ndays and span handling Julien Danjou
@ 2010-11-29 11:14 ` Carsten Dominik
2010-11-29 11:17 ` Julien Danjou
2010-11-30 23:53 ` Carsten Dominik
1 sibling, 1 reply; 17+ messages in thread
From: Carsten Dominik @ 2010-11-29 11:14 UTC (permalink / raw)
To: Julien Danjou; +Cc: emacs-orgmode
Hi Julien,
important testing would be to make sure that *refreshing* the
agenda does this right thing, both for normal and for
custom commands.
- Carsten
On Nov 29, 2010, at 11:49 AM, Julien Danjou wrote:
> * org-agenda.el (org-agenda-custom-commands-local-options):
> Allow org-agenda-span to be a symbol.
> (org-agenda-ndays): Make obsolete.
> (org-agenda-span): New variable superseding org-agenda-ndays.
> (org-agenda-menu): Use org-agenda-current-span.
> (org-agenda-current-span): New local variable storing current
> span.
> (org-agenda-list): Take a span instead of ndays as argument.
> This function is now responsible for computing the ndays based
> on span.
> (org-agenda-ndays-to-span): Return span only if number of days
> really matches.
> (org-agenda-span-to-ndays): New function.
> (org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
> (org-agenda-goto-today): Use org-agenda-compute-starting-span.
> (org-agenda-later): Do not give compute a new span, use the
> current one.
> (org-agenda-day-view, org-agenda-week-view)
> (org-agenda-month-view, org-agenda-year-view): Stop touching
> org-agenda-ndays.
> (org-agenda-change-time-span): Only compute starting-span.
> (org-agenda-compute-starting-span): New function derived from
> the old org-agenda-compute-time-span.
> (org-agenda-set-mode-name): Compute mode based on
> org-agenda-current-span.
> (org-agenda-span-name): New function.
>
> * org-mouse.el: Replace Replace org-agenda-ndays by
> org-agenda-current-span.
>
> * org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-
> span.
>
> Signed-off-by: Julien Danjou <julien@danjou.info>
> ---
>
> Hi,
>
> This patch is pretty huge, so I'll give a bit of context about it.
>
> I'm weird, but I used org-agenda-ndays set to 14. Unfortunately, this
> settings was interpreted as a month view. Pressing 'f' key to see
> later,
> would show me the next month, which was not at all what I wanted.
>
> On the same idea, day view or week view would change my org-agenda-
> ndays
> settings, which I think is not a good idea. Changing user setting is
> *bad*.
> :-)
>
> So I rewrote the things this way:
> - Rename org-agenda-span to org-agenda-current-span
> Which has the same meaning has before, except it can be numeric.
> - Rename org-agenda-ndays to org-agenda-span
> I think the name is better choosen. You can set it to a symbol
> instead of
> only a numeric value. That means you can set it to 'month and it
> will show
> you the number of days of the current month in your agenda. Better
> than
> 30. But you can still set it to 30, or 31, or whatever you want.
> - Do not change org-agenda-span. Never.
> - Use org-agenda-current-span for navigation.
> That means if you press 'f', it will shows you really the next
> org-agenda-current-span ndays, and not something based on "I think
> you
> want a weekly view".
>
> Tested, no bug found so far. :-)
>
> doc/org.texi | 14 ++--
> doc/orgguide.texi | 6 +-
> lisp/org-agenda.el | 188 ++++++++++++++++++++++++++++
> +----------------------
> lisp/org-mouse.el | 4 +-
> 4 files changed, 119 insertions(+), 93 deletions(-)
>
> diff --git a/doc/org.texi b/doc/org.texi
> index e2e9af5..b5b70c9 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the
> current week or day.
> @table @kbd
> @cindex org-agenda, command
> @orgcmd{C-c a a,org-agenda-list}
> -@vindex org-agenda-ndays
> +@vindex org-agenda-span
> Compile an agenda for the current week from a list of Org files.
> The agenda
> shows the entries for each day. With a numeric prefix@footnote{For
> backward
> compatibility, the universal prefix @kbd{C-u} causes all TODO
> entries to be
> listed before the agenda. This feature is deprecated, use the
> dedicated TODO
> list, or a block agenda instead (@pxref{Block agenda}).} (like
> @kbd{C-u 2 1
> C-c a a}) you may set the number of days to be displayed (see also the
> -variable @code{org-agenda-ndays})
> +variable @code{org-agenda-span})
> @end table
>
> Remote editing from the agenda buffer means, for example, that you can
> @@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712
> w} will jump to week 12 in
> be mapped to the interval 1938-2037.
> @c
> @orgcmd{f,org-agenda-later}
> -@vindex org-agenda-ndays
> -Go forward in time to display the following @code{org-agenda-ndays}
> days.
> +@vindex org-agenda-span
> +Go forward in time to display the following @code{org-agenda-
> current-span} days.
> For example, if the display covers a week, switch to the following
> week.
> -With prefix arg, go forward that many times @code{org-agenda-ndays}
> days.
> +With prefix arg, go forward that many times @code{org-agenda-
> current-span} days.
> @c
> @orgcmd{b,org-agenda-earlier}
> Go backward in time to display earlier dates.
> @@ -8369,7 +8369,7 @@ or, if you need to modify some
> parameters@footnote{Quoting depends on the
> system you use, please check the FAQ for examples.}
> @example
> emacs -eval '(org-batch-store-agenda-views \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-start-day "2007-11-01" \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> @@ -14033,7 +14033,7 @@ You may also modify parameters on the fly
> like this:
> @example
> emacs -batch -l ~/.emacs \
> -eval '(org-batch-agenda "a" \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> | lpr
> diff --git a/doc/orgguide.texi b/doc/orgguide.texi
> index b67f7f1..690111b 100644
> --- a/doc/orgguide.texi
> +++ b/doc/orgguide.texi
> @@ -1931,9 +1931,9 @@ Delete other windows.
> Switch to day/week view.
> @c
> @item f @r{and} b
> -Go forward/backward in time to display the following @code{org-
> agenda-ndays}
> -days. For example, if the display covers a week, switch to the
> -following/previous week.
> +Go forward/backward in time to display the following
> +@code{org-agenda-current-span} days. For example, if the display
> covers a
> +week, switch to the following/previous week.
> @c
> @item .
> Go to today.
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index 48856c9..c44595d 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to
> the header. However,
> (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
> (string))
> (list :tag "Number of days in agenda"
> - (const org-agenda-ndays)
> - (integer :value 1))
> + (const org-agenda-span)
> + (choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
> (list :tag "Fixed starting date"
> (const org-agenda-start-day)
> (string :value "2007-11-01"))
> @@ -888,12 +892,25 @@ option will be ignored."
> :group 'org-agenda-windows
> :type 'boolean)
>
> -(defcustom org-agenda-ndays 7
> - "Number of days to include in overview display.
> +(defcustom org-agenda-ndays nil
> + "Number of days to include in overview display.
> Should be 1 or 7.
> +Obsolete, see `org-agenda-span'."
> + :group 'org-agenda-daily/weekly
> + :type 'integer)
> +
> +(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
> +
> +(defcustom org-agenda-span 'week
> + "Number of days to include in overview display.
> +Can be day, week, month, year, or any number of days.
> Custom commands can set this variable in the options section."
> :group 'org-agenda-daily/weekly
> - :type 'integer)
> + :type '(choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
>
> (defcustom org-agenda-start-on-weekday 1
> "Non-nil means start the overview always on the specified weekday.
> @@ -1825,19 +1842,19 @@ The following commands are available:
> ("View"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)
> + :style radio :selected (eq org-agenda-current-span 'day)
> :keys "v d (or just d)"]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)
> + :style radio :selected (eq org-agenda-current-span 'week)
> :keys "v w (or just w)"]
> ["Month View" org-agenda-month-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(28 29 30 31))
> + :style radio :selected (eq org-agenda-current-span 'month)
> :keys "v m"]
> ["Year View" org-agenda-year-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(365 366))
> + :style radio :selected (eq org-agenda-current-span 'year)
> :keys "v y"]
> "--"
> ["Include Diary" org-agenda-toggle-diary
> @@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days
> without any entries."
> (defvar org-agenda-last-arguments nil
> "The arguments of the previous call to `org-agenda'.")
> (defvar org-starting-day nil) ; local variable in the agenda buffer
> -(defvar org-agenda-span nil) ; local variable in the agenda buffer
> +(defvar org-agenda-current-span nil
> + "The current span used in the agenda view.") ; local variable in
> the agenda buffer
> (defvar org-include-all-loc nil) ; local variable
>
> (defvar org-agenda-entry-types
> '(:deadline :scheduled :timestamp :sexp)
> @@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining
> what is included in
> the daily/weekly agenda, see `org-agenda-skip-function'.")
>
> ;;;###autoload
> -(defun org-agenda-list (&optional include-all start-day ndays)
> +(defun org-agenda-list (&optional include-all start-day span)
> "Produce a daily/weekly view from all files in variable `org-
> agenda-files'.
> The view will be for the current day or week, but from the overview
> buffer
> you will be able to go to other days/weeks.
> @@ -3371,35 +3389,36 @@ This feature is considered obsolete, please
> use the TODO list or a block
> agenda instead.
>
> With a numeric prefix argument in an interactive call, the agenda will
> -span INCLUDE-ALL days. Lisp programs should instead specify NDAYS
> to change
> -the number of days. NDAYS defaults to `org-agenda-ndays'.
> +span INCLUDE-ALL days. Lisp programs should instead specify SPAN
> to change
> +the number of days. SPAN defaults to `org-agenda-span'.
>
> START-DAY defaults to TODAY, or to the most recent match for the
> weekday
> given in `org-agenda-start-on-weekday'."
> (interactive "P")
> (if (and (integerp include-all) (> include-all 0))
> - (setq ndays include-all include-all nil))
> - (setq ndays (or ndays org-agenda-ndays)
> - start-day (or start-day org-agenda-start-day))
> + (setq span include-all include-all nil))
> + (setq start-day (or start-day org-agenda-start-day))
> (if org-agenda-overriding-arguments
> (setq include-all (car org-agenda-overriding-arguments)
> start-day (nth 1 org-agenda-overriding-arguments)
> - ndays (nth 2 org-agenda-overriding-arguments)))
> + span (nth 2 org-agenda-overriding-arguments)))
> (if (stringp start-day)
> ;; Convert to an absolute day number
> (setq start-day (time-to-days (org-read-date nil t start-day))))
> - (setq org-agenda-last-arguments (list include-all start-day ndays))
> + (setq org-agenda-last-arguments (list include-all start-day span))
> (org-compile-prefix-format 'agenda)
> (org-set-sorting-strategy 'agenda)
> - (let* ((org-agenda-start-on-weekday
> - (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-
> ndays)))
> - org-agenda-start-on-weekday nil))
> - (thefiles (org-agenda-files nil 'ifmode))
> - (files thefiles)
> + (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays
> org-agenda-span)))
> (today (org-agenda-today))
> (sd (or start-day today))
> + (ndays (org-agenda-span-to-ndays span sd))
> + (org-agenda-start-on-weekday
> + (if (eq ndays 7)
> + org-agenda-start-on-weekday))
> + (thefiles (org-agenda-files nil 'ifmode))
> + (files thefiles)
> (start (if (or (null org-agenda-start-on-weekday)
> - (< org-agenda-ndays 7))
> + (< ndays 7))
> sd
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> @@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
> (day-numbers (list start))
> (day-cnt 0)
> (inhibit-redisplay (not debug-on-error))
> - s e rtn rtnall file date d start-pos end-pos todayp nd
> + s e rtn rtnall file date d start-pos end-pos todayp
> clocktable-start clocktable-end filter)
> (setq org-agenda-redo-command
> - (list 'org-agenda-list (list 'quote include-all) start-day ndays))
> - ;; Make the list of days
> - (setq ndays (or ndays org-agenda-ndays)
> - nd ndays)
> - (while (> ndays 1)
> - (push (1+ (car day-numbers)) day-numbers)
> - (setq ndays (1- ndays)))
> + (list 'org-agenda-list (list 'quote include-all) start-day (list
> 'quote span)))
> + (dotimes (n (1- ndays))
> + (push (1+ (car day-numbers)) day-numbers))
> (setq day-numbers (nreverse day-numbers))
> (setq clocktable-start (car day-numbers)
> clocktable-end (1+ (or (org-last day-numbers) 0)))
> (org-prepare-agenda "Day/Week")
> (org-set-local 'org-starting-day (car day-numbers))
> (org-set-local 'org-include-all-loc include-all)
> - (org-set-local 'org-agenda-span
> - (org-agenda-ndays-to-span nd))
> + (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-
> span span))
> (when (and (or include-all org-agenda-include-all-todo)
> (member today day-numbers))
> (setq files thefiles
> @@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
> (if org-agenda-overriding-header
> (insert (org-add-props (copy-sequence org-agenda-overriding-
> header)
> nil 'face 'org-agenda-structure) "\n")
> - (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
> + (insert (org-agenda-span-name span)
> "-agenda"
> (if (< (- d2 d1) 350)
> (if (= w1 w2)
> @@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
> (if rtnall (insert
> (org-finalize-agenda-entries
> (org-agenda-add-time-grid-maybe
> - rtnall nd todayp))
> + rtnall ndays todayp))
> "\n"))
> (put-text-property s (1- (point)) 'day d)
> (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
> @@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
> (message "")))
>
> (defun org-agenda-ndays-to-span (n)
> - (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
> + "Return a span symbol for a span of N days, or N if none matches."
> + (cond ((symbolp n) n)
> + ((= n 1) 'day)
> + ((= n 7) 'week)
> + (t n)))
> +
> +(defun org-agenda-span-to-ndays (span start-day)
> + "Return ndays from SPAN starting at START-DAY."
> + (cond ((numberp span) span)
> + ((eq span 'day) 1)
> + ((eq span 'week) 7)
> + ((eq span 'month)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (calendar-last-day-of-month (car date) (caddr date))))
> + ((eq span 'year)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (if (calendar-leap-year-p (caddr date)) 366 365)))))
> +
> +(defun org-agenda-span-name (span)
> + "Return a SPAN name."
> + (if (null span)
> + ""
> + (if (symbolp span)
> + (capitalize (symbol-name span))
> + (format "%d days" span))))
>
> ;;; Agenda word search
>
> @@ -6000,11 +6038,9 @@ Negative selection means regexp must not
> match for selection of an entry."
> (cond
> (tdpos (goto-char tdpos))
> ((eq org-agenda-type 'agenda)
> - (let* ((sd (org-agenda-today))
> - (comp (org-agenda-compute-time-span sd org-agenda-span))
> + (let* ((sd (org-agenda-compute-starting-span (org-agenda-
> today) (or org-agenda-ndays org-agenda-span)))
> (org-agenda-overriding-arguments org-agenda-last-arguments))
> - (setf (nth 1 org-agenda-overriding-arguments) (car comp))
> - (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
> + (setf (nth 1 org-agenda-overriding-arguments) sd)
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda)))
> (t (error "Cannot find today")))))
> @@ -6021,28 +6057,28 @@ Negative selection means regexp must not
> match for selection of an entry."
> With prefix ARG, go forward that many times the current span."
> (interactive "p")
> (org-agenda-check-type t 'agenda)
> - (let* ((span org-agenda-span)
> + (let* ((span org-agenda-current-span)
> (sd org-starting-day)
> (greg (calendar-gregorian-from-absolute sd))
> (cnt (org-get-at-bol 'org-day-cnt))
> - greg2 nd)
> + greg2)
> (cond
> ((eq span 'day)
> - (setq sd (+ arg sd) nd 1))
> + (setq sd (+ arg sd)))
> ((eq span 'week)
> - (setq sd (+ (* 7 arg) sd) nd 7))
> + (setq sd (+ (* 7 arg) sd)))
> ((eq span 'month)
> (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar greg2 (1+ (car greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
> + (setcar greg2 (1+ (car greg2))))
> ((eq span 'year)
> (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
> + (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
> + (t
> + (setq sd (+ (* span arg) sd))))
> (let ((org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments) sd nd t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda cnt))))
>
> @@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times
> the current span."
> "Switch to daily view for agenda.
> With argument DAY-OF-YEAR, switch to that day of the year."
> (interactive "P")
> - (setq org-agenda-ndays 1)
> (org-agenda-change-time-span 'day day-of-year))
> (defun org-agenda-week-view (&optional iso-week)
> "Switch to daily view for agenda.
> @@ -6095,7 +6130,6 @@ week. Any digits before this encode a year.
> So 200712 means
> week 12 of year 2007. Years in the range 1938-2037 can also be
> written as 2-digit years."
> (interactive "P")
> - (setq org-agenda-ndays 7)
> (org-agenda-change-time-span 'week iso-week))
> (defun org-agenda-month-view (&optional month)
> "Switch to monthly view for agenda.
> @@ -6120,70 +6154,61 @@ written as 2-digit years."
> "Change the agenda view to SPAN.
> SPAN may be `day', `week', `month', `year'."
> (org-agenda-check-type t 'agenda)
> - (if (and (not n) (equal org-agenda-span span))
> + (if (and (not n) (equal org-agenda-current-span span))
> (error "Viewing span is already \"%s\"" span))
> (let* ((sd (or (org-get-at-bol 'day)
> org-starting-day))
> - (computed (org-agenda-compute-time-span sd span n))
> + (sd (org-agenda-compute-starting-span sd span n))
> (org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments)
> - (car computed) (cdr computed) t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda))
> (org-agenda-set-mode-name)
> (message "Switched to %s view" span))
>
> -(defun org-agenda-compute-time-span (sd span &optional n)
> - "Compute starting date and number of days for agenda.
> +(defun org-agenda-compute-starting-span (sd span &optional n)
> + "Compute starting date for agenda.
> SPAN may be `day', `week', `month', `year'. The return value
> is a cons cell with the starting date and the number of days,
> so that the date SD will be in that range."
> (let* ((greg (calendar-gregorian-from-absolute sd))
> (dg (nth 1 greg))
> (mg (car greg))
> - (yg (nth 2 greg))
> - nd w1 y1 m1 thisweek)
> + (yg (nth 2 greg)))
> (cond
> ((eq span 'day)
> (when n
> (setq sd (+ (calendar-absolute-from-gregorian
> (list mg 1 yg))
> - n -1)))
> - (setq nd 1))
> + n -1))))
> ((eq span 'week)
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> (d (if org-agenda-start-on-weekday
> (- nt org-agenda-start-on-weekday)
> - 0)))
> + 0))
> + y1)
> (setq sd (- sd (+ (if (< d 0) 7 0) d)))
> (when n
> (require 'cal-iso)
> - (setq thisweek (car (calendar-iso-from-absolute sd)))
> (when (> n 99)
> (setq y1 (org-small-year-to-year (/ n 100))
> n (mod n 100)))
> (setq sd
> (calendar-absolute-from-iso
> (list n 1
> - (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
> - (setq nd 7)))
> + (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
> ((eq span 'month)
> - (when (and n (> n 99))
> - (setq y1 (org-small-year-to-year (/ n 100))
> - n (mod n 100)))
> - (setq sd (calendar-absolute-from-gregorian
> - (list (or n mg) 1 (or y1 yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list (1+ (or n mg)) 1 (or y1 yg)))
> - sd)))
> + (let (y1)
> + (when (and n (> n 99))
> + (setq y1 (org-small-year-to-year (/ n 100))
> + n (mod n 100)))
> + (setq sd (calendar-absolute-from-gregorian
> + (list (or n mg) 1 (or y1 yg))))))
> ((eq span 'year)
> (setq sd (calendar-absolute-from-gregorian
> - (list 1 1 (or n yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list 1 1 (1+ (or n yg))))
> - sd))))
> - (cons sd nd)))
> + (list 1 1 (or n yg))))))
> + sd))
>
> (defun org-agenda-next-date-line (&optional arg)
> "Jump to the next line indicating a date in agenda buffer."
> @@ -6338,8 +6363,9 @@ When called with a prefix argument, include
> all archive files as well."
> (setq mode-name
> (concat "Org-Agenda"
> (if (get 'org-agenda-files 'org-restrict) " []" "")
> - (if (equal org-agenda-ndays 1) " Day" "")
> - (if (equal org-agenda-ndays 7) " Week" "")
> + " " (org-agenda-span-name (or org-agenda-current-span
> + org-agenda-ndays
> + org-agenda-span))
> (if org-agenda-follow-mode " Follow" "")
> (if org-agenda-entry-text-mode " ETxt" "")
> (if org-agenda-include-diary " Diary" "")
> diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
> index e16c977..d18a12d 100644
> --- a/lisp/org-mouse.el
> +++ b/lisp/org-mouse.el
> @@ -1100,10 +1100,10 @@ This means, between the beginning of line
> and the point."
> "--"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)]
> + :style radio :selected (eq org-agenda-current-span 'day)]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)]
> + :style radio :selected (eq org-agenda-current-span 'week)]
> "--"
> ["Show Logbook entries" org-agenda-log-mode
> :style toggle :selected org-agenda-show-log
> --
> 1.7.2.3
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
- Carsten
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-11-29 11:14 ` Carsten Dominik
@ 2010-11-29 11:17 ` Julien Danjou
0 siblings, 0 replies; 17+ messages in thread
From: Julien Danjou @ 2010-11-29 11:17 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 404 bytes --]
On Mon, Nov 29 2010, Carsten Dominik wrote:
> important testing would be to make sure that *refreshing* the
> agenda does this right thing, both for normal and for
> custom commands.
Sure. Refreshing as in pressing 'g' seems to do the right thing for me.
I did not test for custom commands though, any volunteer?
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-11-29 10:49 [PATCH] org-agenda: rework ndays and span handling Julien Danjou
2010-11-29 11:14 ` Carsten Dominik
@ 2010-11-30 23:53 ` Carsten Dominik
2010-12-01 3:59 ` Puneeth
2010-12-01 10:15 ` Eric S Fraga
1 sibling, 2 replies; 17+ messages in thread
From: Carsten Dominik @ 2010-11-30 23:53 UTC (permalink / raw)
To: Julien Danjou; +Cc: emacs-orgmode
Hi everyone,
can we have a few testers for this patch? Apply it an play with your
agenda, switching from day to week view etc, refresh with "r" and "g",
and check if everything works as expected? That would be nice, thanks.
- Carsten
On Nov 29, 2010, at 11:49 AM, Julien Danjou wrote:
> * org-agenda.el (org-agenda-custom-commands-local-options):
> Allow org-agenda-span to be a symbol.
> (org-agenda-ndays): Make obsolete.
> (org-agenda-span): New variable superseding org-agenda-ndays.
> (org-agenda-menu): Use org-agenda-current-span.
> (org-agenda-current-span): New local variable storing current
> span.
> (org-agenda-list): Take a span instead of ndays as argument.
> This function is now responsible for computing the ndays based
> on span.
> (org-agenda-ndays-to-span): Return span only if number of days
> really matches.
> (org-agenda-span-to-ndays): New function.
> (org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
> (org-agenda-goto-today): Use org-agenda-compute-starting-span.
> (org-agenda-later): Do not give compute a new span, use the
> current one.
> (org-agenda-day-view, org-agenda-week-view)
> (org-agenda-month-view, org-agenda-year-view): Stop touching
> org-agenda-ndays.
> (org-agenda-change-time-span): Only compute starting-span.
> (org-agenda-compute-starting-span): New function derived from
> the old org-agenda-compute-time-span.
> (org-agenda-set-mode-name): Compute mode based on
> org-agenda-current-span.
> (org-agenda-span-name): New function.
>
> * org-mouse.el: Replace Replace org-agenda-ndays by
> org-agenda-current-span.
>
> * org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-
> span.
>
> Signed-off-by: Julien Danjou <julien@danjou.info>
> ---
>
> Hi,
>
> This patch is pretty huge, so I'll give a bit of context about it.
>
> I'm weird, but I used org-agenda-ndays set to 14. Unfortunately, this
> settings was interpreted as a month view. Pressing 'f' key to see
> later,
> would show me the next month, which was not at all what I wanted.
>
> On the same idea, day view or week view would change my org-agenda-
> ndays
> settings, which I think is not a good idea. Changing user setting is
> *bad*.
> :-)
>
> So I rewrote the things this way:
> - Rename org-agenda-span to org-agenda-current-span
> Which has the same meaning has before, except it can be numeric.
> - Rename org-agenda-ndays to org-agenda-span
> I think the name is better choosen. You can set it to a symbol
> instead of
> only a numeric value. That means you can set it to 'month and it
> will show
> you the number of days of the current month in your agenda. Better
> than
> 30. But you can still set it to 30, or 31, or whatever you want.
> - Do not change org-agenda-span. Never.
> - Use org-agenda-current-span for navigation.
> That means if you press 'f', it will shows you really the next
> org-agenda-current-span ndays, and not something based on "I think
> you
> want a weekly view".
>
> Tested, no bug found so far. :-)
>
> doc/org.texi | 14 ++--
> doc/orgguide.texi | 6 +-
> lisp/org-agenda.el | 188 ++++++++++++++++++++++++++++
> +----------------------
> lisp/org-mouse.el | 4 +-
> 4 files changed, 119 insertions(+), 93 deletions(-)
>
> diff --git a/doc/org.texi b/doc/org.texi
> index e2e9af5..b5b70c9 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the
> current week or day.
> @table @kbd
> @cindex org-agenda, command
> @orgcmd{C-c a a,org-agenda-list}
> -@vindex org-agenda-ndays
> +@vindex org-agenda-span
> Compile an agenda for the current week from a list of Org files.
> The agenda
> shows the entries for each day. With a numeric prefix@footnote{For
> backward
> compatibility, the universal prefix @kbd{C-u} causes all TODO
> entries to be
> listed before the agenda. This feature is deprecated, use the
> dedicated TODO
> list, or a block agenda instead (@pxref{Block agenda}).} (like
> @kbd{C-u 2 1
> C-c a a}) you may set the number of days to be displayed (see also the
> -variable @code{org-agenda-ndays})
> +variable @code{org-agenda-span})
> @end table
>
> Remote editing from the agenda buffer means, for example, that you can
> @@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712
> w} will jump to week 12 in
> be mapped to the interval 1938-2037.
> @c
> @orgcmd{f,org-agenda-later}
> -@vindex org-agenda-ndays
> -Go forward in time to display the following @code{org-agenda-ndays}
> days.
> +@vindex org-agenda-span
> +Go forward in time to display the following @code{org-agenda-
> current-span} days.
> For example, if the display covers a week, switch to the following
> week.
> -With prefix arg, go forward that many times @code{org-agenda-ndays}
> days.
> +With prefix arg, go forward that many times @code{org-agenda-
> current-span} days.
> @c
> @orgcmd{b,org-agenda-earlier}
> Go backward in time to display earlier dates.
> @@ -8369,7 +8369,7 @@ or, if you need to modify some
> parameters@footnote{Quoting depends on the
> system you use, please check the FAQ for examples.}
> @example
> emacs -eval '(org-batch-store-agenda-views \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-start-day "2007-11-01" \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> @@ -14033,7 +14033,7 @@ You may also modify parameters on the fly
> like this:
> @example
> emacs -batch -l ~/.emacs \
> -eval '(org-batch-agenda "a" \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> | lpr
> diff --git a/doc/orgguide.texi b/doc/orgguide.texi
> index b67f7f1..690111b 100644
> --- a/doc/orgguide.texi
> +++ b/doc/orgguide.texi
> @@ -1931,9 +1931,9 @@ Delete other windows.
> Switch to day/week view.
> @c
> @item f @r{and} b
> -Go forward/backward in time to display the following @code{org-
> agenda-ndays}
> -days. For example, if the display covers a week, switch to the
> -following/previous week.
> +Go forward/backward in time to display the following
> +@code{org-agenda-current-span} days. For example, if the display
> covers a
> +week, switch to the following/previous week.
> @c
> @item .
> Go to today.
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index 48856c9..c44595d 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to
> the header. However,
> (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
> (string))
> (list :tag "Number of days in agenda"
> - (const org-agenda-ndays)
> - (integer :value 1))
> + (const org-agenda-span)
> + (choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
> (list :tag "Fixed starting date"
> (const org-agenda-start-day)
> (string :value "2007-11-01"))
> @@ -888,12 +892,25 @@ option will be ignored."
> :group 'org-agenda-windows
> :type 'boolean)
>
> -(defcustom org-agenda-ndays 7
> - "Number of days to include in overview display.
> +(defcustom org-agenda-ndays nil
> + "Number of days to include in overview display.
> Should be 1 or 7.
> +Obsolete, see `org-agenda-span'."
> + :group 'org-agenda-daily/weekly
> + :type 'integer)
> +
> +(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
> +
> +(defcustom org-agenda-span 'week
> + "Number of days to include in overview display.
> +Can be day, week, month, year, or any number of days.
> Custom commands can set this variable in the options section."
> :group 'org-agenda-daily/weekly
> - :type 'integer)
> + :type '(choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
>
> (defcustom org-agenda-start-on-weekday 1
> "Non-nil means start the overview always on the specified weekday.
> @@ -1825,19 +1842,19 @@ The following commands are available:
> ("View"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)
> + :style radio :selected (eq org-agenda-current-span 'day)
> :keys "v d (or just d)"]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)
> + :style radio :selected (eq org-agenda-current-span 'week)
> :keys "v w (or just w)"]
> ["Month View" org-agenda-month-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(28 29 30 31))
> + :style radio :selected (eq org-agenda-current-span 'month)
> :keys "v m"]
> ["Year View" org-agenda-year-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(365 366))
> + :style radio :selected (eq org-agenda-current-span 'year)
> :keys "v y"]
> "--"
> ["Include Diary" org-agenda-toggle-diary
> @@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days
> without any entries."
> (defvar org-agenda-last-arguments nil
> "The arguments of the previous call to `org-agenda'.")
> (defvar org-starting-day nil) ; local variable in the agenda buffer
> -(defvar org-agenda-span nil) ; local variable in the agenda buffer
> +(defvar org-agenda-current-span nil
> + "The current span used in the agenda view.") ; local variable in
> the agenda buffer
> (defvar org-include-all-loc nil) ; local variable
>
> (defvar org-agenda-entry-types
> '(:deadline :scheduled :timestamp :sexp)
> @@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining
> what is included in
> the daily/weekly agenda, see `org-agenda-skip-function'.")
>
> ;;;###autoload
> -(defun org-agenda-list (&optional include-all start-day ndays)
> +(defun org-agenda-list (&optional include-all start-day span)
> "Produce a daily/weekly view from all files in variable `org-
> agenda-files'.
> The view will be for the current day or week, but from the overview
> buffer
> you will be able to go to other days/weeks.
> @@ -3371,35 +3389,36 @@ This feature is considered obsolete, please
> use the TODO list or a block
> agenda instead.
>
> With a numeric prefix argument in an interactive call, the agenda will
> -span INCLUDE-ALL days. Lisp programs should instead specify NDAYS
> to change
> -the number of days. NDAYS defaults to `org-agenda-ndays'.
> +span INCLUDE-ALL days. Lisp programs should instead specify SPAN
> to change
> +the number of days. SPAN defaults to `org-agenda-span'.
>
> START-DAY defaults to TODAY, or to the most recent match for the
> weekday
> given in `org-agenda-start-on-weekday'."
> (interactive "P")
> (if (and (integerp include-all) (> include-all 0))
> - (setq ndays include-all include-all nil))
> - (setq ndays (or ndays org-agenda-ndays)
> - start-day (or start-day org-agenda-start-day))
> + (setq span include-all include-all nil))
> + (setq start-day (or start-day org-agenda-start-day))
> (if org-agenda-overriding-arguments
> (setq include-all (car org-agenda-overriding-arguments)
> start-day (nth 1 org-agenda-overriding-arguments)
> - ndays (nth 2 org-agenda-overriding-arguments)))
> + span (nth 2 org-agenda-overriding-arguments)))
> (if (stringp start-day)
> ;; Convert to an absolute day number
> (setq start-day (time-to-days (org-read-date nil t start-day))))
> - (setq org-agenda-last-arguments (list include-all start-day ndays))
> + (setq org-agenda-last-arguments (list include-all start-day span))
> (org-compile-prefix-format 'agenda)
> (org-set-sorting-strategy 'agenda)
> - (let* ((org-agenda-start-on-weekday
> - (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-
> ndays)))
> - org-agenda-start-on-weekday nil))
> - (thefiles (org-agenda-files nil 'ifmode))
> - (files thefiles)
> + (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays
> org-agenda-span)))
> (today (org-agenda-today))
> (sd (or start-day today))
> + (ndays (org-agenda-span-to-ndays span sd))
> + (org-agenda-start-on-weekday
> + (if (eq ndays 7)
> + org-agenda-start-on-weekday))
> + (thefiles (org-agenda-files nil 'ifmode))
> + (files thefiles)
> (start (if (or (null org-agenda-start-on-weekday)
> - (< org-agenda-ndays 7))
> + (< ndays 7))
> sd
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> @@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
> (day-numbers (list start))
> (day-cnt 0)
> (inhibit-redisplay (not debug-on-error))
> - s e rtn rtnall file date d start-pos end-pos todayp nd
> + s e rtn rtnall file date d start-pos end-pos todayp
> clocktable-start clocktable-end filter)
> (setq org-agenda-redo-command
> - (list 'org-agenda-list (list 'quote include-all) start-day ndays))
> - ;; Make the list of days
> - (setq ndays (or ndays org-agenda-ndays)
> - nd ndays)
> - (while (> ndays 1)
> - (push (1+ (car day-numbers)) day-numbers)
> - (setq ndays (1- ndays)))
> + (list 'org-agenda-list (list 'quote include-all) start-day (list
> 'quote span)))
> + (dotimes (n (1- ndays))
> + (push (1+ (car day-numbers)) day-numbers))
> (setq day-numbers (nreverse day-numbers))
> (setq clocktable-start (car day-numbers)
> clocktable-end (1+ (or (org-last day-numbers) 0)))
> (org-prepare-agenda "Day/Week")
> (org-set-local 'org-starting-day (car day-numbers))
> (org-set-local 'org-include-all-loc include-all)
> - (org-set-local 'org-agenda-span
> - (org-agenda-ndays-to-span nd))
> + (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-
> span span))
> (when (and (or include-all org-agenda-include-all-todo)
> (member today day-numbers))
> (setq files thefiles
> @@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
> (if org-agenda-overriding-header
> (insert (org-add-props (copy-sequence org-agenda-overriding-
> header)
> nil 'face 'org-agenda-structure) "\n")
> - (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
> + (insert (org-agenda-span-name span)
> "-agenda"
> (if (< (- d2 d1) 350)
> (if (= w1 w2)
> @@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
> (if rtnall (insert
> (org-finalize-agenda-entries
> (org-agenda-add-time-grid-maybe
> - rtnall nd todayp))
> + rtnall ndays todayp))
> "\n"))
> (put-text-property s (1- (point)) 'day d)
> (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
> @@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
> (message "")))
>
> (defun org-agenda-ndays-to-span (n)
> - (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
> + "Return a span symbol for a span of N days, or N if none matches."
> + (cond ((symbolp n) n)
> + ((= n 1) 'day)
> + ((= n 7) 'week)
> + (t n)))
> +
> +(defun org-agenda-span-to-ndays (span start-day)
> + "Return ndays from SPAN starting at START-DAY."
> + (cond ((numberp span) span)
> + ((eq span 'day) 1)
> + ((eq span 'week) 7)
> + ((eq span 'month)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (calendar-last-day-of-month (car date) (caddr date))))
> + ((eq span 'year)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (if (calendar-leap-year-p (caddr date)) 366 365)))))
> +
> +(defun org-agenda-span-name (span)
> + "Return a SPAN name."
> + (if (null span)
> + ""
> + (if (symbolp span)
> + (capitalize (symbol-name span))
> + (format "%d days" span))))
>
> ;;; Agenda word search
>
> @@ -6000,11 +6038,9 @@ Negative selection means regexp must not
> match for selection of an entry."
> (cond
> (tdpos (goto-char tdpos))
> ((eq org-agenda-type 'agenda)
> - (let* ((sd (org-agenda-today))
> - (comp (org-agenda-compute-time-span sd org-agenda-span))
> + (let* ((sd (org-agenda-compute-starting-span (org-agenda-
> today) (or org-agenda-ndays org-agenda-span)))
> (org-agenda-overriding-arguments org-agenda-last-arguments))
> - (setf (nth 1 org-agenda-overriding-arguments) (car comp))
> - (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
> + (setf (nth 1 org-agenda-overriding-arguments) sd)
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda)))
> (t (error "Cannot find today")))))
> @@ -6021,28 +6057,28 @@ Negative selection means regexp must not
> match for selection of an entry."
> With prefix ARG, go forward that many times the current span."
> (interactive "p")
> (org-agenda-check-type t 'agenda)
> - (let* ((span org-agenda-span)
> + (let* ((span org-agenda-current-span)
> (sd org-starting-day)
> (greg (calendar-gregorian-from-absolute sd))
> (cnt (org-get-at-bol 'org-day-cnt))
> - greg2 nd)
> + greg2)
> (cond
> ((eq span 'day)
> - (setq sd (+ arg sd) nd 1))
> + (setq sd (+ arg sd)))
> ((eq span 'week)
> - (setq sd (+ (* 7 arg) sd) nd 7))
> + (setq sd (+ (* 7 arg) sd)))
> ((eq span 'month)
> (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar greg2 (1+ (car greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
> + (setcar greg2 (1+ (car greg2))))
> ((eq span 'year)
> (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
> + (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
> + (t
> + (setq sd (+ (* span arg) sd))))
> (let ((org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments) sd nd t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda cnt))))
>
> @@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times
> the current span."
> "Switch to daily view for agenda.
> With argument DAY-OF-YEAR, switch to that day of the year."
> (interactive "P")
> - (setq org-agenda-ndays 1)
> (org-agenda-change-time-span 'day day-of-year))
> (defun org-agenda-week-view (&optional iso-week)
> "Switch to daily view for agenda.
> @@ -6095,7 +6130,6 @@ week. Any digits before this encode a year.
> So 200712 means
> week 12 of year 2007. Years in the range 1938-2037 can also be
> written as 2-digit years."
> (interactive "P")
> - (setq org-agenda-ndays 7)
> (org-agenda-change-time-span 'week iso-week))
> (defun org-agenda-month-view (&optional month)
> "Switch to monthly view for agenda.
> @@ -6120,70 +6154,61 @@ written as 2-digit years."
> "Change the agenda view to SPAN.
> SPAN may be `day', `week', `month', `year'."
> (org-agenda-check-type t 'agenda)
> - (if (and (not n) (equal org-agenda-span span))
> + (if (and (not n) (equal org-agenda-current-span span))
> (error "Viewing span is already \"%s\"" span))
> (let* ((sd (or (org-get-at-bol 'day)
> org-starting-day))
> - (computed (org-agenda-compute-time-span sd span n))
> + (sd (org-agenda-compute-starting-span sd span n))
> (org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments)
> - (car computed) (cdr computed) t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda))
> (org-agenda-set-mode-name)
> (message "Switched to %s view" span))
>
> -(defun org-agenda-compute-time-span (sd span &optional n)
> - "Compute starting date and number of days for agenda.
> +(defun org-agenda-compute-starting-span (sd span &optional n)
> + "Compute starting date for agenda.
> SPAN may be `day', `week', `month', `year'. The return value
> is a cons cell with the starting date and the number of days,
> so that the date SD will be in that range."
> (let* ((greg (calendar-gregorian-from-absolute sd))
> (dg (nth 1 greg))
> (mg (car greg))
> - (yg (nth 2 greg))
> - nd w1 y1 m1 thisweek)
> + (yg (nth 2 greg)))
> (cond
> ((eq span 'day)
> (when n
> (setq sd (+ (calendar-absolute-from-gregorian
> (list mg 1 yg))
> - n -1)))
> - (setq nd 1))
> + n -1))))
> ((eq span 'week)
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> (d (if org-agenda-start-on-weekday
> (- nt org-agenda-start-on-weekday)
> - 0)))
> + 0))
> + y1)
> (setq sd (- sd (+ (if (< d 0) 7 0) d)))
> (when n
> (require 'cal-iso)
> - (setq thisweek (car (calendar-iso-from-absolute sd)))
> (when (> n 99)
> (setq y1 (org-small-year-to-year (/ n 100))
> n (mod n 100)))
> (setq sd
> (calendar-absolute-from-iso
> (list n 1
> - (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
> - (setq nd 7)))
> + (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
> ((eq span 'month)
> - (when (and n (> n 99))
> - (setq y1 (org-small-year-to-year (/ n 100))
> - n (mod n 100)))
> - (setq sd (calendar-absolute-from-gregorian
> - (list (or n mg) 1 (or y1 yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list (1+ (or n mg)) 1 (or y1 yg)))
> - sd)))
> + (let (y1)
> + (when (and n (> n 99))
> + (setq y1 (org-small-year-to-year (/ n 100))
> + n (mod n 100)))
> + (setq sd (calendar-absolute-from-gregorian
> + (list (or n mg) 1 (or y1 yg))))))
> ((eq span 'year)
> (setq sd (calendar-absolute-from-gregorian
> - (list 1 1 (or n yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list 1 1 (1+ (or n yg))))
> - sd))))
> - (cons sd nd)))
> + (list 1 1 (or n yg))))))
> + sd))
>
> (defun org-agenda-next-date-line (&optional arg)
> "Jump to the next line indicating a date in agenda buffer."
> @@ -6338,8 +6363,9 @@ When called with a prefix argument, include
> all archive files as well."
> (setq mode-name
> (concat "Org-Agenda"
> (if (get 'org-agenda-files 'org-restrict) " []" "")
> - (if (equal org-agenda-ndays 1) " Day" "")
> - (if (equal org-agenda-ndays 7) " Week" "")
> + " " (org-agenda-span-name (or org-agenda-current-span
> + org-agenda-ndays
> + org-agenda-span))
> (if org-agenda-follow-mode " Follow" "")
> (if org-agenda-entry-text-mode " ETxt" "")
> (if org-agenda-include-diary " Diary" "")
> diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
> index e16c977..d18a12d 100644
> --- a/lisp/org-mouse.el
> +++ b/lisp/org-mouse.el
> @@ -1100,10 +1100,10 @@ This means, between the beginning of line
> and the point."
> "--"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)]
> + :style radio :selected (eq org-agenda-current-span 'day)]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)]
> + :style radio :selected (eq org-agenda-current-span 'week)]
> "--"
> ["Show Logbook entries" org-agenda-log-mode
> :style toggle :selected org-agenda-show-log
> --
> 1.7.2.3
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-11-30 23:53 ` Carsten Dominik
@ 2010-12-01 3:59 ` Puneeth
2010-12-01 9:24 ` Julien Danjou
2010-12-01 10:15 ` Eric S Fraga
1 sibling, 1 reply; 17+ messages in thread
From: Puneeth @ 2010-12-01 3:59 UTC (permalink / raw)
To: Carsten Dominik; +Cc: Julien Danjou, emacs-orgmode
On Wed, Dec 1, 2010 at 5:23 AM, Carsten Dominik
<carsten.dominik@gmail.com> wrote:
> Hi everyone,
>
> can we have a few testers for this patch? Apply it an play with your
> agenda, switching from day to week view etc, refresh with "r" and "g", and
> check if everything works as expected? That would be nice, thanks.
The patch doesn't apply to the current head. Julien, would it be
possible to send another patch? Or could you tell me the commit to
which it should be applied to?
-- Puneeth
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-01 3:59 ` Puneeth
@ 2010-12-01 9:24 ` Julien Danjou
2010-12-01 9:48 ` Puneeth
0 siblings, 1 reply; 17+ messages in thread
From: Julien Danjou @ 2010-12-01 9:24 UTC (permalink / raw)
To: Puneeth; +Cc: emacs-orgmode, Carsten Dominik
[-- Attachment #1.1.1: Type: text/plain, Size: 254 bytes --]
On Wed, Dec 01 2010, Puneeth wrote:
> The patch doesn't apply to the current head. Julien, would it be
> possible to send another patch? Or could you tell me the commit to
> which it should be applied to?
No problem, here's a rebased patch on master.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-org-agenda-rework-ndays-and-span-handling.patch --]
[-- Type: text/x-diff, Size: 22153 bytes --]
From f265c3fa8cbf448a13f4df5161b077cbad9dd659 Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Fri, 26 Nov 2010 14:22:17 +0100
Subject: [PATCH] org-agenda: rework ndays and span handling
* org-agenda.el (org-agenda-custom-commands-local-options):
Allow org-agenda-span to be a symbol.
(org-agenda-ndays): Make obsolete.
(org-agenda-span): New variable superseding org-agenda-ndays.
(org-agenda-menu): Use org-agenda-current-span.
(org-agenda-current-span): New local variable storing current
span.
(org-agenda-list): Take a span instead of ndays as argument.
This function is now responsible for computing the ndays based
on span.
(org-agenda-ndays-to-span): Return span only if number of days
really matches.
(org-agenda-span-to-ndays): New function.
(org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
(org-agenda-goto-today): Use org-agenda-compute-starting-span.
(org-agenda-later): Do not give compute a new span, use the
current one.
(org-agenda-day-view, org-agenda-week-view)
(org-agenda-month-view, org-agenda-year-view): Stop touching
org-agenda-ndays.
(org-agenda-change-time-span): Only compute starting-span.
(org-agenda-compute-starting-span): New function derived from
the old org-agenda-compute-time-span.
(org-agenda-set-mode-name): Compute mode based on
org-agenda-current-span.
(org-agenda-span-name): New function.
* org-mouse.el: Replace Replace org-agenda-ndays by
org-agenda-current-span.
* org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
doc/org.texi | 14 ++--
doc/orgguide.texi | 6 +-
lisp/org-agenda.el | 188 +++++++++++++++++++++++++++++----------------------
lisp/org-mouse.el | 4 +-
4 files changed, 119 insertions(+), 93 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index e2e9af5..b5b70c9 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the current week or day.
@table @kbd
@cindex org-agenda, command
@orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
+@vindex org-agenda-span
Compile an agenda for the current week from a list of Org files. The agenda
shows the entries for each day. With a numeric prefix@footnote{For backward
compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
listed before the agenda. This feature is deprecated, use the dedicated TODO
list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+variable @code{org-agenda-span})
@end table
Remote editing from the agenda buffer means, for example, that you can
@@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
be mapped to the interval 1938-2037.
@c
@orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+@vindex org-agenda-span
+Go forward in time to display the following @code{org-agenda-current-span} days.
For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
@c
@orgcmd{b,org-agenda-earlier}
Go backward in time to display earlier dates.
@@ -8369,7 +8369,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
system you use, please check the FAQ for examples.}
@example
emacs -eval '(org-batch-store-agenda-views \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
@@ -14033,7 +14033,7 @@ You may also modify parameters on the fly like this:
@example
emacs -batch -l ~/.emacs \
-eval '(org-batch-agenda "a" \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
| lpr
diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index b67f7f1..690111b 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -1931,9 +1931,9 @@ Delete other windows.
Switch to day/week view.
@c
@item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days. For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days. For example, if the display covers a
+week, switch to the following/previous week.
@c
@item .
Go to today.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 48856c9..c44595d 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
(const org-agenda-prefix-format :value " %-12:c%?-12t% s")
(string))
(list :tag "Number of days in agenda"
- (const org-agenda-ndays)
- (integer :value 1))
+ (const org-agenda-span)
+ (choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(list :tag "Fixed starting date"
(const org-agenda-start-day)
(string :value "2007-11-01"))
@@ -888,12 +892,25 @@ option will be ignored."
:group 'org-agenda-windows
:type 'boolean)
-(defcustom org-agenda-ndays 7
- "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+ "Number of days to include in overview display.
Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+ :group 'org-agenda-daily/weekly
+ :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+ "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
Custom commands can set this variable in the options section."
:group 'org-agenda-daily/weekly
- :type 'integer)
+ :type '(choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(defcustom org-agenda-start-on-weekday 1
"Non-nil means start the overview always on the specified weekday.
@@ -1825,19 +1842,19 @@ The following commands are available:
("View"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)
+ :style radio :selected (eq org-agenda-current-span 'day)
:keys "v d (or just d)"]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)
+ :style radio :selected (eq org-agenda-current-span 'week)
:keys "v w (or just w)"]
["Month View" org-agenda-month-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+ :style radio :selected (eq org-agenda-current-span 'month)
:keys "v m"]
["Year View" org-agenda-year-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(365 366))
+ :style radio :selected (eq org-agenda-current-span 'year)
:keys "v y"]
"--"
["Include Diary" org-agenda-toggle-diary
@@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
(defvar org-agenda-last-arguments nil
"The arguments of the previous call to `org-agenda'.")
(defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+ "The current span used in the agenda view.") ; local variable in the agenda buffer
(defvar org-include-all-loc nil) ; local variable
(defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
the daily/weekly agenda, see `org-agenda-skip-function'.")
;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
"Produce a daily/weekly view from all files in variable `org-agenda-files'.
The view will be for the current day or week, but from the overview buffer
you will be able to go to other days/weeks.
@@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
agenda instead.
With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
-the number of days. NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
+the number of days. SPAN defaults to `org-agenda-span'.
START-DAY defaults to TODAY, or to the most recent match for the weekday
given in `org-agenda-start-on-weekday'."
(interactive "P")
(if (and (integerp include-all) (> include-all 0))
- (setq ndays include-all include-all nil))
- (setq ndays (or ndays org-agenda-ndays)
- start-day (or start-day org-agenda-start-day))
+ (setq span include-all include-all nil))
+ (setq start-day (or start-day org-agenda-start-day))
(if org-agenda-overriding-arguments
(setq include-all (car org-agenda-overriding-arguments)
start-day (nth 1 org-agenda-overriding-arguments)
- ndays (nth 2 org-agenda-overriding-arguments)))
+ span (nth 2 org-agenda-overriding-arguments)))
(if (stringp start-day)
;; Convert to an absolute day number
(setq start-day (time-to-days (org-read-date nil t start-day))))
- (setq org-agenda-last-arguments (list include-all start-day ndays))
+ (setq org-agenda-last-arguments (list include-all start-day span))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
- (let* ((org-agenda-start-on-weekday
- (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
- org-agenda-start-on-weekday nil))
- (thefiles (org-agenda-files nil 'ifmode))
- (files thefiles)
+ (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
(today (org-agenda-today))
(sd (or start-day today))
+ (ndays (org-agenda-span-to-ndays span sd))
+ (org-agenda-start-on-weekday
+ (if (eq ndays 7)
+ org-agenda-start-on-weekday))
+ (thefiles (org-agenda-files nil 'ifmode))
+ (files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
- (< org-agenda-ndays 7))
+ (< ndays 7))
sd
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
@@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
(day-numbers (list start))
(day-cnt 0)
(inhibit-redisplay (not debug-on-error))
- s e rtn rtnall file date d start-pos end-pos todayp nd
+ s e rtn rtnall file date d start-pos end-pos todayp
clocktable-start clocktable-end filter)
(setq org-agenda-redo-command
- (list 'org-agenda-list (list 'quote include-all) start-day ndays))
- ;; Make the list of days
- (setq ndays (or ndays org-agenda-ndays)
- nd ndays)
- (while (> ndays 1)
- (push (1+ (car day-numbers)) day-numbers)
- (setq ndays (1- ndays)))
+ (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+ (dotimes (n (1- ndays))
+ (push (1+ (car day-numbers)) day-numbers))
(setq day-numbers (nreverse day-numbers))
(setq clocktable-start (car day-numbers)
clocktable-end (1+ (or (org-last day-numbers) 0)))
(org-prepare-agenda "Day/Week")
(org-set-local 'org-starting-day (car day-numbers))
(org-set-local 'org-include-all-loc include-all)
- (org-set-local 'org-agenda-span
- (org-agenda-ndays-to-span nd))
+ (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
(when (and (or include-all org-agenda-include-all-todo)
(member today day-numbers))
(setq files thefiles
@@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
(if org-agenda-overriding-header
(insert (org-add-props (copy-sequence org-agenda-overriding-header)
nil 'face 'org-agenda-structure) "\n")
- (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+ (insert (org-agenda-span-name span)
"-agenda"
(if (< (- d2 d1) 350)
(if (= w1 w2)
@@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
(if rtnall (insert
(org-finalize-agenda-entries
(org-agenda-add-time-grid-maybe
- rtnall nd todayp))
+ rtnall ndays todayp))
"\n"))
(put-text-property s (1- (point)) 'day d)
(put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
(message "")))
(defun org-agenda-ndays-to-span (n)
- (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+ "Return a span symbol for a span of N days, or N if none matches."
+ (cond ((symbolp n) n)
+ ((= n 1) 'day)
+ ((= n 7) 'week)
+ (t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+ "Return ndays from SPAN starting at START-DAY."
+ (cond ((numberp span) span)
+ ((eq span 'day) 1)
+ ((eq span 'week) 7)
+ ((eq span 'month)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (calendar-last-day-of-month (car date) (caddr date))))
+ ((eq span 'year)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+ "Return a SPAN name."
+ (if (null span)
+ ""
+ (if (symbolp span)
+ (capitalize (symbol-name span))
+ (format "%d days" span))))
;;; Agenda word search
@@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
(cond
(tdpos (goto-char tdpos))
((eq org-agenda-type 'agenda)
- (let* ((sd (org-agenda-today))
- (comp (org-agenda-compute-time-span sd org-agenda-span))
+ (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
(org-agenda-overriding-arguments org-agenda-last-arguments))
- (setf (nth 1 org-agenda-overriding-arguments) (car comp))
- (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+ (setf (nth 1 org-agenda-overriding-arguments) sd)
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda)))
(t (error "Cannot find today")))))
@@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
With prefix ARG, go forward that many times the current span."
(interactive "p")
(org-agenda-check-type t 'agenda)
- (let* ((span org-agenda-span)
+ (let* ((span org-agenda-current-span)
(sd org-starting-day)
(greg (calendar-gregorian-from-absolute sd))
(cnt (org-get-at-bol 'org-day-cnt))
- greg2 nd)
+ greg2)
(cond
((eq span 'day)
- (setq sd (+ arg sd) nd 1))
+ (setq sd (+ arg sd)))
((eq span 'week)
- (setq sd (+ (* 7 arg) sd) nd 7))
+ (setq sd (+ (* 7 arg) sd)))
((eq span 'month)
(setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
sd (calendar-absolute-from-gregorian greg2))
- (setcar greg2 (1+ (car greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+ (setcar greg2 (1+ (car greg2))))
((eq span 'year)
(setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
sd (calendar-absolute-from-gregorian greg2))
- (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+ (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+ (t
+ (setq sd (+ (* span arg) sd))))
(let ((org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments) sd nd t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda cnt))))
@@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
"Switch to daily view for agenda.
With argument DAY-OF-YEAR, switch to that day of the year."
(interactive "P")
- (setq org-agenda-ndays 1)
(org-agenda-change-time-span 'day day-of-year))
(defun org-agenda-week-view (&optional iso-week)
"Switch to daily view for agenda.
@@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
week 12 of year 2007. Years in the range 1938-2037 can also be
written as 2-digit years."
(interactive "P")
- (setq org-agenda-ndays 7)
(org-agenda-change-time-span 'week iso-week))
(defun org-agenda-month-view (&optional month)
"Switch to monthly view for agenda.
@@ -6120,70 +6154,61 @@ written as 2-digit years."
"Change the agenda view to SPAN.
SPAN may be `day', `week', `month', `year'."
(org-agenda-check-type t 'agenda)
- (if (and (not n) (equal org-agenda-span span))
+ (if (and (not n) (equal org-agenda-current-span span))
(error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
org-starting-day))
- (computed (org-agenda-compute-time-span sd span n))
+ (sd (org-agenda-compute-starting-span sd span n))
(org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments)
- (car computed) (cdr computed) t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda))
(org-agenda-set-mode-name)
(message "Switched to %s view" span))
-(defun org-agenda-compute-time-span (sd span &optional n)
- "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+ "Compute starting date for agenda.
SPAN may be `day', `week', `month', `year'. The return value
is a cons cell with the starting date and the number of days,
so that the date SD will be in that range."
(let* ((greg (calendar-gregorian-from-absolute sd))
(dg (nth 1 greg))
(mg (car greg))
- (yg (nth 2 greg))
- nd w1 y1 m1 thisweek)
+ (yg (nth 2 greg)))
(cond
((eq span 'day)
(when n
(setq sd (+ (calendar-absolute-from-gregorian
(list mg 1 yg))
- n -1)))
- (setq nd 1))
+ n -1))))
((eq span 'week)
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
(d (if org-agenda-start-on-weekday
(- nt org-agenda-start-on-weekday)
- 0)))
+ 0))
+ y1)
(setq sd (- sd (+ (if (< d 0) 7 0) d)))
(when n
(require 'cal-iso)
- (setq thisweek (car (calendar-iso-from-absolute sd)))
(when (> n 99)
(setq y1 (org-small-year-to-year (/ n 100))
n (mod n 100)))
(setq sd
(calendar-absolute-from-iso
(list n 1
- (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
- (setq nd 7)))
+ (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
((eq span 'month)
- (when (and n (> n 99))
- (setq y1 (org-small-year-to-year (/ n 100))
- n (mod n 100)))
- (setq sd (calendar-absolute-from-gregorian
- (list (or n mg) 1 (or y1 yg)))
- nd (- (calendar-absolute-from-gregorian
- (list (1+ (or n mg)) 1 (or y1 yg)))
- sd)))
+ (let (y1)
+ (when (and n (> n 99))
+ (setq y1 (org-small-year-to-year (/ n 100))
+ n (mod n 100)))
+ (setq sd (calendar-absolute-from-gregorian
+ (list (or n mg) 1 (or y1 yg))))))
((eq span 'year)
(setq sd (calendar-absolute-from-gregorian
- (list 1 1 (or n yg)))
- nd (- (calendar-absolute-from-gregorian
- (list 1 1 (1+ (or n yg))))
- sd))))
- (cons sd nd)))
+ (list 1 1 (or n yg))))))
+ sd))
(defun org-agenda-next-date-line (&optional arg)
"Jump to the next line indicating a date in agenda buffer."
@@ -6338,8 +6363,9 @@ When called with a prefix argument, include all archive files as well."
(setq mode-name
(concat "Org-Agenda"
(if (get 'org-agenda-files 'org-restrict) " []" "")
- (if (equal org-agenda-ndays 1) " Day" "")
- (if (equal org-agenda-ndays 7) " Week" "")
+ " " (org-agenda-span-name (or org-agenda-current-span
+ org-agenda-ndays
+ org-agenda-span))
(if org-agenda-follow-mode " Follow" "")
(if org-agenda-entry-text-mode " ETxt" "")
(if org-agenda-include-diary " Diary" "")
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index e16c977..d18a12d 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
"--"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)]
+ :style radio :selected (eq org-agenda-current-span 'day)]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)]
+ :style radio :selected (eq org-agenda-current-span 'week)]
"--"
["Show Logbook entries" org-agenda-log-mode
:style toggle :selected org-agenda-show-log
--
1.7.2.3
[-- Attachment #1.1.3: Type: text/plain, Size: 79 bytes --]
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-01 9:24 ` Julien Danjou
@ 2010-12-01 9:48 ` Puneeth
0 siblings, 0 replies; 17+ messages in thread
From: Puneeth @ 2010-12-01 9:48 UTC (permalink / raw)
To: Puneeth, Carsten Dominik, emacs-orgmode
On Wed, Dec 1, 2010 at 2:54 PM, Julien Danjou <julien@danjou.info> wrote:
> On Wed, Dec 01 2010, Puneeth wrote:
>
>> The patch doesn't apply to the current head. Julien, would it be
>> possible to send another patch? Or could you tell me the commit to
>> which it should be applied to?
>
> No problem, here's a rebased patch on master.
Thanks. I tested the patch and works fine for me.
-- Puneeth
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-11-30 23:53 ` Carsten Dominik
2010-12-01 3:59 ` Puneeth
@ 2010-12-01 10:15 ` Eric S Fraga
2010-12-01 13:09 ` Julien Danjou
1 sibling, 1 reply; 17+ messages in thread
From: Eric S Fraga @ 2010-12-01 10:15 UTC (permalink / raw)
To: Carsten Dominik; +Cc: Julien Danjou, emacs-orgmode
Carsten Dominik <carsten.dominik@gmail.com> writes:
> Hi everyone,
>
> can we have a few testers for this patch? Apply it an play with your
> agenda, switching from day to week view etc, refresh with "r" and "g",
> and check if everything works as expected? That would be nice,
> thanks.
>
> - Carsten
Mostly works fine but there is one problem I have encountered. If you
change your view (mine defaults to day so I sometimes switch to week
view), you can go forward and backward as expected. However, if you
/jump/ (j in agenda view) to a given date, the view resets to the
default (well, to single day view in my case). I prefer the view to
remain as I have specified it last until I change it myself.
Thanks,
eric
--
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1
: using Org-mode version 7.3 (release_7.3.159.g23265)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-01 10:15 ` Eric S Fraga
@ 2010-12-01 13:09 ` Julien Danjou
2010-12-01 14:09 ` Eric S Fraga
2010-12-03 2:11 ` Bernt Hansen
0 siblings, 2 replies; 17+ messages in thread
From: Julien Danjou @ 2010-12-01 13:09 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode, Carsten Dominik
[-- Attachment #1.1.1: Type: text/plain, Size: 500 bytes --]
On Wed, Dec 01 2010, Eric S Fraga wrote:
> Mostly works fine but there is one problem I have encountered. If you
> change your view (mine defaults to day so I sometimes switch to week
> view), you can go forward and backward as expected. However, if you
> /jump/ (j in agenda view) to a given date, the view resets to the
> default (well, to single day view in my case). I prefer the view to
> remain as I have specified it last until I change it myself.
Good catch. Patch updated fixing that.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-org-agenda-rework-ndays-and-span-handling.patch --]
[-- Type: text/x-diff, Size: 22531 bytes --]
From 884f93e653ab82e37d34a72d33a87050e49d7493 Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Fri, 26 Nov 2010 14:22:17 +0100
Subject: [PATCH] org-agenda: rework ndays and span handling
* org-agenda.el (org-agenda-custom-commands-local-options):
Allow org-agenda-span to be a symbol.
(org-agenda-ndays): Make obsolete.
(org-agenda-span): New variable superseding org-agenda-ndays.
(org-agenda-menu): Use org-agenda-current-span.
(org-agenda-current-span): New local variable storing current
span.
(org-agenda-list): Take a span instead of ndays as argument.
This function is now responsible for computing the ndays based
on span.
(org-agenda-ndays-to-span): Return span only if number of days
really matches.
(org-agenda-span-to-ndays): New function.
(org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
(org-agenda-goto-today): Use org-agenda-compute-starting-span.
(org-agenda-later): Do not give compute a new span, use the
current one.
(org-agenda-day-view, org-agenda-week-view)
(org-agenda-month-view, org-agenda-year-view): Stop touching
org-agenda-ndays.
(org-agenda-change-time-span): Only compute starting-span.
(org-agenda-compute-starting-span): New function derived from
the old org-agenda-compute-time-span.
(org-agenda-set-mode-name): Compute mode based on
org-agenda-current-span.
(org-agenda-span-name): New function.
* org-mouse.el: Replace Replace org-agenda-ndays by
org-agenda-current-span.
* org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
doc/org.texi | 14 ++--
doc/orgguide.texi | 6 +-
lisp/org-agenda.el | 190 +++++++++++++++++++++++++++++----------------------
lisp/org-mouse.el | 4 +-
4 files changed, 120 insertions(+), 94 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index e2e9af5..b5b70c9 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the current week or day.
@table @kbd
@cindex org-agenda, command
@orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
+@vindex org-agenda-span
Compile an agenda for the current week from a list of Org files. The agenda
shows the entries for each day. With a numeric prefix@footnote{For backward
compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
listed before the agenda. This feature is deprecated, use the dedicated TODO
list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+variable @code{org-agenda-span})
@end table
Remote editing from the agenda buffer means, for example, that you can
@@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
be mapped to the interval 1938-2037.
@c
@orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+@vindex org-agenda-span
+Go forward in time to display the following @code{org-agenda-current-span} days.
For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
@c
@orgcmd{b,org-agenda-earlier}
Go backward in time to display earlier dates.
@@ -8369,7 +8369,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
system you use, please check the FAQ for examples.}
@example
emacs -eval '(org-batch-store-agenda-views \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
@@ -14033,7 +14033,7 @@ You may also modify parameters on the fly like this:
@example
emacs -batch -l ~/.emacs \
-eval '(org-batch-agenda "a" \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
| lpr
diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index b67f7f1..690111b 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -1931,9 +1931,9 @@ Delete other windows.
Switch to day/week view.
@c
@item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days. For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days. For example, if the display covers a
+week, switch to the following/previous week.
@c
@item .
Go to today.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 48856c9..222345c 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
(const org-agenda-prefix-format :value " %-12:c%?-12t% s")
(string))
(list :tag "Number of days in agenda"
- (const org-agenda-ndays)
- (integer :value 1))
+ (const org-agenda-span)
+ (choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(list :tag "Fixed starting date"
(const org-agenda-start-day)
(string :value "2007-11-01"))
@@ -888,12 +892,25 @@ option will be ignored."
:group 'org-agenda-windows
:type 'boolean)
-(defcustom org-agenda-ndays 7
- "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+ "Number of days to include in overview display.
Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+ :group 'org-agenda-daily/weekly
+ :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+ "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
Custom commands can set this variable in the options section."
:group 'org-agenda-daily/weekly
- :type 'integer)
+ :type '(choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(defcustom org-agenda-start-on-weekday 1
"Non-nil means start the overview always on the specified weekday.
@@ -1825,19 +1842,19 @@ The following commands are available:
("View"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)
+ :style radio :selected (eq org-agenda-current-span 'day)
:keys "v d (or just d)"]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)
+ :style radio :selected (eq org-agenda-current-span 'week)
:keys "v w (or just w)"]
["Month View" org-agenda-month-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+ :style radio :selected (eq org-agenda-current-span 'month)
:keys "v m"]
["Year View" org-agenda-year-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(365 366))
+ :style radio :selected (eq org-agenda-current-span 'year)
:keys "v y"]
"--"
["Include Diary" org-agenda-toggle-diary
@@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
(defvar org-agenda-last-arguments nil
"The arguments of the previous call to `org-agenda'.")
(defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+ "The current span used in the agenda view.") ; local variable in the agenda buffer
(defvar org-include-all-loc nil) ; local variable
(defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
the daily/weekly agenda, see `org-agenda-skip-function'.")
;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
"Produce a daily/weekly view from all files in variable `org-agenda-files'.
The view will be for the current day or week, but from the overview buffer
you will be able to go to other days/weeks.
@@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
agenda instead.
With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
-the number of days. NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
+the number of days. SPAN defaults to `org-agenda-span'.
START-DAY defaults to TODAY, or to the most recent match for the weekday
given in `org-agenda-start-on-weekday'."
(interactive "P")
(if (and (integerp include-all) (> include-all 0))
- (setq ndays include-all include-all nil))
- (setq ndays (or ndays org-agenda-ndays)
- start-day (or start-day org-agenda-start-day))
+ (setq span include-all include-all nil))
+ (setq start-day (or start-day org-agenda-start-day))
(if org-agenda-overriding-arguments
(setq include-all (car org-agenda-overriding-arguments)
start-day (nth 1 org-agenda-overriding-arguments)
- ndays (nth 2 org-agenda-overriding-arguments)))
+ span (nth 2 org-agenda-overriding-arguments)))
(if (stringp start-day)
;; Convert to an absolute day number
(setq start-day (time-to-days (org-read-date nil t start-day))))
- (setq org-agenda-last-arguments (list include-all start-day ndays))
+ (setq org-agenda-last-arguments (list include-all start-day span))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
- (let* ((org-agenda-start-on-weekday
- (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
- org-agenda-start-on-weekday nil))
- (thefiles (org-agenda-files nil 'ifmode))
- (files thefiles)
+ (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
(today (org-agenda-today))
(sd (or start-day today))
+ (ndays (org-agenda-span-to-ndays span sd))
+ (org-agenda-start-on-weekday
+ (if (eq ndays 7)
+ org-agenda-start-on-weekday))
+ (thefiles (org-agenda-files nil 'ifmode))
+ (files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
- (< org-agenda-ndays 7))
+ (< ndays 7))
sd
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
@@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
(day-numbers (list start))
(day-cnt 0)
(inhibit-redisplay (not debug-on-error))
- s e rtn rtnall file date d start-pos end-pos todayp nd
+ s e rtn rtnall file date d start-pos end-pos todayp
clocktable-start clocktable-end filter)
(setq org-agenda-redo-command
- (list 'org-agenda-list (list 'quote include-all) start-day ndays))
- ;; Make the list of days
- (setq ndays (or ndays org-agenda-ndays)
- nd ndays)
- (while (> ndays 1)
- (push (1+ (car day-numbers)) day-numbers)
- (setq ndays (1- ndays)))
+ (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+ (dotimes (n (1- ndays))
+ (push (1+ (car day-numbers)) day-numbers))
(setq day-numbers (nreverse day-numbers))
(setq clocktable-start (car day-numbers)
clocktable-end (1+ (or (org-last day-numbers) 0)))
(org-prepare-agenda "Day/Week")
(org-set-local 'org-starting-day (car day-numbers))
(org-set-local 'org-include-all-loc include-all)
- (org-set-local 'org-agenda-span
- (org-agenda-ndays-to-span nd))
+ (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
(when (and (or include-all org-agenda-include-all-todo)
(member today day-numbers))
(setq files thefiles
@@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
(if org-agenda-overriding-header
(insert (org-add-props (copy-sequence org-agenda-overriding-header)
nil 'face 'org-agenda-structure) "\n")
- (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+ (insert (org-agenda-span-name span)
"-agenda"
(if (< (- d2 d1) 350)
(if (= w1 w2)
@@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
(if rtnall (insert
(org-finalize-agenda-entries
(org-agenda-add-time-grid-maybe
- rtnall nd todayp))
+ rtnall ndays todayp))
"\n"))
(put-text-property s (1- (point)) 'day d)
(put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
(message "")))
(defun org-agenda-ndays-to-span (n)
- (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+ "Return a span symbol for a span of N days, or N if none matches."
+ (cond ((symbolp n) n)
+ ((= n 1) 'day)
+ ((= n 7) 'week)
+ (t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+ "Return ndays from SPAN starting at START-DAY."
+ (cond ((numberp span) span)
+ ((eq span 'day) 1)
+ ((eq span 'week) 7)
+ ((eq span 'month)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (calendar-last-day-of-month (car date) (caddr date))))
+ ((eq span 'year)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+ "Return a SPAN name."
+ (if (null span)
+ ""
+ (if (symbolp span)
+ (capitalize (symbol-name span))
+ (format "%d days" span))))
;;; Agenda word search
@@ -5990,7 +6028,7 @@ Negative selection means regexp must not match for selection of an entry."
(interactive (list (let ((org-read-date-prefer-future
(eval org-agenda-jump-prefer-future)))
(org-read-date))))
- (org-agenda-list nil date))
+ (org-agenda-list nil date org-agenda-current-span))
(defun org-agenda-goto-today ()
"Go to today."
@@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
(cond
(tdpos (goto-char tdpos))
((eq org-agenda-type 'agenda)
- (let* ((sd (org-agenda-today))
- (comp (org-agenda-compute-time-span sd org-agenda-span))
+ (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
(org-agenda-overriding-arguments org-agenda-last-arguments))
- (setf (nth 1 org-agenda-overriding-arguments) (car comp))
- (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+ (setf (nth 1 org-agenda-overriding-arguments) sd)
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda)))
(t (error "Cannot find today")))))
@@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
With prefix ARG, go forward that many times the current span."
(interactive "p")
(org-agenda-check-type t 'agenda)
- (let* ((span org-agenda-span)
+ (let* ((span org-agenda-current-span)
(sd org-starting-day)
(greg (calendar-gregorian-from-absolute sd))
(cnt (org-get-at-bol 'org-day-cnt))
- greg2 nd)
+ greg2)
(cond
((eq span 'day)
- (setq sd (+ arg sd) nd 1))
+ (setq sd (+ arg sd)))
((eq span 'week)
- (setq sd (+ (* 7 arg) sd) nd 7))
+ (setq sd (+ (* 7 arg) sd)))
((eq span 'month)
(setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
sd (calendar-absolute-from-gregorian greg2))
- (setcar greg2 (1+ (car greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+ (setcar greg2 (1+ (car greg2))))
((eq span 'year)
(setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
sd (calendar-absolute-from-gregorian greg2))
- (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+ (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+ (t
+ (setq sd (+ (* span arg) sd))))
(let ((org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments) sd nd t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda cnt))))
@@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
"Switch to daily view for agenda.
With argument DAY-OF-YEAR, switch to that day of the year."
(interactive "P")
- (setq org-agenda-ndays 1)
(org-agenda-change-time-span 'day day-of-year))
(defun org-agenda-week-view (&optional iso-week)
"Switch to daily view for agenda.
@@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
week 12 of year 2007. Years in the range 1938-2037 can also be
written as 2-digit years."
(interactive "P")
- (setq org-agenda-ndays 7)
(org-agenda-change-time-span 'week iso-week))
(defun org-agenda-month-view (&optional month)
"Switch to monthly view for agenda.
@@ -6120,70 +6154,61 @@ written as 2-digit years."
"Change the agenda view to SPAN.
SPAN may be `day', `week', `month', `year'."
(org-agenda-check-type t 'agenda)
- (if (and (not n) (equal org-agenda-span span))
+ (if (and (not n) (equal org-agenda-current-span span))
(error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
org-starting-day))
- (computed (org-agenda-compute-time-span sd span n))
+ (sd (org-agenda-compute-starting-span sd span n))
(org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments)
- (car computed) (cdr computed) t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda))
(org-agenda-set-mode-name)
(message "Switched to %s view" span))
-(defun org-agenda-compute-time-span (sd span &optional n)
- "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+ "Compute starting date for agenda.
SPAN may be `day', `week', `month', `year'. The return value
is a cons cell with the starting date and the number of days,
so that the date SD will be in that range."
(let* ((greg (calendar-gregorian-from-absolute sd))
(dg (nth 1 greg))
(mg (car greg))
- (yg (nth 2 greg))
- nd w1 y1 m1 thisweek)
+ (yg (nth 2 greg)))
(cond
((eq span 'day)
(when n
(setq sd (+ (calendar-absolute-from-gregorian
(list mg 1 yg))
- n -1)))
- (setq nd 1))
+ n -1))))
((eq span 'week)
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
(d (if org-agenda-start-on-weekday
(- nt org-agenda-start-on-weekday)
- 0)))
+ 0))
+ y1)
(setq sd (- sd (+ (if (< d 0) 7 0) d)))
(when n
(require 'cal-iso)
- (setq thisweek (car (calendar-iso-from-absolute sd)))
(when (> n 99)
(setq y1 (org-small-year-to-year (/ n 100))
n (mod n 100)))
(setq sd
(calendar-absolute-from-iso
(list n 1
- (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
- (setq nd 7)))
+ (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
((eq span 'month)
- (when (and n (> n 99))
- (setq y1 (org-small-year-to-year (/ n 100))
- n (mod n 100)))
- (setq sd (calendar-absolute-from-gregorian
- (list (or n mg) 1 (or y1 yg)))
- nd (- (calendar-absolute-from-gregorian
- (list (1+ (or n mg)) 1 (or y1 yg)))
- sd)))
+ (let (y1)
+ (when (and n (> n 99))
+ (setq y1 (org-small-year-to-year (/ n 100))
+ n (mod n 100)))
+ (setq sd (calendar-absolute-from-gregorian
+ (list (or n mg) 1 (or y1 yg))))))
((eq span 'year)
(setq sd (calendar-absolute-from-gregorian
- (list 1 1 (or n yg)))
- nd (- (calendar-absolute-from-gregorian
- (list 1 1 (1+ (or n yg))))
- sd))))
- (cons sd nd)))
+ (list 1 1 (or n yg))))))
+ sd))
(defun org-agenda-next-date-line (&optional arg)
"Jump to the next line indicating a date in agenda buffer."
@@ -6338,8 +6363,9 @@ When called with a prefix argument, include all archive files as well."
(setq mode-name
(concat "Org-Agenda"
(if (get 'org-agenda-files 'org-restrict) " []" "")
- (if (equal org-agenda-ndays 1) " Day" "")
- (if (equal org-agenda-ndays 7) " Week" "")
+ " " (org-agenda-span-name (or org-agenda-current-span
+ org-agenda-ndays
+ org-agenda-span))
(if org-agenda-follow-mode " Follow" "")
(if org-agenda-entry-text-mode " ETxt" "")
(if org-agenda-include-diary " Diary" "")
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index e16c977..d18a12d 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
"--"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)]
+ :style radio :selected (eq org-agenda-current-span 'day)]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)]
+ :style radio :selected (eq org-agenda-current-span 'week)]
"--"
["Show Logbook entries" org-agenda-log-mode
:style toggle :selected org-agenda-show-log
--
1.7.2.3
[-- Attachment #1.1.3: Type: text/plain, Size: 79 bytes --]
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-01 13:09 ` Julien Danjou
@ 2010-12-01 14:09 ` Eric S Fraga
2010-12-03 2:11 ` Bernt Hansen
1 sibling, 0 replies; 17+ messages in thread
From: Eric S Fraga @ 2010-12-01 14:09 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
Julien Danjou <julien@danjou.info> writes:
> On Wed, Dec 01 2010, Eric S Fraga wrote:
>
>> Mostly works fine but there is one problem I have encountered. If you
>> change your view (mine defaults to day so I sometimes switch to week
>> view), you can go forward and backward as expected. However, if you
>> /jump/ (j in agenda view) to a given date, the view resets to the
>> default (well, to single day view in my case). I prefer the view to
>> remain as I have specified it last until I change it myself.
>
> Good catch. Patch updated fixing that.
Seems to work just fine now for a variety of date and view changes.
Thanks,
eric
--
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1
: using Org-mode version 7.3 (release_7.3.159.g23265.dirty)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-01 13:09 ` Julien Danjou
2010-12-01 14:09 ` Eric S Fraga
@ 2010-12-03 2:11 ` Bernt Hansen
2010-12-03 8:00 ` Carsten Dominik
2010-12-03 9:30 ` Julien Danjou
1 sibling, 2 replies; 17+ messages in thread
From: Bernt Hansen @ 2010-12-03 2:11 UTC (permalink / raw)
To: Julien Danjou; +Cc: Eric S Fraga, emacs-orgmode, Carsten Dominik
Julien Danjou <julien@danjou.info> writes:
> On Wed, Dec 01 2010, Eric S Fraga wrote:
>
>> Mostly works fine but there is one problem I have encountered. If you
>> change your view (mine defaults to day so I sometimes switch to week
>> view), you can go forward and backward as expected. However, if you
>> /jump/ (j in agenda view) to a given date, the view resets to the
>> default (well, to single day view in my case). I prefer the view to
>> remain as I have specified it last until I change it myself.
>
> Good catch. Patch updated fixing that.
Hi Julien,
I tried your patch out tonight and I'm confused about org-agenda-ndays.
This is stated as obsolete (since 24.1 ? what's that?) but the default
for org-agenda-span doesn't seem to be set based on the existing value
of org-agenda-ndays. Is that on purpose?
I'm fine with customizing org-agenda-span as long as it's documented
that this needs to be done for the next version of org-mode that
includes your patch.
I also noticed the display on the modeline says 'Day', 'Week', 'Month',
or 'Year' when displaying the agenda with 'd', 'w', 'v m', and 'v y'
which is great. However this data is lost and replaced with '1 days' if
moving forwards or backwards in the agenda with 'f' and 'b' or jumping
to a date with 'j'.
Otherwise I think this looks good to me.
Regards,
Bernt
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 2:11 ` Bernt Hansen
@ 2010-12-03 8:00 ` Carsten Dominik
2010-12-03 9:30 ` Julien Danjou
1 sibling, 0 replies; 17+ messages in thread
From: Carsten Dominik @ 2010-12-03 8:00 UTC (permalink / raw)
To: Bernt Hansen; +Cc: Julien Danjou, Eric S Fraga, emacs-orgmode
On Dec 3, 2010, at 3:11 AM, Bernt Hansen wrote:
> Julien Danjou <julien@danjou.info> writes:
>
>> On Wed, Dec 01 2010, Eric S Fraga wrote:
>>
>>> Mostly works fine but there is one problem I have encountered. If
>>> you
>>> change your view (mine defaults to day so I sometimes switch to week
>>> view), you can go forward and backward as expected. However, if you
>>> /jump/ (j in agenda view) to a given date, the view resets to the
>>> default (well, to single day view in my case). I prefer the view to
>>> remain as I have specified it last until I change it myself.
>>
>> Good catch. Patch updated fixing that.
>
> Hi Julien,
>
> I tried your patch out tonight and I'm confused about org-agenda-
> ndays.
> This is stated as obsolete (since 24.1 ? what's that?) but the default
> for org-agenda-span doesn't seem to be set based on the existing value
> of org-agenda-ndays. Is that on purpose?
>
> I'm fine with customizing org-agenda-span as long as it's documented
> that this needs to be done for the next version of org-mode that
> includes your patch.
I guess making org-agenda-ndays should be made an alias for org-agenda-
span.
>
> I also noticed the display on the modeline says 'Day', 'Week',
> 'Month',
> or 'Year' when displaying the agenda with 'd', 'w', 'v m', and 'v y'
> which is great. However this data is lost and replaced with '1
> days' if
> moving forwards or backwards in the agenda with 'f' and 'b' or jumping
> to a date with 'j'.
>
> Otherwise I think this looks good to me.
>
> Regards,
> Bernt
>
>
- Carsten
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 2:11 ` Bernt Hansen
2010-12-03 8:00 ` Carsten Dominik
@ 2010-12-03 9:30 ` Julien Danjou
2010-12-03 10:06 ` Carsten Dominik
1 sibling, 1 reply; 17+ messages in thread
From: Julien Danjou @ 2010-12-03 9:30 UTC (permalink / raw)
To: Bernt Hansen; +Cc: Eric S Fraga, emacs-orgmode, Carsten Dominik
[-- Attachment #1.1.1: Type: text/plain, Size: 1246 bytes --]
On Fri, Dec 03 2010, Bernt Hansen wrote:
> I tried your patch out tonight and I'm confused about org-agenda-ndays.
> This is stated as obsolete (since 24.1 ? what's that?)
An Emacs version. make-obsolete-variable requires a version number to be
set, and that's usually the Emacs version number. The next Emacs release
including this code will be 24.1, therefore I've set this to 24.1, which
is the Good Practice AFAIK.
> but the default
> for org-agenda-span doesn't seem to be set based on the existing value
> of org-agenda-ndays. Is that on purpose?
Yes, but org-agenda-ndays is used instead of org-agenda-span if
org-agenda-ndays has been set.
> I'm fine with customizing org-agenda-span as long as it's documented
> that this needs to be done for the next version of org-mode that
> includes your patch.
I've updated the texi file accordingly (s/ndays/span/).
> I also noticed the display on the modeline says 'Day', 'Week', 'Month',
> or 'Year' when displaying the agenda with 'd', 'w', 'v m', and 'v y'
> which is great. However this data is lost and replaced with '1 days' if
> moving forwards or backwards in the agenda with 'f' and 'b' or jumping
> to a date with 'j'.
Yep, that's a bug. I've fixed it, new version attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-org-agenda-rework-ndays-and-span-handling.patch --]
[-- Type: text/x-diff, Size: 24175 bytes --]
From 8c3bd1ca371bdb39ab1b64f323154a8135335da8 Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Fri, 26 Nov 2010 14:22:17 +0100
Subject: [PATCH] org-agenda: rework ndays and span handling
* org-agenda.el (org-agenda-custom-commands-local-options):
Allow org-agenda-span to be a symbol.
(org-agenda-ndays): Make obsolete.
(org-agenda-span): New variable superseding org-agenda-ndays.
(org-agenda-menu): Use org-agenda-current-span.
(org-agenda-current-span): New local variable storing current
span.
(org-agenda-list): Take a span instead of ndays as argument.
This function is now responsible for computing the ndays based
on span.
(org-agenda-ndays-to-span): Return span only if number of days
really matches.
(org-agenda-span-to-ndays): New function.
(org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
(org-agenda-goto-today): Use org-agenda-compute-starting-span.
(org-agenda-later): Do not give compute a new span, use the
current one.
(org-agenda-day-view, org-agenda-week-view)
(org-agenda-month-view, org-agenda-year-view): Stop touching
org-agenda-ndays.
(org-agenda-change-time-span): Only compute starting-span.
(org-agenda-compute-starting-span): New function derived from
the old org-agenda-compute-time-span.
(org-agenda-set-mode-name): Compute mode based on
org-agenda-current-span.
(org-agenda-span-name): New function.
* org-mouse.el: Replace Replace org-agenda-ndays by
org-agenda-current-span.
* org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-span.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
doc/org.texi | 14 ++--
doc/orgguide.texi | 6 +-
lisp/org-agenda.el | 243 +++++++++++++++++++++++++++++-----------------------
lisp/org-mouse.el | 4 +-
4 files changed, 146 insertions(+), 121 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index e2e9af5..b5b70c9 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the current week or day.
@table @kbd
@cindex org-agenda, command
@orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
+@vindex org-agenda-span
Compile an agenda for the current week from a list of Org files. The agenda
shows the entries for each day. With a numeric prefix@footnote{For backward
compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
listed before the agenda. This feature is deprecated, use the dedicated TODO
list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+variable @code{org-agenda-span})
@end table
Remote editing from the agenda buffer means, for example, that you can
@@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
be mapped to the interval 1938-2037.
@c
@orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+@vindex org-agenda-span
+Go forward in time to display the following @code{org-agenda-current-span} days.
For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
@c
@orgcmd{b,org-agenda-earlier}
Go backward in time to display earlier dates.
@@ -8369,7 +8369,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
system you use, please check the FAQ for examples.}
@example
emacs -eval '(org-batch-store-agenda-views \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
@@ -14033,7 +14033,7 @@ You may also modify parameters on the fly like this:
@example
emacs -batch -l ~/.emacs \
-eval '(org-batch-agenda "a" \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
| lpr
diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index b67f7f1..690111b 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -1931,9 +1931,9 @@ Delete other windows.
Switch to day/week view.
@c
@item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days. For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days. For example, if the display covers a
+week, switch to the following/previous week.
@c
@item .
Go to today.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index c339f60..a4d59a2 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
(const org-agenda-prefix-format :value " %-12:c%?-12t% s")
(string))
(list :tag "Number of days in agenda"
- (const org-agenda-ndays)
- (integer :value 1))
+ (const org-agenda-span)
+ (choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(list :tag "Fixed starting date"
(const org-agenda-start-day)
(string :value "2007-11-01"))
@@ -888,12 +892,25 @@ option will be ignored."
:group 'org-agenda-windows
:type 'boolean)
-(defcustom org-agenda-ndays 7
- "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+ "Number of days to include in overview display.
Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+ :group 'org-agenda-daily/weekly
+ :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+ "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
Custom commands can set this variable in the options section."
:group 'org-agenda-daily/weekly
- :type 'integer)
+ :type '(choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(defcustom org-agenda-start-on-weekday 1
"Non-nil means start the overview always on the specified weekday.
@@ -1825,19 +1842,19 @@ The following commands are available:
("View"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)
+ :style radio :selected (eq org-agenda-current-span 'day)
:keys "v d (or just d)"]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)
+ :style radio :selected (eq org-agenda-current-span 'week)
:keys "v w (or just w)"]
["Month View" org-agenda-month-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+ :style radio :selected (eq org-agenda-current-span 'month)
:keys "v m"]
["Year View" org-agenda-year-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(365 366))
+ :style radio :selected (eq org-agenda-current-span 'year)
:keys "v y"]
"--"
["Include Diary" org-agenda-toggle-diary
@@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
(defvar org-agenda-last-arguments nil
"The arguments of the previous call to `org-agenda'.")
(defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+ "The current span used in the agenda view.") ; local variable in the agenda buffer
(defvar org-include-all-loc nil) ; local variable
(defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
the daily/weekly agenda, see `org-agenda-skip-function'.")
;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
"Produce a daily/weekly view from all files in variable `org-agenda-files'.
The view will be for the current day or week, but from the overview buffer
you will be able to go to other days/weeks.
@@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
agenda instead.
With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
-the number of days. NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
+the number of days. SPAN defaults to `org-agenda-span'.
START-DAY defaults to TODAY, or to the most recent match for the weekday
given in `org-agenda-start-on-weekday'."
(interactive "P")
(if (and (integerp include-all) (> include-all 0))
- (setq ndays include-all include-all nil))
- (setq ndays (or ndays org-agenda-ndays)
- start-day (or start-day org-agenda-start-day))
+ (setq span include-all include-all nil))
+ (setq start-day (or start-day org-agenda-start-day))
(if org-agenda-overriding-arguments
(setq include-all (car org-agenda-overriding-arguments)
start-day (nth 1 org-agenda-overriding-arguments)
- ndays (nth 2 org-agenda-overriding-arguments)))
+ span (nth 2 org-agenda-overriding-arguments)))
(if (stringp start-day)
;; Convert to an absolute day number
(setq start-day (time-to-days (org-read-date nil t start-day))))
- (setq org-agenda-last-arguments (list include-all start-day ndays))
+ (setq org-agenda-last-arguments (list include-all start-day span))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
- (let* ((org-agenda-start-on-weekday
- (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
- org-agenda-start-on-weekday nil))
- (thefiles (org-agenda-files nil 'ifmode))
- (files thefiles)
+ (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
(today (org-agenda-today))
(sd (or start-day today))
+ (ndays (org-agenda-span-to-ndays span sd))
+ (org-agenda-start-on-weekday
+ (if (eq ndays 7)
+ org-agenda-start-on-weekday))
+ (thefiles (org-agenda-files nil 'ifmode))
+ (files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
- (< org-agenda-ndays 7))
+ (< ndays 7))
sd
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
@@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
(day-numbers (list start))
(day-cnt 0)
(inhibit-redisplay (not debug-on-error))
- s e rtn rtnall file date d start-pos end-pos todayp nd
+ s e rtn rtnall file date d start-pos end-pos todayp
clocktable-start clocktable-end filter)
(setq org-agenda-redo-command
- (list 'org-agenda-list (list 'quote include-all) start-day ndays))
- ;; Make the list of days
- (setq ndays (or ndays org-agenda-ndays)
- nd ndays)
- (while (> ndays 1)
- (push (1+ (car day-numbers)) day-numbers)
- (setq ndays (1- ndays)))
+ (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+ (dotimes (n (1- ndays))
+ (push (1+ (car day-numbers)) day-numbers))
(setq day-numbers (nreverse day-numbers))
(setq clocktable-start (car day-numbers)
clocktable-end (1+ (or (org-last day-numbers) 0)))
(org-prepare-agenda "Day/Week")
(org-set-local 'org-starting-day (car day-numbers))
(org-set-local 'org-include-all-loc include-all)
- (org-set-local 'org-agenda-span
- (org-agenda-ndays-to-span nd))
+ (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
(when (and (or include-all org-agenda-include-all-todo)
(member today day-numbers))
(setq files thefiles
@@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
(if org-agenda-overriding-header
(insert (org-add-props (copy-sequence org-agenda-overriding-header)
nil 'face 'org-agenda-structure) "\n")
- (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+ (insert (org-agenda-span-name span)
"-agenda"
(if (< (- d2 d1) 350)
(if (= w1 w2)
@@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
(if rtnall (insert
(org-finalize-agenda-entries
(org-agenda-add-time-grid-maybe
- rtnall nd todayp))
+ rtnall ndays todayp))
"\n"))
(put-text-property s (1- (point)) 'day d)
(put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
(message "")))
(defun org-agenda-ndays-to-span (n)
- (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+ "Return a span symbol for a span of N days, or N if none matches."
+ (cond ((symbolp n) n)
+ ((= n 1) 'day)
+ ((= n 7) 'week)
+ (t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+ "Return ndays from SPAN starting at START-DAY."
+ (cond ((numberp span) span)
+ ((eq span 'day) 1)
+ ((eq span 'week) 7)
+ ((eq span 'month)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (calendar-last-day-of-month (car date) (caddr date))))
+ ((eq span 'year)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+ "Return a SPAN name."
+ (if (null span)
+ ""
+ (if (symbolp span)
+ (capitalize (symbol-name span))
+ (format "%d days" span))))
;;; Agenda word search
@@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
(cond
(tdpos (goto-char tdpos))
((eq org-agenda-type 'agenda)
- (let* ((sd (org-agenda-today))
- (comp (org-agenda-compute-time-span sd org-agenda-span))
+ (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
(org-agenda-overriding-arguments org-agenda-last-arguments))
- (setf (nth 1 org-agenda-overriding-arguments) (car comp))
- (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+ (setf (nth 1 org-agenda-overriding-arguments) sd)
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda)))
(t (error "Cannot find today")))))
@@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
With prefix ARG, go forward that many times the current span."
(interactive "p")
(org-agenda-check-type t 'agenda)
- (let* ((span org-agenda-span)
+ (let* ((span org-agenda-current-span)
(sd org-starting-day)
(greg (calendar-gregorian-from-absolute sd))
(cnt (org-get-at-bol 'org-day-cnt))
- greg2 nd)
+ greg2)
(cond
((eq span 'day)
- (setq sd (+ arg sd) nd 1))
+ (setq sd (+ arg sd)))
((eq span 'week)
- (setq sd (+ (* 7 arg) sd) nd 7))
+ (setq sd (+ (* 7 arg) sd)))
((eq span 'month)
(setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
sd (calendar-absolute-from-gregorian greg2))
- (setcar greg2 (1+ (car greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+ (setcar greg2 (1+ (car greg2))))
((eq span 'year)
(setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
sd (calendar-absolute-from-gregorian greg2))
- (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+ (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+ (t
+ (setq sd (+ (* span arg) sd))))
(let ((org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments) sd nd t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda cnt))))
@@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
"Switch to daily view for agenda.
With argument DAY-OF-YEAR, switch to that day of the year."
(interactive "P")
- (setq org-agenda-ndays 1)
(org-agenda-change-time-span 'day day-of-year))
(defun org-agenda-week-view (&optional iso-week)
"Switch to daily view for agenda.
@@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
week 12 of year 2007. Years in the range 1938-2037 can also be
written as 2-digit years."
(interactive "P")
- (setq org-agenda-ndays 7)
(org-agenda-change-time-span 'week iso-week))
(defun org-agenda-month-view (&optional month)
"Switch to monthly view for agenda.
@@ -6120,70 +6154,61 @@ written as 2-digit years."
"Change the agenda view to SPAN.
SPAN may be `day', `week', `month', `year'."
(org-agenda-check-type t 'agenda)
- (if (and (not n) (equal org-agenda-span span))
+ (if (and (not n) (equal org-agenda-current-span span))
(error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
org-starting-day))
- (computed (org-agenda-compute-time-span sd span n))
+ (sd (org-agenda-compute-starting-span sd span n))
(org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments)
- (car computed) (cdr computed) t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda))
(org-agenda-set-mode-name)
(message "Switched to %s view" span))
-(defun org-agenda-compute-time-span (sd span &optional n)
- "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+ "Compute starting date for agenda.
SPAN may be `day', `week', `month', `year'. The return value
is a cons cell with the starting date and the number of days,
so that the date SD will be in that range."
(let* ((greg (calendar-gregorian-from-absolute sd))
(dg (nth 1 greg))
(mg (car greg))
- (yg (nth 2 greg))
- nd w1 y1 m1 thisweek)
+ (yg (nth 2 greg)))
(cond
((eq span 'day)
(when n
(setq sd (+ (calendar-absolute-from-gregorian
(list mg 1 yg))
- n -1)))
- (setq nd 1))
+ n -1))))
((eq span 'week)
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
(d (if org-agenda-start-on-weekday
(- nt org-agenda-start-on-weekday)
- 0)))
+ 0))
+ y1)
(setq sd (- sd (+ (if (< d 0) 7 0) d)))
(when n
(require 'cal-iso)
- (setq thisweek (car (calendar-iso-from-absolute sd)))
(when (> n 99)
(setq y1 (org-small-year-to-year (/ n 100))
n (mod n 100)))
(setq sd
(calendar-absolute-from-iso
(list n 1
- (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
- (setq nd 7)))
+ (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
((eq span 'month)
- (when (and n (> n 99))
- (setq y1 (org-small-year-to-year (/ n 100))
- n (mod n 100)))
- (setq sd (calendar-absolute-from-gregorian
- (list (or n mg) 1 (or y1 yg)))
- nd (- (calendar-absolute-from-gregorian
- (list (1+ (or n mg)) 1 (or y1 yg)))
- sd)))
+ (let (y1)
+ (when (and n (> n 99))
+ (setq y1 (org-small-year-to-year (/ n 100))
+ n (mod n 100)))
+ (setq sd (calendar-absolute-from-gregorian
+ (list (or n mg) 1 (or y1 yg))))))
((eq span 'year)
(setq sd (calendar-absolute-from-gregorian
- (list 1 1 (or n yg)))
- nd (- (calendar-absolute-from-gregorian
- (list 1 1 (1+ (or n yg))))
- sd))))
- (cons sd nd)))
+ (list 1 1 (or n yg))))))
+ sd))
(defun org-agenda-next-date-line (&optional arg)
"Jump to the next line indicating a date in agenda buffer."
@@ -6336,36 +6361,36 @@ When called with a prefix argument, include all archive files as well."
(defun org-agenda-set-mode-name ()
"Set the mode name to indicate all the small mode settings."
(setq mode-name
- (concat "Org-Agenda"
- (if (get 'org-agenda-files 'org-restrict) " []" "")
- (if (equal org-agenda-ndays 1) " Day" "")
- (if (equal org-agenda-ndays 7) " Week" "")
- (if org-agenda-follow-mode " Follow" "")
- (if org-agenda-entry-text-mode " ETxt" "")
- (if org-agenda-include-diary " Diary" "")
- (if org-agenda-include-deadlines " Ddl" "")
- (if org-agenda-use-time-grid " Grid" "")
- (if (and (boundp 'org-habit-show-habits)
- org-habit-show-habits) " Habit" "")
- (if (consp org-agenda-show-log) " LogAll"
- (if org-agenda-show-log " Log" ""))
- (if (or org-agenda-filter (get 'org-agenda-filter
- :preset-filter))
- (concat " {" (mapconcat
- 'identity
- (append (get 'org-agenda-filter
- :preset-filter)
- org-agenda-filter) "") "}")
- "")
- (if org-agenda-archives-mode
- (if (eq org-agenda-archives-mode t)
- " Archives"
- (format " :%s:" org-archive-tag))
- "")
- (if org-agenda-clockreport-mode
- (if (eq org-agenda-clockreport-mode 'with-filter)
- " Clock{}" " Clock")
- "")))
+ (list "Org-Agenda"
+ (if (get 'org-agenda-files 'org-restrict) " []" "")
+ " "
+ '(:eval (org-agenda-span-name org-agenda-current-span))
+ (if org-agenda-follow-mode " Follow" "")
+ (if org-agenda-entry-text-mode " ETxt" "")
+ (if org-agenda-include-diary " Diary" "")
+ (if org-agenda-include-deadlines " Ddl" "")
+ (if org-agenda-use-time-grid " Grid" "")
+ (if (and (boundp 'org-habit-show-habits)
+ org-habit-show-habits) " Habit" "")
+ (if (consp org-agenda-show-log) " LogAll"
+ (if org-agenda-show-log " Log" ""))
+ (if (or org-agenda-filter (get 'org-agenda-filter
+ :preset-filter))
+ (concat " {" (mapconcat
+ 'identity
+ (append (get 'org-agenda-filter
+ :preset-filter)
+ org-agenda-filter) "") "}")
+ "")
+ (if org-agenda-archives-mode
+ (if (eq org-agenda-archives-mode t)
+ " Archives"
+ (format " :%s:" org-archive-tag))
+ "")
+ (if org-agenda-clockreport-mode
+ (if (eq org-agenda-clockreport-mode 'with-filter)
+ " Clock{}" " Clock")
+ "")))
(force-mode-line-update))
(defun org-agenda-post-command-hook ()
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index e16c977..d18a12d 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
"--"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)]
+ :style radio :selected (eq org-agenda-current-span 'day)]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)]
+ :style radio :selected (eq org-agenda-current-span 'week)]
"--"
["Show Logbook entries" org-agenda-log-mode
:style toggle :selected org-agenda-show-log
--
1.7.2.3
[-- Attachment #1.1.3: Type: text/plain, Size: 79 bytes --]
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 9:30 ` Julien Danjou
@ 2010-12-03 10:06 ` Carsten Dominik
2010-12-03 11:50 ` Julien Danjou
0 siblings, 1 reply; 17+ messages in thread
From: Carsten Dominik @ 2010-12-03 10:06 UTC (permalink / raw)
To: Julien Danjou; +Cc: Bernt Hansen, Eric S Fraga, emacs-orgmode
Hi Julien,
please see comments below and resubmit.
- Carsten
On Dec 3, 2010, at 10:30 AM, Julien Danjou wrote:
> On Fri, Dec 03 2010, Bernt Hansen wrote:
>
>> I tried your patch out tonight and I'm confused about org-agenda-
>> ndays.
>> This is stated as obsolete (since 24.1 ? what's that?)
>
> An Emacs version. make-obsolete-variable requires a version number
> to be
> set, and that's usually the Emacs version number. The next Emacs
> release
> including this code will be 24.1, therefore I've set this to 24.1,
> which
> is the Good Practice AFAIK.
>
>> but the default
>> for org-agenda-span doesn't seem to be set based on the existing
>> value
>> of org-agenda-ndays. Is that on purpose?
>
> Yes, but org-agenda-ndays is used instead of org-agenda-span if
> org-agenda-ndays has been set.
>
>> I'm fine with customizing org-agenda-span as long as it's documented
>> that this needs to be done for the next version of org-mode that
>> includes your patch.
>
> I've updated the texi file accordingly (s/ndays/span/).
>
>> I also noticed the display on the modeline says 'Day', 'Week',
>> 'Month',
>> or 'Year' when displaying the agenda with 'd', 'w', 'v m', and 'v y'
>> which is great. However this data is lost and replaced with '1
>> days' if
>> moving forwards or backwards in the agenda with 'f' and 'b' or
>> jumping
>> to a date with 'j'.
>
> Yep, that's a bug. I've fixed it, new version attached.
>
> From 8c3bd1ca371bdb39ab1b64f323154a8135335da8 Mon Sep 17 00:00:00 2001
> From: Julien Danjou <julien@danjou.info>
> Date: Fri, 26 Nov 2010 14:22:17 +0100
> Subject: [PATCH] org-agenda: rework ndays and span handling
>
> * org-agenda.el (org-agenda-custom-commands-local-options):
> Allow org-agenda-span to be a symbol.
> (org-agenda-ndays): Make obsolete.
> (org-agenda-span): New variable superseding org-agenda-ndays.
> (org-agenda-menu): Use org-agenda-current-span.
> (org-agenda-current-span): New local variable storing current
> span.
> (org-agenda-list): Take a span instead of ndays as argument.
> This function is now responsible for computing the ndays based
> on span.
> (org-agenda-ndays-to-span): Return span only if number of days
> really matches.
> (org-agenda-span-to-ndays): New function.
> (org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
> (org-agenda-goto-today): Use org-agenda-compute-starting-span.
> (org-agenda-later): Do not give compute a new span, use the
> current one.
> (org-agenda-day-view, org-agenda-week-view)
> (org-agenda-month-view, org-agenda-year-view): Stop touching
> org-agenda-ndays.
> (org-agenda-change-time-span): Only compute starting-span.
> (org-agenda-compute-starting-span): New function derived from
> the old org-agenda-compute-time-span.
> (org-agenda-set-mode-name): Compute mode based on
> org-agenda-current-span.
> (org-agenda-span-name): New function.
>
> * org-mouse.el: Replace Replace org-agenda-ndays by
> org-agenda-current-span.
>
> * org.texi, orgguide.texi: Replace org-agenda-ndays by org-agenda-
> span.
>
> Signed-off-by: Julien Danjou <julien@danjou.info>
> ---
> doc/org.texi | 14 ++--
> doc/orgguide.texi | 6 +-
> lisp/org-agenda.el | 243 ++++++++++++++++++++++++++++
> +-----------------------
> lisp/org-mouse.el | 4 +-
> 4 files changed, 146 insertions(+), 121 deletions(-)
>
> diff --git a/doc/org.texi b/doc/org.texi
Somewhere in the docs, there should be a reference to the older
variable, with an index entry and a mention that the other variable
should be used instead. I believe that many people have
org-agenda-ndays in there config, in multiple places
(in custom commands...)
Thanks.
I do like this change, because I agree with your sentiment
that it is totally wrong to change a defcustom variable.
I think that this variable is so old, maybe from even before
there was a defcustom :)
When you resubmit, please make sure that the extensive explanation you
had earlier is part of the commit message.
- Carsten
- Carsten
> index e2e9af5..b5b70c9 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -6966,14 +6966,14 @@ paper agenda, showing all the tasks for the
> current week or day.
> @table @kbd
> @cindex org-agenda, command
> @orgcmd{C-c a a,org-agenda-list}
> -@vindex org-agenda-ndays
> +@vindex org-agenda-span
> Compile an agenda for the current week from a list of Org files.
> The agenda
> shows the entries for each day. With a numeric prefix@footnote{For
> backward
> compatibility, the universal prefix @kbd{C-u} causes all TODO
> entries to be
> listed before the agenda. This feature is deprecated, use the
> dedicated TODO
> list, or a block agenda instead (@pxref{Block agenda}).} (like
> @kbd{C-u 2 1
> C-c a a}) you may set the number of days to be displayed (see also the
> -variable @code{org-agenda-ndays})
> +variable @code{org-agenda-span})
> @end table
>
> Remote editing from the agenda buffer means, for example, that you can
> @@ -7621,10 +7621,10 @@ argument as well. For example, @kbd{200712
> w} will jump to week 12 in
> be mapped to the interval 1938-2037.
> @c
> @orgcmd{f,org-agenda-later}
> -@vindex org-agenda-ndays
> -Go forward in time to display the following @code{org-agenda-ndays}
> days.
> +@vindex org-agenda-span
> +Go forward in time to display the following @code{org-agenda-
> current-span} days.
> For example, if the display covers a week, switch to the following
> week.
> -With prefix arg, go forward that many times @code{org-agenda-ndays}
> days.
> +With prefix arg, go forward that many times @code{org-agenda-
> current-span} days.
> @c
> @orgcmd{b,org-agenda-earlier}
> Go backward in time to display earlier dates.
> @@ -8369,7 +8369,7 @@ or, if you need to modify some
> parameters@footnote{Quoting depends on the
> system you use, please check the FAQ for examples.}
> @example
> emacs -eval '(org-batch-store-agenda-views \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-start-day "2007-11-01" \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> @@ -14033,7 +14033,7 @@ You may also modify parameters on the fly
> like this:
> @example
> emacs -batch -l ~/.emacs \
> -eval '(org-batch-agenda "a" \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> | lpr
> diff --git a/doc/orgguide.texi b/doc/orgguide.texi
> index b67f7f1..690111b 100644
> --- a/doc/orgguide.texi
> +++ b/doc/orgguide.texi
> @@ -1931,9 +1931,9 @@ Delete other windows.
> Switch to day/week view.
> @c
> @item f @r{and} b
> -Go forward/backward in time to display the following @code{org-
> agenda-ndays}
> -days. For example, if the display covers a week, switch to the
> -following/previous week.
> +Go forward/backward in time to display the following
> +@code{org-agenda-current-span} days. For example, if the display
> covers a
> +week, switch to the following/previous week.
> @c
> @item .
> Go to today.
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index c339f60..a4d59a2 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to
> the header. However,
> (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
> (string))
> (list :tag "Number of days in agenda"
> - (const org-agenda-ndays)
> - (integer :value 1))
> + (const org-agenda-span)
> + (choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
The constants above need to be without quote, I think. Please fix
*and* verify.
More comments below.
> + (integer :tag "Custom")))
> (list :tag "Fixed starting date"
> (const org-agenda-start-day)
> (string :value "2007-11-01"))
> @@ -888,12 +892,25 @@ option will be ignored."
> :group 'org-agenda-windows
> :type 'boolean)
>
> -(defcustom org-agenda-ndays 7
> - "Number of days to include in overview display.
> +(defcustom org-agenda-ndays nil
> + "Number of days to include in overview display.
> Should be 1 or 7.
> +Obsolete, see `org-agenda-span'."
> + :group 'org-agenda-daily/weekly
> + :type 'integer)
> +
> +(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
> +
> +(defcustom org-agenda-span 'week
> + "Number of days to include in overview display.
> +Can be day, week, month, year, or any number of days.
> Custom commands can set this variable in the options section."
> :group 'org-agenda-daily/weekly
> - :type 'integer)
> + :type '(choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
The constants above need to be without quote, I think. Please fix
*and* verify.
Still more comments below.
>
> (defcustom org-agenda-start-on-weekday 1
> "Non-nil means start the overview always on the specified weekday.
> @@ -1825,19 +1842,19 @@ The following commands are available:
> ("View"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)
> + :style radio :selected (eq org-agenda-current-span 'day)
> :keys "v d (or just d)"]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)
> + :style radio :selected (eq org-agenda-current-span 'week)
> :keys "v w (or just w)"]
> ["Month View" org-agenda-month-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(28 29 30 31))
> + :style radio :selected (eq org-agenda-current-span 'month)
> :keys "v m"]
> ["Year View" org-agenda-year-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(365 366))
> + :style radio :selected (eq org-agenda-current-span 'year)
> :keys "v y"]
> "--"
> ["Include Diary" org-agenda-toggle-diary
> @@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days
> without any entries."
> (defvar org-agenda-last-arguments nil
> "The arguments of the previous call to `org-agenda'.")
> (defvar org-starting-day nil) ; local variable in the agenda buffer
> -(defvar org-agenda-span nil) ; local variable in the agenda buffer
> +(defvar org-agenda-current-span nil
> + "The current span used in the agenda view.") ; local variable in
> the agenda buffer
> (defvar org-include-all-loc nil) ; local variable
>
> (defvar org-agenda-entry-types
> '(:deadline :scheduled :timestamp :sexp)
> @@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining
> what is included in
> the daily/weekly agenda, see `org-agenda-skip-function'.")
>
> ;;;###autoload
> -(defun org-agenda-list (&optional include-all start-day ndays)
> +(defun org-agenda-list (&optional include-all start-day span)
> "Produce a daily/weekly view from all files in variable `org-
> agenda-files'.
> The view will be for the current day or week, but from the overview
> buffer
> you will be able to go to other days/weeks.
> @@ -3371,35 +3389,36 @@ This feature is considered obsolete, please
> use the TODO list or a block
> agenda instead.
>
> With a numeric prefix argument in an interactive call, the agenda will
> -span INCLUDE-ALL days. Lisp programs should instead specify NDAYS
> to change
> -the number of days. NDAYS defaults to `org-agenda-ndays'.
> +span INCLUDE-ALL days. Lisp programs should instead specify SPAN
> to change
> +the number of days. SPAN defaults to `org-agenda-span'.
>
> START-DAY defaults to TODAY, or to the most recent match for the
> weekday
> given in `org-agenda-start-on-weekday'."
> (interactive "P")
> (if (and (integerp include-all) (> include-all 0))
> - (setq ndays include-all include-all nil))
> - (setq ndays (or ndays org-agenda-ndays)
> - start-day (or start-day org-agenda-start-day))
> + (setq span include-all include-all nil))
> + (setq start-day (or start-day org-agenda-start-day))
> (if org-agenda-overriding-arguments
> (setq include-all (car org-agenda-overriding-arguments)
> start-day (nth 1 org-agenda-overriding-arguments)
> - ndays (nth 2 org-agenda-overriding-arguments)))
> + span (nth 2 org-agenda-overriding-arguments)))
> (if (stringp start-day)
> ;; Convert to an absolute day number
> (setq start-day (time-to-days (org-read-date nil t start-day))))
> - (setq org-agenda-last-arguments (list include-all start-day ndays))
> + (setq org-agenda-last-arguments (list include-all start-day span))
> (org-compile-prefix-format 'agenda)
> (org-set-sorting-strategy 'agenda)
> - (let* ((org-agenda-start-on-weekday
> - (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-
> ndays)))
> - org-agenda-start-on-weekday nil))
> - (thefiles (org-agenda-files nil 'ifmode))
> - (files thefiles)
> + (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays
> org-agenda-span)))
> (today (org-agenda-today))
> (sd (or start-day today))
> + (ndays (org-agenda-span-to-ndays span sd))
> + (org-agenda-start-on-weekday
> + (if (eq ndays 7)
> + org-agenda-start-on-weekday))
> + (thefiles (org-agenda-files nil 'ifmode))
> + (files thefiles)
> (start (if (or (null org-agenda-start-on-weekday)
> - (< org-agenda-ndays 7))
> + (< ndays 7))
> sd
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> @@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
> (day-numbers (list start))
> (day-cnt 0)
> (inhibit-redisplay (not debug-on-error))
> - s e rtn rtnall file date d start-pos end-pos todayp nd
> + s e rtn rtnall file date d start-pos end-pos todayp
> clocktable-start clocktable-end filter)
> (setq org-agenda-redo-command
> - (list 'org-agenda-list (list 'quote include-all) start-day ndays))
> - ;; Make the list of days
> - (setq ndays (or ndays org-agenda-ndays)
> - nd ndays)
> - (while (> ndays 1)
> - (push (1+ (car day-numbers)) day-numbers)
> - (setq ndays (1- ndays)))
> + (list 'org-agenda-list (list 'quote include-all) start-day (list
> 'quote span)))
> + (dotimes (n (1- ndays))
> + (push (1+ (car day-numbers)) day-numbers))
> (setq day-numbers (nreverse day-numbers))
> (setq clocktable-start (car day-numbers)
> clocktable-end (1+ (or (org-last day-numbers) 0)))
> (org-prepare-agenda "Day/Week")
> (org-set-local 'org-starting-day (car day-numbers))
> (org-set-local 'org-include-all-loc include-all)
> - (org-set-local 'org-agenda-span
> - (org-agenda-ndays-to-span nd))
> + (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-
> span span))
> (when (and (or include-all org-agenda-include-all-todo)
> (member today day-numbers))
> (setq files thefiles
> @@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
> (if org-agenda-overriding-header
> (insert (org-add-props (copy-sequence org-agenda-overriding-
> header)
> nil 'face 'org-agenda-structure) "\n")
> - (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
> + (insert (org-agenda-span-name span)
> "-agenda"
> (if (< (- d2 d1) 350)
> (if (= w1 w2)
> @@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
> (if rtnall (insert
> (org-finalize-agenda-entries
> (org-agenda-add-time-grid-maybe
> - rtnall nd todayp))
> + rtnall ndays todayp))
> "\n"))
> (put-text-property s (1- (point)) 'day d)
> (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
> @@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
> (message "")))
>
> (defun org-agenda-ndays-to-span (n)
> - (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
> + "Return a span symbol for a span of N days, or N if none matches."
> + (cond ((symbolp n) n)
> + ((= n 1) 'day)
> + ((= n 7) 'week)
> + (t n)))
> +
> +(defun org-agenda-span-to-ndays (span start-day)
> + "Return ndays from SPAN starting at START-DAY."
> + (cond ((numberp span) span)
> + ((eq span 'day) 1)
> + ((eq span 'week) 7)
> + ((eq span 'month)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (calendar-last-day-of-month (car date) (caddr date))))
> + ((eq span 'year)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (if (calendar-leap-year-p (caddr date)) 366 365)))))
> +
> +(defun org-agenda-span-name (span)
> + "Return a SPAN name."
> + (if (null span)
> + ""
> + (if (symbolp span)
> + (capitalize (symbol-name span))
> + (format "%d days" span))))
>
> ;;; Agenda word search
>
> @@ -6000,11 +6038,9 @@ Negative selection means regexp must not
> match for selection of an entry."
> (cond
> (tdpos (goto-char tdpos))
> ((eq org-agenda-type 'agenda)
> - (let* ((sd (org-agenda-today))
> - (comp (org-agenda-compute-time-span sd org-agenda-span))
> + (let* ((sd (org-agenda-compute-starting-span (org-agenda-
> today) (or org-agenda-ndays org-agenda-span)))
> (org-agenda-overriding-arguments org-agenda-last-arguments))
> - (setf (nth 1 org-agenda-overriding-arguments) (car comp))
> - (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
> + (setf (nth 1 org-agenda-overriding-arguments) sd)
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda)))
> (t (error "Cannot find today")))))
> @@ -6021,28 +6057,28 @@ Negative selection means regexp must not
> match for selection of an entry."
> With prefix ARG, go forward that many times the current span."
> (interactive "p")
> (org-agenda-check-type t 'agenda)
> - (let* ((span org-agenda-span)
> + (let* ((span org-agenda-current-span)
> (sd org-starting-day)
> (greg (calendar-gregorian-from-absolute sd))
> (cnt (org-get-at-bol 'org-day-cnt))
> - greg2 nd)
> + greg2)
> (cond
> ((eq span 'day)
> - (setq sd (+ arg sd) nd 1))
> + (setq sd (+ arg sd)))
> ((eq span 'week)
> - (setq sd (+ (* 7 arg) sd) nd 7))
> + (setq sd (+ (* 7 arg) sd)))
> ((eq span 'month)
> (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar greg2 (1+ (car greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
> + (setcar greg2 (1+ (car greg2))))
> ((eq span 'year)
> (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
> + (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
> + (t
> + (setq sd (+ (* span arg) sd))))
> (let ((org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments) sd nd t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda cnt))))
>
> @@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times
> the current span."
> "Switch to daily view for agenda.
> With argument DAY-OF-YEAR, switch to that day of the year."
> (interactive "P")
> - (setq org-agenda-ndays 1)
> (org-agenda-change-time-span 'day day-of-year))
> (defun org-agenda-week-view (&optional iso-week)
> "Switch to daily view for agenda.
> @@ -6095,7 +6130,6 @@ week. Any digits before this encode a year.
> So 200712 means
> week 12 of year 2007. Years in the range 1938-2037 can also be
> written as 2-digit years."
> (interactive "P")
> - (setq org-agenda-ndays 7)
> (org-agenda-change-time-span 'week iso-week))
> (defun org-agenda-month-view (&optional month)
> "Switch to monthly view for agenda.
> @@ -6120,70 +6154,61 @@ written as 2-digit years."
> "Change the agenda view to SPAN.
> SPAN may be `day', `week', `month', `year'."
> (org-agenda-check-type t 'agenda)
> - (if (and (not n) (equal org-agenda-span span))
> + (if (and (not n) (equal org-agenda-current-span span))
> (error "Viewing span is already \"%s\"" span))
> (let* ((sd (or (org-get-at-bol 'day)
> org-starting-day))
> - (computed (org-agenda-compute-time-span sd span n))
> + (sd (org-agenda-compute-starting-span sd span n))
> (org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments)
> - (car computed) (cdr computed) t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda))
> (org-agenda-set-mode-name)
> (message "Switched to %s view" span))
>
> -(defun org-agenda-compute-time-span (sd span &optional n)
> - "Compute starting date and number of days for agenda.
> +(defun org-agenda-compute-starting-span (sd span &optional n)
> + "Compute starting date for agenda.
> SPAN may be `day', `week', `month', `year'. The return value
> is a cons cell with the starting date and the number of days,
> so that the date SD will be in that range."
> (let* ((greg (calendar-gregorian-from-absolute sd))
> (dg (nth 1 greg))
> (mg (car greg))
> - (yg (nth 2 greg))
> - nd w1 y1 m1 thisweek)
> + (yg (nth 2 greg)))
> (cond
> ((eq span 'day)
> (when n
> (setq sd (+ (calendar-absolute-from-gregorian
> (list mg 1 yg))
> - n -1)))
> - (setq nd 1))
> + n -1))))
> ((eq span 'week)
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> (d (if org-agenda-start-on-weekday
> (- nt org-agenda-start-on-weekday)
> - 0)))
> + 0))
> + y1)
> (setq sd (- sd (+ (if (< d 0) 7 0) d)))
> (when n
> (require 'cal-iso)
> - (setq thisweek (car (calendar-iso-from-absolute sd)))
> (when (> n 99)
> (setq y1 (org-small-year-to-year (/ n 100))
> n (mod n 100)))
> (setq sd
> (calendar-absolute-from-iso
> (list n 1
> - (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
> - (setq nd 7)))
> + (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
> ((eq span 'month)
> - (when (and n (> n 99))
> - (setq y1 (org-small-year-to-year (/ n 100))
> - n (mod n 100)))
> - (setq sd (calendar-absolute-from-gregorian
> - (list (or n mg) 1 (or y1 yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list (1+ (or n mg)) 1 (or y1 yg)))
> - sd)))
> + (let (y1)
> + (when (and n (> n 99))
> + (setq y1 (org-small-year-to-year (/ n 100))
> + n (mod n 100)))
> + (setq sd (calendar-absolute-from-gregorian
> + (list (or n mg) 1 (or y1 yg))))))
> ((eq span 'year)
> (setq sd (calendar-absolute-from-gregorian
> - (list 1 1 (or n yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list 1 1 (1+ (or n yg))))
> - sd))))
> - (cons sd nd)))
> + (list 1 1 (or n yg))))))
> + sd))
>
> (defun org-agenda-next-date-line (&optional arg)
> "Jump to the next line indicating a date in agenda buffer."
> @@ -6336,36 +6361,36 @@ When called with a prefix argument, include
> all archive files as well."
> (defun org-agenda-set-mode-name ()
> "Set the mode name to indicate all the small mode settings."
> (setq mode-name
> - (concat "Org-Agenda"
> - (if (get 'org-agenda-files 'org-restrict) " []" "")
> - (if (equal org-agenda-ndays 1) " Day" "")
> - (if (equal org-agenda-ndays 7) " Week" "")
> - (if org-agenda-follow-mode " Follow" "")
> - (if org-agenda-entry-text-mode " ETxt" "")
> - (if org-agenda-include-diary " Diary" "")
> - (if org-agenda-include-deadlines " Ddl" "")
> - (if org-agenda-use-time-grid " Grid" "")
> - (if (and (boundp 'org-habit-show-habits)
> - org-habit-show-habits) " Habit" "")
> - (if (consp org-agenda-show-log) " LogAll"
> - (if org-agenda-show-log " Log" ""))
> - (if (or org-agenda-filter (get 'org-agenda-filter
> - :preset-filter))
> - (concat " {" (mapconcat
> - 'identity
> - (append (get 'org-agenda-filter
> - :preset-filter)
> - org-agenda-filter) "") "}")
> - "")
> - (if org-agenda-archives-mode
> - (if (eq org-agenda-archives-mode t)
> - " Archives"
> - (format " :%s:" org-archive-tag))
> - "")
> - (if org-agenda-clockreport-mode
> - (if (eq org-agenda-clockreport-mode 'with-filter)
> - " Clock{}" " Clock")
> - "")))
> + (list "Org-Agenda"
> + (if (get 'org-agenda-files 'org-restrict) " []" "")
> + " "
> + '(:eval (org-agenda-span-name org-agenda-current-span))
> + (if org-agenda-follow-mode " Follow" "")
> + (if org-agenda-entry-text-mode " ETxt" "")
> + (if org-agenda-include-diary " Diary" "")
> + (if org-agenda-include-deadlines " Ddl" "")
> + (if org-agenda-use-time-grid " Grid" "")
> + (if (and (boundp 'org-habit-show-habits)
> + org-habit-show-habits) " Habit" "")
> + (if (consp org-agenda-show-log) " LogAll"
> + (if org-agenda-show-log " Log" ""))
> + (if (or org-agenda-filter (get 'org-agenda-filter
> + :preset-filter))
> + (concat " {" (mapconcat
> + 'identity
> + (append (get 'org-agenda-filter
> + :preset-filter)
> + org-agenda-filter) "") "}")
> + "")
> + (if org-agenda-archives-mode
> + (if (eq org-agenda-archives-mode t)
> + " Archives"
> + (format " :%s:" org-archive-tag))
> + "")
> + (if org-agenda-clockreport-mode
> + (if (eq org-agenda-clockreport-mode 'with-filter)
> + " Clock{}" " Clock")
> + "")))
> (force-mode-line-update))
>
> (defun org-agenda-post-command-hook ()
> diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
> index e16c977..d18a12d 100644
> --- a/lisp/org-mouse.el
> +++ b/lisp/org-mouse.el
> @@ -1100,10 +1100,10 @@ This means, between the beginning of line
> and the point."
> "--"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)]
> + :style radio :selected (eq org-agenda-current-span 'day)]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)]
> + :style radio :selected (eq org-agenda-current-span 'week)]
> "--"
> ["Show Logbook entries" org-agenda-log-mode
> :style toggle :selected org-agenda-show-log
> --
> 1.7.2.3
>
>
> --
> Julien Danjou
> // ᐰ <julien@danjou.info> http://julien.danjou.info
- Carsten
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 10:06 ` Carsten Dominik
@ 2010-12-03 11:50 ` Julien Danjou
2010-12-03 12:09 ` [Accepted] " Carsten Dominik
0 siblings, 1 reply; 17+ messages in thread
From: Julien Danjou @ 2010-12-03 11:50 UTC (permalink / raw)
To: Carsten Dominik; +Cc: Bernt Hansen, Eric S Fraga, emacs-orgmode
[-- Attachment #1.1.1: Type: text/plain, Size: 562 bytes --]
On Fri, Dec 03 2010, Carsten Dominik wrote:
> please see comments below and resubmit.
Ok.
> Somewhere in the docs, there should be a reference to the older
> variable, with an index entry and a mention that the other variable
> should be used instead. I believe that many people have
> org-agenda-ndays in there config, in multiple places
> (in custom commands...)
Done, I've added a paragraph about that.
> When you resubmit, please make sure that the extensive explanation you
> had earlier is part of the commit message.
I think it's ok.
Here it is.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-org-agenda-rework-ndays-and-span-handling.patch --]
[-- Type: text/x-diff, Size: 24758 bytes --]
From decbd6fdab2211c435dd174b84c3945c6aaf6346 Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Fri, 26 Nov 2010 14:22:17 +0100
Subject: [PATCH] org-agenda: rework ndays and span handling
* org-agenda.el (org-agenda-custom-commands-local-options):
Allow org-agenda-span to be a symbol.
(org-agenda-ndays): Make obsolete.
(org-agenda-span): New variable superseding org-agenda-ndays.
(org-agenda-menu): Use org-agenda-current-span.
(org-agenda-current-span): New local variable storing current
span.
(org-agenda-list): Take a span instead of ndays as argument.
This function is now responsible for computing the ndays based
on span.
(org-agenda-ndays-to-span): Return span only if number of days
really matches.
(org-agenda-span-to-ndays): New function.
(org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
(org-agenda-goto-today): Use org-agenda-compute-starting-span.
(org-agenda-later): Do not give compute a new span, use the
current one.
(org-agenda-day-view, org-agenda-week-view)
(org-agenda-month-view, org-agenda-year-view): Stop touching
org-agenda-ndays.
(org-agenda-change-time-span): Only compute starting-span.
(org-agenda-compute-starting-span): New function derived from
the old org-agenda-compute-time-span.
(org-agenda-set-mode-name): Compute mode based on
org-agenda-current-span.
(org-agenda-span-name): New function.
* org-mouse.el: Replace Replace org-agenda-ndays by
org-agenda-current-span.
* org.texi, orgguide.texi: Replace org-agenda-ndays by
org-agenda-span. Add a paragraph about org-agenda-span and say that
org-agenda-ndays is now deprecated.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
doc/org.texi | 21 +++--
doc/orgguide.texi | 6 +-
lisp/org-agenda.el | 243 +++++++++++++++++++++++++++++-----------------------
lisp/org-mouse.el | 4 +-
4 files changed, 152 insertions(+), 122 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index e2e9af5..159191f 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6966,16 +6966,22 @@ paper agenda, showing all the tasks for the current week or day.
@table @kbd
@cindex org-agenda, command
@orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
Compile an agenda for the current week from a list of Org files. The agenda
shows the entries for each day. With a numeric prefix@footnote{For backward
compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
listed before the agenda. This feature is deprecated, use the dedicated TODO
list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
-C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+C-c a a}) you may set the number of days to be displayed.
@end table
+@vindex org-agenda-span
+@vindex org-agenda-ndays
+The default number of days displayed in the agenda is set by the variable
+@code{org-agenda-span} (or the obsolete @code{org-agenda-ndays}). This
+variable can be set to any number of days you want to see by default in the
+agenda, or to a span name, such a @code{day}, @code{week}, @code{month} or
+@code{year}.
+
Remote editing from the agenda buffer means, for example, that you can
change the dates of deadlines and appointments from the agenda buffer.
The commands available in the Agenda buffer are listed in @ref{Agenda
@@ -7621,10 +7627,9 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
be mapped to the interval 1938-2037.
@c
@orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+Go forward in time to display the following @code{org-agenda-current-span} days.
For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
@c
@orgcmd{b,org-agenda-earlier}
Go backward in time to display earlier dates.
@@ -8369,7 +8374,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
system you use, please check the FAQ for examples.}
@example
emacs -eval '(org-batch-store-agenda-views \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-start-day "2007-11-01" \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
@@ -14033,7 +14038,7 @@ You may also modify parameters on the fly like this:
@example
emacs -batch -l ~/.emacs \
-eval '(org-batch-agenda "a" \
- org-agenda-ndays 30 \
+ org-agenda-span month \
org-agenda-include-diary nil \
org-agenda-files (quote ("~/org/project.org")))' \
| lpr
diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index b67f7f1..690111b 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -1931,9 +1931,9 @@ Delete other windows.
Switch to day/week view.
@c
@item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days. For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days. For example, if the display covers a
+week, switch to the following/previous week.
@c
@item .
Go to today.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index c339f60..a4d59a2 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
(const org-agenda-prefix-format :value " %-12:c%?-12t% s")
(string))
(list :tag "Number of days in agenda"
- (const org-agenda-ndays)
- (integer :value 1))
+ (const org-agenda-span)
+ (choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(list :tag "Fixed starting date"
(const org-agenda-start-day)
(string :value "2007-11-01"))
@@ -888,12 +892,25 @@ option will be ignored."
:group 'org-agenda-windows
:type 'boolean)
-(defcustom org-agenda-ndays 7
- "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+ "Number of days to include in overview display.
Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+ :group 'org-agenda-daily/weekly
+ :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+ "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
Custom commands can set this variable in the options section."
:group 'org-agenda-daily/weekly
- :type 'integer)
+ :type '(choice (const :tag "Day" 'day)
+ (const :tag "Week" 'week)
+ (const :tag "Month" 'month)
+ (const :tag "Year" 'year)
+ (integer :tag "Custom")))
(defcustom org-agenda-start-on-weekday 1
"Non-nil means start the overview always on the specified weekday.
@@ -1825,19 +1842,19 @@ The following commands are available:
("View"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)
+ :style radio :selected (eq org-agenda-current-span 'day)
:keys "v d (or just d)"]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)
+ :style radio :selected (eq org-agenda-current-span 'week)
:keys "v w (or just w)"]
["Month View" org-agenda-month-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+ :style radio :selected (eq org-agenda-current-span 'month)
:keys "v m"]
["Year View" org-agenda-year-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (member org-agenda-ndays '(365 366))
+ :style radio :selected (eq org-agenda-current-span 'year)
:keys "v y"]
"--"
["Include Diary" org-agenda-toggle-diary
@@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
(defvar org-agenda-last-arguments nil
"The arguments of the previous call to `org-agenda'.")
(defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+ "The current span used in the agenda view.") ; local variable in the agenda buffer
(defvar org-include-all-loc nil) ; local variable
(defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
the daily/weekly agenda, see `org-agenda-skip-function'.")
;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
"Produce a daily/weekly view from all files in variable `org-agenda-files'.
The view will be for the current day or week, but from the overview buffer
you will be able to go to other days/weeks.
@@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
agenda instead.
With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
-the number of days. NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
+the number of days. SPAN defaults to `org-agenda-span'.
START-DAY defaults to TODAY, or to the most recent match for the weekday
given in `org-agenda-start-on-weekday'."
(interactive "P")
(if (and (integerp include-all) (> include-all 0))
- (setq ndays include-all include-all nil))
- (setq ndays (or ndays org-agenda-ndays)
- start-day (or start-day org-agenda-start-day))
+ (setq span include-all include-all nil))
+ (setq start-day (or start-day org-agenda-start-day))
(if org-agenda-overriding-arguments
(setq include-all (car org-agenda-overriding-arguments)
start-day (nth 1 org-agenda-overriding-arguments)
- ndays (nth 2 org-agenda-overriding-arguments)))
+ span (nth 2 org-agenda-overriding-arguments)))
(if (stringp start-day)
;; Convert to an absolute day number
(setq start-day (time-to-days (org-read-date nil t start-day))))
- (setq org-agenda-last-arguments (list include-all start-day ndays))
+ (setq org-agenda-last-arguments (list include-all start-day span))
(org-compile-prefix-format 'agenda)
(org-set-sorting-strategy 'agenda)
- (let* ((org-agenda-start-on-weekday
- (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
- org-agenda-start-on-weekday nil))
- (thefiles (org-agenda-files nil 'ifmode))
- (files thefiles)
+ (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
(today (org-agenda-today))
(sd (or start-day today))
+ (ndays (org-agenda-span-to-ndays span sd))
+ (org-agenda-start-on-weekday
+ (if (eq ndays 7)
+ org-agenda-start-on-weekday))
+ (thefiles (org-agenda-files nil 'ifmode))
+ (files thefiles)
(start (if (or (null org-agenda-start-on-weekday)
- (< org-agenda-ndays 7))
+ (< ndays 7))
sd
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
@@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
(day-numbers (list start))
(day-cnt 0)
(inhibit-redisplay (not debug-on-error))
- s e rtn rtnall file date d start-pos end-pos todayp nd
+ s e rtn rtnall file date d start-pos end-pos todayp
clocktable-start clocktable-end filter)
(setq org-agenda-redo-command
- (list 'org-agenda-list (list 'quote include-all) start-day ndays))
- ;; Make the list of days
- (setq ndays (or ndays org-agenda-ndays)
- nd ndays)
- (while (> ndays 1)
- (push (1+ (car day-numbers)) day-numbers)
- (setq ndays (1- ndays)))
+ (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+ (dotimes (n (1- ndays))
+ (push (1+ (car day-numbers)) day-numbers))
(setq day-numbers (nreverse day-numbers))
(setq clocktable-start (car day-numbers)
clocktable-end (1+ (or (org-last day-numbers) 0)))
(org-prepare-agenda "Day/Week")
(org-set-local 'org-starting-day (car day-numbers))
(org-set-local 'org-include-all-loc include-all)
- (org-set-local 'org-agenda-span
- (org-agenda-ndays-to-span nd))
+ (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
(when (and (or include-all org-agenda-include-all-todo)
(member today day-numbers))
(setq files thefiles
@@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
(if org-agenda-overriding-header
(insert (org-add-props (copy-sequence org-agenda-overriding-header)
nil 'face 'org-agenda-structure) "\n")
- (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+ (insert (org-agenda-span-name span)
"-agenda"
(if (< (- d2 d1) 350)
(if (= w1 w2)
@@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
(if rtnall (insert
(org-finalize-agenda-entries
(org-agenda-add-time-grid-maybe
- rtnall nd todayp))
+ rtnall ndays todayp))
"\n"))
(put-text-property s (1- (point)) 'day d)
(put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
(message "")))
(defun org-agenda-ndays-to-span (n)
- (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+ "Return a span symbol for a span of N days, or N if none matches."
+ (cond ((symbolp n) n)
+ ((= n 1) 'day)
+ ((= n 7) 'week)
+ (t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+ "Return ndays from SPAN starting at START-DAY."
+ (cond ((numberp span) span)
+ ((eq span 'day) 1)
+ ((eq span 'week) 7)
+ ((eq span 'month)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (calendar-last-day-of-month (car date) (caddr date))))
+ ((eq span 'year)
+ (let ((date (calendar-gregorian-from-absolute start-day)))
+ (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+ "Return a SPAN name."
+ (if (null span)
+ ""
+ (if (symbolp span)
+ (capitalize (symbol-name span))
+ (format "%d days" span))))
;;; Agenda word search
@@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
(cond
(tdpos (goto-char tdpos))
((eq org-agenda-type 'agenda)
- (let* ((sd (org-agenda-today))
- (comp (org-agenda-compute-time-span sd org-agenda-span))
+ (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
(org-agenda-overriding-arguments org-agenda-last-arguments))
- (setf (nth 1 org-agenda-overriding-arguments) (car comp))
- (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+ (setf (nth 1 org-agenda-overriding-arguments) sd)
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda)))
(t (error "Cannot find today")))))
@@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
With prefix ARG, go forward that many times the current span."
(interactive "p")
(org-agenda-check-type t 'agenda)
- (let* ((span org-agenda-span)
+ (let* ((span org-agenda-current-span)
(sd org-starting-day)
(greg (calendar-gregorian-from-absolute sd))
(cnt (org-get-at-bol 'org-day-cnt))
- greg2 nd)
+ greg2)
(cond
((eq span 'day)
- (setq sd (+ arg sd) nd 1))
+ (setq sd (+ arg sd)))
((eq span 'week)
- (setq sd (+ (* 7 arg) sd) nd 7))
+ (setq sd (+ (* 7 arg) sd)))
((eq span 'month)
(setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
sd (calendar-absolute-from-gregorian greg2))
- (setcar greg2 (1+ (car greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+ (setcar greg2 (1+ (car greg2))))
((eq span 'year)
(setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
sd (calendar-absolute-from-gregorian greg2))
- (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
- (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+ (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+ (t
+ (setq sd (+ (* span arg) sd))))
(let ((org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments) sd nd t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda cnt))))
@@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
"Switch to daily view for agenda.
With argument DAY-OF-YEAR, switch to that day of the year."
(interactive "P")
- (setq org-agenda-ndays 1)
(org-agenda-change-time-span 'day day-of-year))
(defun org-agenda-week-view (&optional iso-week)
"Switch to daily view for agenda.
@@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
week 12 of year 2007. Years in the range 1938-2037 can also be
written as 2-digit years."
(interactive "P")
- (setq org-agenda-ndays 7)
(org-agenda-change-time-span 'week iso-week))
(defun org-agenda-month-view (&optional month)
"Switch to monthly view for agenda.
@@ -6120,70 +6154,61 @@ written as 2-digit years."
"Change the agenda view to SPAN.
SPAN may be `day', `week', `month', `year'."
(org-agenda-check-type t 'agenda)
- (if (and (not n) (equal org-agenda-span span))
+ (if (and (not n) (equal org-agenda-current-span span))
(error "Viewing span is already \"%s\"" span))
(let* ((sd (or (org-get-at-bol 'day)
org-starting-day))
- (computed (org-agenda-compute-time-span sd span n))
+ (sd (org-agenda-compute-starting-span sd span n))
(org-agenda-overriding-arguments
- (list (car org-agenda-last-arguments)
- (car computed) (cdr computed) t)))
+ (list (car org-agenda-last-arguments) sd span t)))
(org-agenda-redo)
(org-agenda-find-same-or-today-or-agenda))
(org-agenda-set-mode-name)
(message "Switched to %s view" span))
-(defun org-agenda-compute-time-span (sd span &optional n)
- "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+ "Compute starting date for agenda.
SPAN may be `day', `week', `month', `year'. The return value
is a cons cell with the starting date and the number of days,
so that the date SD will be in that range."
(let* ((greg (calendar-gregorian-from-absolute sd))
(dg (nth 1 greg))
(mg (car greg))
- (yg (nth 2 greg))
- nd w1 y1 m1 thisweek)
+ (yg (nth 2 greg)))
(cond
((eq span 'day)
(when n
(setq sd (+ (calendar-absolute-from-gregorian
(list mg 1 yg))
- n -1)))
- (setq nd 1))
+ n -1))))
((eq span 'week)
(let* ((nt (calendar-day-of-week
(calendar-gregorian-from-absolute sd)))
(d (if org-agenda-start-on-weekday
(- nt org-agenda-start-on-weekday)
- 0)))
+ 0))
+ y1)
(setq sd (- sd (+ (if (< d 0) 7 0) d)))
(when n
(require 'cal-iso)
- (setq thisweek (car (calendar-iso-from-absolute sd)))
(when (> n 99)
(setq y1 (org-small-year-to-year (/ n 100))
n (mod n 100)))
(setq sd
(calendar-absolute-from-iso
(list n 1
- (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
- (setq nd 7)))
+ (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
((eq span 'month)
- (when (and n (> n 99))
- (setq y1 (org-small-year-to-year (/ n 100))
- n (mod n 100)))
- (setq sd (calendar-absolute-from-gregorian
- (list (or n mg) 1 (or y1 yg)))
- nd (- (calendar-absolute-from-gregorian
- (list (1+ (or n mg)) 1 (or y1 yg)))
- sd)))
+ (let (y1)
+ (when (and n (> n 99))
+ (setq y1 (org-small-year-to-year (/ n 100))
+ n (mod n 100)))
+ (setq sd (calendar-absolute-from-gregorian
+ (list (or n mg) 1 (or y1 yg))))))
((eq span 'year)
(setq sd (calendar-absolute-from-gregorian
- (list 1 1 (or n yg)))
- nd (- (calendar-absolute-from-gregorian
- (list 1 1 (1+ (or n yg))))
- sd))))
- (cons sd nd)))
+ (list 1 1 (or n yg))))))
+ sd))
(defun org-agenda-next-date-line (&optional arg)
"Jump to the next line indicating a date in agenda buffer."
@@ -6336,36 +6361,36 @@ When called with a prefix argument, include all archive files as well."
(defun org-agenda-set-mode-name ()
"Set the mode name to indicate all the small mode settings."
(setq mode-name
- (concat "Org-Agenda"
- (if (get 'org-agenda-files 'org-restrict) " []" "")
- (if (equal org-agenda-ndays 1) " Day" "")
- (if (equal org-agenda-ndays 7) " Week" "")
- (if org-agenda-follow-mode " Follow" "")
- (if org-agenda-entry-text-mode " ETxt" "")
- (if org-agenda-include-diary " Diary" "")
- (if org-agenda-include-deadlines " Ddl" "")
- (if org-agenda-use-time-grid " Grid" "")
- (if (and (boundp 'org-habit-show-habits)
- org-habit-show-habits) " Habit" "")
- (if (consp org-agenda-show-log) " LogAll"
- (if org-agenda-show-log " Log" ""))
- (if (or org-agenda-filter (get 'org-agenda-filter
- :preset-filter))
- (concat " {" (mapconcat
- 'identity
- (append (get 'org-agenda-filter
- :preset-filter)
- org-agenda-filter) "") "}")
- "")
- (if org-agenda-archives-mode
- (if (eq org-agenda-archives-mode t)
- " Archives"
- (format " :%s:" org-archive-tag))
- "")
- (if org-agenda-clockreport-mode
- (if (eq org-agenda-clockreport-mode 'with-filter)
- " Clock{}" " Clock")
- "")))
+ (list "Org-Agenda"
+ (if (get 'org-agenda-files 'org-restrict) " []" "")
+ " "
+ '(:eval (org-agenda-span-name org-agenda-current-span))
+ (if org-agenda-follow-mode " Follow" "")
+ (if org-agenda-entry-text-mode " ETxt" "")
+ (if org-agenda-include-diary " Diary" "")
+ (if org-agenda-include-deadlines " Ddl" "")
+ (if org-agenda-use-time-grid " Grid" "")
+ (if (and (boundp 'org-habit-show-habits)
+ org-habit-show-habits) " Habit" "")
+ (if (consp org-agenda-show-log) " LogAll"
+ (if org-agenda-show-log " Log" ""))
+ (if (or org-agenda-filter (get 'org-agenda-filter
+ :preset-filter))
+ (concat " {" (mapconcat
+ 'identity
+ (append (get 'org-agenda-filter
+ :preset-filter)
+ org-agenda-filter) "") "}")
+ "")
+ (if org-agenda-archives-mode
+ (if (eq org-agenda-archives-mode t)
+ " Archives"
+ (format " :%s:" org-archive-tag))
+ "")
+ (if org-agenda-clockreport-mode
+ (if (eq org-agenda-clockreport-mode 'with-filter)
+ " Clock{}" " Clock")
+ "")))
(force-mode-line-update))
(defun org-agenda-post-command-hook ()
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index e16c977..d18a12d 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
"--"
["Day View" org-agenda-day-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 1)]
+ :style radio :selected (eq org-agenda-current-span 'day)]
["Week View" org-agenda-week-view
:active (org-agenda-check-type nil 'agenda)
- :style radio :selected (equal org-agenda-ndays 7)]
+ :style radio :selected (eq org-agenda-current-span 'week)]
"--"
["Show Logbook entries" org-agenda-log-mode
:style toggle :selected org-agenda-show-log
--
1.7.2.3
[-- Attachment #1.1.3: Type: text/plain, Size: 79 bytes --]
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [Accepted] Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 11:50 ` Julien Danjou
@ 2010-12-03 12:09 ` Carsten Dominik
2010-12-06 13:27 ` Julien Danjou
0 siblings, 1 reply; 17+ messages in thread
From: Carsten Dominik @ 2010-12-03 12:09 UTC (permalink / raw)
To: emacs-orgmode
Patch 434 (http://patchwork.newartisans.com/patch/434/) is now "Accepted".
Maintainer comment: I still fixed the commit message to contain your original explanation, and the defcustom type of the new variable, here day, week etc must not be quoted. Thanks.
This relates to the following submission:
http://mid.gmane.org/%3Csa3vd3baxd1.fsf%40cigue.easter-eggs.fr%3E
Here is the original message containing the patch:
> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode] Re: [PATCH] org-agenda: rework ndays and span handling
> Date: Fri, 03 Dec 2010 16:50:50 -0000
> From: Julien Danjou <julien@danjou.info>
> X-Patchwork-Id: 434
> Message-Id: <sa3vd3baxd1.fsf@cigue.easter-eggs.fr>
> To: Carsten Dominik <carsten.dominik@gmail.com>
> Cc: Bernt Hansen <bernt@norang.ca>, Eric S Fraga <ucecesf@ucl.ac.uk>,
> emacs-orgmode@gnu.org
>
> On Fri, Dec 03 2010, Carsten Dominik wrote:
>
> > please see comments below and resubmit.
>
> Ok.
>
> > Somewhere in the docs, there should be a reference to the older
> > variable, with an index entry and a mention that the other variable
> > should be used instead. I believe that many people have
> > org-agenda-ndays in there config, in multiple places
> > (in custom commands...)
>
> Done, I've added a paragraph about that.
>
> > When you resubmit, please make sure that the extensive explanation you
> > had earlier is part of the commit message.
>
> I think it's ok.
>
> Here it is.
>
>
> >From decbd6fdab2211c435dd174b84c3945c6aaf6346 Mon Sep 17 00:00:00 2001
> From: Julien Danjou <julien@danjou.info>
> Date: Fri, 26 Nov 2010 14:22:17 +0100
> Subject: [PATCH] org-agenda: rework ndays and span handling
>
> * org-agenda.el (org-agenda-custom-commands-local-options):
> Allow org-agenda-span to be a symbol.
> (org-agenda-ndays): Make obsolete.
> (org-agenda-span): New variable superseding org-agenda-ndays.
> (org-agenda-menu): Use org-agenda-current-span.
> (org-agenda-current-span): New local variable storing current
> span.
> (org-agenda-list): Take a span instead of ndays as argument.
> This function is now responsible for computing the ndays based
> on span.
> (org-agenda-ndays-to-span): Return span only if number of days
> really matches.
> (org-agenda-span-to-ndays): New function.
> (org-agenda-manipulate-query): Use org-agenda-compute-starting-span.
> (org-agenda-goto-today): Use org-agenda-compute-starting-span.
> (org-agenda-later): Do not give compute a new span, use the
> current one.
> (org-agenda-day-view, org-agenda-week-view)
> (org-agenda-month-view, org-agenda-year-view): Stop touching
> org-agenda-ndays.
> (org-agenda-change-time-span): Only compute starting-span.
> (org-agenda-compute-starting-span): New function derived from
> the old org-agenda-compute-time-span.
> (org-agenda-set-mode-name): Compute mode based on
> org-agenda-current-span.
> (org-agenda-span-name): New function.
>
> * org-mouse.el: Replace Replace org-agenda-ndays by
> org-agenda-current-span.
>
> * org.texi, orgguide.texi: Replace org-agenda-ndays by
> org-agenda-span. Add a paragraph about org-agenda-span and say that
> org-agenda-ndays is now deprecated.
>
> Signed-off-by: Julien Danjou <julien@danjou.info>
> ---
> doc/org.texi | 21 +++--
> doc/orgguide.texi | 6 +-
> lisp/org-agenda.el | 243 +++++++++++++++++++++++++++++-----------------------
> lisp/org-mouse.el | 4 +-
> 4 files changed, 152 insertions(+), 122 deletions(-)
>
> diff --git a/doc/org.texi b/doc/org.texi
> index e2e9af5..159191f 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -6966,16 +6966,22 @@ paper agenda, showing all the tasks for the current week or day.
> @table @kbd
> @cindex org-agenda, command
> @orgcmd{C-c a a,org-agenda-list}
> -@vindex org-agenda-ndays
> Compile an agenda for the current week from a list of Org files. The agenda
> shows the entries for each day. With a numeric prefix@footnote{For backward
> compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
> listed before the agenda. This feature is deprecated, use the dedicated TODO
> list, or a block agenda instead (@pxref{Block agenda}).} (like @kbd{C-u 2 1
> -C-c a a}) you may set the number of days to be displayed (see also the
> -variable @code{org-agenda-ndays})
> +C-c a a}) you may set the number of days to be displayed.
> @end table
>
> +@vindex org-agenda-span
> +@vindex org-agenda-ndays
> +The default number of days displayed in the agenda is set by the variable
> +@code{org-agenda-span} (or the obsolete @code{org-agenda-ndays}). This
> +variable can be set to any number of days you want to see by default in the
> +agenda, or to a span name, such a @code{day}, @code{week}, @code{month} or
> +@code{year}.
> +
> Remote editing from the agenda buffer means, for example, that you can
> change the dates of deadlines and appointments from the agenda buffer.
> The commands available in the Agenda buffer are listed in @ref{Agenda
> @@ -7621,10 +7627,9 @@ argument as well. For example, @kbd{200712 w} will jump to week 12 in
> be mapped to the interval 1938-2037.
> @c
> @orgcmd{f,org-agenda-later}
> -@vindex org-agenda-ndays
> -Go forward in time to display the following @code{org-agenda-ndays} days.
> +Go forward in time to display the following @code{org-agenda-current-span} days.
> For example, if the display covers a week, switch to the following week.
> -With prefix arg, go forward that many times @code{org-agenda-ndays} days.
> +With prefix arg, go forward that many times @code{org-agenda-current-span} days.
> @c
> @orgcmd{b,org-agenda-earlier}
> Go backward in time to display earlier dates.
> @@ -8369,7 +8374,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
> system you use, please check the FAQ for examples.}
> @example
> emacs -eval '(org-batch-store-agenda-views \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-start-day "2007-11-01" \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> @@ -14033,7 +14038,7 @@ You may also modify parameters on the fly like this:
> @example
> emacs -batch -l ~/.emacs \
> -eval '(org-batch-agenda "a" \
> - org-agenda-ndays 30 \
> + org-agenda-span month \
> org-agenda-include-diary nil \
> org-agenda-files (quote ("~/org/project.org")))' \
> | lpr
> diff --git a/doc/orgguide.texi b/doc/orgguide.texi
> index b67f7f1..690111b 100644
> --- a/doc/orgguide.texi
> +++ b/doc/orgguide.texi
> @@ -1931,9 +1931,9 @@ Delete other windows.
> Switch to day/week view.
> @c
> @item f @r{and} b
> -Go forward/backward in time to display the following @code{org-agenda-ndays}
> -days. For example, if the display covers a week, switch to the
> -following/previous week.
> +Go forward/backward in time to display the following
> +@code{org-agenda-current-span} days. For example, if the display covers a
> +week, switch to the following/previous week.
> @c
> @item .
> Go to today.
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index c339f60..a4d59a2 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header. However,
> (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
> (string))
> (list :tag "Number of days in agenda"
> - (const org-agenda-ndays)
> - (integer :value 1))
> + (const org-agenda-span)
> + (choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
> (list :tag "Fixed starting date"
> (const org-agenda-start-day)
> (string :value "2007-11-01"))
> @@ -888,12 +892,25 @@ option will be ignored."
> :group 'org-agenda-windows
> :type 'boolean)
>
> -(defcustom org-agenda-ndays 7
> - "Number of days to include in overview display.
> +(defcustom org-agenda-ndays nil
> + "Number of days to include in overview display.
> Should be 1 or 7.
> +Obsolete, see `org-agenda-span'."
> + :group 'org-agenda-daily/weekly
> + :type 'integer)
> +
> +(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
> +
> +(defcustom org-agenda-span 'week
> + "Number of days to include in overview display.
> +Can be day, week, month, year, or any number of days.
> Custom commands can set this variable in the options section."
> :group 'org-agenda-daily/weekly
> - :type 'integer)
> + :type '(choice (const :tag "Day" 'day)
> + (const :tag "Week" 'week)
> + (const :tag "Month" 'month)
> + (const :tag "Year" 'year)
> + (integer :tag "Custom")))
>
> (defcustom org-agenda-start-on-weekday 1
> "Non-nil means start the overview always on the specified weekday.
> @@ -1825,19 +1842,19 @@ The following commands are available:
> ("View"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)
> + :style radio :selected (eq org-agenda-current-span 'day)
> :keys "v d (or just d)"]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)
> + :style radio :selected (eq org-agenda-current-span 'week)
> :keys "v w (or just w)"]
> ["Month View" org-agenda-month-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(28 29 30 31))
> + :style radio :selected (eq org-agenda-current-span 'month)
> :keys "v m"]
> ["Year View" org-agenda-year-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (member org-agenda-ndays '(365 366))
> + :style radio :selected (eq org-agenda-current-span 'year)
> :keys "v y"]
> "--"
> ["Include Diary" org-agenda-toggle-diary
> @@ -3323,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
> (defvar org-agenda-last-arguments nil
> "The arguments of the previous call to `org-agenda'.")
> (defvar org-starting-day nil) ; local variable in the agenda buffer
> -(defvar org-agenda-span nil) ; local variable in the agenda buffer
> +(defvar org-agenda-current-span nil
> + "The current span used in the agenda view.") ; local variable in the agenda buffer
> (defvar org-include-all-loc nil) ; local variable
>
> (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
> @@ -3360,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
> the daily/weekly agenda, see `org-agenda-skip-function'.")
>
> ;;;###autoload
> -(defun org-agenda-list (&optional include-all start-day ndays)
> +(defun org-agenda-list (&optional include-all start-day span)
> "Produce a daily/weekly view from all files in variable `org-agenda-files'.
> The view will be for the current day or week, but from the overview buffer
> you will be able to go to other days/weeks.
> @@ -3371,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
> agenda instead.
>
> With a numeric prefix argument in an interactive call, the agenda will
> -span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
> -the number of days. NDAYS defaults to `org-agenda-ndays'.
> +span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
> +the number of days. SPAN defaults to `org-agenda-span'.
>
> START-DAY defaults to TODAY, or to the most recent match for the weekday
> given in `org-agenda-start-on-weekday'."
> (interactive "P")
> (if (and (integerp include-all) (> include-all 0))
> - (setq ndays include-all include-all nil))
> - (setq ndays (or ndays org-agenda-ndays)
> - start-day (or start-day org-agenda-start-day))
> + (setq span include-all include-all nil))
> + (setq start-day (or start-day org-agenda-start-day))
> (if org-agenda-overriding-arguments
> (setq include-all (car org-agenda-overriding-arguments)
> start-day (nth 1 org-agenda-overriding-arguments)
> - ndays (nth 2 org-agenda-overriding-arguments)))
> + span (nth 2 org-agenda-overriding-arguments)))
> (if (stringp start-day)
> ;; Convert to an absolute day number
> (setq start-day (time-to-days (org-read-date nil t start-day))))
> - (setq org-agenda-last-arguments (list include-all start-day ndays))
> + (setq org-agenda-last-arguments (list include-all start-day span))
> (org-compile-prefix-format 'agenda)
> (org-set-sorting-strategy 'agenda)
> - (let* ((org-agenda-start-on-weekday
> - (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
> - org-agenda-start-on-weekday nil))
> - (thefiles (org-agenda-files nil 'ifmode))
> - (files thefiles)
> + (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
> (today (org-agenda-today))
> (sd (or start-day today))
> + (ndays (org-agenda-span-to-ndays span sd))
> + (org-agenda-start-on-weekday
> + (if (eq ndays 7)
> + org-agenda-start-on-weekday))
> + (thefiles (org-agenda-files nil 'ifmode))
> + (files thefiles)
> (start (if (or (null org-agenda-start-on-weekday)
> - (< org-agenda-ndays 7))
> + (< ndays 7))
> sd
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> @@ -3409,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
> (day-numbers (list start))
> (day-cnt 0)
> (inhibit-redisplay (not debug-on-error))
> - s e rtn rtnall file date d start-pos end-pos todayp nd
> + s e rtn rtnall file date d start-pos end-pos todayp
> clocktable-start clocktable-end filter)
> (setq org-agenda-redo-command
> - (list 'org-agenda-list (list 'quote include-all) start-day ndays))
> - ;; Make the list of days
> - (setq ndays (or ndays org-agenda-ndays)
> - nd ndays)
> - (while (> ndays 1)
> - (push (1+ (car day-numbers)) day-numbers)
> - (setq ndays (1- ndays)))
> + (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
> + (dotimes (n (1- ndays))
> + (push (1+ (car day-numbers)) day-numbers))
> (setq day-numbers (nreverse day-numbers))
> (setq clocktable-start (car day-numbers)
> clocktable-end (1+ (or (org-last day-numbers) 0)))
> (org-prepare-agenda "Day/Week")
> (org-set-local 'org-starting-day (car day-numbers))
> (org-set-local 'org-include-all-loc include-all)
> - (org-set-local 'org-agenda-span
> - (org-agenda-ndays-to-span nd))
> + (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
> (when (and (or include-all org-agenda-include-all-todo)
> (member today day-numbers))
> (setq files thefiles
> @@ -3454,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
> (if org-agenda-overriding-header
> (insert (org-add-props (copy-sequence org-agenda-overriding-header)
> nil 'face 'org-agenda-structure) "\n")
> - (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
> + (insert (org-agenda-span-name span)
> "-agenda"
> (if (< (- d2 d1) 350)
> (if (= w1 w2)
> @@ -3519,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
> (if rtnall (insert
> (org-finalize-agenda-entries
> (org-agenda-add-time-grid-maybe
> - rtnall nd todayp))
> + rtnall ndays todayp))
> "\n"))
> (put-text-property s (1- (point)) 'day d)
> (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
> @@ -3560,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
> (message "")))
>
> (defun org-agenda-ndays-to-span (n)
> - (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
> + "Return a span symbol for a span of N days, or N if none matches."
> + (cond ((symbolp n) n)
> + ((= n 1) 'day)
> + ((= n 7) 'week)
> + (t n)))
> +
> +(defun org-agenda-span-to-ndays (span start-day)
> + "Return ndays from SPAN starting at START-DAY."
> + (cond ((numberp span) span)
> + ((eq span 'day) 1)
> + ((eq span 'week) 7)
> + ((eq span 'month)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (calendar-last-day-of-month (car date) (caddr date))))
> + ((eq span 'year)
> + (let ((date (calendar-gregorian-from-absolute start-day)))
> + (if (calendar-leap-year-p (caddr date)) 366 365)))))
> +
> +(defun org-agenda-span-name (span)
> + "Return a SPAN name."
> + (if (null span)
> + ""
> + (if (symbolp span)
> + (capitalize (symbol-name span))
> + (format "%d days" span))))
>
> ;;; Agenda word search
>
> @@ -6000,11 +6038,9 @@ Negative selection means regexp must not match for selection of an entry."
> (cond
> (tdpos (goto-char tdpos))
> ((eq org-agenda-type 'agenda)
> - (let* ((sd (org-agenda-today))
> - (comp (org-agenda-compute-time-span sd org-agenda-span))
> + (let* ((sd (org-agenda-compute-starting-span (org-agenda-today) (or org-agenda-ndays org-agenda-span)))
> (org-agenda-overriding-arguments org-agenda-last-arguments))
> - (setf (nth 1 org-agenda-overriding-arguments) (car comp))
> - (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
> + (setf (nth 1 org-agenda-overriding-arguments) sd)
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda)))
> (t (error "Cannot find today")))))
> @@ -6021,28 +6057,28 @@ Negative selection means regexp must not match for selection of an entry."
> With prefix ARG, go forward that many times the current span."
> (interactive "p")
> (org-agenda-check-type t 'agenda)
> - (let* ((span org-agenda-span)
> + (let* ((span org-agenda-current-span)
> (sd org-starting-day)
> (greg (calendar-gregorian-from-absolute sd))
> (cnt (org-get-at-bol 'org-day-cnt))
> - greg2 nd)
> + greg2)
> (cond
> ((eq span 'day)
> - (setq sd (+ arg sd) nd 1))
> + (setq sd (+ arg sd)))
> ((eq span 'week)
> - (setq sd (+ (* 7 arg) sd) nd 7))
> + (setq sd (+ (* 7 arg) sd)))
> ((eq span 'month)
> (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar greg2 (1+ (car greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
> + (setcar greg2 (1+ (car greg2))))
> ((eq span 'year)
> (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
> sd (calendar-absolute-from-gregorian greg2))
> - (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
> - (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
> + (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
> + (t
> + (setq sd (+ (* span arg) sd))))
> (let ((org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments) sd nd t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda cnt))))
>
> @@ -6085,7 +6121,6 @@ With prefix ARG, go backward that many times the current span."
> "Switch to daily view for agenda.
> With argument DAY-OF-YEAR, switch to that day of the year."
> (interactive "P")
> - (setq org-agenda-ndays 1)
> (org-agenda-change-time-span 'day day-of-year))
> (defun org-agenda-week-view (&optional iso-week)
> "Switch to daily view for agenda.
> @@ -6095,7 +6130,6 @@ week. Any digits before this encode a year. So 200712 means
> week 12 of year 2007. Years in the range 1938-2037 can also be
> written as 2-digit years."
> (interactive "P")
> - (setq org-agenda-ndays 7)
> (org-agenda-change-time-span 'week iso-week))
> (defun org-agenda-month-view (&optional month)
> "Switch to monthly view for agenda.
> @@ -6120,70 +6154,61 @@ written as 2-digit years."
> "Change the agenda view to SPAN.
> SPAN may be `day', `week', `month', `year'."
> (org-agenda-check-type t 'agenda)
> - (if (and (not n) (equal org-agenda-span span))
> + (if (and (not n) (equal org-agenda-current-span span))
> (error "Viewing span is already \"%s\"" span))
> (let* ((sd (or (org-get-at-bol 'day)
> org-starting-day))
> - (computed (org-agenda-compute-time-span sd span n))
> + (sd (org-agenda-compute-starting-span sd span n))
> (org-agenda-overriding-arguments
> - (list (car org-agenda-last-arguments)
> - (car computed) (cdr computed) t)))
> + (list (car org-agenda-last-arguments) sd span t)))
> (org-agenda-redo)
> (org-agenda-find-same-or-today-or-agenda))
> (org-agenda-set-mode-name)
> (message "Switched to %s view" span))
>
> -(defun org-agenda-compute-time-span (sd span &optional n)
> - "Compute starting date and number of days for agenda.
> +(defun org-agenda-compute-starting-span (sd span &optional n)
> + "Compute starting date for agenda.
> SPAN may be `day', `week', `month', `year'. The return value
> is a cons cell with the starting date and the number of days,
> so that the date SD will be in that range."
> (let* ((greg (calendar-gregorian-from-absolute sd))
> (dg (nth 1 greg))
> (mg (car greg))
> - (yg (nth 2 greg))
> - nd w1 y1 m1 thisweek)
> + (yg (nth 2 greg)))
> (cond
> ((eq span 'day)
> (when n
> (setq sd (+ (calendar-absolute-from-gregorian
> (list mg 1 yg))
> - n -1)))
> - (setq nd 1))
> + n -1))))
> ((eq span 'week)
> (let* ((nt (calendar-day-of-week
> (calendar-gregorian-from-absolute sd)))
> (d (if org-agenda-start-on-weekday
> (- nt org-agenda-start-on-weekday)
> - 0)))
> + 0))
> + y1)
> (setq sd (- sd (+ (if (< d 0) 7 0) d)))
> (when n
> (require 'cal-iso)
> - (setq thisweek (car (calendar-iso-from-absolute sd)))
> (when (> n 99)
> (setq y1 (org-small-year-to-year (/ n 100))
> n (mod n 100)))
> (setq sd
> (calendar-absolute-from-iso
> (list n 1
> - (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
> - (setq nd 7)))
> + (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
> ((eq span 'month)
> - (when (and n (> n 99))
> - (setq y1 (org-small-year-to-year (/ n 100))
> - n (mod n 100)))
> - (setq sd (calendar-absolute-from-gregorian
> - (list (or n mg) 1 (or y1 yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list (1+ (or n mg)) 1 (or y1 yg)))
> - sd)))
> + (let (y1)
> + (when (and n (> n 99))
> + (setq y1 (org-small-year-to-year (/ n 100))
> + n (mod n 100)))
> + (setq sd (calendar-absolute-from-gregorian
> + (list (or n mg) 1 (or y1 yg))))))
> ((eq span 'year)
> (setq sd (calendar-absolute-from-gregorian
> - (list 1 1 (or n yg)))
> - nd (- (calendar-absolute-from-gregorian
> - (list 1 1 (1+ (or n yg))))
> - sd))))
> - (cons sd nd)))
> + (list 1 1 (or n yg))))))
> + sd))
>
> (defun org-agenda-next-date-line (&optional arg)
> "Jump to the next line indicating a date in agenda buffer."
> @@ -6336,36 +6361,36 @@ When called with a prefix argument, include all archive files as well."
> (defun org-agenda-set-mode-name ()
> "Set the mode name to indicate all the small mode settings."
> (setq mode-name
> - (concat "Org-Agenda"
> - (if (get 'org-agenda-files 'org-restrict) " []" "")
> - (if (equal org-agenda-ndays 1) " Day" "")
> - (if (equal org-agenda-ndays 7) " Week" "")
> - (if org-agenda-follow-mode " Follow" "")
> - (if org-agenda-entry-text-mode " ETxt" "")
> - (if org-agenda-include-diary " Diary" "")
> - (if org-agenda-include-deadlines " Ddl" "")
> - (if org-agenda-use-time-grid " Grid" "")
> - (if (and (boundp 'org-habit-show-habits)
> - org-habit-show-habits) " Habit" "")
> - (if (consp org-agenda-show-log) " LogAll"
> - (if org-agenda-show-log " Log" ""))
> - (if (or org-agenda-filter (get 'org-agenda-filter
> - :preset-filter))
> - (concat " {" (mapconcat
> - 'identity
> - (append (get 'org-agenda-filter
> - :preset-filter)
> - org-agenda-filter) "") "}")
> - "")
> - (if org-agenda-archives-mode
> - (if (eq org-agenda-archives-mode t)
> - " Archives"
> - (format " :%s:" org-archive-tag))
> - "")
> - (if org-agenda-clockreport-mode
> - (if (eq org-agenda-clockreport-mode 'with-filter)
> - " Clock{}" " Clock")
> - "")))
> + (list "Org-Agenda"
> + (if (get 'org-agenda-files 'org-restrict) " []" "")
> + " "
> + '(:eval (org-agenda-span-name org-agenda-current-span))
> + (if org-agenda-follow-mode " Follow" "")
> + (if org-agenda-entry-text-mode " ETxt" "")
> + (if org-agenda-include-diary " Diary" "")
> + (if org-agenda-include-deadlines " Ddl" "")
> + (if org-agenda-use-time-grid " Grid" "")
> + (if (and (boundp 'org-habit-show-habits)
> + org-habit-show-habits) " Habit" "")
> + (if (consp org-agenda-show-log) " LogAll"
> + (if org-agenda-show-log " Log" ""))
> + (if (or org-agenda-filter (get 'org-agenda-filter
> + :preset-filter))
> + (concat " {" (mapconcat
> + 'identity
> + (append (get 'org-agenda-filter
> + :preset-filter)
> + org-agenda-filter) "") "}")
> + "")
> + (if org-agenda-archives-mode
> + (if (eq org-agenda-archives-mode t)
> + " Archives"
> + (format " :%s:" org-archive-tag))
> + "")
> + (if org-agenda-clockreport-mode
> + (if (eq org-agenda-clockreport-mode 'with-filter)
> + " Clock{}" " Clock")
> + "")))
> (force-mode-line-update))
>
> (defun org-agenda-post-command-hook ()
> diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
> index e16c977..d18a12d 100644
> --- a/lisp/org-mouse.el
> +++ b/lisp/org-mouse.el
> @@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
> "--"
> ["Day View" org-agenda-day-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 1)]
> + :style radio :selected (eq org-agenda-current-span 'day)]
> ["Week View" org-agenda-week-view
> :active (org-agenda-check-type nil 'agenda)
> - :style radio :selected (equal org-agenda-ndays 7)]
> + :style radio :selected (eq org-agenda-current-span 'week)]
> "--"
> ["Show Logbook entries" org-agenda-log-mode
> :style toggle :selected org-agenda-show-log
> --
> 1.7.2.3
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Accepted] Re: [PATCH] org-agenda: rework ndays and span handling
2010-12-03 12:09 ` [Accepted] " Carsten Dominik
@ 2010-12-06 13:27 ` Julien Danjou
0 siblings, 0 replies; 17+ messages in thread
From: Julien Danjou @ 2010-12-06 13:27 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 384 bytes --]
On Fri, Dec 03 2010, Carsten Dominik wrote:
> Maintainer comment: I still fixed the commit message to contain your
> original explanation.
Sorry, I misunderstand you, and had no idea I was allowed to add more
text beside the Emacs-formatted-changelog-entry part. I'll know for
the next time! :)
--
Julien Danjou
// ᐰ <julien@danjou.info> http://julien.danjou.info
[-- Attachment #1.2: Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2010-12-06 13:28 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-29 10:49 [PATCH] org-agenda: rework ndays and span handling Julien Danjou
2010-11-29 11:14 ` Carsten Dominik
2010-11-29 11:17 ` Julien Danjou
2010-11-30 23:53 ` Carsten Dominik
2010-12-01 3:59 ` Puneeth
2010-12-01 9:24 ` Julien Danjou
2010-12-01 9:48 ` Puneeth
2010-12-01 10:15 ` Eric S Fraga
2010-12-01 13:09 ` Julien Danjou
2010-12-01 14:09 ` Eric S Fraga
2010-12-03 2:11 ` Bernt Hansen
2010-12-03 8:00 ` Carsten Dominik
2010-12-03 9:30 ` Julien Danjou
2010-12-03 10:06 ` Carsten Dominik
2010-12-03 11:50 ` Julien Danjou
2010-12-03 12:09 ` [Accepted] " Carsten Dominik
2010-12-06 13:27 ` Julien Danjou
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).