Skip to content

Commit 4fe7e7c

Browse files
tenfyzhongianding1
authored andcommitted
Add options to hide topics or companies section.
Add an option named `g:leetcode_hide_topics` to hide the topics section. Add an option named `g:leetcode_hide_companies` to hide the companies section.
1 parent d84917f commit 4fe7e7c

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ Hide the paid only problems on the list.
9494

9595
Default value is `0`.
9696

97+
### `g:leetcode_hide_topics`
98+
99+
Hide the topics section.
100+
101+
Default value is `0`
102+
103+
### `g:leetcode_hide_companies`
104+
105+
Hide the companies section.
106+
107+
Default value is `0`
108+
97109
## Updates
98110

99111
- 2019/12/20: Fix the login issue caused by reCAPTCHA.

autoload/leetcode.vim

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -399,24 +399,28 @@ function! leetcode#ListProblems(refresh) abort
399399
let topics = s:topics_and_companies['topics']
400400
let companies = s:topics_and_companies['companies']
401401

402-
" concatenate the topics into a string
403-
let topic_slugs = map(copy(topics), 'v:val["topic_slug"] . ":" . v:val["num_problems"]')
404-
let topic_lines = s:FormatIntoColumns(topic_slugs)
402+
if g:leetcode_hide_topics == 0
403+
" concatenate the topics into a string
404+
let topic_slugs = map(copy(topics), 'v:val["topic_slug"] . ":" . v:val["num_problems"]')
405+
let topic_lines = s:FormatIntoColumns(topic_slugs)
405406

406-
call append('$', ['# LeetCode', '', '## Topics', ''])
407+
call append('$', ['# LeetCode', '', '## Topics', ''])
407408

408-
let b:leetcode_topic_start_line = line('$')
409-
call append('$', topic_lines)
410-
let b:leetcode_topic_end_line = line('$')
409+
let b:leetcode_topic_start_line = line('$')
410+
call append('$', topic_lines)
411+
let b:leetcode_topic_end_line = line('$')
412+
endif
411413

412-
let company_slugs = map(copy(companies), 'v:val["company_slug"] . ":" . v:val["num_problems"]')
413-
let company_lines = s:FormatIntoColumns(company_slugs)
414+
if g:leetcode_hide_companies == 0
415+
let company_slugs = map(copy(companies), 'v:val["company_slug"] . ":" . v:val["num_problems"]')
416+
let company_lines = s:FormatIntoColumns(company_slugs)
414417

415-
call append('$', ['', '## Companies', ''])
418+
call append('$', ['', '## Companies', ''])
416419

417-
let b:leetcode_company_start_line = line('$')
418-
call append('$', company_lines)
419-
let b:leetcode_company_end_line = line('$')
420+
let b:leetcode_company_start_line = line('$')
421+
call append('$', company_lines)
422+
let b:leetcode_company_end_line = line('$')
423+
endif
420424

421425
call append('$', '')
422426
call s:PrintProblemList()
@@ -461,8 +465,8 @@ function! s:HandleProblemListCR() abort
461465
" Parse the problem number from the line
462466
let line_nr = line('.')
463467

464-
if line_nr >= b:leetcode_topic_start_line &&
465-
\ line_nr < b:leetcode_topic_end_line
468+
if line_nr >= get(b:, 'leetcode_topic_start_line', 0) &&
469+
\ line_nr < get(b:, 'leetcode_topic_end_line', 0)
466470
let topic_slug = expand('<cWORD>')
467471
let topic_slug = s:TagName(topic_slug)
468472
if topic_slug != ''
@@ -471,8 +475,8 @@ function! s:HandleProblemListCR() abort
471475
return
472476
endif
473477

474-
if line_nr >= b:leetcode_company_start_line &&
475-
\ line_nr < b:leetcode_company_end_line
478+
if line_nr >= get(b:, 'leetcode_company_start_line', 0) &&
479+
\ line_nr < get(b:, 'leetcode_company_end_line', 0)
476480
let company_slug = expand('<cWORD>')
477481
let company_slug = s:TagName(company_slug)
478482
if company_slug != ''

doc/leetcode.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ g:leetcode_solution_filetype
8383
g:leetcode_hide_paid_only
8484
Hide the paid only problems on the list.
8585

86+
Default: 0
87+
88+
*g:leetcode_hide_topics*
89+
g:leetcode_hide_topics
90+
Hide the topics section.
91+
92+
Default: 0
93+
94+
*g:leetcode_hide_companies*
95+
g:leetcode_hide_companies
96+
Hide the companies section.
97+
8698
Default: 0
8799

88100
vim:tw=78:ts=8:et:ft=help:norl:

plugin/leetcode.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ if !exists('g:leetcode_hide_paid_only')
2424
let g:leetcode_hide_paid_only = 0
2525
endif
2626

27+
if !exists('g:leetcode_hide_topics')
28+
let g:leetcode_hide_topics = 0
29+
endif
30+
31+
if !exists('g:leetcode_hide_companies')
32+
let g:leetcode_hide_companies = 0
33+
endif
34+
2735
command! -nargs=0 LeetCodeList call leetcode#ListProblems('redraw')
2836
command! -nargs=0 LeetCodeReset call leetcode#ResetSolution(0)
2937
command! -nargs=0 LeetCodeTest call leetcode#TestSolution()

0 commit comments

Comments
 (0)