help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: (Flaw in) tab completion of email addresses in mail buffer


From: Joakim Hove
Subject: Re: (Flaw in) tab completion of email addresses in mail buffer
Date: Thu, 10 Jul 2003 12:33:41 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.2 (gnu/linux)

Kaustuv <kaustuv@stanford.edu> writes:

> Hi all,
>   I wrote a elisp function, which is supposed to do the following:
> When in the mail mode pressing TAB shall either work as a normal TAB if the
> begining of the line where tab was pressed does not has string
> "To:". However if the begining of the line is "To:" then it simple calls
> bbdb-name-completion function to complete the email address.

I don't use bbdb myself - but I would be very surprised if this
functionality was not already available - others might help you with that.

> (defun bbdb-tab-complete-name 
>   "Tab complete name using BBDB database "
>   (interactive)
>   (setq p (point))
>   (beginning-of-line)
>   (setq tag (read (current-buffer)))
>   (goto-char p)
>   (if (string= tag "To:") (bbdb-complete-name)))


Use the (let ) construction to bind p locally, the current
implementation pollutes the *complete* emacs namespace with the quite
uninteresting variable p:

(let ((p (point)))
  ;; do your stuff
  ;;) ;; p goes out of scope here.
        
Have you checked the value of tag? 


I would maybe write something like

(if (save-excursion
      (beginning-of-line)
      (looking-at "^To: "))
    (bbdb-complete-name)
    (normal-tab-command))
        
C-h f to find out more about the functions/forms (save-excursion ) /
(looking-at )


> (add-hook 'mail-mode-hook  
>         (lambda ()
>           (local-set-key [(tab)] 'bbdb-tab-complete-name)))
>
> Even though I can exectue each line of the function correctly when I call
> the function as a whole I get Invalid-Function. Can some one suggest why?

I would rather bind it directly into the mail-mode-map:

(define-key mail-mode-map [(tab)] 'bbdb-tab-complete-name)


HTH - Joakim

-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/


reply via email to

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