Load functions only when needed.
Even if this plugin is small, DNS zone editing may not be very frequent. Therefore, there is no point defining those functions every time vim start. Moving them to the autoload directory solve this problem.
This commit is contained in:
parent
c648319928
commit
bea1fc4b9a
2 changed files with 40 additions and 27 deletions
|
@ -12,30 +12,4 @@
|
|||
" See the License for the specific language governing permissions and
|
||||
" limitations under the License.
|
||||
|
||||
function! s:IncrementSerial(old_date, old_nb)
|
||||
let curr_date = strftime("%Y%m%d")
|
||||
if a:old_date ==? curr_date
|
||||
let curr_nb = a:old_nb + 1
|
||||
if curr_nb < 10
|
||||
let curr_nb = "0".curr_nb
|
||||
endif
|
||||
else
|
||||
let curr_nb = "01"
|
||||
endif
|
||||
return curr_date.curr_nb
|
||||
endfunction
|
||||
|
||||
function! s:DNSSerialUpdate()
|
||||
let pattern = '\(\d\{8}\)\(\d\+\)\s*;\s*\cserial'
|
||||
if search(pattern) == 0
|
||||
echom "No serial found."
|
||||
return 0
|
||||
endif
|
||||
let old_pattern = matchlist(getline('.'), pattern)
|
||||
let old_serial = old_pattern[1].old_pattern[2]
|
||||
let new_serial = s:IncrementSerial(old_pattern[1], old_pattern[2])
|
||||
execute "s/".old_serial."/".new_serial."/"
|
||||
echom "Serial updated to ".new_serial."."
|
||||
endfunction
|
||||
|
||||
command! DNSSerialUpdate call s:DNSSerialUpdate()
|
||||
command! DNSSerialUpdate call dnsserial#DNSSerialUpdate()
|
||||
|
|
Reference in a new issue