Package: vim-runtime
Version: 2:7.3.547-7
Severity: wishlist
Tags: patch

Dear Maintainer,
I am experimenting with https://github.com/mcagl/snipmate.vim (which is the
snipmate plugin, plus https://github.com/robhudson/snipmate_for_django to
handle specific django snippets).

I found that the django specific snippets are triggered when vim is aware that
I am editing a htmldjango or python.django file. The former is already taken
care of in /usr/share/vim/vim73/filetype.vim but the latter is not.

I never wrote a vimscript, so maybe the proposed patch isn't the better way to
handle this, but for me it seems to work. I used the function that distinguishes
html and htmldjango as a base for my patch.

If '.*django.*' (I thought that in the beginning of the file there will be some
import from django.something) is found in the first 20 lines of the .py file,
vim will set 'python.django' (and snipmate will expand, for example, 
model<TAB>),
otherwise it will set 'python' (and the django related snippets aren't loaded).

Kind regards,
Mark



-- System Information:
Debian Release: 7.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.5-trunk-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

vim-runtime depends on no packages.

Versions of packages vim-runtime recommends:
ii  vim-gnome [vim]  2:7.3.547-7
ii  vim-gtk [vim]    2:7.3.547-7
ii  vim-nox [vim]    2:7.3.547-7
ii  vim-tiny         2:7.3.547-7

vim-runtime suggests no packages.

-- no debconf information

-- 
. ''`.  | GPG Public Key  : 0xCD542422 - Download it from http://is.gd/fOa7Vm
: :'  : | GPG Fingerprint : 0823 A40D F31B 67A8 5621 AD32 E293 A2EB CD54 2422
`. `'`  | Powered by Debian GNU/Linux, http://www.debian.org
  `-    | Try not. Do, or do not. There is no try. - Master Yoda, TESB.
--- filetype.vim.original	2013-04-03 17:43:34.074603035 +0200
+++ filetype.vim	2013-04-03 17:47:58.595510818 +0200
@@ -1530,7 +1530,20 @@
 au BufNewFile,BufRead *.pyx,*.pxd		setf pyrex
 
 " Python
-au BufNewFile,BufRead *.py,*.pyw		setf python
+au BufNewFile,BufRead *.py,*.pyw		call s:FTpydjango()
+
+" Distinguish between Python and Django
+func! s:FTpydjango()
+  let n = 1
+  while n < 20 && n < line("$")
+    if getline(n) =~ '.*django.*'
+      setf python.django
+      return
+    endif
+    let n = n + 1
+  endwhile
+  setf python
+endfunc
 
 " Quixote (Python-based web framework)
 au BufNewFile,BufRead *.ptl			setf python

Attachment: signature.asc
Description: Digital signature

Reply via email to