Skip to content

Commit fb93f9e

Browse files
committed
Added pymode modelines
1 parent f677732 commit fb93f9e

File tree

6 files changed

+89
-28
lines changed

6 files changed

+89
-28
lines changed

Changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Changelog
33

44
## 2012-XX-XX .....
55
-------------------
6-
* Update Pep8 to version 1.3.3
6+
* Updated Pep8 to version 1.3.3
7+
* Fixed virtualenv support for windows users
8+
* Added pymode modeline ':help PythonModeModeline'
79

810
## 2012-05-24 0.6.4
911
-------------------

autoload/pymode.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ fun! pymode#Default(name, default) "{{{
1212
endfunction "}}}
1313

1414

15+
fun! pymode#Option(name) "{{{
16+
if exists('b:pymode_'.a:name)
17+
return {'b:pymode_'.a:name}
18+
else
19+
return {'g:pymode_'.a:name}
20+
endif
21+
endfunction "}}}
22+
23+
1524
fun! pymode#QuickfixOpen(onlyRecognized, holdCursor, maxHeight, minHeight, jumpError) "{{{
1625
" DESC: Open quickfix window
1726
"
@@ -149,4 +158,15 @@ fun! pymode#BlockEnd(lnum, ...) "{{{
149158
endfunction "}}}
150159

151160

161+
fun! pymode#Modeline() "{{{
162+
let modeline = getline('$')
163+
if modeline =~ '^#\s\+pymode:'
164+
for ex in split(modeline, ':')[1:]
165+
let [name, value] = split(ex, '=')
166+
let {'b:pymode_'.name} = value
167+
endfor
168+
endif
169+
endfunction "}}}
170+
171+
152172
" vim: fdm=marker:fdl=0

doc/pymode.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CONTENTS *Python-mode-contents*
1414
1.Intro...................................|PythonMode|
1515
2.Options.................................|PythonModeOptions|
1616
2.1.Customisation details.............|PythonModeOptionsDetails|
17+
2.2.Modeline..........................|PythonModeModeline|
1718
3.Default Keys............................|PythonModeKeys|
1819
4.Commands................................|PythonModeCommands|
1920
5.FAQ.....................................|PythonModeFAQ|
@@ -118,6 +119,32 @@ PythonMode. These options should be set in your vimrc.
118119
To enable any of the below options you should put the given line in your
119120
'$HOME/.vimrc'. See |vimrc-intro|.
120121

122+
------------------------------------------------------------------------------
123+
2.2. Modeline ~
124+
*PythonModeModeline*
125+
126+
Feature like VIM modeline `:help modeline`. Allow changing pymode options for
127+
edited file. Pymode modeline should always be the last line in the file and
128+
look like:
129+
130+
>
131+
# pymode:lint_ignore=E0202:doc=0:lint_write=0
132+
<
133+
134+
Examples:
135+
136+
Disable folding on current file:
137+
>
138+
# pymode:folding=0
139+
<
140+
141+
Set linters and mccabe complexity.
142+
>
143+
# pymode:lint_checker=pip,mccabe:lint_mccabe_complexity=10
144+
<
145+
146+
This changes will work only in current buffer.
147+
121148
------------------------------------------------------------------------------
122149
*'pymode_paths'*
123150
Values: List of strings

ftplugin/python/pymode.vim

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ if pymode#Default('b:pymode', 1)
33
endif
44

55
" Syntax highlight
6-
if !pymode#Default('g:pymode_syntax', 1) || g:pymode_syntax
6+
if pymode#Option('syntax')
77
let python_highlight_all=1
88
endif
99

1010

11+
" Parse pymode modeline
12+
call pymode#Modeline()
13+
14+
1115
" Options {{{
1216

1317
" Python indent options
14-
if !pymode#Default('g:pymode_options_indent', 1) || g:pymode_options_indent
18+
if pymode#Option('options_indent')
1519
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class
1620
setlocal cindent
1721
setlocal tabstop=4
@@ -25,7 +29,7 @@ if !pymode#Default('g:pymode_options_indent', 1) || g:pymode_options_indent
2529
endif
2630

2731
" Python other options
28-
if !pymode#Default('g:pymode_options_other', 1) || g:pymode_options_other
32+
if pymode#Option('options_other')
2933
setlocal complete+=t
3034
setlocal formatoptions-=t
3135
if v:version > 702 && !&relativenumber
@@ -40,7 +44,7 @@ endif
4044

4145
" Documentation {{{
4246

43-
if g:pymode_doc
47+
if pymode#Option('doc')
4448

4549
" DESC: Set commands
4650
command! -buffer -nargs=1 Pydoc call pymode#doc#Show("<args>")
@@ -56,7 +60,7 @@ endif
5660

5761
" Lint {{{
5862

59-
if g:pymode_lint
63+
if pymode#Option('lint')
6064

6165
let b:qf_list = []
6266

@@ -67,15 +71,15 @@ if g:pymode_lint
6771
command! -buffer -nargs=0 PyLint :call pymode#lint#Check()
6872

6973
" DESC: Set autocommands
70-
if g:pymode_lint_write
74+
if pymode#Option('lint_write')
7175
au BufWritePost <buffer> PyLint
7276
endif
7377

74-
if g:pymode_lint_onfly
78+
if pymode#Option('lint_onfly')
7579
au InsertLeave <buffer> PyLint
7680
endif
7781

78-
if g:pymode_lint_message
82+
if pymode#Option('lint_message')
7983

8084
" DESC: Show message flag
8185
let b:show_message = 0
@@ -95,7 +99,7 @@ endif
9599

96100
" Rope {{{
97101

98-
if g:pymode_rope
102+
if pymode#Option('rope')
99103

100104
" DESC: Set keys
101105
exe "noremap <silent> <buffer> " . g:pymode_rope_short_prefix . "g :RopeGotoDefinition<CR>"
@@ -115,7 +119,7 @@ endif
115119

116120
" Execution {{{
117121

118-
if g:pymode_run
122+
if pymode#Option('run')
119123

120124
" DESC: Set commands
121125
command! -buffer -nargs=0 -range=% Pyrun call pymode#run#Run(<f-line1>, <f-line2>)
@@ -131,7 +135,7 @@ endif
131135

132136
" Breakpoints {{{
133137

134-
if g:pymode_breakpoint
138+
if pymode#Option('breakpoint')
135139

136140
" DESC: Set keys
137141
exe "nnoremap <silent> <buffer> " g:pymode_breakpoint_key ":call pymode#breakpoint#Set(line('.'))<CR>"
@@ -143,7 +147,7 @@ endif
143147

144148
" Utils {{{
145149

146-
if g:pymode_utils_whitespaces
150+
if pymode#Option('utils_whitespaces')
147151
au BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
148152
endif
149153

@@ -152,7 +156,7 @@ endif
152156

153157
" Folding {{{
154158

155-
if g:pymode_folding
159+
if pymode#Option('folding')
156160

157161
setlocal foldmethod=expr
158162
setlocal foldexpr=pymode#folding#expr(v:lnum)
@@ -162,5 +166,4 @@ endif
162166

163167
" }}}
164168

165-
166169
" vim: fdm=marker:fdl=0

plugin/pymode.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,16 @@ endif
272272
" OPTION: g:pymode_folding -- bool. Enable python-mode folding for pyfiles.
273273
call pymode#Default("g:pymode_folding", 1)
274274

275+
" OPTION: g:pymode_syntax -- bool. Enable python-mode syntax for pyfiles.
276+
call pymode#Default("g:pymode_syntax", 1)
277+
275278
" OPTION: g:pymode_utils_whitespaces -- bool. Remove unused whitespaces on save
276279
call pymode#Default("g:pymode_utils_whitespaces", 1)
277280

281+
" OPTION: g:pymode_options_indent -- bool. To set indent options.
282+
call pymode#Default("g:pymode_options_indent", 1)
283+
284+
" OPTION: g:pymode_options_other -- bool. To set other options.
285+
call pymode#Default("g:pymode_options_other", 1)
286+
278287
" vim: fdm=marker:fdl=0

pylibs/pymode.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@
99

1010
def check_file():
1111
filename = vim.current.buffer.name
12-
checkers = vim.eval('g:pymode_lint_checker').split(',')
13-
ignore = vim.eval("g:pymode_lint_ignore")
12+
checkers = vim.eval("pymode#Option('lint_checker')").split(',')
13+
ignore = vim.eval("pymode#Option('lint_ignore')")
1414
ignore = ignore and ignore.split(',') or []
15-
select = vim.eval("g:pymode_lint_select")
15+
select = vim.eval("pymode#Option('lint_select')")
1616
select = select and select.split(',') or []
1717
errors = []
1818

1919
for c in checkers:
2020
checker = globals().get(c)
2121
if checker:
2222
try:
23-
errors += checker(filename)
23+
for e in checker(filename):
24+
e.update(
25+
col=e.get('col') or '',
26+
text="%s [%s]" % (e.get('text', '').replace("'", "\"").split('\n')[0], c),
27+
filename=filename,
28+
bufnr=vim.current.buffer.number,
29+
)
30+
errors.append(e)
31+
2432
except SyntaxError, e:
2533
errors.append(dict(
2634
lnum=e.lineno,
@@ -31,14 +39,6 @@ def check_file():
3139
except Exception, e:
3240
print e
3341

34-
for e in errors:
35-
e.update(
36-
col=e.get('col') or '',
37-
text=e.get('text', '').replace("'", "\"").split('\n')[0],
38-
filename=filename,
39-
bufnr=vim.current.buffer.number,
40-
)
41-
4242
errors = filter(lambda e: _ignore_error(e, select, ignore), errors)
4343
errors = sorted(errors, key=lambda x: x['lnum'])
4444

@@ -48,7 +48,7 @@ def check_file():
4848
def mccabe(filename):
4949
import mccabe as mc
5050

51-
complexity = int(vim.eval("g:pymode_lint_mccabe_complexity"))
51+
complexity = int(vim.eval("pymode#Option('lint_mccabe_complexity')"))
5252
return mc.get_module_complexity(filename, min=complexity)
5353

5454

0 commit comments

Comments
 (0)