Skip to content

Commit 13f6fff

Browse files
committed
Replace - with _ in filename
1 parent 0de8507 commit 13f6fff

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

autoload/leetcode.vim

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ function! leetcode#ListProblems(refresh) abort
381381
endif
382382
endfunction
383383

384+
function! s:FileNameToSlug(file_name) abort
385+
return substitute(a:file_name, '_', '-', 'g')
386+
endfunction
387+
388+
function! s:SlugToFileName(slug) abort
389+
return substitute(a:slug, '-', '_', 'g')
390+
endfunction
391+
384392
function! s:HandleProblemListCR() abort
385393
" Parse the problem number from the line
386394
let line_nr = line('.')
@@ -408,7 +416,8 @@ function! s:HandleProblemListCR() abort
408416
let problem_nr = line_nr - b:leetcode_problem_start_line
409417
let problem_slug = b:leetcode_problems[problem_nr]['slug']
410418
let problem_ext = s:SolutionFileExt(g:leetcode_solution_filetype)
411-
let problem_file_name = printf('%s.%s', problem_slug, problem_ext)
419+
let problem_file_name = printf('%s.%s', s:SlugToFileName(problem_slug),
420+
\ problem_ext)
412421

413422
if buflisted(problem_file_name)
414423
execute bufnr(problem_file_name) . 'buffer'
@@ -498,7 +507,7 @@ function! leetcode#ResetSolution(with_latest_submission) abort
498507
return
499508
endif
500509

501-
let problem_slug = expand('%:t:r')
510+
let problem_slug = s:FileNameToSlug(expand('%:t:r'))
502511
let expr = printf('leetcode.get_problem("%s")', problem_slug)
503512
let problem = py3eval(expr)
504513
if type(problem) != v:t_dict
@@ -640,7 +649,7 @@ function! leetcode#TestSolution() abort
640649
return
641650
endif
642651

643-
let file_name = expand('%:t:r')
652+
let file_name = s:FileNameToSlug(expand('%:t:r'))
644653
if file_name == ''
645654
echo 'no file name'
646655
return
@@ -745,7 +754,7 @@ function! leetcode#SubmitSolution() abort
745754
return
746755
endif
747756

748-
let file_name = expand('%:t:r')
757+
let file_name = s:FileNameToSlug(expand('%:t:r'))
749758
if file_name == ''
750759
echo 'no file name'
751760
return
@@ -1026,8 +1035,8 @@ function! s:HandleSubmissionsCR() abort
10261035
return
10271036
endif
10281037

1029-
let file_name = printf('%s.%s.%s', submission['slug'], submission_id,
1030-
\ s:SolutionFileExt(submission['filetype']))
1038+
let file_name = printf('%s.%s.%s', s:SlugToFileName(submission['slug']),
1039+
\ submission_id, s:SolutionFileExt(submission['filetype']))
10311040

10321041
if bufexists(file_name)
10331042
execute bufnr(file_name) . 'buffer'

0 commit comments

Comments
 (0)