emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Possibly new function to view your notes in chronological order
@ 2011-07-17  9:03 Marc-Oliver Ihm
  2011-07-18  8:20 ` Bastien
  2011-07-22 18:43 ` New version which is compatible with emacs 24: New " Marc-Oliver Ihm
  0 siblings, 2 replies; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-07-17  9:03 UTC (permalink / raw)
  To: emacs-orgmode

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 (point-min))
            ;; beautify the occur-buffer by replacing the potentially long original regexp
            (while (search-forward (concat " for \"" date-regex "\"") nil t)
              (replace-match "" nil t))
            (goto-char (point-min))
            ;; Sort results by matching date ?
            (when (y-or-n-p "Sort results by date ? ")
              (when (string= collect-method "multi-occur")
                ;; bring all header lines ('xx matches for ..') to top of buffer, all lines with matches to bottom
                (sort-subr t
                           'forward-line
                           'end-of-line
                           ;; search-key for this sort only differentiates between header-lines and matche-lines
                           (lambda () (if (looking-at-p occur-header-regex) 2 1))
                           nil)
                )
              ;; goto first line of matches
              (goto-char (point-max))
              (search-backward-regexp occur-header-regex)
              (forward-line)
              ;; sort all matches according to date, that matched the regex
              (sort-subr t
                         'forward-line
                         'end-of-line
                         ;; search-key for this sort is date
                         (lambda () (search-forward-regexp date-regex) (match-string 0))
                         nil 
                         'string<)
              ;; pretend, that we did not modify the occur-buffer
              )
            (set-buffer-modified-p nil)
            (toggle-read-only)
            (message (concat "occur-buffer with matches " pretty-dates " (`C-h m' for help)"))
            )
          ;; switch to occur-buffer
          (if (get-buffer occur-buffer-name)
              (switch-to-buffer occur-buffer-name))
          )
        )
  )

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

* Re: Possibly new function to view your notes in chronological order
  2011-07-17  9:03 Possibly new function to view your notes in chronological order Marc-Oliver Ihm
@ 2011-07-18  8:20 ` Bastien
  2011-07-18 19:06   ` Marc-Oliver Ihm
  2011-07-18 19:11   ` Marc-Oliver Ihm
  2011-07-22 18:43 ` New version which is compatible with emacs 24: New " Marc-Oliver Ihm
  1 sibling, 2 replies; 17+ messages in thread
From: Bastien @ 2011-07-18  8:20 UTC (permalink / raw)
  To: Marc-Oliver Ihm; +Cc: emacs-orgmode

Hi Marc-Oliver,

Marc-Oliver Ihm <ihm@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

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

* Re: Possibly new function to view your notes in chronological order
  2011-07-18  8:20 ` Bastien
@ 2011-07-18 19:06   ` Marc-Oliver Ihm
  2011-07-18 19:11   ` Marc-Oliver Ihm
  1 sibling, 0 replies; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-07-18 19:06 UTC (permalink / raw)
  To: emacs-orgmode

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 Ihm<ihm@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?
>

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

* Re: Possibly new function to view your notes in chronological order
  2011-07-18  8:20 ` Bastien
  2011-07-18 19:06   ` Marc-Oliver Ihm
@ 2011-07-18 19:11   ` Marc-Oliver Ihm
  1 sibling, 0 replies; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-07-18 19:11 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: 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 Ihm<ihm@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?
>

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

* New version which is compatible with emacs 24: New function to view your notes in chronological order
  2011-07-17  9:03 Possibly new function to view your notes in chronological order Marc-Oliver Ihm
  2011-07-18  8:20 ` Bastien
@ 2011-07-22 18:43 ` Marc-Oliver Ihm
  2011-07-26 11:55   ` Bastien
  1 sibling, 1 reply; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-07-22 18:43 UTC (permalink / raw)
  To: emacs-orgmode, Bastien; +Cc: Marc-Oliver Ihm

Hello !

Unfortunately, org-find-timestamps as posted before was not compatible with emacs 24.
(More precise, it hat problems with the read-only property, that emacs 24 applies to text within the occur-buffer)

The version below is now compatible with both emacs 23 and 24.


Have fun !

with kind regards, Marc-Oliver Ihm



(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 ((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
      (with-temp-buffer
        ;; ask user for date-range
        (setq last-date (org-read-date nil nil nil "End date (or start): " nil nil))
        (setq first-date (org-read-date nil nil nil "Start date (or end): " 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)))
        )
      )
    ;; 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))
        (let ((original-inhibit-read-only inhibit-read-only))
          (unwind-protect 
              (progn
                ;; next line might be risky, so we unwind-protect it
                (setq inhibit-read-only t)
                (set-buffer occur-buffer-name)
                (goto-char (point-min))
                ;; beautify the occur-buffer by replacing the potentially long original regexp
                (while (search-forward (concat " for \"" date-regex "\"") nil t)
                  (replace-match "" nil t))
                (goto-char (point-min))
                ;; Sort results by matching date ?
                (when (y-or-n-p "Sort results by date ? ")
                  (when (string= collect-method "multi-occur")
                    ;; bring all header lines ('xx matches for ..') to top of buffer, all lines with matches to bottom
                    (sort-subr t
                               'forward-line
                               'end-of-line
                               ;; search-key for this sort only differentiates between header-lines and matche-lines
                               (lambda () (if (looking-at-p occur-header-regex) 2 1))
                               nil)
                    )
                  ;; goto first line of matches
                  (goto-char (point-max))
                  (search-backward-regexp occur-header-regex)
                  (forward-line)
                  ;; sort all matches according to date, that matched the regex
                  (sort-subr t
                             'forward-line
                             'end-of-line
                             ;; search-key for this sort is date
                             (lambda () (search-forward-regexp date-regex) (match-string 0))
                             nil 
                             'string<)
                  ;; pretend, that we did not modify the occur-buffer
                  )
                (insert "Searched " pretty-dates "\n")
                (goto-char (point-min))
                (set-buffer-modified-p nil)
                (message (concat "occur-buffer with matches " pretty-dates " (`C-h m' for help)"))
                )
            (setq inhibit-read-only original-inhibit-read-only)
            )
          )
        )
      ;; switch to occur-buffer
      (if (get-buffer occur-buffer-name)
          (switch-to-buffer occur-buffer-name))
      )
    )
  )

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

* Re: New version which is compatible with emacs 24: New function to view your notes in chronological order
  2011-07-22 18:43 ` New version which is compatible with emacs 24: New " Marc-Oliver Ihm
@ 2011-07-26 11:55   ` Bastien
  2011-07-26 19:17     ` Marc-Oliver Ihm
  0 siblings, 1 reply; 17+ messages in thread
From: Bastien @ 2011-07-26 11:55 UTC (permalink / raw)
  To: Marc-Oliver Ihm; +Cc: emacs-orgmode, Marc-Oliver Ihm

Hi Marc-Oliver,

Marc-Oliver Ihm <marc-oliver.ihm@online.de> writes:

> Unfortunately, org-find-timestamps as posted before was not compatible
> with emacs 24. (More precise, it hat problems with the read-only
> property, that emacs 24 applies to text within the occur-buffer)
>
> The version below is now compatible with both emacs 23 and 24.

Thanks for updating this function, it works okay here (Emacs 24).

One possible improvement: consider other timestamps than just 
inactive timestamps?  

As I said, part of this function can be integrated into
`org-sparse-tree' by allowing the user to be prompted for 
a range of dates, but the display of ordered timestamps
in the occur is still useful.

Thanks,

-- 
 Bastien

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

* Re: New version which is compatible with emacs 24: New function to view your notes in chronological order
  2011-07-26 11:55   ` Bastien
@ 2011-07-26 19:17     ` Marc-Oliver Ihm
  2011-07-28  7:54       ` Bastien
  0 siblings, 1 reply; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-07-26 19:17 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Marc-Oliver Ihm

Am 26.07.2011 13:55, schrieb Bastien:
> Hi Marc-Oliver,
>
> Marc-Oliver Ihm<marc-oliver.ihm@online.de>  writes:
>
>> Unfortunately, org-find-timestamps as posted before was not compatible
>> with emacs 24. (More precise, it hat problems with the read-only
>> property, that emacs 24 applies to text within the occur-buffer)
>>
>> The version below is now compatible with both emacs 23 and 24.
>
> Thanks for updating this function, it works okay here (Emacs 24).
>
> One possible improvement: consider other timestamps than just
> inactive timestamps?
>
> As I said, part of this function can be integrated into
> `org-sparse-tree' by allowing the user to be prompted for
> a range of dates, but the display of ordered timestamps
> in the occur is still useful.
>
> Thanks,
>

Hello Bastien,

Thanx for testing again !

I will try to figure out, how to patch `org-sparse-tree'.

And I will add active timestamps. Which was a think, that I have thought of before, but postponed until
someone would suggest/request this feature :-)

Cheers !

with kind regards, Marc-Oliver Ihm

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

* Re: New version which is compatible with emacs 24: New function to view your notes in chronological order
  2011-07-26 19:17     ` Marc-Oliver Ihm
@ 2011-07-28  7:54       ` Bastien
  2011-08-14 15:00         ` Progress of org-find-timestamps Marc-Oliver Ihm
  0 siblings, 1 reply; 17+ messages in thread
From: Bastien @ 2011-07-28  7:54 UTC (permalink / raw)
  To: Marc-Oliver Ihm; +Cc: emacs-orgmode, Marc-Oliver Ihm

Hi Marc-Oliver,

Marc-Oliver Ihm <marc-oliver.ihm@online.de> writes:

> Thanx for testing again !

You're welcome.

> I will try to figure out, how to patch `org-sparse-tree'.

Thanks -- let us know how it goes, and take the time to grasp 
Org's internals...

> And I will add active timestamps. Which was a think, that I have
> thought of before, but postponed until someone would suggest/request
> this feature :-)

Yep.  It will make your `org-find-timestamps' function quite useful.
Please be aware that I will spend some time and trying to create a cache
for timestamps (see recent discussions about calfw), and that such a
cache could help a lot in making your solution easier to implement.

Best,

-- 
 Bastien

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

* Progress of org-find-timestamps
  2011-07-28  7:54       ` Bastien
@ 2011-08-14 15:00         ` Marc-Oliver Ihm
  2011-08-14 15:17           ` exporting to HTML: <strong> instead of <b> for *bold text* iminet
  2011-08-14 15:22           ` *bold*text iminet
  0 siblings, 2 replies; 17+ messages in thread
From: Marc-Oliver Ihm @ 2011-08-14 15:00 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Marc-Oliver Ihm

Am 28.07.2011 09:54, schrieb Bastien:
> Hi Marc-Oliver,
> 
> Marc-Oliver Ihm<marc-oliver.ihm@online.de>  writes:
> 
>> Thanx for testing again !
> 
> You're welcome.
> 
>> I will try to figure out, how to patch `org-sparse-tree'.
> 
> Thanks -- let us know how it goes, and take the time to grasp
> Org's internals...
> 
>> And I will add active timestamps. Which was a think, that I have
>> thought of before, but postponed until someone would suggest/request
>> this feature :-)
> 
> Yep.  It will make your `org-find-timestamps' function quite useful.
> Please be aware that I will spend some time and trying to create a cache
> for timestamps (see recent discussions about calfw), and that such a
> cache could help a lot in making your solution easier to implement.
> 
> Best,
> 



Hello Bastien,


Just to keep you and the newsgroup updated :-)

Down below you will find the current version of org-find-timestamps.

It is, as you did suggest, now capable of finding active timestamps as well as inactive ones.
However, studying the code of org-sparse-tree, I realized, that it would be beneficial, to be able to
find CLOSED, SCHEDULED and DEADLINE timestamps as well. Therefore I have started to implement these features as well.
Moreover I would like to make available some of the functionality of org-find-timestamps within org-sparse-tree.

As soon as I am done with this, I will post a patch to org.el.


with kind regards, Marc-Oliver Ihm


P.s.: I realized the the features of org-sparse-tree and org-find-timestamps overlap to a considerable degree, 
although the do not share any code. This is probably a sign, that both functions should be reworked to use some 
common helper functions. This might be a secound step, once org-find-timestamps has found its way into the code ...



(defun org-find-timestamps (&optional first-date last-date buffer-name which collect-method sort)
  "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.

Argument FIRST-DATE and LAST-DATE (yyyy-mm-dd) define the range
of timestamps to search for. 

BUFFER-NAME specifies the name of the buffer to search. If nil, use 
current buffer.

WHICH (`active', `inactive' or `both'), tells which timestamps to use.

COLLECT-METHOD can be one of `org-occur', `occur' and
`multi-occur', thus telling: Which buffers to search (current or
all org-mode buffers) and how to present matches.

Results will be sorted according to SORT (either the symbol `y'
or `n'); this is only possible, if results are presented with
`occur' or `multi-occur'.

All Arguments can be `nil' (or ommitted), in which case their values are
queried interactively.

"
  (interactive)
  
  (let ((occur-buffer-name "*Occur*")
        (occur-header-regex "^[0-9]+ match\\(es\\)?") ;; regexp to match for header-lines in *Occur* buffer
        description
        swap-dates
        (days 0) 
        date-regex
        buff
        org-buffers
        )
    (if buffer-name (switch-to-buffer buffer-name))
    (save-window-excursion
      ;; ask for type of timestamp to search, if not supplied as an argument
      (cond ((null which)
             (setq which (intern-soft (car (split-string (org-icompleting-read "Please choose, which type of timestamp  to search: " '("active" "inactive" "both") nil t nil nil "inactive"))))))
            ((not (member which '(active inactive both)))
             (error "Argument `WHICH' can not be `%s'" which)))
      ;; ask for date-range, if not supplied as argument
      (or last-date (setq last-date (org-read-date nil nil nil "End date (or start): " nil nil)))
      (or first-date (setq first-date (org-read-date nil nil nil "Start date (or end): " 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))
      ;; readable description of what we searched for
      (setq description (format "%s timestamps from %s to %s in %s, %s" 
                                (if (eq which 'both) "active and inactive" (symbol-name which))
                                first-date last-date
                                (if (eq collect-method 'multi-occur) "all org-buffers" (concat "buffer " (buffer-name)))
                                (if (and (eq sort 'yes) (not (eq collect-method 'org-occur))) "sorted" "not sorted")))
      ;; temporary buffer for date-manipulations
      (with-temp-buffer
        ;; construct list of dates in working buffer, loop as long we did not reach end-date
        (while (not (looking-at-p last-date))
          (goto-char (point-max))
          ;; Type of timstamp (inactive) might be wrong, will be corrected below
          (insert "[")
          ;; Day of week (Mo) might be wrong, will be corrected below
          (insert first-date " Mo]\n") 
          (forward-line -1)
          ;; advance number of days and correct day of week
          (org-timestamp-change days 'day) 
          (setq days (1+ days))
          (when (eq which 'both)
            ;; double last timestamp
            (let (start content)
              (move-to-column 0)
              (setq start (point))
              (forward-line)
              (setq content (delete-and-extract-region start (point)))
              (insert content)
              (insert content)
              (forward-line -1)
              )
            )
          (unless (eq which 'inactive)
            ;; inserted inactive timestamp above, now we correct this
            (org-toggle-timestamp-type)
            )
          (move-to-column 1)
          )
        (goto-char (point-max))
        ;; transform constructed list of dates into a single, optimized regex
        (setq date-regex (regexp-opt (split-string (buffer-string) "\n" t)))
        )
      )
    ;; If no argument supplied, ask user, which buffers to search and how to present results 
    (or collect-method (setq collect-method (intern (car (split-string (org-icompleting-read "Please choose, which buffers to search and how to present the matches: " '("occur -- this buffer, list" "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 ((eq collect-method 'occur)
             (occur date-regex)
             )
            ((eq collect-method 'org-occur)
             (if (string= major-mode "org-mode")
                 (org-occur date-regex)
               (error "Buffer not in org-mode"))
             )
            ((eq 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))
            (t (error (format "Argument `COLLECT-METHOD' can not be `%s'" collect-method)))
            )
      )
    ;; Postprocessing: Optionally sort buffer with results
    ;; org-occur operates on the current buffer, so we cannot modify its results afterwards
    (if (eq collect-method 'org-occur)
        (message (concat "Sparse tree with " description))
      ;; switch to occur-buffer and modify it
      (if (not (get-buffer occur-buffer-name))
          (message (concat "Did not find any matches for " description))
        (let ((original-inhibit-read-only inhibit-read-only))
          (unwind-protect 
              (progn
                ;; next line might be risky, so we unwind-protect it
                (setq inhibit-read-only t)
                (set-buffer occur-buffer-name)
                (goto-char (point-min))
                ;; beautify the occur-buffer by replacing the potentially long original regexp
                (while (search-forward (concat " for \"" date-regex "\"") nil t)
                  (replace-match "" nil t))
                (goto-char (point-min))
                ;; Sort results by matching date ?
                (when (cond ((eq sort 'yes) t)
                            ((eq sort 'no) nil)
                            ((null sort) (y-or-n-p "Sort results by date ? "))
                            (t (error "Argument `SORT' can not be `%s'" sort)))
                  (when (eq collect-method 'multi-occur)
                    ;; bring all header lines ('xx matches for ..') to top of buffer, all lines with matches to bottom
                    (sort-subr t
                               'forward-line
                               'end-of-line
                               ;; search-key for this sort only differentiates between header-lines and matche-lines
                               (lambda () (if (looking-at-p occur-header-regex) 2 1))
                               nil)
                    )
                  ;; goto first line of matches
                  (goto-char (point-max))
                  (search-backward-regexp occur-header-regex)
                  (forward-line)
                  ;; sort all matches according to date, that matched the regex
                  (sort-subr t
                             'forward-line
                             'end-of-line
                             ;; search-key for this sort is date
                             (lambda () (search-forward-regexp date-regex) (substring (match-string 0) 1 -1))
                             nil 
                             'string<)
                  ;; pretend, that we did not modify the occur-buffer
                  )
                (insert (format "Searched for %s.\n" description))
                (goto-char (point-min))
                (set-buffer-modified-p nil)
                )
            (setq inhibit-read-only original-inhibit-read-only)
            )
          )
        ;; show result
        (switch-to-buffer occur-buffer-name)
        )
      )
    )
  )

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

* exporting to HTML: <strong> instead of <b> for *bold text*
  2011-08-14 15:00         ` Progress of org-find-timestamps Marc-Oliver Ihm
@ 2011-08-14 15:17           ` iminet
  2011-08-14 16:06             ` Nicolas Goaziou
  2011-08-14 16:19             ` Bastien
  2011-08-14 15:22           ` *bold*text iminet
  1 sibling, 2 replies; 17+ messages in thread
From: iminet @ 2011-08-14 15:17 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

Exporting org to HTML, is there a way to use the <strong>-tag instead of 
<b> for *bold text* and <em> instead of <i> for /italic text/?

Thanks in advance.
Bye.

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

* *bold*text
  2011-08-14 15:00         ` Progress of org-find-timestamps Marc-Oliver Ihm
  2011-08-14 15:17           ` exporting to HTML: <strong> instead of <b> for *bold text* iminet
@ 2011-08-14 15:22           ` iminet
  2011-08-14 16:20             ` *bold*text Bastien
  1 sibling, 1 reply; 17+ messages in thread
From: iminet @ 2011-08-14 15:22 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

*bold*text or /italic/text doesn't work unless you seperate those words.
You can work it around with @<b>foo@</b>bar but that'd neither be 
generic nor work on multiple export-backends.

It'd be great if that'd work =)


(Thanks to Thumper_ from #orgmode for the work-around.)


Bye.

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

* Re: exporting to HTML: <strong> instead of <b> for *bold text*
  2011-08-14 15:17           ` exporting to HTML: <strong> instead of <b> for *bold text* iminet
@ 2011-08-14 16:06             ` Nicolas Goaziou
  2011-08-14 17:18               ` iminet
  2011-08-14 16:19             ` Bastien
  1 sibling, 1 reply; 17+ messages in thread
From: Nicolas Goaziou @ 2011-08-14 16:06 UTC (permalink / raw)
  To: iminet@ymail.com; +Cc: emacs-orgmode

Hello,

"iminet@ymail.com" <iminet@ymail.com> writes:

> Exporting org to HTML, is there a way to use the <strong>-tag instead
> of <b> for *bold text* and <em> instead of <i> for /italic text/?

See `org-emphasis-alist'.


Regards,

-- 
Nicolas Goaziou

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

* Re: exporting to HTML: <strong> instead of <b> for *bold text*
  2011-08-14 15:17           ` exporting to HTML: <strong> instead of <b> for *bold text* iminet
  2011-08-14 16:06             ` Nicolas Goaziou
@ 2011-08-14 16:19             ` Bastien
  2011-08-14 17:18               ` iminet
  1 sibling, 1 reply; 17+ messages in thread
From: Bastien @ 2011-08-14 16:19 UTC (permalink / raw)
  To: iminet@ymail.com; +Cc: emacs-orgmode

"iminet@ymail.com" <iminet@ymail.com> writes:

> Exporting org to HTML, is there a way to use the <strong>-tag instead of
> <b> for *bold text* and <em> instead of <i> for /italic text/?

You want to customize `org-emphasis-alist'.

HTH,

-- 
 Bastien

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

* Re: *bold*text
  2011-08-14 15:22           ` *bold*text iminet
@ 2011-08-14 16:20             ` Bastien
  2011-08-14 17:17               ` *bold*text iminet
  0 siblings, 1 reply; 17+ messages in thread
From: Bastien @ 2011-08-14 16:20 UTC (permalink / raw)
  To: iminet@ymail.com; +Cc: emacs-orgmode

Hi,

"iminet@ymail.com" <iminet@ymail.com> writes:

> *bold*text or /italic/text doesn't work unless you seperate those words.
> You can work it around with @<b>foo@</b>bar but that'd neither be generic
> nor work on multiple export-backends.
>
> It'd be great if that'd work =)

See the docstring of `org-emphasis-regexp-components':

,----
| Components used to build the regular expression for emphasis.
| This is a list with five entries.  Terminology:  In an emphasis string
| like " *strong word* ", we call the initial space PREMATCH, the final
| space POSTMATCH, the stars MARKERS, "s" and "d" are BORDER characters
| and "trong wor" is the body.  The different components in this variable
| specify what is allowed/forbidden in each part:
| 
| pre          Chars allowed as prematch.  Beginning of line will be allowed too.
| post         Chars allowed as postmatch.  End of line will be allowed too.
| border       The chars *forbidden* as border characters.
| body-regexp  A regexp like "." to match a body character.  Don't use
|              non-shy groups here, and don't allow newline here.
| newline      The maximum number of newlines allowed in an emphasis exp.
`----

HTH,

-- 
 Bastien

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

* Re: *bold*text
  2011-08-14 16:20             ` *bold*text Bastien
@ 2011-08-14 17:17               ` iminet
  0 siblings, 0 replies; 17+ messages in thread
From: iminet @ 2011-08-14 17:17 UTC (permalink / raw)
  To: emacs-orgmode

Am 14.08.2011 18:20, schrieb Bastien:
> Hi,
>
> "iminet@ymail.com"<iminet@ymail.com>  writes:
>
>> *bold*text or /italic/text doesn't work unless you seperate those words.
>> You can work it around with @<b>foo@</b>bar but that'd neither be generic
>> nor work on multiple export-backends.
>>
>> It'd be great if that'd work =)
> See the docstring of `org-emphasis-regexp-components':
>
> ,----
> | Components used to build the regular expression for emphasis.
> | This is a list with five entries.  Terminology:  In an emphasis string
> | like " *strong word* ", we call the initial space PREMATCH, the final
> | space POSTMATCH, the stars MARKERS, "s" and "d" are BORDER characters
> | and "trong wor" is the body.  The different components in this variable
> | specify what is allowed/forbidden in each part:
> |
> | pre          Chars allowed as prematch.  Beginning of line will be allowed too.
> | post         Chars allowed as postmatch.  End of line will be allowed too.
> | border       The chars *forbidden* as border characters.
> | body-regexp  A regexp like "." to match a body character.  Don't use
> |              non-shy groups here, and don't allow newline here.
> | newline      The maximum number of newlines allowed in an emphasis exp.
> `----
>
> HTH,
>
thank you very much!

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

* Re: exporting to HTML: <strong> instead of <b> for *bold text*
  2011-08-14 16:06             ` Nicolas Goaziou
@ 2011-08-14 17:18               ` iminet
  0 siblings, 0 replies; 17+ messages in thread
From: iminet @ 2011-08-14 17:18 UTC (permalink / raw)
  To: emacs-orgmode

Am 14.08.2011 18:06, schrieb Nicolas Goaziou:
> Hello,
>
> "iminet@ymail.com"<iminet@ymail.com>  writes:
>
>> Exporting org to HTML, is there a way to use the<strong>-tag instead
>> of<b>  for *bold text* and<em>  instead of<i>  for /italic text/?
> See `org-emphasis-alist'.
>
>
> Regards,
>
thank you very much!

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

* Re: exporting to HTML: <strong> instead of <b> for *bold text*
  2011-08-14 16:19             ` Bastien
@ 2011-08-14 17:18               ` iminet
  0 siblings, 0 replies; 17+ messages in thread
From: iminet @ 2011-08-14 17:18 UTC (permalink / raw)
  To: emacs-orgmode

Am 14.08.2011 18:19, schrieb Bastien:
> "iminet@ymail.com"<iminet@ymail.com>  writes:
>
>> Exporting org to HTML, is there a way to use the<strong>-tag instead of
>> <b>  for *bold text* and<em>  instead of<i>  for /italic text/?
> You want to customize `org-emphasis-alist'.
>
> HTH,
>
thank you very much!

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

end of thread, other threads:[~2011-08-14 17:18 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-17  9:03 Possibly new function to view your notes in chronological order Marc-Oliver Ihm
2011-07-18  8:20 ` Bastien
2011-07-18 19:06   ` Marc-Oliver Ihm
2011-07-18 19:11   ` Marc-Oliver Ihm
2011-07-22 18:43 ` New version which is compatible with emacs 24: New " Marc-Oliver Ihm
2011-07-26 11:55   ` Bastien
2011-07-26 19:17     ` Marc-Oliver Ihm
2011-07-28  7:54       ` Bastien
2011-08-14 15:00         ` Progress of org-find-timestamps Marc-Oliver Ihm
2011-08-14 15:17           ` exporting to HTML: <strong> instead of <b> for *bold text* iminet
2011-08-14 16:06             ` Nicolas Goaziou
2011-08-14 17:18               ` iminet
2011-08-14 16:19             ` Bastien
2011-08-14 17:18               ` iminet
2011-08-14 15:22           ` *bold*text iminet
2011-08-14 16:20             ` *bold*text Bastien
2011-08-14 17:17               ` *bold*text iminet

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).