|
30 | 30 |
|
31 | 31 | " Come here when loading the script the first time.
|
32 | 32 |
|
33 |
| -function s:get_line_trimmed(lnum) |
| 33 | +function! s:get_line_trimmed(lnum) |
34 | 34 | " Get the line and remove a trailing comment.
|
35 | 35 | " Use syntax highlighting attributes when possible.
|
36 | 36 | " NOTE: this is not accurate; /* */ or a line continuation could trick it
|
@@ -61,6 +61,20 @@ function s:get_line_trimmed(lnum)
|
61 | 61 | endif
|
62 | 62 | endfunction
|
63 | 63 |
|
| 64 | +function! s:is_string_comment(lnum, col) |
| 65 | + if has('syntax_items') |
| 66 | + for id in synstack(a:lnum, a:col) |
| 67 | + let synname = synIDattr(id, "name") |
| 68 | + if synname == "rustString" || synname =~ "^rustComment" |
| 69 | + return 1 |
| 70 | + endif |
| 71 | + endfor |
| 72 | + else |
| 73 | + " without syntax, let's not even try |
| 74 | + return 0 |
| 75 | + endif |
| 76 | +endfunction |
| 77 | + |
64 | 78 | function GetRustIndent(lnum)
|
65 | 79 |
|
66 | 80 | " Starting assumption: cindent (called at the end) will do it right
|
@@ -152,8 +166,10 @@ function GetRustIndent(lnum)
|
152 | 166 | " column zero)
|
153 | 167 |
|
154 | 168 | call cursor(a:lnum, 1)
|
155 |
| - if searchpair('{\|(', '', '}\|)', 'nbW') == 0 |
156 |
| - if searchpair('\[', '', '\]', 'nbW') == 0 |
| 169 | + if searchpair('{\|(', '', '}\|)', 'nbW' |
| 170 | + \ 's:is_string_comment(line("."), col("."))') == 0 |
| 171 | + if searchpair('\[', '', '\]', 'nbW', |
| 172 | + \ 's:is_string_comment(line("."), col("."))') == 0 |
157 | 173 | " Global scope, should be zero
|
158 | 174 | return 0
|
159 | 175 | else
|
|
0 commit comments