24 February, 2012

 

Tabbing through fields in wanderlust

I sometimes automatically press TAB, expecting to move from the To: field to the right place on the next line (the subject: field) to start typing.  Or from there a few lines down to where my e-mail should start.  The problem is, I have TAB bound to yas/expand, which falls back to the function wl-draft-mode usually has bound to tab for other completion and possibly even inserting a tab.  I think I've written the least intrusive bit of code to sit between these two and do what I want when TAB is pressed on the field lines.


    
(add-hook
 'wl-draft-mode-hook
 '(lambda ()
    ;; Key bindings
   
    (yas/minor-mode)
 
    (setq yas/fallback-behavior
          '(apply jks-draft-magic-tab))

    ))



;This function came from: http://snarfed.org/emacs_lisp_for_flowed_text_email
(defun starts-with (string prefix)
  (and (>= (length string) (length prefix))
       (equal prefix (substring string 0 (length prefix)))))



(defun jks-draft-magic-tab (&optional start-pos)
  "Try do something sensible in wl-draft-mode under various
circumstances when tab is pressed"
  (interactive)
  (let* ((orig (thing-at-point 'line))
         (typed (downcase orig)))

    (cond ((or (starts-with typed "to:") (starts-with typed "cc:") (starts-with typed "bcc:"))
           (search-forward "ect: ")) 
          ((starts-with typed "subject:")
           (search-forward "--text follows this line--\n"))
          (t (wl-complete-field-body-or-tab))))

  )

This page is powered by Blogger. Isn't yours?

Social bookmarks

Delicious

Bookmark this on Delicious

Links

Support The Commons









This site:

Free your code:

archives