Attached.

-- 
Antonio Terceiro <[EMAIL PROTECTED]>
http://people.softwarelivre.org/~terceiro/
GnuPG ID: 0F9CB28F


diff --git a/debian/patches/00list b/debian/patches/00list
index 6416da1..d56fec8 100644
--- a/debian/patches/00list
+++ b/debian/patches/00list
@@ -9,6 +9,7 @@ disabledby-tetris
 disabledby-themes
 disabledby-whatdomain
 disabledby-xml
+disabledby-detectindent
 git-defaults
 sokoboan_path
 usagestring-dtd2vim
diff --git a/debian/patches/disabledby-detectindent.dpatch b/debian/patches/disabledby-detectindent.dpatch
new file mode 100755
index 0000000..0b38fe1
--- /dev/null
+++ b/debian/patches/disabledby-detectindent.dpatch
@@ -0,0 +1,22 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## disabledby-detectindent.dpatch by Antonio Terceiro <[EMAIL PROTECTED]>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: No description.
+
[EMAIL PROTECTED]@
+diff -urNad vim-scripts~/plugin/detectindent.vim vim-scripts/plugin/detectindent.vim
+--- vim-scripts~/plugin/detectindent.vim	2008-03-20 19:18:45.000000000 -0300
++++ vim-scripts/plugin/detectindent.vim	2008-03-20 19:34:14.558980407 -0300
+@@ -19,6 +19,11 @@
+ "
+ " Requirements:  Untested on Vim versions below 6.2
+ 
++if exists("loaded_detectindent")
++  finish
++endif
++let loaded_detectindent = 1
++
+ fun! <SID>IsCommentStart(line)
+     " &comments isn't reliable
+     if &ft == "c" || &ft == "cpp"
diff --git a/debian/vim-scripts.status b/debian/vim-scripts.status
index b627965..db72224 100644
--- a/debian/vim-scripts.status
+++ b/debian/vim-scripts.status
@@ -389,6 +389,18 @@ email:       benw at plasticboy.com
 license:     no license
 version:     6
 
+script_name: plugin/detectindent.vim
+addon:       detectindent
+description: detects the current indentation of files
+script_url:  http://www.vim.org/scripts/script.php?script_id=1171
+author:      Ciaran McCreesh
+author_url:  http://www.vim.org/account/profile.php?user_id=4078
+email:       ciaranm at ciaranm.org
+license:     Vim's license [4], see below
+extras:      doc/detectindent.txt
+disabledby:  let loaded_detectindent = 1
+version:     1.0
+
 --
 
 Licenses referenced above
diff --git a/doc/detectindent.txt b/doc/detectindent.txt
new file mode 100644
index 0000000..526e695
--- /dev/null
+++ b/doc/detectindent.txt
@@ -0,0 +1,40 @@
+*detectindent.txt*	The Detect Indent Plugin	     1.0, Jan 04, 2005
+
+Author:  Ciaran McCreesh <ciaranm at gentoo dot org>
+
+==============================================================================
+1. Contents				*detectindent* *detectindent-contents*
+
+    1. Contents                                    |detectindent-contents|
+    2. :DetectIndent Command                               |:DetectIndent|
+	Settings                                   |detectindent-settings|
+    3. Uptime ChangeLog                                 |uptime-changelog|
+
+==============================================================================
+2. :DetectIndent Command				       *:DetectIndent*
+
+	The :DetectIndent command tries to intelligently set the 'shiftwidth',
+	'expandtab' and 'tabstop' options based upon the existing settings in
+	use in the active file.
+
+    Settings					       *detectindent-settings*
+
+	When the correct value for 'expandtab' cannot be determined, it will
+	usually retain its existing value. To specify that 'expandtab' should
+	be used where autodetection is impossible, set: >
+		:let g:detectindent_preferred_expandtab = 1
+<	in your |vimrc| file.
+
+	To set a preferred value for 'shiftwidth' and 'tabstop' when they
+	cannot be automatically detected, set: >
+		:let g:detectindent_preferred_indent = 4
+<       in your |vimrc| file.
+
+==============================================================================
+3. DetectIndent ChangeLog			      *detectindent-changelog*
+
+	v1.0 (20050105)
+	    * initial release after discussion on irc.freenode.net:#vim
+
+==============================================================================
+vim:tw=78:ts=8:ft=help
diff --git a/plugin/detectindent.vim b/plugin/detectindent.vim
new file mode 100644
index 0000000..0bc3463
--- /dev/null
+++ b/plugin/detectindent.vim
@@ -0,0 +1,127 @@
+" Name:          detectindent (global plugin)
+" Version:       1.0
+" Author:        Ciaran McCreesh <ciaranm at gentoo.org>
+" Updates:       http://dev.gentoo.org/~ciaranm/vim/
+" Purpose:       Detect file indent settings
+"
+" License:       You may redistribute this plugin under the same terms as Vim
+"                itself.
+"
+" Usage:         :DetectIndent
+"
+"                " to prefer expandtab to noexpandtab when detection is
+"                " impossible:
+"                :let g:detectindent_preferred_expandtab = 1
+"
+"                " to set a preferred indent level when detection is
+"                " impossible:
+"                :let g:detectindent_preferred_indent = 4
+"
+" Requirements:  Untested on Vim versions below 6.2
+
+fun! <SID>IsCommentStart(line)
+    " &comments isn't reliable
+    if &ft == "c" || &ft == "cpp"
+        return -1 != match(a:line, '/\*')
+    else
+        return 0
+    endif
+endfun
+
+fun! <SID>IsCommentEnd(line)
+    if &ft == "c" || &ft == "cpp"
+        return -1 != match(a:line, '\*/')
+    else
+        return 0
+    endif
+endfun
+
+fun! <SID>DetectIndent()
+    let l:has_leading_tabs            = 0
+    let l:has_leading_spaces          = 0
+    let l:shortest_leading_spaces_run = 0
+    let l:longest_leading_spaces_run  = 0
+
+    let l:idx_end = line("$")
+    let l:idx = 1
+    while l:idx <= l:idx_end
+        let l:line = getline(l:idx)
+
+        " try to skip over comment blocks, they can give really screwy indent
+        " settings in c/c++ files especially
+        if <SID>IsCommentStart(l:line)
+            while l:idx <= l:idx_end && ! <SID>IsCommentEnd(l:line)
+                let l:line = getline(l:idx)
+                let l:idx = l:idx + 1
+            endwhile
+            let l:idx = l:idx + 1
+            continue
+        endif
+
+        let l:leading_char = strpart(l:line, 0, 1)
+
+        if l:leading_char == "\t"
+            let l:has_leading_tabs = 1
+
+        elseif l:leading_char == " "
+            " only interested if we don't have a run of spaces followed by a
+            " tab.
+            if -1 == match(l:line, '^ \+\t')
+                let l:has_leading_spaces = 1
+                let l:spaces = strlen(matchstr(l:line, '^ \+'))
+                if l:shortest_leading_spaces_run == 0 ||
+                            \ l:spaces < l:shortest_leading_spaces_run
+                    let l:shortest_leading_spaces_run = l:spaces
+                endif
+                if l:spaces > l:longest_leading_spaces_run
+                    let l:longest_leading_spaces_run = l:spaces
+                endif
+            endif
+
+        endif
+
+        let l:idx = l:idx + 1
+    endwhile
+
+    if l:has_leading_tabs && ! l:has_leading_spaces
+        " tabs only, no spaces
+        set noexpandtab
+        if exists("g:detectindent_preferred_tabsize")
+            let &shiftwidth  = g:detectindent_preferred_indent
+            let &tabstop     = g:detectindent_preferred_indent
+        endif
+
+    elseif l:has_leading_spaces && ! l:has_leading_tabs
+        " spaces only, no tabs
+        set expandtab
+        let &shiftwidth  = l:shortest_leading_spaces_run
+
+    elseif l:has_leading_spaces && l:has_leading_tabs
+        " spaces and tabs
+        set noexpandtab
+        let &shiftwidth = l:shortest_leading_spaces_run
+
+        " mmmm, time to guess how big tabs are
+        if l:longest_leading_spaces_run < 2
+            let &tabstop = 2
+        elseif l:longest_leading_spaces_run < 4
+            let &tabstop = 4
+        else
+            let &tabstop = 8
+        endif
+
+    else
+        " no spaces, no tabs
+        if exists("g:detectindent_preferred_tabsize")
+            let &shiftwidth  = g:detectindent_preferred_indent
+            let &tabstop     = g:detectindent_preferred_indent
+        endif
+        if exists("g:detectindent_preferred_expandtab")
+            set expandtab
+        endif
+
+    endif
+endfun
+
+command! -nargs=0 DetectIndent call <SID>DetectIndent()
+

Reply via email to