xaizek / vim-includefixer (License: BSLv1) (since 2018-12-07)
Vim plugin to automatically categorize and alphabetize #include headers
Commit ef8428ac05ea91fcced5350ea6be6b5e00e7fcb1

Sort paths in a structural way
That is a/a is smaller than a.h, for example.
Author: xaizek
Author date (UTC): 2016-09-03 19:56
Committer name: xaizek
Committer date (UTC): 2016-09-03 19:56
Parent(s): dec4dabd70965de12941c93d8a420846d55c1626
Signing key: 99DC5E4DB05F6BE2
Tree: 06abe93cf1abaf76fe9a4a33c56bba72075012b6
File Lines added Lines deleted
plugin/includefixer.vim 28 1
File plugin/includefixer.vim changed (mode: 100644) (index dac6348..c5fb7d0)
... ... function! s:IsCustom(list, include)
170 170 return 0 return 0
171 171 endfunction endfunction
172 172
173 function! s:IncludeCompare(i1, i2)
174 " extract paths
175 let l:i1 = substitute(a:i1, '.*["<]\([^">]\+\)[">].*', '\1', '')
176 let l:i2 = substitute(a:i2, '.*["<]\([^">]\+\)[">].*', '\1', '')
177
178 while 1
179 " check for presence of slashes in both paths
180 let l:s1 = (stridx(l:i1, '/') != -1)
181 let l:s2 = (stridx(l:i2, '/') != -1)
182 " path without slashes is greater than path with them
183 if l:s1 != l:s2
184 return l:s1 ? -1 : 1
185 endif
186
187 " extract next entries from both paths
188 let l:e1 = substitute(l:i1, '\([^/\\]\+\).*', '\1', '')
189 let l:e2 = substitute(l:i2, '\([^/\\]\+\).*', '\1', '')
190 let l:i1 = l:i1[len(l:e1) + 1:]
191 let l:i2 = l:i2[len(l:e2) + 1:]
192
193 " compare entries and exit if they differ
194 if l:e1 !=# l:e2
195 return l:e1 ># l:e2 ? 1 : -1
196 endif
197 endwhile
198 endfunction
199
173 200 function! s:WriteOut(start,list) function! s:WriteOut(start,list)
174 201 " check the list is empty " check the list is empty
175 202 if len(a:list) == 0 if len(a:list) == 0
 
... ... function! s:WriteOut(start,list)
179 206 let l:end = a:start + len(a:list) let l:end = a:start + len(a:list)
180 207
181 208 " sort the list " sort the list
182 call sort(a:list)
209 call sort(a:list, "<SID>IncludeCompare")
183 210
184 211 " write out the list and an empty line " write out the list and an empty line
185 212 call append(a:start,a:list) call append(a:start,a:list)
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vim-includefixer

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vim-includefixer

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master