Hi,

I wrote a emacs function to automatically switch between your
controller and the template of the enclosing def you're working on.
It's not perfect but saves a *lot* of time.

It currently works with Kid templates only but I think it will work
with other template engines making some minor changes.

Just copy this into your ~/.emacs and restart emacs:
-- cut --
(defun tg-open-template nil
 "Open a Turbogears template defined by the @expose
  decorator. Otherwise switch back to 'tg-prev-file, if defined

  Author: Julio Castillo <[EMAIL PROTECTED]>"
 (interactive)
 (if (local-variable-p 'tg-prev-file)
     (find-file tg-prev-file)
   (save-excursion
     (py-beginning-of-def-or-class)
     (let ((max-pos (point)) (min-pos (point)))
       (forward-line -1)
       (while (looking-at "^\s*\\(@.*\\)?$")
         (setq min-pos (point))
         (forward-line -1)
         (beginning-of-line))
       (goto-char min-pos)
       (if (re-search-forward "template\s*=\s*\"\\(.?*\\)\"" max-pos t 1)
           (let ((template (concat (replace-regexp-in-string "\\."
"/" (match-string 1)) ".kid"))
                 (directory (file-name-directory buffer-file-name))
                 (ok t))
             (while (and ok directory (> (length directory) 0))
               (if (file-exists-p (concat directory template))
                   (let ((oldfn buffer-file-name))
                     (find-file (concat directory template))
                     (make-local-variable 'tg-prev-file)
                     (setq tg-prev-file oldfn)
                     (setq ok nil))
                 (setq directory (file-name-directory (substring
directory 0 -1))))))
         (message "No template defined for this function"))))))


(add-hook 'python-mode-hook
         '(lambda nil
            (local-set-key [(f12)] 'tg-open-template)))

(add-hook 'find-file-hook
         '(lambda nil
            (if (string= "kid" (file-name-extension buffer-file-name))
                (local-set-key [(f12)] 'tg-open-template))))

-- cut --

Now just open a controller, go to some exposed method with a kid
template and hit F12. Hit F12 and you're back to the controller!

I hope someone finds this useful.

--
Julio C.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to