From: Francois Fleuret Date: Tue, 2 Mar 2010 20:05:57 +0000 (+0100) Subject: Added enotes/default-time-fields. X-Git-Url: https://ant.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=451cd872c40a21611618f23e0873ac18cf97c644;p=elisp.git Added enotes/default-time-fields. --- diff --git a/enotes.el b/enotes.el index 8f806b3..5870df1 100644 --- a/enotes.el +++ b/enotes.el @@ -100,6 +100,11 @@ :type 'list :group 'enotes) +(defcustom enotes/default-time-fields "6:00" + "The default values for non-specified time fields when setting a date." + :type 'string + :group 'enotes) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconst enotes/help-string " n,TAB: go to next note p,S-TAB: go to prev note @@ -417,23 +422,48 @@ heuristic. Improvements are welcome" )) (defun enotes/default-list (l default-l) - (when l (cons (or (car l) (car default-l)) (enotes/default-list (cdr l) (cdr default-l))))) + (when l (cons (or (car l) (car default-l)) + (enotes/default-list (cdr l) (cdr default-l))))) + +(defun enotes/default-time-fields () + (let ((time (decode-time (current-time)))) + (enotes/default-list + (parse-time-string enotes/default-time-fields) + `(0 0 6 1 ,(elt time 4) ,(elt time 5))) + )) (defun enotes/string-to-float-time (date) (let ((time (decode-time (current-time)))) (float-time (apply 'encode-time - (enotes/default-list (parse-time-string date) `(0 0 6 1 ,(elt time 4) ,(elt time 5))))))) + (enotes/default-list + (parse-time-string date) + (enotes/default-time-fields)))))) (defun enotes/second-to-delay (second) "Returns a string describing a delay in english" - (cond ((< second (- enotes/day-duration)) (format "%d day%s ago" (/ second -86400) (if (> (ftruncate (/ second -86400)) 1) "s" ""))) - ((< second -3600) (format "%dh ago" (/ second -3600))) - ((< second -300) (format "%dmin ago" (/ second -60))) - ((< second 0) (format "now!!!" (/ second -60))) - ((< second 3600) (format "in %dmin" (/ second 60))) - ((< second enotes/day-duration) (format "in %dh" (/ second 3600))) - ((< second enotes/month-duration) (format "in %d day%s" (/ second 86400) (if (> (ftruncate (/ second 86400)) 1) "s" ""))) - (t (format "in ~ %d month%s" (/ second 2592000) (if (> (ftruncate (/ second 2592000)) 1) "s" ""))))) + (cond ((< second (- enotes/day-duration)) + (format "%d day%s ago" + (/ second -86400) + (if (> (ftruncate (/ second -86400)) 1) + "s" ""))) + ((< second -3600) + (format "%dh ago" (/ second -3600))) + ((< second -300) + (format "%dmin ago" (/ second -60))) + ((< second 0) + (format "now!!!" (/ second -60))) + ((< second 3600) + (format "in %dmin" (/ second 60))) + ((< second enotes/day-duration) + (format "in %dh" (/ second 3600))) + ((< second enotes/month-duration) + (format "in %d day%s" (/ second 86400) + (if (> (ftruncate (/ second 86400)) 1) + "s" ""))) + (t + (format "in ~ %d month%s" (/ second 2592000) + (if (> (ftruncate (/ second 2592000)) 1) + "s" ""))))) (defun enotes/cond-propertize (cnd str prop) "Propertize STR if both CND and PROP are non-nil"