Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
vimagit
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
jreybert
vimagit
Commits
e4c37d90
Commit
e4c37d90
authored
8 years ago
by
Jerome Reybert
Browse files
Options
Downloads
Patches
Plain Diff
move helper functions in autoload/helper.vim
parent
f4b2053f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
autoload/magit/helper.vim
+29
-0
29 additions, 0 deletions
autoload/magit/helper.vim
plugin/magit.vim
+11
-58
11 additions, 58 deletions
plugin/magit.vim
with
40 additions
and
58 deletions
autoload/magit/helper.vim
0 → 100644
+
29
−
0
View file @
e4c37d90
" magit#helper#get_filename: helper function to get the current filename, according to
" cursor position
" return: filename
function
!
magit#helper#get_filename
()
return
substitute
(
getline
(
search
(
g:magit_file_re
,
"cbnW"
)),
g:magit_file_re
,
'\2'
,
''
)
endfunction
" magit#helper#get_hunkheader: helper function to get the current hunk header,
" according to cursor position
" return: hunk header
function
!
magit#helper#get_hunkheader
()
return
getline
(
search
(
g:magit_hunk_re
,
"cbnW"
))
endfunction
" magit#utils#get_section: helper function to get the current section, according to
" cursor position
" return: section id, empty string if no section found
function
!
magit#helper#get_section
()
let
section_line
=
getline
(
search
(
g:magit_section_re
,
"bnW"
))
for
[
section_name
,
section_str
]
in
items
(
g:magit_sections
)
if
(
section_line
==
section_str
)
return
section_name
endif
endfor
return
''
endfunction
This diff is collapsed.
Click to expand it.
plugin/magit.vim
+
11
−
58
View file @
e4c37d90
...
...
@@ -424,8 +424,8 @@ function! s:mg_create_diff_from_select(select_lines)
if
(
start_select_line
<
starthunk
||
end_select_line
>
endhunk
)
throw
'out of hunk selection'
endif
let
section
=
<
SID
>
mg_
get_section
()
let
filename
=
<
SID
>
mg_
get_filename
()
let
section
=
magit#helper#
get_section
()
let
filename
=
magit#helper#
get_filename
()
let
hunks
=
b:state
.
get_file
(
section
,
filename
).
get_hunks
()
for
hunk
in
hunks
if
(
hunk
.
header
==
getline
(
starthunk
)
)
...
...
@@ -479,57 +479,10 @@ function! s:mg_mark_lines_in_hunk(start_select_line, end_select_line)
return
magit#
sign
#toggle_signs
(
'M'
,
a:start_select_line
,
a:end_select_line
)
endfunction
" s:mg_get_section: helper function to get the current section, according to
" cursor position
" return: section id, empty string if no section found
function
!
s:mg_get_section
()
let
section_line
=
getline
(
search
(
g:magit_section_re
,
"bnW"
))
for
[
section_name
,
section_str
]
in
items
(
g:magit_sections
)
if
(
section_line
==
section_str
)
return
section_name
endif
endfor
return
''
endfunction
" s:mg_get_filename: helper function to get the current filename, according to
" cursor position
" return: filename
function
!
s:mg_get_filename
()
return
substitute
(
getline
(
search
(
g:magit_file_re
,
"cbnW"
)),
g:magit_file_re
,
'\2'
,
''
)
endfunction
" s:mg_get_hunkheader: helper function to get the current hunk header,
" according to cursor position
" return: hunk header
function
!
s:mg_get_hunkheader
()
return
getline
(
search
(
g:magit_hunk_re
,
"cbnW"
))
endfunction
" }}}
" {{{ User functions and commands
" magit#open_close_folding_wrapper: wrapper function to
" magit#open_close_folding. If line under cursor is not a cursor, execute
" normal behavior
" param[in] mapping: which has been set
" param[in] visible : boolean, force visible value. If not set, toggle
" visibility
function
!
magit#open_close_folding_wrapper
(
mapping
,
...)
if
(
getline
(
"."
)
=~
g:magit_file_re
)
return
call
(
'magit#open_close_folding'
,
a:000
)
elseif
(
foldlevel
(
line
(
"."
))
==
2
)
if
(
foldclosed
(
line
(
'.'
))
==
-1
)
foldclose
else
foldopen
endif
else
silent
!
execute
"silent! normal! "
.
a:mapping
endif
endfunction
" magit#open_close_folding()
" param[in] visible : boolean, force visible value. If not set, toggle
" visibility
...
...
@@ -539,7 +492,7 @@ function! magit#open_close_folding(...)
throw
'non file header line: '
.
getline
(
"."
)
endif
let
filename
=
list
[
2
]
let
section
=
<
SID
>
mg_
get_section
()
let
section
=
magit#helper#
get_section
()
" if first param is set, force visible to this value
" else, toggle value
let
file
=
b:state
.
get_file
(
section
,
filename
,
0
)
...
...
@@ -906,7 +859,7 @@ function! s:mg_stage_closed_file(discard)
if
(
getline
(
"."
)
=~
g:magit_file_re
)
let
list
=
matchlist
(
getline
(
"."
),
g:magit_file_re
)
let
filename
=
list
[
2
]
let
section
=
<
SID
>
mg_
get_section
()
let
section
=
magit#helper#
get_section
()
let
file
=
b:state
.
get_file
(
section
,
filename
)
if
(
file
.
is_visible
()
==
0
||
...
...
@@ -966,8 +919,8 @@ endfunction
" param[in] discard: boolean, if true, discard instead of (un)stage
" return: no
function
!
magit#stage_block
(
selection
,
discard
)
abort
let
section
=
<
SID
>
mg_
get_section
()
let
filename
=
<
SID
>
mg_
get_filename
()
let
section
=
magit#helper#
get_section
()
let
filename
=
magit#helper#
get_filename
()
let
file
=
b:state
.
get_file
(
section
,
filename
,
0
)
let
header
=
file
.
get_header
()
...
...
@@ -1122,7 +1075,7 @@ endfunction
" magit#ignore_file: this function add the file under cursor to .gitignore
" FIXME: git diff adds some strange characters to end of line
function
!
magit#ignore_file
()
abort
let
ignore_file
=
<
SID
>
mg_
get_filename
()
let
ignore_file
=
magit#helper#
get_filename
()
call
magit#utils#append_file
(
magit#git#top_dir
()
.
".gitignore"
,
\
[
ignore_file
]
)
call
magit#update_buffer
()
...
...
@@ -1148,7 +1101,7 @@ function! magit#commit_command(mode)
if
(
a:mode
==
'CF'
)
call
<
SID
>
mg_git_commit
(
a:mode
)
else
let
section
=
<
SID
>
mg_
get_section
()
let
section
=
magit#helper#
get_section
()
if
(
section
==
'commit'
&&
\
!(
b:magit_current_commit_mode
==
'CC'
&&
a:mode
==
'CA'
)
)
if
(
b:magit_current_commit_mode
==
''
)
...
...
@@ -1245,9 +1198,9 @@ endfunction
" if this file is already displayed in a window, jump to the window, if not,
" jump to last window and open buffer, at the beginning of the hunk
function
!
magit#jump_to
()
let
section
=
<
SID
>
mg_
get_section
()
let
filename
=
fnameescape
(
magit#git#top_dir
()
.
<
SID
>
mg_
get_filename
())
let
line
=
substitute
(
s:mg_
get_hunkheader
(),
let
section
=
magit#helper#
get_section
()
let
filename
=
fnameescape
(
magit#git#top_dir
()
.
magit#helper#
get_filename
())
let
line
=
substitute
(
magit#helper#
get_hunkheader
(),
\
'^@@ -\d\+,\d\+ +\(\d\+\),\d\+ @@.*$'
,
'\1'
,
""
)
let
context
=
magit#git#get_config
(
"diff.context"
,
3
)
let
line
+=
context
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment