Mercurial > vim-lawrencium
comparison autoload/lawrencium/annotate.vim @ 148:fb65725f2872
Use winsaveview() and winrestview() to save a few lines of code.
author | Shane Harper <shane@shaneharper.net> |
---|---|
date | Sat, 11 Jan 2020 14:29:47 +1100 |
parents | 652a6f5df0f3 |
children |
comparison
equal
deleted
inserted
replaced
147:06f4d2c01fd6 | 148:fb65725f2872 |
---|---|
41 echom "Local edits found, will show the annotations for the parent revision." | 41 echom "Local edits found, will show the annotations for the parent revision." |
42 execute 'edit ' . fnameescape(l:annotation_path) | 42 execute 'edit ' . fnameescape(l:annotation_path) |
43 setlocal nowrap nofoldenable | 43 setlocal nowrap nofoldenable |
44 setlocal filetype=hgannotate | 44 setlocal filetype=hgannotate |
45 else | 45 else |
46 " Store some info about the current buffer. | 46 " Store some info about the current window. |
47 let l:cur_topline = line('w0') + &scrolloff | 47 let l:view = winsaveview() |
48 let l:cur_line = line('.') | |
49 let l:cur_wrap = &wrap | 48 let l:cur_wrap = &wrap |
50 let l:cur_foldenable = &foldenable | 49 let l:cur_foldenable = &foldenable |
51 | 50 |
52 " Open the annotated file in a split buffer on the left, after | 51 " Open the annotated file in a split buffer on the left, after |
53 " having disabled wrapping and folds on the current file. | 52 " having disabled wrapping and folds on the current file. |
68 endif | 67 endif |
69 if l:cur_foldenable | 68 if l:cur_foldenable |
70 call l:annotate_buffer.OnDelete('setlocal foldenable') | 69 call l:annotate_buffer.OnDelete('setlocal foldenable') |
71 endif | 70 endif |
72 | 71 |
73 " Go to the line we were at in the source buffer when we | 72 call winrestview({'lnum': l:view.lnum, 'topline': l:view.topline}) |
74 " opened the annotation window. | |
75 execute l:cur_topline | |
76 normal! zt | |
77 execute l:cur_line | |
78 syncbind | 73 syncbind |
79 | 74 |
80 " Set the correct window width for the annotations. | 75 " Set the correct window width for the annotations. |
81 if a:verbose | 76 if a:verbose |
82 let l:last_token = match(getline('.'), '\v\d{4}:\s') | 77 let l:last_token = match(getline('.'), '\v\d{4}:\s') |