Re: [O] Possibly new function to view your notes in chronological order

2011-07-18 Thread Bastien
Hi Marc-Oliver,

Marc-Oliver Ihm i...@online.de writes:

 I would like to submit the new function org-find-timestamps for
 disussion. 

Thanks for this piece of code and for this idea!

I've tested it a bit and I encourage others to test it.

I was able to create a sparse tree with inactive timestamps, 
but I was not able to display a buffer with ordered items.
I will test more carefully and give feedback/debugging.

My main reaction is: your idea/code could partially sneak into
`org-sparse-tree' by adding a new ran[g]e option, asking the 
starting and ending dates, and creating the sparse tree.

What do you think?

-- 
 Bastien



Re: [O] Possibly new function to view your notes in chronological order

2011-07-18 Thread Marc-Oliver Ihm

Hello Bastien !

Thanx for testing !

Currently I think, that this function is most useful, if applied to all 
org-buffers.
So I personally prefer the mulit-occur option, which gives me a list for all of 
my org-buffers.

Therefore I feel a bit ashamed, that this does not work for you :-/
Did you get any errors ? Anything within the *Messages* Buffer ?
Is at least an *Occur*-Buffer created ?

A guess about a possible cause:
I assume that you alread use emacs 24, whereas I still cling to emacs 23.
Maybe some details of the contents of the created *Occur*-buffer has changed,
which might have broken my code (I found that I need to rely on the contents of 
the *Occur*-buffer).
If you find that such an *Occur*-Buffer is created, when you run my function, 
would it be possible to
send it to me ?

Thanx a lot !

with kind regards, Marc-Oliver Ihm



Am 18.07.2011 10:20, schrieb Bastien:

Hi Marc-Oliver,

Marc-Oliver Ihmi...@online.de  writes:


I would like to submit the new function org-find-timestamps for
disussion.


Thanks for this piece of code and for this idea!

I've tested it a bit and I encourage others to test it.

I was able to create a sparse tree with inactive timestamps,
but I was not able to display a buffer with ordered items.
I will test more carefully and give feedback/debugging.

My main reaction is: your idea/code could partially sneak into
`org-sparse-tree' by adding a new ran[g]e option, asking the
starting and ending dates, and creating the sparse tree.

What do you think?







[O] Possibly new function to view your notes in chronological order

2011-07-17 Thread Marc-Oliver Ihm
Hello All !

I would like to submit the new function org-find-timestamps for disussion. 
Citing its documentation:


 Find inactive timestamps within a date-range and maybe sort them.

 This function can help to bring the notes, that you take within
 org-mode, into a chronological order, even if they are scattered
 among many different nodes. The result is somewhat like a diary,
 listing your notes for each successive day. Please be aware
 however: This intended usage requires, that you routinely
 insert inactive timestamps into the notes that you write.

 org-find-timstamps works by creating a regular expression to
 match a given range of dates, doing a search for it and
 displaying the results either as a sparse tree or with the help
 of occur. The original buffer is not modified.


I would be grateful to for any comments; please find the defun below.


regards, Marc




(defun org-find-timestamps ()
  Find inactive timestamps within a date-range and maybe sort them.

This function can help to bring the notes, that you take within
org-mode, into a chronological order, even if they are scattered
among many different nodes. The result is somewhat like a diary,
listing your notes for each successive day. Please be aware
however: This intended usage requires, that you routinely
insert inactive timestamps into the notes that you write.

org-find-timstamps works by creating a regular expression to
match a given range of dates, doing a search for it and
displaying the results either as a sparse tree or with the help
of occur. The original buffer is not modified.

  (interactive)
  (let ((working-buffer (get-buffer-create *org-find-timestamps working 
buffer*))
(occur-buffer-name *Occur*)
(occur-header-regex ^[0-9]+ match\\(es\\)?) ;; regexp to match for 
header-lines in *Occur* buffer
first-date 
last-date 
pretty-dates
swap-dates
(days 0) 
date-regex
position-before-year
collect-method
buff
org-buffers)
(save-window-excursion
  ;; temporary buffer for date-manipulations
  (set-buffer working-buffer)
  (erase-buffer)
  ;; ask user for date-range
  (setq first-date (org-read-date nil nil nil Starting date:  nil nil))
  (setq last-date (org-read-date nil nil nil End date:  nil nil))
  ;; swap dates, if required
  (when (string last-date first-date)
(setq swap-dates last-date)
(setq last-date first-date)
(setq first-date swap-dates))
  (setq pretty-dates (concat from  first-date  to  last-date))
  ;; construct list of dates in working buffer
  ;; loop as long we did not reach end-date
  (while (not (looking-at-p last-date))
(end-of-buffer)
;; only look for inactive timestamps
(insert [)
(setq position-before-year (point))
;; Monday is probably wrong, will be corrected below
(insert first-date  Mo]\n) 
(goto-char position-before-year)
;; advance number of days and correct day of week
(org-timestamp-change days 'day) 
(setq days (1+ days))
)
  (end-of-buffer)
  ;; transform constructed list of dates into a single, optimized regex
  (setq date-regex (regexp-opt (split-string (buffer-string) \n t)))
  ;; done with temporary buffer
  (kill-buffer working-buffer)
  )
;; ask user, which buffers to search and how to present results
(setq collect-method 
  (car (split-string (org-icompleting-read Please choose, which 
buffers to search and how to present the matches:  '(multi-occur -- all 
org-buffers, list org-occur -- this-buffer, sparse tree) nil t nil nil 
occur -- this buffer, list)))
  )
;; Perform the actual search
(save-window-excursion
  (cond ((string= collect-method occur)
 (occur date-regex)
 )
((string= collect-method org-occur)
 (if (string= major-mode org-mode)
 (org-occur date-regex)
   (error Buffer not in org-mode))
 )
((string= collect-method multi-occur)
 ;; construct list of all org-buffers
 (dolist (buff (buffer-list))
   (set-buffer buff)
   (if (string= major-mode org-mode)
   (setq org-buffers (cons buff org-buffers
 (multi-occur org-buffers date-regex)))
  )
;; Postprocessing: Optionally sort buffer with results
;; org-occur operates on the current buffer, so we cannot modify its 
results afterwards
(if (string= collect-method org-occur)
(message (concat Sparse tree with matches  pretty-dates))
  ;; switch to occur-buffer and modify it
  (if (not (get-buffer occur-buffer-name))
  (message (concat Did not find any matches  pretty-dates))
(set-buffer occur-buffer-name)
(toggle-read-only)
(goto-char