emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs-wiki-discuss] auto-bbdb'izing?


From: Chris Parsons
Subject: Re: [emacs-wiki-discuss] auto-bbdb'izing?
Date: Thu, 10 Feb 2005 09:33:37 +0000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (windows-nt)

On the 9th of February 2005 at 16:29, Paul Lussier <pll#permabit.com> wrote:

> I often have notes or tasks which reference a person.  So I want to be
> able to turn the string 'jdoe', automatically, into something like
> [[bbdb://jdoe][John Doe]].  I'm thinking this would perhaps be bound
> to some key sequence, and could work on either the string immediately
> to the right, or left of point, depending up a prefix arg.

I've done something similar with a custom skeleton - I mark the region I
want (say the name Chris Parsons) and then hit '<f9> <f10> b' and it
bbdb-izes it:

[[bbdb://Chris.Parsons][Chris Parsons]]

It also works rather nicely in the minibuffer, so I can use it whilst
entering a task description :) If you don't need it to work in the
minibuffer, just use it with no region

See this post I made to the list on this subject last month.

http://thread.gmane.org/gmane.emacs.wiki.general/1515

> Does that make sense?  I was also thinking this same sort of behavior
> might be nice for other keywords like 'yesterday', 'today', and
> 'tomorrow'.  Such that if you needed to write one of these, you could
> then morph it into something like [[2005.02.08][yesterday]].

Here's a stab at what you want - try the function below.

It will let you mark a region of text or numbers and it will convert into a
wiki link. Just add more things to rel-days for it to recognise other
strings. Note that it'll work with "+/-<number>" also.

Note: use the following modified chrismdp/skeleton-read-or-use-region -
don't use the one from the post above as it's an old version.

--------------------------------------------------

(defun chrismdp/skeleton-read-or-use-region (prompt &optional initial-input)
 "If we have an active region, use that, else prompt for input. This is
 to allow quick input to skeleton functions, and easy minibuffer use."
(if mark-active
                (save-excursion 
                        (delete-and-extract-region (region-beginning) 
(region-end))) 
        (skeleton-read prompt initial-input)))

(defvar chrismdp/planner-skeleton-relative-day-link-default "today"
   "Defines the default value of relative day link if you don't have a
   region highlighted.")

(defvar chrismdp/planner-skeleton-relative-day-string-alist
   '(("yesterday" . -1) ("today" . 0) ("tomorrow" . 1))
   "Defines a list of strings that map to relative day offsets")

(define-skeleton chrismdp/planner-skeleton-relative-day-link
        "Insert a link to a relative day page"
  ""
        '(setq str (chrismdp/skeleton-read-or-use-region 
                "Relative day (e.g. 'yesterday' or '+2'): " "today"))
  '(setq retdate (let ((offset (if (string-match "^\\(\\-\\|\\+\\)?[0-9]+" str)
                                  (string-to-number str) (cdr 
                         (assoc str 
chrismdp/planner-skeleton-relative-day-string-alist)))))
                    (if offset (planner-calculate-date-from-day-offset 
                                   (planner-today) offset) "Unknown Date")))
        "[[" retdate "]]")

--------------------------------------------------

Egs (for today): 

M-x chrismdp/planner-skeleton-relative-day-link 10000

=> [[2032.06.28]]

M-x chrismdp/planner-skeleton-relative-day-link -2

=> [[2005.02.08]]

M-x chrismdp/planner-skeleton-relative-day-link tomorrow

=> [[2005.02.11]]

Hope this is useful.
Chris

-- 
Chris Parsons
address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]