6097 comments
2357 subscribers
6254 on Twitter
Subscribe! Feed reader E-mail

Proof-of-concept code for autosensing task information

(defun sacha/planner-create-task-from-buffer ()
  (interactive)
  (let ((annotation (run-hook-with-args-until-success 'planner-annotation-functions))
        (default-text "")
        task-text
        plan
        date
        (case-fold-search t))
    (setq planner-default-page
          (if (and (planner-derived-mode-p 'planner-mode)
                   (planner-page-name)
                   (not (string-match planner-date-regexp
                                      (planner-page-name))))
              (planner-page-name)
            planner-default-page))
    ;; INTERESTING CODE STARTS HERE
    (save-excursion
      (goto-char (point-min))
      (when (and (re-search-forward "^+++" nil t)
                 (re-search-forward "^@@" nil t))
        (setq default-text "Merge patch for ")))
    (setq task-text (read-string "Describe task: "
                                 default-text))
    (when (or (string-match "planner" annotation)
              (string-match "planner" task-text))
      (setq planner-default-page "PlannerModeMaintenance"))
    ;; END INTERESTING CODE
    (setq date (cond
                ;; Universal prefix means pick up from current page
                ((and current-prefix-arg
                      (derived-mode-p 'planner-mode)
                      (string-match planner-date-regexp (planner-page-name)))
                 (planner-page-name))
                ;; Date selected in calendar
                ((condition-case nil (calendar-cursor-to-date) (error nil))
                 (planner-date-to-filename (calendar-cursor-to-date)))
                ;; Prompt for date
                (t (let ((planner-expand-name-favor-future-p
                          (or planner-expand-name-favor-future-p
                              planner-task-dates-favor-future-p)))
                     (planner-read-date)))))
    (setq plan
          (if (and current-prefix-arg (planner-derived-mode-p 'planner-mode)
                   (not (string-match planner-date-regexp (planner-page-name))))
              ;; Universal prefix means pick up from current page
              (planner-page-name)
            (planner-read-non-date-page
             (planner-file-alist))))
    (planner-create-task-from-buffer task-text date plan)))

../emacs/planner-config.el

Short URL: http://sachachua.com/blog/p/2518

On This Day...

  • 2012: 2012 as a sketch — Here’s how I’d like to remember 2012. =) (See also this quick month-by-month summary) For comparison, here’s the sketch and summary [...]
  • 2011: How I used the 5-day holiday — I took Friday off because I had worked the previous weekend, so our Christmas / Boxing Day holiday turned into [...]
  • 2010: The great washing machine adventure — There’s this odd little holiday called Boxing Day right after Christmas. In Canada, it seems to be primarily celebrated through [...]
  • 2009: Meeting resolutions — I want to participate in and facilitate better meetings. Here are some resolutions I will strive towards: I will make sure [...]
  • 2007: Everything looks better
  • 2006: Games — I realized today that Nethack isn’t fun for me. I admit, I like some of it, and it’s kinda cool that [...]
  • 2006: Starting life on the lecture circuit — My dad gave a day-long seminar on photography to more than fifty photographers from Naga and surrounding areas. He’s been thinking about [...]
  • 2004: FreeBSD installation plans — I would like to install FreeBSD, just for kicks. I need a primary partition free, though. That means I’ll need to [...]
  • 2004: Waah. Bad day, code-wise — A bit of code thrashing in planner.el as I… err… committed silly mistakes. How embarrassing. I’m so, so sorry. I hope [...]
  • 2004: sacha/planner-strip-task-numbers — (defun sacha/planner-strip-task-numbers () (interactive) (while (re-search-forward "^#.\\([0-9]+\\)\\s-+.\\s-+" nil t) (replace-match "" t t nil 1)) [...]
  • 2003: Herding cats — Neko batted playfully at the USB drives dangling from my fingers as I chatted on the phone. A little too playfully, [...]
  • 2003: Oooh, one of my students is into GTK! — I’m pleasantly surprised to see one of my students exploring GTK by porting his old class projects from Java to C [...]
  • 2003: Chat with Jerome about friendship — <sigh> Sorry, encrypted; this is for me to remember, and you probably won’t want to read this anyway.
  • 2003: Christmas memories — Before I forget, let me go through a backlog of stories. Dropped by the CompSAt Christmas party and the Trend Micro [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!