2

I have created TODO/Tag match agenda view as follows,

====+=======================================================================
##### ##### ##### project dept + 3d
work:       TODO E&H TT PROBLEM in ALE                             :project:

It matches project tag and scheduled < 3days from today.

I have matched following key-binding to operate through single key in agenda itself.

⚫ Function to reschedule agenda items by a day:

(defun my/org-agenda-reschedule-week ()   
(interactive)   
  (org-agenda-date-later 1))

This function can schedule org "agenda" item by 1 day recursively.

⚫ Relevant key-bindings:

(eval-after-load "org-agenda"  
  '(progn  
    (define-key org-agenda-mode-map "m" 'my/org-agenda-reschedule-week)  
    (define-key org-agenda-mode-map "x" 'my/org-agenda-done)  
    (define-key org-agenda-mode-map "X" 'my/org-agenda-mark-done-and-add-followup)))

My problem is that the above-mentioned key-bindings do not work in todo/tag match list in agenda.

It gives this error,

----- start -----

Debugger entered--Lisp error: (error "Not allowed in tags-type agenda buffers")  
signal(error **("Not allowed in tags-type agenda buffers")**)  
error("Not allowed in %s-type agenda buffers" tags)  
org-agenda-check-type(t agenda timeline)  
org-agenda-date-later(1)  
my/org-agenda-reschedule-week()  
funcall-interactively(my/org-agenda-reschedule-week)  
call-interactively(my/org-agenda-reschedule-week nil nil)  
command-execute(my/org-agenda-reschedule-week)  

----- end -----

It says that this commands only available in scheduled agenda type buffer, not available in tags type agenda buffer.

Is there any ways to align these tag match list with scheduled agenda items ?
what is equivalent for org-agenda-date-later function in tag matched list of agenda?

2

The author of org-agenda-date-later has expressly determined that this function should not be used in an *Org Agenda* buffer created by a tags search -- e.g., by using org-tags-view.

If we examine the function at issue by typing M-x find-function RET org-agenda-date-later RET, we see that the first line of code after the interactive statement is (org-agenda-check-type t 'agenda 'timeline). As we can see, only agenda and timeline type agenda views are supported -- not tags.

So, the above-mentioned analysis explains why we cannot use org-agenda-date-later in said buffer. To the extent that another forum participant wishes to write up and test a new function that will work similar to org-agenda-date-later in a tags buffer, or modify the existing function, please feel free to do so.

In the event that anyone wishes to experiment by modifying org-agenda-date-later to support the tags view buffer, step one might be to add the 'tags symbol to the aforementioned line of code; e.g., (org-agenda-check-type t 'agenda 'timeline 'tags). I would imagine that there will be some glitches since the author of org-agenda-date-later clearly could have added that feature had he/she really wanted to.

Opinion/Guess: @lawlist opines/guesses that org-agenda-date-later does not support the tags view agenda buffer because not all entries will contain timestamps; whereas, the agenda and timeline buffers contain entries with timestamps.

  • lawlist, even after adding 'tags it doesn't works. i have to write new function to check if entry is scheduled and post that schedule it by n days in recursive manner. – nirag Dec 27 '16 at 6:28
  • thanks for logical answer. i can't upvote your answer as i am beginner with se. – nirag Dec 27 '16 at 6:31
2

Lawlist's answer has a good survey of why org-agenda-date-later won't work here. Here's the function I wrote to remedy the problem when I ran into it for myself:

(defun aph/org-agenda-date-later (arg)
  "As `org-agenda-date-later' but also work in TODO agendas.

Unlike `org-agenda-date-later', there is some question of which
timestamp to use.  If the entry contains a timestamp for today's
date, that timestamp is changed; otherwise, the first active
timestamp in the entry is changed.

Unlike `org-agenda-date-later', this command does not support
changing timestamps by increments other than days."
  ;; TODO: Make this undoable.
  (interactive "p")
  (if (org-agenda-check-type nil 'agenda 'timeline)
      (org-agenda-date-later arg)
    (let ((marker (or (org-get-at-bol 'org-marker)
                      (org-agenda-error)))
          stamp)
      (org-agenda-with-point-at-orig-entry nil 
        ;; First try today's date, then find any active timestamp.
        (unless (or (aph/org-find-timestamp nil 'active
                                            (aph/org-relative-timestamp))
                    (aph/org-find-timestamp nil 'active))
          (error "Could not find a timestamp to change"))
        (org-timestamp-up-day arg)
        (setq stamp (aph/org-timestamp-at-point)))
      (org-agenda-show-new-time marker stamp))))

In order to make this work, I have to actively search the entry text to find an appropriate timestamp (since, unlike in agenda-type agendas, the timestamp isn't part of the agenda entry information). To do so, I use the following subroutines. (Sorry there are so many of them; I find the org code is very bad about providing the end user with tools at the appropriate level of abstraction for many common tasks, so I tend to write a lot of these things.)

(defun aph/org-timestamp-at-point (&optional pos)
  "Return timestamp at point, or nil if none.

If POS is non-nil, it is used in place of point."
  (save-excursion
    (goto-char (or pos (point)))
    (when (org-at-timestamp-p)
      (match-string 0))))

(defun aph/org-find-timestamp (&optional pos type date)
  "Move point to timestamp in entry at POS, and return point.
If no timestamp is found, return nil and do not move point.

POS defaults to point if omitted.

The TYPE parameter has the same meaning as in `org-re-timestamp'
and restricts which timestamps are considered.  The
first (earliest appearing) allowable timestamp is used.

If DATE is supplied (as a timestamp), only timestamps for that
date are considered."
  (let ((target
         (save-excursion
           (save-restriction
             (widen)
             (goto-char (or pos (point)))
             (org-back-to-heading)
             (aph/org-narrow-to-entry)
             (let ((regexp (org-re-timestamp type)))
               (catch 'found
                 (while (re-search-forward regexp nil :noerror)
                   (when (or (not date)
                             (org-time=
                              (aph/org-timestamp-date-only (match-string 1))
                              (aph/org-timestamp-date-only date)))
                     (throw 'found (point))))))))))
    (when target (goto-char target))))

(defun aph/org-narrow-to-entry ()
  "Narrow buffer to current entry.

An entry is the text between a heading and the start of its first
child."
  (interactive)
  (save-excursion
    (outline-show-subtree)
    (narrow-to-region
     (progn (org-back-to-heading)        (point))
     (progn (org-next-visible-heading 1) (point)))))

(defun aph/org-timestamp-date-only (timestamp)
  "Remove time info from TIMESTAMP and return new timestamp.
TIMESTAMP is not modified."
  (replace-regexp-in-string " ?[0-9][0-9]:[0-9][0-9]" "" timestamp))

(defun aph/org-relative-timestamp (&optional days hours inactive)
  "Return a properly-formatted Org timestamp relative to today.

The timestamp differs from the current time by DAYS and HOURS;
positive values are in the future.  The hours are only included
in the timestamp if HOURS is supplied.  (To get the current
timestamp, including the hour, supply 0 for HOURS.)

The timestamp is active unless INACTIVE is non-nil."
  (let* ((format  (funcall (if hours #'cdr #'car) org-time-stamp-formats))
         (time    (current-time))
         (hours   (+ (or hours 0) (* 24 (or days 0)))))
    (cl-incf (nth 1 time) (* 60 60 hours))
    (when inactive
      (setq format (concat "[" (substring format 1 -1) "]")))
    (format-time-string format time)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.