Commit f5726c4
Refactor (#100)
* Allow per-buffer toggling to override global
Fixes #98
* Respect global choice in current detection
* Refactor for readability/maintanability
Also addresses issues raised in #98.
Reorder code, organise in sections.
- Simplify utility functions: only keep InitVariable, remove its :exe
- Whitespace patterns and highlighting mechanisms defined once
- Prefs current_line_whitespace_disabled_* can be set only when loading
the plugin (*), as this allows a lot of simplification.
Clarify variables use/responsability.
- Set buffer-local settings b:better_whitespace_enabled and
b:strip_whitespace_on_save *only* when Enable/Disable/Toggle is
called, or when the determination based on the filetype can be made.
- Change SetupAutoCommands to be the only function to be called by:
a) checking the buffer-local setting
b) taking responsability for clearing the highlighting
* Update docs to mirror refactor, fix #91 collisions
* Fix #92: Correctly re-init on colorscheme change
Bug was caused by snyIDattr() returning a string, empty when the
highlight group is undefined, rather than an int with -1 for undefined.
* Add mechanism for confirming whitespace stripping
Based on PR #69 by @advocateddrummer
Also make sure that EOF stripping of empty lines is only done when the
EOF is in the given range.
* Add option to only strip whitespace on modified lines
Diff-based technique to close #38
* Add option to disable stripping-on-save on large files
Using the number of lines in the file, based on PR #97 by @kurikomoe
Also fix docs.
* Adjust documentations
* Check if file exists instead of file name non-emtpy
Files that were created in vim printed errors on first save. E.g.:
:tabe new_file
:w
* Fix typo in doc/better-whitespace.txt
Co-Authored-By: Cimbali <me@cimba.li>
* Fix whitespace search to also match current line
Co-Authored-By: Cimbali <me@cimba.li>
* Correct missing sentence in doc
* Clarify ShouldStripWhitespace role, call diff less
Use &modified and &modifiable to skip diff and disable strippping
(by default) whitespace on save.
* Fix incorrect diff for last line of file
Appending "\n" to joined buffer lines allows to diff until EOF.
Co-Authored-By: Nate Peterson <ntpeters@mtu.edu>
* Make max lines more explicit and default to 1000
* Make a command to manually strip lines on changed lines
* Remove unused bangs from commands
Bangs are only used of `:w` for now
* Show errors to user, except E486: Pattern not found
That error is the only legitimate one, but is already ignored with the
e flag on :s, see :help s_e
* Add error for &noro, respect range for changed lines
Make commands aware of &readonly and show proper errors.
Also improve StripWhitespaceOnChangedLines to take into account the
range it is passed. The range to defaults to % which means no different
behaviour. With any other range, only perform the stripping on the
intersection of the changed lines and that range.
* Add a deprecation warning about in the doc
* Add error number so people can look the error up
The explanation says (emphasis mine):
You tried to execute a command that is neither an Ex command nor
*a user-defined command*.1 parent 70a38fa commit f5726c4
File tree
3 files changed
+426
-287
lines changed- doc
- plugin
3 files changed
+426
-287
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
71 | 69 | | |
72 | 70 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
82 | 78 | | |
83 | 79 | | |
84 | 80 | | |
| |||
128 | 124 | | |
129 | 125 | | |
130 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
131 | 151 | | |
132 | 152 | | |
133 | 153 | | |
| |||
300 | 320 | | |
301 | 321 | | |
302 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
303 | 360 | | |
304 | 361 | | |
305 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | | - | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | | - | |
25 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | | - | |
| 36 | + | |
28 | 37 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 38 | + | |
33 | 39 | | |
34 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
| 45 | + | |
37 | 46 | | |
38 | | - | |
39 | 47 | | |
40 | | - | |
41 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
42 | 53 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 54 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
55 | 57 | | |
56 | | - | |
57 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
58 | 78 | | |
59 | | - | |
60 | 79 | | |
61 | | - | |
| 80 | + | |
62 | 81 | | |
63 | | - | |
| 82 | + | |
| 83 | + | |
64 | 84 | | |
65 | 85 | | |
66 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
67 | 126 | | |
68 | 127 | | |
69 | 128 | | |
| |||
0 commit comments