GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix bug · chxuan/cpp-mode@1d3e47d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • autoload/cppmode
    • go_to_fun_impl.vim
    • switch.vim
    • util.vim
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎autoload/cppmode/go_to_fun_impl.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/go_to_fun_impl.vim
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ endfunction
4242

4343
" 获得实现文件路径
4444
function! s:get_impl_file_path()
45-
let file_path = cppmode#util#get_current_file_path()
46-
let suffix = cppmode#util#get_current_file_suffix()
45+
let file_path = cppmode#util#get_file_path()
46+
let suffix = cppmode#util#get_file_suffix()
4747

4848
if suffix == "cpp"
4949
return file_path
@@ -57,8 +57,8 @@ endfunction
5757

5858
" 获得头文件路径
5959
function! s:get_head_file_path()
60-
let file_path = cppmode#util#get_current_file_path()
61-
let suffix = cppmode#util#get_current_file_suffix()
60+
let file_path = cppmode#util#get_file_path()
61+
let suffix = cppmode#util#get_file_suffix()
6262

6363
if suffix == "h"
6464
return file_path
@@ -72,12 +72,12 @@ endfunction
7272

7373
" 转到函数实现
7474
function! s:go_to_impl_with_class(file_path)
75-
let fun_name = cppmode#util#get_current_cursor_word()
75+
let fun_name = cppmode#util#get_cursor_word()
7676
let lines = cppmode#util#read_file(a:file_path)
7777
let row_num = <sid>get_row_num_with_class(lines, fun_name)
7878

7979
if row_num != -1
80-
if a:file_path != cppmode#util#get_current_file_path()
80+
if a:file_path != cppmode#util#get_file_path()
8181
call cppmode#util#open_tab(a:file_path)
8282
endif
8383

@@ -93,12 +93,12 @@ endfunction
9393

9494
" 转到函数实现
9595
function! s:go_to_impl_not_with_class(file_path)
96-
let fun_name = cppmode#util#get_current_cursor_word()
96+
let fun_name = cppmode#util#get_cursor_word()
9797
let lines = cppmode#util#read_file(a:file_path)
9898
let row_num = <sid>get_row_num_not_with_class(lines, fun_name)
9999

100100
if row_num != -1
101-
if a:file_path != cppmode#util#get_current_file_path()
101+
if a:file_path != cppmode#util#get_file_path()
102102
call cppmode#util#open_tab(a:file_path)
103103
endif
104104

Collapse file

‎autoload/cppmode/switch.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/switch.vim
+7-21Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
" .h -> .cpp or .cpp -> .h
99
function! cppmode#switch#switch_file()
10-
let suffix = cppmode#util#get_current_file_suffix()
10+
let suffix = cppmode#util#get_file_suffix()
1111
if suffix == "h" || suffix == "hpp"
1212
call <sid>switch_to_implement_file(suffix)
1313
elseif suffix == "cc" || suffix == "cpp"
@@ -45,36 +45,22 @@ endfunction
4545

4646
" 获得头文件
4747
function! s:get_head_file_path(suffix)
48-
let file_path = cppmode#util#get_current_file_path()
4948
let paths = []
50-
let name = ""
49+
let name = cppmode#util#get_base_name_with_path()
5150

52-
if a:suffix == "cpp"
53-
let name = cppmode#util#substr(file_path, 0, len(file_path) - 3)
54-
elseif a:suffix == "cc"
55-
let name = cppmode#util#substr(file_path, 0, len(file_path) - 2)
56-
endif
57-
58-
call add(paths, name . "h")
59-
call add(paths, name . "hpp")
51+
call add(paths, name . ".h")
52+
call add(paths, name . ".hpp")
6053

6154
return paths
6255
endfunction
6356

6457
" 获得实现文件
6558
function! s:get_implement_file_path(suffix)
66-
let file_path = cppmode#util#get_current_file_path()
6759
let paths = []
68-
let name = ""
69-
70-
if a:suffix == "h"
71-
let name = cppmode#util#substr(file_path, 0, len(file_path) - 1)
72-
elseif a:suffix == "hpp"
73-
let name = cppmode#util#substr(file_path, 0, len(file_path) - 3)
74-
endif
60+
let name = cppmode#util#get_base_name_with_path()
7561

76-
call add(paths, name . "cpp")
77-
call add(paths, name . "cc")
62+
call add(paths, name . ".cpp")
63+
call add(paths, name . ".cc")
7864

7965
return paths
8066
endfunction
Collapse file

‎autoload/cppmode/util.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/util.vim
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,30 @@ function! cppmode#util#is_exist(file_path)
146146
endfunction
147147

148148
" 获取当前文件路径
149-
function! cppmode#util#get_current_file_path()
149+
function! cppmode#util#get_file_path()
150150
return expand("%:p")
151151
endfunction
152152

153153
" 获取当前文件的base name
154-
function! cppmode#util#get_current_file_base_name()
155-
let file_path = cppmode#util#get_current_file_path()
154+
function! cppmode#util#get_file_base_name()
155+
let file_path = cppmode#util#get_file_path()
156156
return fnamemodify(file_path, ":t:r")
157157
endfunction
158158

159+
" 获取当前文件的base name
160+
function! cppmode#util#get_base_name_with_path()
161+
let file_path = cppmode#util#get_file_path()
162+
let pos = cppmode#util#find(file_path, ".")
163+
return cppmode#util#substr(file_path, 0, pos)
164+
endfunction
165+
159166
" 获取当前文件后缀名
160-
function! cppmode#util#get_current_file_suffix()
167+
function! cppmode#util#get_file_suffix()
161168
return expand("%:e")
162169
endfunction
163170

164171
" 获取光标下的单词
165-
function! cppmode#util#get_current_cursor_word()
172+
function! cppmode#util#get_cursor_word()
166173
return expand("<cword>")
167174
endfunction
168175

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.