Michael Olson <[EMAIL PROTECTED]> writes:
> True ... timestamps should probably need to be explicitly enabled.
> Hmm.  Perhaps a new file would be better after all.

To that end, below is a slightly updated planner-timestamp.el.  I
changed the default timestamp prefix to 'Created' and add a small bit
of documentation.  I'm happy if this can be included with planner.

;;; planner-timestamp.el --- planner extension for adding timestamps to tasks
;;
;; Author: Seth Falcon <[EMAIL PROTECTED]>
;; Date: 2006-08-23
;;
;; planner-timestamp adds a timestamp to each newly created task.
;; Here is an example:
;;
;;   #B1 _ Example task to demo timestamp {{Created:20060823}} (TaskPool)
;;
;; You can customize the prefix by setting planner-timestamp-key, the
;; default is "Created".
;;
;; To use planner-timestamp, put
;;
;;    (require 'planner-timestamp)
;;
;; in your config.  Options can be set using:
;;    M-x customize-group <RET> planner-timestamp
;;

(require 'planner)

(defgroup planner-timestamp nil
  "Planner Timestamp options."
  :prefix "planner-timestamp-"
  :group 'planner)

(defcustom planner-timestamp-add-stamp-flag t
  "If non-nil, add timestamps when creating new tasks."
  :type 'boolean
  :group 'planner-timestamp)

(defcustom planner-timestamp-key "Created"
  "String used on the left of the ':' in the timestamp"
  :type 'file
  :group 'planner-timestamp)

(defface planner-timestamp-face
  '((((class color) (background light))
     (:foreground "lightgray"))
    (t (:foreground "darkgray")))
  "Face for planner timestamp annotations."
  :group 'planner-timestamp)

(defun planner-timestamp-remove-dots (string)
  (while (string-match "\\." string)
    (setq string (replace-match "" t t string)))
  string)

(defun planner-timestamp-make-stamp ()
  (let ((stamp (planner-timestamp-remove-dots (planner-today))))
    (concat "{{" planner-timestamp-key ":" stamp "}}")))

(defun planner-timestamp-get-stamp-from-string (string)
  "Return the timestamp in found in STRING"
  (when (string-match
         (concat "{{\\("
                 planner-timestamp-key
                 "\\):\\([0-9.]+\\)}}") string)
    (cons (planner-match-string-no-properties 1 string)
          (planner-match-string-no-properties 2 string))))

(defun planner-timestamp-get-current-stamp ()
  "Return the planner timestamp on the current line."
  (planner-timestamp-get-stamp-from-string
   (buffer-substring (planner-line-beginning-position)
                     (planner-line-end-position))))

(defun planner-timestamp-add-stamp-maybe ()
  "Add timestamp if `planner-timestamp-add-stamp-flag' is non-nil."
  (when planner-timestamp-add-stamp-flag
    (planner-timestamp-add-stamp)))

(defun planner-timestamp-add-stamp ()
  "Add a timestamp to the current task if it does not have one yet.
Update the linked task page, if any."
  (interactive)
  (save-window-excursion
    (save-excursion
      (let* ((task-info (planner-current-task-info)))
        (unless (or (not task-info) (planner-timestamp-get-current-stamp))
          (planner-edit-task-description
           (concat (planner-task-description task-info) " "
                   (planner-timestamp-make-stamp))))))))

(defun planner-timestamp-highlight (beg end &optional verbose)
  "Highlight timestamps as unobtrusive, clickable text from BEG to END.
VERBOSE is ignored."
  (goto-char beg)
  (while (re-search-forward "{{[^}]+}}" end t)
    (planner-highlight-region
     (match-beginning 0)
     (match-end 0)
     'planner-timestamp 60
     (list
      'face 'planner-timestamp-face
      'intangible nil
      ))))

(defun planner-timestamp-font-setup ()
  (add-hook 'muse-colors-buffer-hook
            'planner-timestamp-highlight t t))

(add-hook 'planner-mode-hook 'planner-timestamp-font-setup)
(add-hook 'planner-create-task-hook 'planner-timestamp-add-stamp-maybe)

(provide 'planner-timestamp)



_______________________________________________
Planner-el-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/planner-el-discuss

Reply via email to