6098 comments
2357 subscribers
6258 on Twitter
Subscribe! Feed reader E-mail

Planner support for action-lock.el

action-lock.el is part
of HOWM. The following code enables Planner-style links
_anywhere_. Add it to your ~/.emacs and use M-x action-lock-mode
to turn action locking on.

(add-to-list 'action-lock-default-rules
             (list (with-planner emacs-wiki-url-or-name-regexp)
                   'planner-action-lock-follow-name-at-point))
(setq action-lock-rules action-lock-default-rules)
(defvar planner-action-lock-default-directory planner-directory "Expand files relative to this directory.")
(defun planner-action-lock-follow-name-at-point (&optional other-window)
  (let ((link-name (match-string 0))
        (base-buffer (current-buffer))
        ;; the name of the buffer that contains the link.  check
        ;; whether buffer-name is a WikiName, else make it one
        (parent-name (or (emacs-wiki-page-name)
                         (concat "[[" (buffer-name) "]]")))
        (refresh-buffer nil))
    (with-planner
      (let ((link (emacs-wiki-wiki-link-target link-name)))
        (if (emacs-wiki-wiki-url-p link)
            (emacs-wiki-browse-url link other-window)
          ;; The name list is current since the last time the buffer was
          ;; highlighted
          (let* ((base (emacs-wiki-wiki-base link-name))
                 (file (emacs-wiki-page-file base))
                 (tag  (and (not (emacs-wiki-wiki-url-p link))
                            (emacs-wiki-wiki-tag link)))
                 (find-file-function (if other-window
                                         'find-file-other-window
                                       'find-file))
                 (parent-allowed-backlink-p
                  (not (string-match
                        emacs-wiki-exclude-backlink-parent-regexp
                        parent-name)))
                 (parent-backlink (and parent-allowed-backlink-p
				   (emacs-wiki-get-current-backlink)))
                 (newbuf
                  (funcall find-file-function
                           (or file
                               (expand-file-name
                                       base
                                       (or planner-action-lock-default-directory
                                           (and (buffer-file-name)
                                                (file-name-directory
                                                 (buffer-file-name)))
                                           default-directory)))))
                 (emacs-wiki-create-backlinks
                  (and emacs-wiki-create-backlinks parent-allowed-backlink-p))
                 (make-link-p (and emacs-wiki-create-backlinks
                                   ;; insert backlink only in new files
                                   (null file)
                                   (not (string-match
                                         emacs-wiki-exclude-backlink-regexp
                                         (emacs-wiki-page-name
                                          (buffer-file-name newbuf)))))))
            (when tag
              (goto-char (point-min))
              (re-search-forward (concat "^\\.?#" tag) nil t))
            (when refresh-buffer
              (when make-link-p
                (emacs-wiki-insert-backlink parent-name parent-backlink))
              ;; todo: is with-current-buffer necessary here?
              (with-current-buffer newbuf
                (add-hook 'after-save-hook
                          'emacs-wiki-refresh-buffers-once t t)
                ;; save the new file to avoid another backlink if the
                ;; buffer is visited again before being saved
                (when (or make-link-p
                          (and (null file)
                               (not parent-allowed-backlink-p)))
                  ;; set modified status to t: pages with excluded
                  ;; parents may not be modified, but we want to save
                  ;; anyway
                  (set-buffer-modified-p t)
                  (save-buffer))))))))))

コンピュータの知識はすべての科学」にとって基本である。 Knowledge of computers is basic to all sciences.

On Technorati: ,

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

On This Day...

  • 2012: Quantified Awesome: Analyzing my cellphone data — I’m curious about how much I use my cellphone, and for what purposes. Does it make sense to switch plans? [...]
  • 2011: Weekly review: Week ending June 18, 2011 — Tired after lots of biking, cooking, and gardening, but it’s a happy sort of tired. New hack working well: leaving [...]
  • 2011: An abundance of cilantro, now freezing in cubes; strawberries and peas — Awesome Garden Lady down the street gave us two large bunches of lettuce and a bag of cilantro, so I [...]
  • 2010: Planning ahead — I like planning ahead. Thinking through best-case scenarios and wild successes helps me clarify the decisions I need to make [...]
  • 2009: Social media and education — There’s an insightful 82-page PDF entitled Educating the Net Generation: A Handbook of Findings for Practice and Policy. Support for [...]
  • 2009: Taking the Stage: The Power of Voice — The second session in the Taking the Stage women’s leadership program I’m taking at IBM was called The Power of [...]
  • 2009: Twitter brings down walls — In addition to Twitter, YouTube has been a critical tool to spread videos from Iran when traditional media outlets have [...]
  • 2009: Weekly review: Week ending June 14, 2009 — From last week’s plans Relationships More photography, tidying up Wealth/career Give presentation on ABCs of Boomers, X, Ys, Zs (nonprofits and [...]
  • 2009: 129 summer camp ideas — J- doesn’t want to go to any camps this summer. Instead, she’ll try to come up with interesting things to [...]
  • 2009: Notes from the Social Recruiting Summit — I love being part of industry conferences outside my field. I learn so much from the sessions and the conversations, [...]
  • 2007: Monday rituals — It’s Monday! Mondays are getting easier and easier for me. My Sunday ritual of reviewing the past week and planning the next [...]
  • 2004: Got my TOEFL score back! — I got 297 out of 300. Perfect essay. Made one mistake in the listening section, though. Oh well! <laugh> It was [...]
  • 2004: More nuggets from the luser who’s trying to hit on me — Out of the Minix OS there rose the linux 0.01 kernel. If u did not used it and depend much with [...]
  • 2004: Clueless lamer — Hah. Just got a text message from someone with a high luser rating. Helo sacha. Ur a linux chiq i suppose. [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!