Compare commits

...

No commits in common. "master" and "debug" have entirely different histories.

23 changed files with 161 additions and 6461 deletions

9
.gitmodules vendored
View File

@ -1,9 +0,0 @@
[submodule ".vim/bundle/Vundle.vim"]
path = .vim/bundle/Vundle.vim
url = https://github.com/gmarik/Vundle.vim.git
[submodule "ModernCppStarter"]
path = ModernCppStarter
url = https://github.com/TheLartians/ModernCppStarter
[submodule "hello-world-debian-android"]
path = hello-world-debian-android
url = https://gitlab.com/Matrixcoffee/hello-world-debian-android

@ -1 +0,0 @@
Subproject commit cfd3b2d388a8c2e9903d7a9d80a65539aabfe933

View File

@ -1,478 +0,0 @@
#
# Indentation finder, by Philippe Fremy <phil at freehackers dot org>
# Copyright 2002-2008 Philippe Fremy
#
# This program is distributed under the BSD license. You should have received
# a copy of the file LICENSE.txt along with this software.
#
import sys
import re
help = \
"""Usage : %s [ --vim-output ] [ --verbose ] file1 file2 ... fileN
Display indentation used in the list of files. Possible answers are (with X
being the number of spaces used for indentation):
space X
tab 8
mixed tab X space Y
mixed means that indentation style is tab at the beginning of the line (tab
being 8 positions) and then spaces to do the indentation, unless you reach 8
spaces which are replaced by a tab. This is the vim source file indentation
for example. In my opinion, this is the worst possible style.
--vim-output: output suitable to use inside vim:
set sts=0 | set tabstop=4 | set noexpandtab | set shiftwidth=4
"""
VERSION='1.4'
### Used when indentation is tab, to set tabstop in vim
DEFAULT_TAB_WIDTH = 8
### default values for files where indentation is not meaningful (empty files)
# possible values:
# DEFAULT_RESULT = ('space', 4 )
# DEFAULT_RESULT = ('space', 2 )
# DEFAULT_RESULT = ('space', 8 )
# DEFAULT_RESULT = ('tab', DEFAULT_TAB_WIDTH )
DEFAULT_RESULT = ('space', 8 )
VERBOSE_QUIET = 0
VERBOSE_INFO = 1
VERBOSE_DEBUG = 2
VERBOSE_DEEP_DEBUG = 3
DEFAULT_VERBOSITY = VERBOSE_QUIET
###
class LineType:
NoIndent = 'NoIndent'
SpaceOnly = 'SpaceOnly'
TabOnly = 'TabOnly'
Mixed = 'Mixed'
BeginSpace = 'BeginSpace'
def info( s ): log( VERBOSE_INFO, s )
def dbg( s ): log( VERBOSE_DEBUG, s )
def deepdbg( s ): log( VERBOSE_DEEP_DEBUG, s )
def log( level, s ):
if level <= IndentFinder.VERBOSITY:
print s
class IndentFinder:
"""
IndentFinder reports the indentation used in a source file. Its approach
is not tied to any particular language. It was tested successfully with
python, C, C++ and Java code.
How does it work ?
It scans each line of the entry file for a space character (white space or
tab) repeated until a non space character is found. Such a line
is considered to be a properly indented line of code. Blank lines and
comments line (starting with # or /* or * ) are ignored. Lines coming
after a line ending in '\\' have higher chance of being not properly
indented, and are thus ignored too.
Only the increment in indentation are fed in. Dedentation or maintaining
the same indentation is not taken into account when analysing a file. Increment
in indentation from zero indentation to some indentation is also ignored because
it's wrong in many cases (header file with many structures for example, do not always
obey the indentation of the rest of the code).
Each line is analysed as:
- SpaceOnly: indentation of more than 8 space
- TabOnly: indentation of tab only
- Mixed: indentation of tab, then less than 8 spaces
- BeginSpace: indentation of less than 8 space, that could be either a mixed indentation
or a pure space indentation.
- non-significant
Then two consecutive significant lines are then considered. The only valid combinations are:
- (NoIndent, BeginSpace) => space or mixed
- (NoIndent, Tab) => tab
- (BeginSpace, BeginSpace) => space or mixed
- (BeginSpace, SpaceOnly) => space
- (SpaceOnly, SpaceOnly) => space
- (TabOnly, TabOnly) => tab
- (TabOnly, Mixed) => mixed
- (Mixed, TabOnly) => mixed
The increment in number of spaces is then recorded.
At the end, the number of lines with space indentation, mixed space and tab indentation
are compared and a decision is made.
If no decision can be made, DEFAULT_RESULT is returned.
If IndentFinder ever reports wrong indentation, send me immediately a
mail, if possible with the offending file.
"""
def __init__(self, default_result=DEFAULT_RESULT):
self.clear()
self.default_result = default_result
VERBOSITY = DEFAULT_VERBOSITY
def parse_file_list( self, file_list ):
for fname in file_list:
self.parse_file( fname )
def parse_file( self, fname ):
f = open( fname )
l = f.readline()
while( l ):
self.analyse_line( l )
l = f.readline()
f.close()
def clear( self ):
self.lines = {}
for i in range(2,9): self.lines['space%d' % i] = 0
for i in range(2,9): self.lines['mixed%d' % i] = 0
self.lines['tab'] = 0
self.nb_processed_lines = 0
self.nb_indent_hint = 0
self.indent_re = re.compile( "^([ \t]+)([^ \t]+)" )
self.mixed_re = re.compile( "^(\t+)( +)$" )
self.skip_next_line = False
self.previous_line_info = None
def analyse_line( self, line ):
if line[-1:] == '\n':
line = line[:-1]
deepdbg( 'analyse_line: "%s"' % line.replace(' ', '.' ).replace('\t','\\t') )
self.nb_processed_lines += 1
skip_current_line = self.skip_next_line
self.skip_next_line = False
if line[-1:] == '\\':
deepdbg( 'analyse_line: Ignoring next line!' )
# skip lines after lines ending in \
self.skip_next_line = True
if skip_current_line:
deepdbg( 'analyse_line: Ignoring current line!' )
return
ret = self.analyse_line_indentation( line )
if ret:
self.nb_indent_hint += 1
deepdbg( 'analyse_line: Result of line analysis: %s' % str(ret) )
return ret
def analyse_line_type( self, line ):
'''Analyse the type of line and return (LineType, <indentation part of
the line>).
The function will reject improperly formatted lines (mixture of tab
and space for example) and comment lines.
'''
mixed_mode = False
tab_part = ''
space_part = ''
if len(line) > 0 and line[0] != ' ' and line[0] != '\t':
return (LineType.NoIndent, '')
mo = self.indent_re.match( line )
if not mo:
deepdbg( 'analyse_line_type: line is not indented' )
return None
indent_part = mo.group(1)
text_part = mo.group(2)
deepdbg( 'analyse_line_type: indent_part="%s" text_part="%s"' %
(indent_part.replace(' ', '.').replace('\t','\\t').replace('\n', '\\n' ),
text_part ) )
if text_part[0] == '*':
# continuation of a C/C++ comment, unlikely to be indented correctly
return None
if text_part[0:2] == '/*' or text_part[0] == '#':
# python, C/C++ comment, might not be indented correctly
return None
if '\t' in indent_part and ' ' in indent_part:
# mixed mode
mo = self.mixed_re.match( indent_part )
if not mo:
# line is not composed of '\t\t\t ', ignore it
return None
mixed_mode = True
tab_part = mo.group(1)
space_part = mo.group(2)
if mixed_mode:
if len(space_part) >= 8:
# this is not mixed mode, this is garbage !
return None
return (LineType.Mixed, tab_part, space_part )
if '\t' in indent_part:
return (LineType.TabOnly, indent_part)
if ' ' in indent_part:
if len(indent_part) < 8:
# this could be mixed mode too
return (LineType.BeginSpace, indent_part)
else:
# this is really a line indented with spaces
return (LineType.SpaceOnly, indent_part )
assert False, 'We should never get there !'
def analyse_line_indentation( self, line ):
previous_line_info = self.previous_line_info
current_line_info = self.analyse_line_type( line )
self.previous_line_info = current_line_info
if current_line_info == None or previous_line_info == None:
deepdbg('analyse_line_indentation: Not enough line info to analyse line: %s, %s' % (str(previous_line_info), str(current_line_info)))
return
t = (previous_line_info[0], current_line_info[0])
deepdbg( 'analyse_line_indentation: Indent analysis: %s %s' % t )
if (t == (LineType.TabOnly, LineType.TabOnly)
or t == (LineType.NoIndent, LineType.TabOnly) ):
if len(current_line_info[1]) - len(previous_line_info[1]) == 1 :
self.lines['tab'] += 1
return 'tab'
elif (t == (LineType.SpaceOnly, LineType.SpaceOnly)
or t == (LineType.BeginSpace, LineType.SpaceOnly)
or t == (LineType.NoIndent, LineType.SpaceOnly) ):
nb_space = len(current_line_info[1]) - len(previous_line_info[1])
if 1 < nb_space <= 8:
key = 'space%d' % nb_space
self.lines[key] += 1
return key
elif (t == (LineType.BeginSpace, LineType.BeginSpace)
or t == (LineType.NoIndent, LineType.BeginSpace) ):
nb_space = len(current_line_info[1]) - len(previous_line_info[1])
if 1 < nb_space <= 8:
key1 = 'space%d' % nb_space
key2 = 'mixed%d' % nb_space
self.lines[ key1 ] += 1
self.lines[ key2 ] += 1
return key1
elif t == (LineType.BeginSpace, LineType.TabOnly):
# we assume that mixed indentation used 8 characters tabs
if len(current_line_info[1]) == 1:
# more than one tab on the line --> not mixed mode !
nb_space = len(current_line_info[1])*8 - len(previous_line_info[1])
if 1 < nb_space <= 8:
key = 'mixed%d' % nb_space
self.lines[ key ] += 1
return key
elif t == (LineType.TabOnly, LineType.Mixed):
tab_part, space_part = tuple(current_line_info[1:3])
if len(previous_line_info[1]) == len(tab_part):
nb_space = len(space_part)
if 1 < nb_space <= 8:
key = 'mixed%d' % nb_space
self.lines[ key ] += 1
return key
elif t == (LineType.Mixed, LineType.TabOnly):
tab_part, space_part = previous_line_info[1:3]
if len(tab_part)+1 == len(current_line_info[1]):
nb_space = 8-len(space_part)
if 1 < nb_space <= 8:
key = 'mixed%d' % nb_space
self.lines[ key ] += 1
return key
else:
pass
return None
def results( self ):
dbg( "Nb of scanned lines : %d" % self.nb_processed_lines )
dbg( "Nb of indent hint : %d" % self.nb_indent_hint )
dbg( "Collected data:" )
for key in self.lines:
if self.lines[key] > 0:
dbg( '%s: %d' % (key, self.lines[key] ) )
max_line_space = max( [ self.lines['space%d'%i] for i in range(2,9) ] )
max_line_mixed = max( [ self.lines['mixed%d'%i] for i in range(2,9) ] )
max_line_tab = self.lines['tab']
dbg( 'max_line_space: %d' % max_line_space )
dbg( 'max_line_mixed: %d' % max_line_mixed )
dbg( 'max_line_tab: %d' % max_line_tab )
### Result analysis
#
# 1. Space indented file
# - lines indented with less than 8 space will fill mixed and space array
# - lines indented with 8 space or more will fill only the space array
# - almost no lines indented with tab
#
# => more lines with space than lines with mixed
# => more a lot more lines with space than tab
#
# 2. Tab indented file
# - most lines will be tab only
# - very few lines as mixed
# - very few lines as space only
#
# => a lot more lines with tab than lines with mixed
# => a lot more lines with tab than lines with space
#
# 3. Mixed tab/space indented file
# - some lines are tab-only (lines with exactly 8 step indentation)
# - some lines are space only (less than 8 space)
# - all other lines are mixed
#
# If mixed is tab + 2 space indentation:
# - a lot more lines with mixed than with tab
# If mixed is tab + 4 space indentation
# - as many lines with mixed than with tab
#
# If no lines exceed 8 space, there will be only lines with space
# and tab but no lines with mixed. Impossible to detect mixed indentation
# in this case, the file looks like it's actually indented as space only
# and will be detected so.
#
# => same or more lines with mixed than lines with tab only
# => same or more lines with mixed than lines with space only
#
result = None
# Detect space indented file
if max_line_space >= max_line_mixed and max_line_space > max_line_tab:
nb = 0
indent_value = None
for i in range(8,1,-1):
if self.lines['space%d'%i] > int( nb * 1.1 ) : # give a 10% threshold
indent_value = i
nb = self.lines[ 'space%d' % indent_value ]
if indent_value == None: # no lines
result = self.default_result
else:
result = ('space', indent_value )
# Detect tab files
elif max_line_tab > max_line_mixed and max_line_tab > max_line_space:
result = ('tab', DEFAULT_TAB_WIDTH )
# Detect mixed files
elif max_line_mixed >= max_line_tab and max_line_mixed > max_line_space:
nb = 0
indent_value = None
for i in range(8,1,-1):
if self.lines['mixed%d'%i] > int( nb * 1.1 ) : # give a 10% threshold
indent_value = i
nb = self.lines[ 'mixed%d' % indent_value ]
if indent_value == None: # no lines
result = self.default_result
else:
result = ('mixed', (8,indent_value) )
else:
# not enough information to make a decision
result = self.default_result
info( "Result: %s" % str( result ) )
return result
def __str__ (self):
itype, ival = self.results()
if itype != 'mixed':
return '%s %d' % (itype, ival)
else:
itab, ispace = ival
return '%s tab %d space %d' % (itype, itab, ispace)
def vim_output( self ):
result = self.results()
indent_type, n = result
if indent_type == "space":
# spaces:
# => set sts to the number of spaces
# => set tabstop to the number of spaces
# => expand tabs to spaces
# => set shiftwidth to the number of spaces
return "set sts=%d | set tabstop=%d | set expandtab | set shiftwidth=%d \" (%s %d)" % (n,n,n,indent_type,n)
elif indent_type == "tab":
# tab:
# => set sts to 0
# => set tabstop to preferred value
# => set expandtab to false
# => set shiftwidth to tabstop
return "set sts=0 | set tabstop=%d | set noexpandtab | set shiftwidth=%d \" (%s)" % (DEFAULT_TAB_WIDTH, DEFAULT_TAB_WIDTH, indent_type )
if indent_type == 'mixed':
tab_indent, space_indent = n
# tab:
# => set sts to 0
# => set tabstop to tab_indent
# => set expandtab to false
# => set shiftwidth to space_indent
return "set sts=4 | set tabstop=%d | set noexpandtab | set shiftwidth=%d \" (%s %d)" % (tab_indent, space_indent, indent_type, space_indent )
def main():
VIM_OUTPUT = 0
file_list = []
for opt in sys.argv[1:]:
if opt == "--vim-output":
VIM_OUTPUT = 1
elif opt == "--verbose" or opt == '-v':
IndentFinder.VERBOSITY += 1
elif opt == "--version":
print 'IndentFinder v%s' % VERSION
return
elif opt[0] == "-":
print help % sys.argv[0]
return
else:
file_list.append( opt )
fi = IndentFinder()
if len(file_list) > 1:
# multiple files
for fname in file_list:
fi.clear()
fi.parse_file( fname )
if VIM_OUTPUT:
print "%s : %s" % (fname, fi.vim_output())
else:
print "%s : %s" % (fname, str(fi))
return
else:
# only one file, don't print filename
fi.parse_file_list( file_list )
if VIM_OUTPUT:
sys.stdout.write( fi.vim_output() )
else:
print str(fi)
if __name__ == "__main__":
main()

View File

@ -1,10 +0,0 @@
" Done in .vimrc
augroup IndentFinder
au! IndentFinder
au BufRead *.* let b:indent_finder_result = system('python2 -c "import indent_finder; indent_finder.main()" --vim-output "' . expand('%') . '"' )
au BufRead *.* execute b:indent_finder_result
"
" " Uncomment the next line to see which indentation is applied on all your loaded files
" " au BufRead *.* echo "Indent Finder: " . b:indent_finder_result
augroup End

View File

@ -1,539 +0,0 @@
" autotags plugin: a wrapper for ctags and cscope, so tags for all languages
" supported by ctags can be build (cscope is additionally used for C/C++).
" Tags are stored in a separate directory and don't clog you project tree
" vim: set sw=4 sts=4 et ft=vim :
" Script: autotags.vim
" Author: Basil Gor <basil.gor at gmail.com>
" Homepage: http://github.com/basilgor/vim-autotags
" Version: 1.0 (10 Oct 2012)
" License: Redistribute under the same terms as Vim itself
" Purpose: ctags and cscope tags handling
" Documentation:
" This script is a wrapper for ctags and cscope, so tags for all languages
" supported by ctags can be build (cscope is additionally used for C/C++).
"
" Features
" 1. No configuration needed
" 2. Build/rebuild index for project with a single key stroke
" 3. Tags are loaded then automatically when a file is opened anywhere in
" project tree
" 4. Tags are stored in a separate directory and don't clog you project tree
" 5. Extra directories (like library source or includes) can be added with a
" single key stroke too
"
" Put autotags.vim in your ~/.vim/plugin directory, open source code and
" press F3 (map AutotagsUpdate to change it).
"
" You can reindex sources by pressing F3 again.
"
" To build and load additional tags for another directory (i.e. external
" project or library code you want to navigate to) press S-F3 (or map
" AutotagsAdd).
"
" Script builds and loads ctags and cscope databases via a single command.
" All ctags and cscope files are stored in separate directory ~/.autotags by
" default. You can set it via
" let g:autotagsdir = $HOME."/boo"
"
" Project root directory will be asked when indexing new project. After that
" tags will be loaded automatically when source files somewhere in project
" tree are opened (if path contains project root).
"
" Exact tags location:
" ~/.autotags/byhash/<source dir name hash>/<ctags and cscope files>
"
" Also `origin` symlink points back to source dir
" ~/.autotags/byhash/<source dir name hash>/origin
"
" `include_*` symlinks point to additional tags for external directories
" ~/.autotags/byhash/<source dir name hash>/include_*
"
" Tags for non-existing source directories are removed automatically
" (checked at startup)
"
" Also ctags file ~/.autotags/global_tags is built for /usr/include once
"
" Below are configuration variables for the script you can set in .vimrc:
"
" let g:autotagsdir = $HOME . "/.autotags/byhash"
" let g:autotags_global = $HOME . "/.autotags/global_tags"
"
" Set to 1 to get paths with metachars replaced by . as path hashes
" Default is 0, md5sum hash is used
" let g:autotags_pathhash_humanreadable = 0
" let g:autotags_ctags_exe = "ctags"
" let g:autotags_ctags_opts = "--c++-kinds=+p --fields=+iaS --extra=+q"
"
" see `man ctags` "--languages" options
" let g:autotags_ctags_languages = "all"
"
" see `man ctags` "--langmap" options
" let g:autotags_ctags_langmap = "default"
"
" set to 1 to avoid generating global tags for /usr/include
" let g:autotags_no_global = 0
" let g:autotags_ctags_global_include = "/usr/include/*"
" let g:autotags_cscope_exe = "cscope"
" let g:autotags_cscope_file_extensions = ".cpp .cc .cxx .m .hpp .hh .h .hxx .c .idl"
"
" set to 1 to export $CSCOPE_DIR during initialization and tags build
" let g:autotags_export_cscope_dir = 0
"
" Public Interface:
" AutotagsUpdate() build/rebuild tags (mapped to F3 by default)
" AutotagsAdd() build and load additional tags for another directory
" AutotagsRemove() remove currently used tags
"
" AutotagsUpdatePath(path) build/rebuild tags (no user interaction)
" AutotagsAddPath(path) build and load additional tags for another
" directory (no user interaction)
"
" Last two calls can be used to generate tags from batch mode, i.e.:
" $ vim -E -v >/dev/null 2>&1 <<EOF
" :call AutotagsUpdatePath("/you/project/source")
" :call AutotagsAddPath("/external/library/source")
" :call AutotagsAddPath("/external/library2/source")
" :call AutotagsAddPath("/external/library3/source")
" :quit
" EOF
"
" Dependencies:
" ctags and cscope
" md5sum
" cscope_maps.vim plugin is recommended
"
if exists("g:loaded_autotags") || &cp
finish
endif
let g:loaded_autotags = 1.0
let s:keepcpo = &cpo
set cpo&vim
" Global Maps:
"
if !hasmapto('AutotagsUpdate')
map <F3> :call AutotagsUpdate()<CR>
endif
if !hasmapto('AutotagsAdd')
map <S-F3> :call AutotagsAdd()<CR>
endif
fun! s:PathHash(val)
if g:autotags_pathhash_humanreadable == 0
return substitute(system("sha1sum", a:val), " .*", "", "")
else
return substitute(strpart(a:val, 1),
\ '/\|\s\|\[\|\]\|;\|<\|>\|\\\|\*\|`\|&\||\|\$\|#\|!\|(\|)\|{\|}\|:\|"\|'."'", ".", "g")
endif
endfun
" find and load tags, delete stale tags
fun! s:AutotagsInit()
if !exists("g:autotagsdir")
let g:autotagsdir = $HOME . "/.autotags/byhash"
endif
if !exists("g:autotags_pathhash_humanreadable")
let g:autotags_pathhash_humanreadable = 0
endif
if !exists("g:autotags_global")
let g:autotags_global = $HOME . "/.autotags/global_tags"
endif
if !exists("g:autotags_no_global")
let g:autotags_no_global = 0
endif
if g:autotags_no_global == 0 && filereadable(g:autotags_global)
exe "set tags=" . g:autotags_global
endif
if !exists("g:autotags_search_tags")
let g:autotags_search_tags = 0
endif
if !exists("g:autotags_ctags_exe")
let g:autotags_ctags_exe = "ctags"
endif
if !exists("g:autotags_ctags_opts")
let g:autotags_ctags_opts = "--c++-kinds=+p --fields=+iaS --extra=+q"
endif
if !exists("g:autotags_ctags_languages")
let g:autotags_ctags_languages = "all"
endif
if !exists("g:autotags_ctags_langmap")
let g:autotags_ctags_langmap = "default"
endif
if !exists("g:autotags_ctags_global_include")
let g:autotags_ctags_global_include = "/usr/include/* /usr/include/sys/* " .
\ "/usr/include/net* /usr/include/bits/* /usr/include/arpa/* " .
\ "/usr/include/asm/* /usr/include/asm-generic/* /usr/include/linux/*"
endif
if !exists("g:autotags_cscope_exe")
let g:autotags_cscope_exe = "cscope"
endif
if !exists("g:autotags_pycscope_cmd")
let g:autotags_pycscope_pyt = "/usr/bin/python"
let g:autotags_pycscope_scr = "~/.vim/plugin/pycscope.py"
let g:autotags_pycscope_cmd = g:autotags_pycscope_pyt . " " . g:autotags_pycscope_scr
endif
if !exists("g:autotags_cscope_file_extensions")
let g:autotags_cscope_file_extensions = ".cpp .cc .cxx .m .hpp .hh .h .hxx .c .idl .java"
endif
let s:cscope_file_pattern = '.*\' .
\ join(split(g:autotags_cscope_file_extensions, " "), '\|.*\')
if !exists("g:autotags_export_cscope_dir")
let g:autotags_export_cscope_dir = 0
endif
if executable(g:autotags_ctags_exe) == 0
echomsg "autotags warning: `" . g:autotags_ctags_exe .
\ "' cannot be found on your system"
endif
if executable(g:autotags_cscope_exe) == 0
echomsg "autotags warning: `" . g:autotags_cscope_exe .
\ "' cannot be found on your system"
endif
call s:AutotagsCleanup()
" find autotags subdir
let l:dir = getcwd()
while l:dir != "/"
if getftype(g:autotagsdir . '/' . s:PathHash(l:dir)) == "dir"
let s:autotags_subdir = g:autotagsdir . '/' . s:PathHash(l:dir)
echomsg "autotags subdir exist: " . s:autotags_subdir
break
endif
" get parent directory
let l:dir = fnamemodify(l:dir, ":p:h:h")
endwhile
if exists("s:autotags_subdir")
call s:AutotagsReload(s:autotags_subdir)
else
call s:AutotagsSearchLoadTags()
endif
endfun
fun! s:AutotagsIsC()
if &ft == "cpp" || &ft == "c"
return 1
else
return 0
endif
endfun
fun! GetLocalCscopeDb(pathname)
if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/'
return
endif
let s:cscopefile = a:pathname."/cscope.out"
if filereadable(s:cscopefile)
" echo "Add cscope db for ".a:pathname
execute "cscope add ".s:cscopefile." ".a:pathname
endif
unlet s:cscopefile
call GetLocalCscopeDb(fnamemodify(a:pathname, ":h"))
endfunction
fun! GetLocalTags(pathname)
if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/'
return
endif
let s:ctagsfile = a:pathname."/tags"
if filereadable(s:ctagsfile)
" echo "Add tags db for ".a:pathname
exe "set tags+=" . s:ctagsfile
endif
unlet s:ctagsfile
call GetLocalTags(fnamemodify(a:pathname, ":h"))
endfunction
fun! s:AutotagsSearchLoadTags()
" search ctags in current tree
call GetLocalTags(expand("%:p:h"))
" if filereadable(findfile("tags", ".;"))
" let l:ctagsfile = findfile("tags", ".;")
" exe "set tags+=" . l:ctagsfile
" echomsg "found local ctags file: " . l:ctagsfile
" endif
call GetLocalCscopeDb(expand("%:p:h"))
" search cscope db in current tree
" if filereadable(findfile("cscope.out", ".;"))
" let l:cscopedb = findfile("cscope.out", ".;")
" exe "cs add " . l:cscopedb . " " . fnamemodify(l:cscopedb, ":p:h")
" echomsg "found local cscopedb file: " . l:cscopedb
" endif
endfun
" remove stale tags for non-existing source directories
fun! s:AutotagsCleanup()
if !isdirectory(g:autotagsdir)
return
endif
for l:entry in split(system("ls " . g:autotagsdir), "\n")
let l:path = g:autotagsdir . "/" . l:entry
if getftype(l:path) == "dir"
let l:origin = l:path . "/origin"
if getftype(l:origin) == 'link' && !isdirectory(l:origin)
echomsg "deleting stale tags for " .
\ fnamemodify(resolve(l:origin), ":p")
call system("rm -r " . shellescape(l:path))
endif
endif
endfor
endfun
fun! s:AutotagsValidatePath(path)
if a:path == ""
echomsg "no directory specified"
return ""
endif
let l:fullpath = fnamemodify(a:path, ":p")
if !isdirectory(l:fullpath)
echomsg "directory " . l:fullpath . " doesn't exist"
return ""
endif
let l:fullpath = substitute(l:fullpath, "\/$", "", "")
return l:fullpath
endfun
fun! s:AutotagsAskPath(hint, msg)
call inputsave()
let l:path = input(a:msg, a:hint, "file")
call inputrestore()
echomsg " "
return s:AutotagsValidatePath(l:path)
endfun
fun! s:AutotagsMakeTagsDir(sourcedir)
let l:tagsdir = g:autotagsdir . '/' . s:PathHash(a:sourcedir)
if !isdirectory(l:tagsdir) && !mkdir(l:tagsdir, "p")
echomsg "cannot create dir " . l:tagsdir
return ""
endif
call system("ln -s " . shellescape(a:sourcedir) . " " .
\ shellescape(l:tagsdir . "/origin"))
return l:tagsdir
endfun
fun! s:AutotagsGenerateGlobal()
echomsg "updating global ctags " . g:autotags_global . " for " .
\ g:autotags_ctags_global_include
echomsg system("nice -15 " . g:autotags_ctags_exe . " " .
\ g:autotags_ctags_opts .
\ " -f " . shellescape(g:autotags_global) . " " .
\ g:autotags_ctags_global_include)
endfun
fun! s:AutotagsGenerate(sourcedir, tagsdir)
let l:ctagsfile = a:tagsdir . "/tags"
echomsg "updating ctags " . shellescape(l:ctagsfile) ." for " .
\ shellescape(a:sourcedir)
echomsg system("nice -15 " . g:autotags_ctags_exe . " -R " .
\ g:autotags_ctags_opts .
\ " '--languages=" . g:autotags_ctags_languages .
\ "' '--langmap=" . g:autotags_ctags_langmap .
\ "' -f " . shellescape(l:ctagsfile) . " " .
\ shellescape(a:sourcedir))
let l:cscopedir = a:tagsdir
echomsg "updating cscopedb in " . shellescape(l:cscopedir) ." for " .
\ shellescape(a:sourcedir)
echomsg system("cd " . shellescape(l:cscopedir) . " && " .
\ " nice -15 find " . shellescape(a:sourcedir) .
\ " -not -regex '.*/\\..*' " .
\ " -not -regex '.*/\\%.*' " .
\ " -regex '" . s:cscope_file_pattern . "' " .
\ " -fprint cscope.files")
if getfsize(l:cscopedir . "/cscope.files") > 0
if g:autotags_no_global == 0
echomsg system("cd " . shellescape(l:cscopedir) . " && " .
\ "nice -15 " . g:autotags_cscope_exe . " -b -q")
else
echomsg system("cd " . shellescape(l:cscopedir) . " && " .
\ "nice -15 " . g:autotags_cscope_exe . " -b -q -k")
endif
endif
echomsg system("cd " . shellescape(l:cscopedir) . " && " .
\ " nice -15 find " . shellescape(a:sourcedir) .
\ " -not -regex '.*/\\..*' " .
\ " -not -regex '.*/\\%.*' " .
\ " -name '*.py' " .
\ " -fprint cscope_py.files")
if getfsize(l:cscopedir . "/cscope_py.files") > 0
echomsg system("cd " . shellescape(l:cscopedir) . " && " .
\ "nice -15 " . g:autotags_pycscope_cmd . " -i cscope_py.files -f cscope_py.out" )
endif
endfun
fun! s:AutotagsReload(tagsdir)
if g:autotags_export_cscope_dir == 1
let $CSCOPE_DIR=a:tagsdir
endif
set nocsverb
exe "cs kill -1"
if g:autotags_no_global == 0 && filereadable(g:autotags_global)
exe "set tags=" . g:autotags_global
else
exe "set tags="
endif
call s:AutotagsLoad(a:tagsdir)
for l:entry in split(system("ls " . a:tagsdir), "\n")
if stridx(l:entry, "include_") == 0
let l:path = a:tagsdir . "/" . l:entry
if getftype(l:path) == 'link' && isdirectory(l:path)
call s:AutotagsLoad(l:path)
endif
endif
endfor
endfun
fun! s:AutotagsLoad(tagsdir)
let l:ctagsfile = a:tagsdir . "/tags"
if filereadable(l:ctagsfile)
exe "set tags+=" . l:ctagsfile
endif
let l:cscopedb = a:tagsdir . "/cscope.out"
if filereadable(l:cscopedb)
exe "cs add " . l:cscopedb
endif
let l:cscopepydb = a:tagsdir . "/cscope_py.out"
if filereadable(l:cscopepydb)
exe "cs add " . l:cscopepydb
endif
endfun
fun! s:AutotagsIsLoaded()
if !exists("s:autotags_subdir") ||
\ !isdirectory(s:autotags_subdir) ||
\ !isdirectory(s:autotags_subdir . '/origin')
return 0
else
return 1
endif
endfun
fun! AutotagsUpdate()
if s:AutotagsIsLoaded() == 0
let l:sourcedir = s:AutotagsAskPath(getcwd(), "Select project root: ")
if l:sourcedir == ""
return
endif
else
let l:sourcedir = resolve(s:autotags_subdir . "/origin")
endif
call AutotagsUpdatePath(l:sourcedir)
endfun
fun! AutotagsUpdatePath(sourcedir)
if s:AutotagsIsLoaded() == 0
let l:sourcedir = s:AutotagsValidatePath(a:sourcedir)
if l:sourcedir == ""
return
endif
let s:autotags_subdir = s:AutotagsMakeTagsDir(l:sourcedir)
if s:autotags_subdir == ""
unlet s:autotags_subdir
return
endif
else
let l:sourcedir = resolve(s:autotags_subdir . "/origin")
endif
if g:autotags_no_global == 0 && !filereadable(g:autotags_global)
call s:AutotagsGenerateGlobal()
endif
call s:AutotagsGenerate(l:sourcedir, s:autotags_subdir)
call s:AutotagsReload(s:autotags_subdir)
endfun
" Add dependent source directory, tags for that directory will be loaded to
" current project
fun! AutotagsAdd()
if s:AutotagsIsLoaded() == 0
call AutotagsUpdate()
endif
let l:sourcedir = s:AutotagsAskPath(getcwd(), "Select additional directory: ")
if l:sourcedir == ""
return
endif
call AutotagsAddPath(l:sourcedir)
endfun
fun! AutotagsAddPath(sourcedir)
if s:AutotagsIsLoaded() == 0
echomsg "call AutotagsUpdate first"
return
endif
let l:sourcedir = s:AutotagsValidatePath(a:sourcedir)
if l:sourcedir == "" ||
\ l:sourcedir == resolve(s:autotags_subdir . "/origin")
return
endif
let l:tagsdir = s:AutotagsMakeTagsDir(l:sourcedir)
if l:tagsdir == ""
return
endif
call s:AutotagsGenerate(l:sourcedir, l:tagsdir)
call system("ln -s " . shellescape(l:tagsdir) . " " .
\ shellescape(s:autotags_subdir . "/include_" . s:PathHash(l:sourcedir)))
call s:AutotagsReload(s:autotags_subdir)
endfun
fun! AutotagsRemove()
if exists("s:autotags_subdir")
echomsg "deleting autotags " . s:autotags_subdir . " for " .
\ fnamemodify(resolve(s:autotags_subdir . "/origin"), ":p")
call system("rm -r " . shellescape(s:autotags_subdir))
if g:autotags_no_global == 0 && filereadable(g:autotags_global)
exe "set tags=" . g:autotags_global
else
exe "set tags="
endif
exe "cs kill -1"
exe "cs reset"
endif
endfun
set nocsverb
call <SID>AutotagsInit()
let &cpo= s:keepcpo
unlet s:keepcpo

View File

@ -1,103 +0,0 @@
" cscope keymaping plugin
" (a tool to browse through C source files)
"
" if compiled with --enable-cscope
if has("cscope")
if exists("g:loaded_cscope") || &cp
finish
endif
let g:loaded_cscope = 1.0
function! GoToDefinition()
try
execute "cscope find g " . expand("<cword>")
catch /:E259:/
try
execute "tag " . expand("<cword>")
catch /:E257:/
execute "normal! gd"
execute "nohlsearch"
endtry
endtry
endfunction
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetag
" use ctags before cscope
set csto=0
" add any cscope database in current directory
if filereadable("cscope.out")
cscope add cscope.out
endif
" add the database pointed by environment variable.
" Cscope file added from db should contains full path to file. Otherwise they
" should be added with cscope add PATH_TO_CSCOPE_FILE PATH_TO_SRC_ROOT
if $CSCOPE_DB != ""
if filereadable($CSCOPE_DB)
cscope add $CSCOPE_DB
endif
endif
" show message when any other cscope db added
set cscopeverbose
" open include file with F4 and split with shift+F4
nmap <F4> :cscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <S-F4> :scscope find f <C-R>=expand("<cfile>")<CR><CR>
" find this C symbol with F5 and split with shift+F5
nmap <F5> :cscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <S-F5> :scscope find s <C-R>=expand("<cword>")<CR><CR>
" go to definition with F6 and split with shift+F6 and use ctags with alt+shift+F6
"nmap <F6> :cscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <F6> :call GoToDefinition()<CR>
nmap <S-F6> :scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <M-S-F6> :tag <C-R>=expand("<cword>")<CR><CR>
" go to calls with F7 and split with shift+F7
nmap <F7> :cscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <S-F7> :scscope find c <C-R>=expand("<cword>")<CR><CR>
" go to ... with 'ctrl+s letter' and go back with ctrl+t
nmap <C-s>s :cscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>g :cscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>c :cscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>t :cscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>e :cscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-s>f :cscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-s>i :cscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-s>d :cscope find d <C-R>=expand("<cword>")<CR><CR>
" split to ... with 'ctrl+space letter'
nmap <C-@>s :scscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :scscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :scscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :scscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :scscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :scscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :scscope find d <C-R>=expand("<cword>")<CR><CR>
" vertical split to ... with 'ctrl+space ctrl+space letter'
nmap <C-@><C-@>s :vertical scscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>g :vertical scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>c :vertical scscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>t :vertical scscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>e :vertical scscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>f :vertical scscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@><C-@>i :vertical scscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@><C-@>d :vertical scscope find d <C-R>=expand("<cword>")<CR><CR>
" s symbol find all references to the token under cursor
" //find this C symbol
" g global find global definition of the token under cursor
" //find this definition
" c calls find all calls to the function name under cursor
" //find function calling this function
" d called find functions that function under cursor calls
" //find function called by this function
" t text find all instances of the text under cursor
" //find this text string
" e egrep egrep search for the word under cursor
" //find this egrep pattern
" f file open the filename under cursor
" //find this file
" i includes find files that include the filename under cursor
" //find files #including this file
endif

View File

@ -1,45 +0,0 @@
" if compiled with --enable-cscope
if has("cscope")
if exists("g:loaded_cscope_plus") || &cp
finish
endif
let g:loaded_cscope_plus = 1.0
" cat Makefile | grep '\-I\/' | tr '[:space:]' '\n' | grep '\-I/' | sort -u | tr '\n' ' '
" build tags database with shift+F8 or alt+F8 to ignore /usr/include
" --c++-kinds=+p : Adds prototypes in the database for C/C++ files.
" --fields=+iaS : Adds inheritance (i), access (a) and function
" signatures (S) information.
" --extra=+q : Adds context to the tag name. Note: Without this
" option, the script cannot get class members.
command! CtagsBuild
\ :!echo 'building ctags database...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p &&
\ echo 'adding system headers...' ;
\ find -exec gcc -M '{}' \; 2>&- | tr '[:space:]' '\n' | grep '^/.*' | sort -u |
\ ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extra=+q -aL-
command! CtagsKernelBuild
\ :!echo 'building ctags database in kernel mode...' ;
\ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p
command! CscopeBuild
\ :!echo 'building cscope database...' ;
\ cscope -bR
command! CscopeKernelBuild
\ :!echo 'building cscope database in kernel mode...' ;
\ cscope -bkR
if has("cscope")
map <S-F8> :CtagsBuild<CR><CR>:CscopeBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>:CscopeKernelBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>
else
map <S-F8> :CtagsBuild<CR><CR>
map <M-F8> :CtagsKernelBuild<CR><CR>
endif
set tags+=./tags " in file directory
set tags+=tags " in current directory
"for when programming in build dir
set tags+=../tags
endif

View File

@ -1,40 +0,0 @@
" Enjoy the right click button!
" Custom right click menu to call cscope functions
"
if exists("loaded_menu")
finish
endif
let loaded_menu = 1
set mousemodel=popup
function! PopulateMenu()
exe "amenu PopUp.-Sep- :"
exe "amenu PopUp.Help\\ !<Tab><F1> :call Help()<CR>"
exe "amenu PopUp.-Sep1- :"
exe "amenu PopUp.Find\\ File<Tab><F4> :cscope find f <C-R>=expand('<cfile>')<CR><CR>"
exe "amenu PopUp.Find\\ Symbol<Tab><F5> :cscope find s <C-R>=expand('<cword>')<CR><CR>"
exe "amenu PopUp.Find\\ Definition<Tab><F6> :cscope find g <C-R>=expand('<cword>')<CR><CR>"
exe "amenu PopUp.Find\\ Call<Tab><F7> :cscope find c <C-R>=expand('<cword>')<CR><CR>"
exe "amenu PopUp.Find\\ Text<Tab> :cscope find t <C-R>=expand('<cword>')<CR><CR>"
exe "amenu PopUp.Find\\ Egrep<Tab> :cscope find e <C-R>=expand('<cword>')<CR><CR>"
exe "amenu PopUp.Go\\ Back<Tab><Ctl-t> <C-t>"
exe "amenu PopUp.-Sep2- :"
exe "amenu PopUp.Create\\ local\\ code\\ reference<Tab><M-F8> :CtagsKernelBuild<CR><CR>:CscopeKernelBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>"
exe "amenu PopUp.Create\\ local\\ code\\ reference\\ with\\ system\\ headers<Tab><S-F8> :CtagsBuild<CR><CR>:CscopeBuild<CR><CR>:cscope reset<CR><CR>:cscope add cscope.out<CR><CR>"
exe "amenu PopUp.Create\\ global\\ code\\ reference<Tab><F3> :call AutotagsUpdate()<CR>"
exe "amenu PopUp.Create\\ global\\ code\\ reference\\ for\\ path<Tab><Shift-F3> :call AutotagsAdd()<CR>"
exe "amenu PopUp.-Sep3- :"
exe "amenu PopUp.Toggle\\ show\\ function<Tab><F8> :TlistToggle<CR>"
endfunc
if has("vim_starting")
augroup LoadBufferPopup
au! VimEnter * call PopulateMenu()
au VimEnter * au! LoadBufferPopup
augroup END
else
call PopulateMenu()
endif

File diff suppressed because it is too large Load Diff

300
.vimrc
View File

@ -1,300 +0,0 @@
"""""""""""""
" SHORTCUTS "
"""""""""""""
" F1 help
" F2 open file in a new tab
" S-F2 Split and open file
" F3 autotags Update
" S-F3 autotags Add
" F4 open include file
" F5 find C symbol
" F6 go to definition
" F7 go to calls
" F8 view tag list
" S-F8 build ctags/cscope databases
" M-F8 build kernel ctags/cscope databases
" F9 Open NerdTree
" M-F9 Show diff line
" S-F9 Highlight diff line
" C-left/right switch tab
" C-up/down switch window
" M-left/right horizontal size
" M-up/down vertical size
"""""""""""
" GENERAL "
"""""""""""
" disable vi-compatible mode
set nocompatible
filetype plugin on
syntax on
""""""""
" SAVE "
""""""""
" disable backup
set nobackup
" save before compilation
set autowrite
" jump to last known position when reopening a file
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute "normal! g`\"" |
\ endif
endif
" command line history
set history=50
" Check that file have not been changed
" CursorHold : after cursor move
" WinEnter or BufWinEnter
au WinEnter * checktime
au BufWinEnter * checktime
"""""""""
" INPUT "
"""""""""
" Enable mouse for 'a'll mode
set mouse=a
"""""""""""
" DISPLAY "
"""""""""""
" highlight the cursor line
set cursorline
" show the status line
set laststatus=2
" show the cursor position
set ruler
" show mode
set showmode
" display incomplete commands
set showcmd
" display line number"
set number
" set status line
set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
" always display status line
set laststatus=2
" show bad white spaces
let c_space_errors = 1
let python_space_error_highlight = 1
highlight link cSpaceError SpaceError
highlight link pythonSpaceError SpaceError
highlight SpaceError ctermfg=235 cterm=reverse
"""""""""""""""
" INDENTATION "
"""""""""""""""
" use tabs at the start of a line, spaces elsewhere
set smarttab
set smartindent
set autoindent
"" tab=4
"set tabstop=4
"set softtabstop=4
"set shiftwidth=4
" tab=8
set tabstop=8
set softtabstop=8
set shiftwidth=8
" real tabs
" set noexpandtab
if has("autocmd")
" enable file type detection and do language-dependent indenting
" filetype plugin indent on
" detect indentation see http://www.freehackers.org/Indent_Finder
if has('python')
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output "' . expand('%') . '"' )
endif
else
" auto-indent
set autoindent
" smart-indent
set smartindent
" C-indent
"set cindent
" indent-expr
"set indentexpr ""
endif
""""""""""
" SEARCH "
""""""""""
" highlight search
set hlsearch
" unhighlight current search
map <silent> <F11> :nohlsearch<CR>
imap <F11> <ESC><F11>a
" highlight search while typing
set incsearch
" show matching brackets -> key %
set showmatch
" tenths of a second before blink matching brackets
set mat=5
""""""""""
" WINDOW "
""""""""""
" create window below or at right of the current one
set splitbelow
set splitright
" if multiple windows
if bufwinnr(1)
" vertically increase/decrease window size with alt+up/alt+down
map <M-Up> <C-W>+
map <M-Down> <C-W>-
imap <M-Up> <ESC><M-Up>a
imap <M-Down> <ESC><M-Down>a
" horizontally increase/decrease window size with alt+right/alt+left
map <M-Right> <C-W>>
map <M-Left> <C-W><
imap <M-Right> <ESC><M-Right>a
imap <M-Left> <ESC><M-Left>a
" switch to next/previous tab with ctrl+right/ctrl+left
map <C-Right> gt
map <C-Left> gT
imap <C-Right> <ESC><C-Right>a
imap <C-Left> <ESC><C-Left>a
" switch to next/previous window with ctrl+down/ctrl+up
map <C-Down> <C-W>w
map <C-Up> <C-W>W
imap <C-Down> <ESC><C-Down>a
imap <C-Up> <ESC><C-Up>a
endif
" open automatically quickfix window
if has("autocmd")
autocmd QuickFixCmdPost * cw
endif
" open a file in the same directory as the current file with F2 and split with shift+F2
map <F2> :tabe <C-R>=expand("%:h") . "/"<CR>
nmap <S-F2> :split <C-R>=expand("%:h") . "/"<CR>
colorscheme desert
set nocursorline
""""""""
" HELP "
""""""""
" allow embedded man page
runtime! ftplugin/man.vim
" show vimrc with shift+F1
nmap <silent> <S-F1> :tabe ~/.vimrc<CR>gg
imap <S-F1> <Esc><S-F1>
" show contextual help with F1
function Help()
try
if exists('b:current_syntax') && b:current_syntax == "python"
:call ShowPyDoc(expand("<cword>"), 1)
else
execute "Man " . expand("<cword>")
endif
catch /:E149:/
execute "help " . expand("<cword>")
endtry
endfunction
nmap <silent> <F1> :call Help()<CR>
imap <F1> <Esc><F1>
" show VIM help with alt+shift+F1
nmap <silent> <M-S-F1> :help <C-R>=expand("<cword>")<CR><CR>
imap <M-S-F1> <Esc><M-S-F1>
""""""""""""""""""""""""""""""""""""""""""""""""""
"Omni-completion par CTRL-X_CTRL-O
"""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin on
set omnifunc=syntaxcomplete#Complete
" Enable omnicppcompletion
set nocp
filetype plugin on
let OmniCpp_ShowAccess = 0
let OmniCpp_LocalSearchDecl=1
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
set path=.,..,/usr/local/include,/usr/include
"""""""""""
" NerdTree
"""""""""""
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
map <F9> :NERDTreeToggle<CR>
"""""""""""
" GitGutter
"""""""""""
map <M-F9> :GitGutterSignsToggle <CR>
map <S-F9> :GitGutterLineHighlightsToggle <CR>
"""""""""
" Plugin"
"""""""""
" plugin taglist
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Process_File_Always = 1
let Tlist_Exit_OnlyWindow = 1
"let Tlist_Close_On_Select = 1
let Tlist_Auto_Highlight_Tag = 1
let Tlist_Display_Prototype = 0
let Tlist_Display_Tag_Scope = 0
let Tlist_Show_One_File = 1
let Tlist_Compact_Format = 1
let Tlist_Enable_Fold_Column = 0
" sort by name or order ?
let Tlist_Sort_Type = "name"
"let Tlist_File_Fold_Auto_Close = 1
let Tlist_Inc_Winwidth = 0
"let Tlist_Use_Horiz_Window = 1
let Tlist_Use_Right_Window = 1
" open/close tag list window with F8
map <silent> <F8> :TlistToggle<CR>
" close preview window after a completion
if has("autocmd")
autocmd CursorMovedI *.{[hc],cpp} if pumvisible() == 0|pclose|endif
autocmd InsertLeave *.{[hc],cpp} if pumvisible() == 0|pclose|endif
endif
"Using vundle
"cf. https://github.com/gmarik/Vundle.vim
":PluginInstall to install them
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" Show current modified line
Plugin 'airblade/vim-gitgutter'
" Communication with git
Plugin 'tpope/vim-fugitive'
" Omni completion for cpp
Plugin 'vim-scripts/OmniCppComplete'
" Filesystem exploration
Plugin 'scrooloose/nerdtree'
" List current file function
" This version is buggy. Use a local one
"Plugin 'vim-scripts/taglist.vim'
" echofunc -> what is the current function signature
Plugin 'mbbill/echofunc'
" % match if/then/else/html ...
Plugin 'tmhedberg/matchit'
"Syntax checking
Plugin 'scrooloose/syntastic.git'
call vundle#end()

107
HIB.cpp Normal file
View File

@ -0,0 +1,107 @@
#include "HIB.h"
#define MAX_PIN 15
HIB *HibList[MAX_PIN+1];
void ICACHE_RAM_ATTR sws_isr_0() { HibList[0]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_1() { HibList[1]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_2() { HibList[2]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_3() { HibList[3]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_4() { HibList[4]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_5() { HibList[5]->IRQ_handler(); }
// Pin 6 to 11 can not be used
void ICACHE_RAM_ATTR sws_isr_12() { HibList[12]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_13() { HibList[13]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_14() { HibList[14]->IRQ_handler(); }
void ICACHE_RAM_ATTR sws_isr_15() { HibList[15]->IRQ_handler(); }
static void (*ISRList[MAX_PIN+1])() = {
sws_isr_0,
sws_isr_1,
sws_isr_2,
sws_isr_3,
sws_isr_4,
sws_isr_5,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
sws_isr_12,
sws_isr_13,
sws_isr_14,
sws_isr_15
};
void __timerCallback(void *data) {
Serial.printf("%s\n", __func__);
HIB *hib = static_cast<HIB *>(data);
hib->debouncing = false;
hib->invertState();
Serial.printf("New State %d \n", hib->state);
if (hib->state != digitalRead(hib->pin)){
hib->state = !hib->state;
Serial.printf("%s. Debounce failed\n", __func__);
return;
}
if(hib->state != hib->initialState){
Serial.printf("Button Pressed\n");
hib->onInternalButtonPressed();
}
else{
Serial.printf("Button Released\n");
hib->onInternalButtonReleased();
}
}
HIB::HIB(uint8_t p, uint8_t initState,
void (* userOnButtonPressed)(uint8_t pin, int state),
void (* userOnButtonReleased)(uint8_t pin, int state),
void (* userOnLongButtonPressed)(uint8_t pin),
unsigned long longPress, unsigned long shortPress):
previousMillis(0),
longPressMsec(longPress),
shortPressMsec(shortPress),
onButtonPressed(userOnButtonPressed),
onButtonReleased(userOnButtonReleased),
onLongButtonPressed(userOnLongButtonPressed),
pin(p), initialState(initState),
state(initState), debouncing(false) {
pinMode(pin, INPUT_PULLUP);
HibList[pin] = this;
attachInterrupt(digitalPinToInterrupt(pin), ISRList[pin], CHANGE);
os_timer_setfn(&timer, __timerCallback, this);
}
void HIB::IRQ_handler(){
Serial.printf("IRQ_handler on pin %d, debouncing %d\n", pin, debouncing);
if(!debouncing){
debouncing = true;
os_timer_arm(&timer, shortPressMsec, 0);
}
}
void HIB::onInternalButtonPressed(){
previousMillis = millis();
if(onButtonPressed)
onButtonPressed(pin, state);
}
void HIB::onInternalLongButtonPressed(){
if(onLongButtonPressed)
onLongButtonPressed(pin);
}
void HIB::onInternalButtonReleased(){
if(onButtonReleased)
onButtonReleased(pin, state);
if(millis() - previousMillis >= longPressMsec){
onInternalLongButtonPressed();
}
}
void HIB::invertState(){
state = !state;
}

33
HIB.h Normal file
View File

@ -0,0 +1,33 @@
#pragma once
#include "Arduino.h"
extern "C" {
#include "osapi.h"
}
// Human Interface Button
class HIB {
private:
ETSTimer timer;
unsigned long previousMillis;
unsigned long longPressMsec;
unsigned long shortPressMsec;
void onInternalButtonPressed();
void onInternalButtonReleased();
void onInternalLongButtonPressed();
void invertState();
void (* onButtonPressed)(uint8_t pin, int state);
void (* onButtonReleased)(uint8_t pin, int state);
void (* onLongButtonPressed)(uint8_t pin);
friend void __timerCallback(void *data);
public:
uint8_t pin;
uint8_t initialState;
uint8_t state;
uint8_t debouncing;
HIB(uint8_t pin, uint8_t initialState,
void (* onButtonPressed)(uint8_t pin, int state) = NULL,
void (* onButtonReleased)(uint8_t pin, int state) = NULL,
void (* onLongButtonPressed)(uint8_t pin) = NULL,
unsigned long longPressMsec = 5000, unsigned long shortPressMsec = 50);
void IRQ_handler();
};

View File

@ -1,72 +0,0 @@
# Preproc options
# -MMD is used to generate .d files for user header dependencies (use -MD for system and user header instead)
CPPFLAGS = -MMD
# main compilation
CFLAGS ?= -Werror -Wall -Wextra $(shell pkg-config --cflags sdl)
# C++ flags
CXXFLAGS =
#Linker flags
LDFLAGS =
#Linker path
LDLIBS = $(shell pkg-config --libs sdl)
# Force shell to an known one
SHELL := bash
.SHELLFLAGS := -eu -o -pipefail -c
# each recipe in ran as one single shell session (Rather than one new shell per line)
.ONESHELL
# delete target on error
.DELETE_ON_ERROR
MAKEFLAGS += --warn-undefined-variables
ifneq ($(CROSS_COMPILE),)
CC :=$(CROSS_COMPILE)$(CC)
CXX :=$(CROSS_COMPILE)$(CXX)
LD :=$(CROSS_COMPILE)$(LD)
endif
bin = main
cxxbin = cxxmain
lib = libexample.so
#Will be compiled with -fpic
lib_src = lib.c
lib_obj = $(lib_src:%.c=%.o)
lib_dep = $(lib_src:%.c=%.d)
sources = $(filter-out $(lib_src), $(wildcard *.c))
objects = $(sources:%.c=%.o)
depends = $(sources:%.c=%.d)
# Do not have same file prefix between C and C++ (e.g. main.c and main.cpp)
cxx_sources = $(wildcard *.cpp)
cxx_objects = $(cxx_sources:%.cpp=%.o)
cxx_depends = $(cxx_sources:%.cpp=%.d)
all: $(bin) $(cxxbin) $(lib)
$(bin): $(objects)
$(cxxbin) : $(cxx_objects)
$(lib): CFLAGS += -fpic
$(lib): $(lib_obj)
# C++ compilation (Use implicit LINK.CC)
$(cxxbin):
$(LINK.cc) $^ $(LDLIBS) -o $@
%.so:
$(LINK.c) -shared $^ $(LDLIBS) -o $@
.PHONY: clean
clean:
$(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends) $(lib) $(lib_obj) $(lib_dep)
ifneq ($(MAKECMDGOALS),clean)
-include $(depends)
-include $(cxx_depends)
-include $(lib_dep)
endif

View File

@ -1,8 +0,0 @@
#include <iostream>
#include "lib.h"
int main(int argc, const char *argv[])
{
std::cout << "C++ Hello World!" << std::endl;
return 0;
}

View File

@ -1,3 +0,0 @@
#include "lib.h"
void lib() { return; }

View File

@ -1,3 +0,0 @@
#pragma once
void lib();

View File

@ -1,8 +0,0 @@
#include <stdio.h>
#include "lib.h"
int main(int argc, const char *argv[])
{
printf("Hello world\n");
return 0;
}

View File

@ -1,32 +0,0 @@
#NIH: https://ricardoanderegg.com/posts/makefile-python-project-tricks/
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
# .DELETE_ON_ERROR:
MAKEFLAGS = --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# Override PWD so that it's always based on the location of the file and **NOT**
# based on where the shell is when calling `make`. This is useful if `make`
# is called like `make -C <some path>`
PWD := $(realpath $(dir $(abspath $(firstword $(MAKEFILE_LIST)))))
WORKTREE_ROOT := $(shell git rev-parse --show-toplevel 2> /dev/null)
# Using $$() instead of $(shell) to run evaluation only when it's accessed
# https://unix.stackexchange.com/a/687206
py = $$(if [ -d $(PWD)/'.venv' ]; then echo $(PWD)/".venv/bin/python3"; else echo "python3"; fi)
pip = $(py) -m pip
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display this help section
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z\$$/]+.*:.*?##\s/ {printf "\033[36m%-38s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.venv: requirements.txt ## Build the virtual environment
$(py) -m venv .venv
$(pip) install -U pip setuptools wheel build
$(pip) install -U -r requirements.txt
touch .venv

@ -1 +0,0 @@
Subproject commit e68141bfd8bdbff800393d390a1a388e821fa261

View File

@ -1,29 +1,24 @@
# Developers Tools
This library is intended to interact with button pluged on a ESP8266 using the Arduino SDK
This repo contains a set of tools and configuration files used for development.
Especially for Android Rom development
Code Example
```Arduino
#include <HIB.h>
## Install tool
First get git submodule:
HIB *button ;
HIB *button2 ;
void onButtonPressed(uint8_t pin){
Serial.printf("Sketch on button %d pressed \n", pin);
}
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
button = new HIB(0, HIGH, onButtonPressed);
button2 = new HIB(4, HIGH, onButtonPressed);
}
void loop() {
}
```
git submodule update --init
```
then you can use the vim configuration file
```
ln -s PATH_TO_THIS_REPO/.vim ~/.vim
ln -s PATH_TO_THIS_REPO/.vimrc ~/.vimrc
```
copy tools/aosp_cscope in your PATH
source shell/function.sh in your bashrc or zshrc or ...
## Vim
Vim plugins are managed by vundle. So at first lunch you have to run in vim
```
:PluginInstall
```

@ -1 +0,0 @@
Subproject commit 39bf760edb093c1cba9f397db610cc8c1300a754

View File

@ -1,60 +0,0 @@
mgrep () {
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
}
cgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
}
jgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
}
cjgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name "*.java" \) -print0 | xargs -0 grep --color -n "$@"
}
resgrep () {
for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`
do
find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"
done
}
gettop ()
{
local TOPFILE=build/core/envsetup.mk;
if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ]; then
echo $TOP;
else
if [ -f $TOPFILE ]; then
PWD= /bin/pwd;
else
local HERE=$PWD;
T=;
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
\cd ..;
T=`PWD= /bin/pwd`;
done;
\cd $HERE;
if [ -f "$T/$TOPFILE" ]; then
echo $T;
fi;
fi;
fi
}
croot ()
{
T=$(gettop);
if [ "$T" ]; then
\cd $(gettop);
else
echo "Couldn't locate the top of the tree. Try setting TOP.";
fi
}
apush() {
adb root && adb wait-for-device && adb remount && adb wait-for-device && adb push $1 $2
}

View File

@ -1,45 +0,0 @@
DIR="dalvik device frameworks hardware libnativehelper system packages"
TMP=$(mktemp /tmp/XXXXX-cscope.files)
gettop ()
{
local TOPFILE=build/core/envsetup.mk;
if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ]; then
echo $TOP;
else
if [ -f $TOPFILE ]; then
PWD= /bin/pwd;
else
local HERE=$PWD;
T=;
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
\cd ..;
T=`PWD= /bin/pwd`;
done;
\cd $HERE;
if [ -f "$T/$TOPFILE" ]; then
echo $T;
fi;
fi;
fi
}
T=$(gettop);
if [ "$T" ]; then
\cd $(gettop);
else
echo "Couldn't locate the top of the tree. Try setting TOP.";
exit
fi
for dir in $DIR;
do
echo "Looking for files in $dir"
find $PWD/$dir -name .git -prune -o -type f \( -iname '*.c' -o -iname '*.cc' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' -o -iname "*.mk" -o -iname "*.java" -o -iname "*.aidl" \) | egrep -v "/\.git$" >> $TMP
done
echo "generate cscope"
cscope -bkq -i $TMP
rm $TMP