[Remind-Fans] Sorting the reminders file

Gerhard Kirchmann gerhardkmn at yahoo.de
Thu Sep 16 08:58:53 EDT 2010


Am Thu, 16 Sep 2010 13:23:25 +0200
schrieb Jostein Berntsen <jbernts at broadpark.no>:

> Has anyone found a script or another way to sort the reminders file,
> so that all entries are sorted by date with the most recent at the
> end of the file? I am thinking about entries like: 
> 
> REM Sep 17 2010 MSG ...
> REM Sep 16 2010 MSG ...  
> REM Sep 15 2010 MSG ...
> REM Sep 17 2010 *1 ...
> 
> should be sorted to:
> 
> 
> REM Sep 15 2010 MSG ...
> REM Sep 16 2010 MSG ...  
> REM Sep 17 2010 *1 ...
> REM Sep 17 2010 MSG ...
> 

If you use emacs I've written a function sort-remind, which is able to
sort regions (but only those regions beginning with REM 15 SEP 2010 and
so on. Text after the year is arbitrary. Besides my routine sorts the
other way round. Anyway her it is:

;; Own sort function for REMIND
(defun keystart ()
  (buffer-substring (+ 4 (point)) (+ 15 (point)))
  )
(defun keyend ()
  (+ 15 (point))
  )
(defun monnr (monat)
  (if (string= monat "Jan") "01"
    (if (string= monat "Feb") "02" 
      (if (string= monat "Mar") "03"
	(if (string= monat "Apr") "04"
	  (if (string= monat "May") "05"
	    (if (string= monat "Jun") "06"
	      (if (string= monat "Jul") "07"
		(if (string= monat "Aug") "08"
		  (if (string= monat "Sep") "09"
		    (if (string= monat "Oct") "10"
		      (if (string= monat "Nov") "11"
			(if (string= monat "Dec") "12" "13")))))))))))))
(defun arrange-date (a)
  (let ((tag (substring a 0 2))
	(monat (monnr (substring a 3 6)))
	(jahr (substring a 7 11)))
    (concat jahr monat tag)
    )
  )

(defun sort-date (a b)
  (string< (arrange-date a) (arrange-date b))
  )

(defun sort-remind (beg end)
  "Sort Remind Dates descending."
  (interactive "r") ;r bedeutet region start und ende
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (let ;; To make `end-of-line' and etc. to ignore fields.
	  ((inhibit-field-text-motion t))
	(sort-subr t 'forward-line 
		   'end-of-line 
		   'keystart 
		   'keyend 
		   'sort-date
		   )
	)
      )
    )
  )
;; End of sort function

This routine should be in .emacs.el file and this file should contain a
line:

(provide 'sort-remind)

so you are able to call the function with M-x sort-remind.

To change the sort-order and the order of day and month is a simple
excercise.

I hope this is helpful. I use it daily.

Regards,

Gerhard Kirchmann


More information about the Remind-fans mailing list