vim-eof-comment 0.5.0__py3-none-any.whl → 0.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vim_eof_comment/eof.py CHANGED
@@ -9,7 +9,7 @@ Copyright (c) 2025 Guennadi Maximov C. All Rights Reserved.
9
9
  __all__ = ["append_eof_comment", "eof_comment_search", "main"]
10
10
 
11
11
  from io import TextIOWrapper
12
- from typing import Dict, List, NoReturn
12
+ from typing import Dict, List, NoReturn, Tuple
13
13
 
14
14
  from colorama import Fore, Style
15
15
  from colorama import init as color_init
@@ -32,7 +32,7 @@ def eof_comment_search(
32
32
  files: Dict[str, BatchPathDict],
33
33
  comments: Comments,
34
34
  **kwargs
35
- ) -> Dict[str, EOFCommentSearch]:
35
+ ) -> Tuple[Dict[str, EOFCommentSearch], bool]:
36
36
  """
37
37
  Search through opened files.
38
38
 
@@ -71,7 +71,7 @@ def eof_comment_search(
71
71
  ext: str = file["ft_ext"]
72
72
 
73
73
  wrapper = get_last_line(file_obj)
74
- last_line, had_nwl = wrapper["line"], wrapper["had_nwl"]
74
+ last_line, had_nwl, crlf = wrapper["line"], wrapper["had_nwl"], wrapper["crlf"]
75
75
 
76
76
  verbose_print(f"{_RESET} - {path} ==> ", verbose=verbose, end="", sep="")
77
77
  if last_line != comment_map[ext] or (newline and not had_nwl):
@@ -79,18 +79,19 @@ def eof_comment_search(
79
79
  result[path] = EOFCommentSearch(
80
80
  state=IOWrapperBool(file=open(path, "r"), had_nwl=had_nwl),
81
81
  lang=ext,
82
- match=matches(last_line, verbose)
82
+ match=matches(last_line)
83
83
  )
84
84
  else:
85
85
  verbose_print(f"{_BRIGHT}{_GREEN}OK", verbose=verbose)
86
86
 
87
- return result
87
+ return result, crlf
88
88
 
89
89
 
90
90
  def append_eof_comment(
91
91
  files: Dict[str, EOFCommentSearch],
92
92
  comments: Comments,
93
- newline: bool
93
+ newline: bool,
94
+ crlf: bool
94
95
  ) -> NoReturn:
95
96
  """
96
97
  Append a Vim EOF comment to files missing it.
@@ -103,6 +104,8 @@ def append_eof_comment(
103
104
  The ``Comments`` object containing the hardcoded comments per file extension.
104
105
  newline : bool
105
106
  Indicates whether a newline should be added before the comment.
107
+ crlf : bool
108
+ Whether the file is CRLF-terminated.
106
109
  """
107
110
  comment_map = comments.generate()
108
111
  for path, file in files.items():
@@ -166,9 +169,9 @@ def main() -> int:
166
169
  die("No matching files found!", code=code)
167
170
 
168
171
  comments = Comments(gen_indent_maps(indent.copy()))
169
- results = eof_comment_search(files, comments, verbose=verbose, newline=newline)
172
+ results, crlf = eof_comment_search(files, comments, verbose=verbose, newline=newline)
170
173
  if len(results) > 0 and not dry_run:
171
- append_eof_comment(results, comments, newline)
174
+ append_eof_comment(results, comments, newline, crlf)
172
175
 
173
176
  return 0
174
177
 
vim_eof_comment/eof.pyi CHANGED
@@ -5,7 +5,7 @@ from .types import BatchPathDict, EOFCommentSearch
5
5
 
6
6
  __all__ = ['append_eof_comment', 'eof_comment_search', 'main']
7
7
 
8
- def eof_comment_search(files: dict[str, BatchPathDict], comments: Comments, **kwargs) -> dict[str, EOFCommentSearch]:
8
+ def eof_comment_search(files: dict[str, BatchPathDict], comments: Comments, **kwargs) -> tuple[dict[str, EOFCommentSearch], bool]:
9
9
  """
10
10
  Search through opened files.
11
11
 
@@ -30,7 +30,7 @@ def eof_comment_search(files: dict[str, BatchPathDict], comments: Comments, **kw
30
30
  vim_eof_comment.types.EOFCommentSearch
31
31
  The object type for the returning dictionary values.
32
32
  """
33
- def append_eof_comment(files: dict[str, EOFCommentSearch], comments: Comments, newline: bool) -> NoReturn:
33
+ def append_eof_comment(files: dict[str, EOFCommentSearch], comments: Comments, newline: bool, crlf: bool) -> NoReturn:
34
34
  """
35
35
  Append a Vim EOF comment to files missing it.
36
36
 
@@ -42,6 +42,8 @@ def append_eof_comment(files: dict[str, EOFCommentSearch], comments: Comments, n
42
42
  The ``Comments`` object containing the hardcoded comments per file extension.
43
43
  newline : bool
44
44
  Indicates whether a newline should be added before the comment.
45
+ crlf : bool
46
+ Whether the file is CRLF-terminated.
45
47
  """
46
48
  def main() -> int:
47
49
  """
vim_eof_comment/file.py CHANGED
@@ -137,7 +137,7 @@ def modify_file(file: TextIOWrapper, comments: Dict[str, str], ext: str, **kwarg
137
137
  ext : str
138
138
  The file-type/file-extension given by the user.
139
139
  **kwargs
140
- Contains the ``newline``, and ``matching`` boolean attributes.
140
+ Contains the ``newline``, ``matching`` and ``crlf`` boolean attributes.
141
141
 
142
142
  Returns
143
143
  -------
@@ -146,11 +146,15 @@ def modify_file(file: TextIOWrapper, comments: Dict[str, str], ext: str, **kwarg
146
146
  """
147
147
  matching: bool = kwargs.get("matching", False)
148
148
  newline: bool = kwargs.get("newline", False)
149
+ crlf: bool = kwargs.get("crlf", False)
149
150
 
150
151
  bdata: str = file.read()
151
- data: List[str] = bdata.split("\n")
152
152
  file.close()
153
153
 
154
+ data: List[str] = bdata.split("\n")
155
+ if crlf:
156
+ data[-2] = ""
157
+
154
158
  data_len = len(data)
155
159
  comment = comments[ext]
156
160
  if data_len == 0:
@@ -173,6 +177,9 @@ def modify_file(file: TextIOWrapper, comments: Dict[str, str], ext: str, **kwarg
173
177
  if not newline and data[-3] == "":
174
178
  data.pop(-3)
175
179
 
180
+ if crlf:
181
+ data.insert(-1, "\r")
182
+
176
183
  return "\n".join(data)
177
184
 
178
185
 
@@ -194,15 +201,22 @@ def get_last_line(file: TextIOWrapper) -> LineBool:
194
201
  data: List[str] = bdata.split("\n")
195
202
  file.close()
196
203
 
197
- had_newline, line = False, ""
198
- if len(data) <= 1:
204
+ if data[-1] != "":
205
+ data.append("")
206
+
207
+ had_nwl, crlf, line = False, False, ""
208
+ if len(data) == 0:
209
+ line = ""
210
+ elif len(data) == 1:
199
211
  line = data[0]
200
212
  elif len(data) >= 2:
201
213
  line: str = data[-2]
214
+ if line == "\r":
215
+ line, crlf = "", True
202
216
 
203
217
  if len(data) >= 3:
204
- had_newline = data[-3] == ""
218
+ had_nwl = data[-3] == ""
205
219
 
206
- return LineBool(line=line, had_nwl=had_newline)
220
+ return LineBool(line=line, had_nwl=had_nwl, crlf=crlf)
207
221
 
208
222
  # vim: set ts=4 sts=4 sw=4 et ai si sta:
vim_eof_comment/file.pyi CHANGED
@@ -61,7 +61,7 @@ def modify_file(file: TextIOWrapper, comments: dict[str, str], ext: str, **kwarg
61
61
  ext : str
62
62
  The file-type/file-extension given by the user.
63
63
  **kwargs
64
- Contains the ``newline``, and ``matching`` boolean attributes.
64
+ Contains the ``newline``, ``matching`` and ``crlf`` boolean attributes.
65
65
 
66
66
  Returns
67
67
  -------
vim_eof_comment/regex.py CHANGED
@@ -7,11 +7,11 @@ Copyright (c) 2025 Guennadi Maximov C. All Rights Reserved.
7
7
  """
8
8
  __all__ = ["matches"]
9
9
 
10
- from re import compile
11
- from typing import Tuple
10
+ from re import Pattern, compile
11
+ from typing import AnyStr, List
12
12
 
13
13
 
14
- def matches(s: str, verbose: bool = False) -> bool:
14
+ def matches(s: str) -> bool:
15
15
  """
16
16
  Check if given string matches any of the given patterns.
17
17
 
@@ -19,21 +19,18 @@ def matches(s: str, verbose: bool = False) -> bool:
19
19
  ----------
20
20
  s : str
21
21
  The string to be matched.
22
- verbose : bool, optional, default=False
23
- Enables verbose mode.
24
22
 
25
23
  Returns
26
24
  -------
27
25
  bool
28
26
  Whether the string matches the default regex.
29
27
  """
30
- pats: Tuple[str, str] = (
31
- "vim:([a-zA-Z]+(=[a-zA-Z0-9_]*)?:)+",
32
- "vim:\\sset(\\s[a-zA-Z]+(=[a-zA-Z0-9_]*)?)*\\s[a-zA-Z]+(=[a-zA-Z0-9_]*)?:"
33
- )
34
- for pattern in [compile(pat) for pat in pats]:
35
- match = pattern.search(s)
36
- if match is not None:
28
+ pats: List[Pattern[AnyStr]] = [
29
+ compile("vim:([a-zA-Z]+(=[a-zA-Z0-9_]*)?:)+"),
30
+ compile("vim:\\sset(\\s[a-zA-Z]+(=[a-zA-Z0-9_]*)?)*\\s[a-zA-Z]+(=[a-zA-Z0-9_]*)?:"),
31
+ ]
32
+ for pattern in pats:
33
+ if pattern.search(s) is not None:
37
34
  return True
38
35
 
39
36
  return False
vim_eof_comment/regex.pyi CHANGED
@@ -1,6 +1,6 @@
1
1
  __all__ = ['matches']
2
2
 
3
- def matches(s: str, verbose: bool = False) -> bool:
3
+ def matches(s: str) -> bool:
4
4
  """
5
5
  Check if given string matches any of the given patterns.
6
6
 
@@ -8,8 +8,6 @@ def matches(s: str, verbose: bool = False) -> bool:
8
8
  ----------
9
9
  s : str
10
10
  The string to be matched.
11
- verbose : bool, optional, default=False
12
- Enables verbose mode.
13
11
 
14
12
  Returns
15
13
  -------
vim_eof_comment/types.py CHANGED
@@ -266,7 +266,7 @@ class IndentHandler(TypedDict):
266
266
 
267
267
  class IOWrapperBool(TypedDict):
268
268
  """
269
- A dict containing ``file`` and ``had_nwl`` as keys.
269
+ A dict containing ``file``, ``had_nwl`` and ``crlf`` as keys.
270
270
 
271
271
  This is a ``TypedDict``-like object.
272
272
 
@@ -276,15 +276,18 @@ class IOWrapperBool(TypedDict):
276
276
  The opened file as a ``TextIO`` wrapper.
277
277
  had_nwl : bool
278
278
  Whether the file has a newline or not.
279
+ crlf : bool
280
+ Whether the file is CRLF-terminated.
279
281
  """
280
282
 
281
283
  file: TextIO
282
284
  had_nwl: bool
285
+ crlf: bool
283
286
 
284
287
 
285
288
  class LineBool(TypedDict):
286
289
  """
287
- A dict containing ``line`` and ``had_nwl`` as keys.
290
+ A dict containing ``line``, ``had_nwl`` and ``crlf`` as keys.
288
291
 
289
292
  This is a ``TypedDict``-like object.
290
293
 
@@ -294,10 +297,13 @@ class LineBool(TypedDict):
294
297
  The last line of the target file.
295
298
  had_nwl : bool
296
299
  Whether the file has a newline or not.
300
+ crlf : bool
301
+ Whether the file is CRLF-terminated.
297
302
  """
298
303
 
299
304
  line: str
300
305
  had_nwl: bool
306
+ crlf: bool
301
307
 
302
308
 
303
309
  class BatchPathDict(TypedDict):
vim_eof_comment/types.pyi CHANGED
@@ -208,7 +208,7 @@ class IndentHandler(TypedDict):
208
208
 
209
209
  class IOWrapperBool(TypedDict):
210
210
  """
211
- A dict containing ``file`` and ``had_nwl`` as keys.
211
+ A dict containing ``file``, ``had_nwl`` and ``crlf`` as keys.
212
212
 
213
213
  This is a ``TypedDict``-like object.
214
214
 
@@ -218,13 +218,16 @@ class IOWrapperBool(TypedDict):
218
218
  The opened file as a ``TextIO`` wrapper.
219
219
  had_nwl : bool
220
220
  Whether the file has a newline or not.
221
+ crlf : bool
222
+ Whether the file is CRLF-terminated.
221
223
  """
222
224
  file: TextIO
223
225
  had_nwl: bool
226
+ crlf: bool
224
227
 
225
228
  class LineBool(TypedDict):
226
229
  """
227
- A dict containing ``line`` and ``had_nwl`` as keys.
230
+ A dict containing ``line``, ``had_nwl`` and ``crlf`` as keys.
228
231
 
229
232
  This is a ``TypedDict``-like object.
230
233
 
@@ -234,9 +237,12 @@ class LineBool(TypedDict):
234
237
  The last line of the target file.
235
238
  had_nwl : bool
236
239
  Whether the file has a newline or not.
240
+ crlf : bool
241
+ Whether the file is CRLF-terminated.
237
242
  """
238
243
  line: str
239
244
  had_nwl: bool
245
+ crlf: bool
240
246
 
241
247
  class BatchPathDict(TypedDict):
242
248
  """
@@ -81,6 +81,8 @@ version_info = VersionInfo([
81
81
  (0, 4, 1),
82
82
  (0, 4, 2),
83
83
  (0, 5, 0),
84
+ (0, 5, 1),
85
+ (0, 5, 2),
84
86
  ])
85
87
 
86
88
  __version__: str = str(version_info)
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vim-eof-comment
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Adds Vim EOF modeline comments for given filetypes in given directories
5
5
  Author-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
6
6
  Maintainer-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
7
7
  License-Expression: GPL-2.0-only
8
8
  Project-URL: Download, https://github.com/DrKJeff16/vim-eof-comment/releases/latest
9
+ Project-URL: Funding, https://github.com/sponsors/DrKJeff16
9
10
  Project-URL: Issues, https://github.com/DrKJeff16/vim-eof-comment/issues
10
11
  Project-URL: Repository, https://github.com/DrKJeff16/vim-eof-comment
11
12
  Keywords: eof comments,eof,files,preprocessing,text,vim modeline,vim,vim-eof
@@ -7,18 +7,18 @@ docs/source/installation.rst,sha256=PkiS3E_ujNTWeKXicZ7aBPch2l1R0TsRRL6pFj_oMJI,
7
7
  vim_eof_comment/__init__.py,sha256=ESbmhca9mTst3TYMer8zFw73IRsJvn5EESci_RpfLbQ,487
8
8
  vim_eof_comment/__init__.pyi,sha256=Eh8FQwE_F9TrQEiT7CR1mdGHBT6fHUzfV6VP8uSN33g,478
9
9
  vim_eof_comment/__main__.py,sha256=0AFVSkz8RuxSuPbJJWycyxs6u5Yypl8FKUMR3ZVLJbk,343
10
- vim_eof_comment/eof.py,sha256=3iCP_fL3aUrPndKve3DoSpikZSvyIR0kwaE46EAlJqA,5158
11
- vim_eof_comment/eof.pyi,sha256=BTw9brhrHBTX12fYuwfO8_D-Gyrf0387ErmgrcTdvh0,1786
12
- vim_eof_comment/file.py,sha256=HNtwUMteUeKldBcVJEjdxlHLWNDXPbgjswJ-9PKRlQA,5100
13
- vim_eof_comment/file.pyi,sha256=S02kb4Ta5kDXpC3fYAVboC89jSUzHv6AHoll5HMICUg,2265
10
+ vim_eof_comment/eof.py,sha256=X2E-6yH45NbPK4kyWfa5nJyMeAHcs3vxinXea-sWrdo,5287
11
+ vim_eof_comment/eof.pyi,sha256=eFaIkPQ3ZXS3CE6QpTEA9QCQmJpmG_5N3Kb3_Iz_tOo,1872
12
+ vim_eof_comment/file.py,sha256=QGpj91dy7YgyCplVI52-eDZ6094-6FxSKYtAgjhX5Ok,5394
13
+ vim_eof_comment/file.pyi,sha256=XOYsJnW72i7Zt9N0jSLpscls-ggzL08aQKXpxrLFiwY,2274
14
14
  vim_eof_comment/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- vim_eof_comment/regex.py,sha256=rGfFIBMbfWlIxAScXqvgBlB-tMJBUxQwTVjEkoxDZ3o,1007
16
- vim_eof_comment/regex.pyi,sha256=LJt6HN9s0Vo1B5plpaYURVZ3okmtl5jnV6kKdn1KyqA,433
17
- vim_eof_comment/types.py,sha256=YumpVIUl1wxbn_QIEkWeUbxsa9b9RJYdVEBzx-Kt4xo,8195
18
- vim_eof_comment/types.pyi,sha256=r6QziOKE9nKaZ02TR1NZDWCtEcLtMCnsOqnDNXvXJfw,7083
15
+ vim_eof_comment/regex.py,sha256=48oxUO3YDdM30U0qAsqyH_AycYCrcnaQ6cghy3NXHrw,903
16
+ vim_eof_comment/regex.pyi,sha256=W0ZX_J9mLRckCdBNE-Bl09hsQ61VFqjuLwDlevEeeUM,336
17
+ vim_eof_comment/types.py,sha256=kujXMK19J0Nngf6eoHyg04ZfD-WKAB_Cdna7uRVJTKQ,8367
18
+ vim_eof_comment/types.pyi,sha256=OnXme5rgPq9vt8LHTRCSeOpkBAuc2J_7pcwcXFHOk1A,7255
19
19
  vim_eof_comment/util.py,sha256=MHLt-FJz4uhsa56J2sug74uqk6W3S0mVLugvz7KNRUU,4287
20
20
  vim_eof_comment/util.pyi,sha256=5RQukLgpVZTwbALhBOtd1NqFkiqC-V6JEWeT1_B9-2k,2675
21
- vim_eof_comment/version.py,sha256=TQzYqwQZB_r20lmzgs1-xwdDTAIin2dVYGP88Io2jUc,1883
21
+ vim_eof_comment/version.py,sha256=OrehJsWieQkG3G4Wz8wj6ph5iZS7MAJ4PiILc-bnEM4,1913
22
22
  vim_eof_comment/version.pyi,sha256=P90IRWMKlsG_YU8G8a1e1eyTd8rC-6fUGvQrD3zjwbE,525
23
23
  vim_eof_comment/args/__init__.py,sha256=Hyqun15456NVFLAJ3cpdtuNEz5XaFH93vfVlbC-aeuc,318
24
24
  vim_eof_comment/args/__init__.pyi,sha256=cXK7nEpYBveD4kxtVTe2x8oUxT9mhENS5r3wK3AAX2U,151
@@ -31,9 +31,9 @@ vim_eof_comment/comments/__init__.pyi,sha256=cecbbrShh0If8btwJ8zKYpBt9dIsMwrDXbd
31
31
  vim_eof_comment/comments/filetypes.json,sha256=JpSrnBNO2AivLYi-C5--8yVocyBwye3IkMesNIz1uHA,2973
32
32
  vim_eof_comment/comments/generator.py,sha256=yuRvTuVd6qQ1ei496w8NQ0c1MR1e3qJHf1pOTalXlv8,7814
33
33
  vim_eof_comment/comments/generator.pyi,sha256=ue8oMa7yEoKfgQDJbeTzx0Qm5Wck2gHrDb_wF00xIyo,3687
34
- vim_eof_comment-0.5.0.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
35
- vim_eof_comment-0.5.0.dist-info/METADATA,sha256=eri3jmB75CaTiK42raTS2kZSMUSWWyModjqc1v_Wp0o,2766
36
- vim_eof_comment-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- vim_eof_comment-0.5.0.dist-info/entry_points.txt,sha256=vm47g4hoUbow4elcHr9yylYfj6IvAs10wSFKqwqTu6E,61
38
- vim_eof_comment-0.5.0.dist-info/top_level.txt,sha256=TkaQ5vuhVzXaJnfUdcLJCQ81ILK2V6OtvX5-hIMZAc0,21
39
- vim_eof_comment-0.5.0.dist-info/RECORD,,
34
+ vim_eof_comment-0.5.2.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
35
+ vim_eof_comment-0.5.2.dist-info/METADATA,sha256=iXYWdGCwNRdaZ1vnU1bvfmEjMYGJmSPegdYTm7KbNPA,2826
36
+ vim_eof_comment-0.5.2.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
37
+ vim_eof_comment-0.5.2.dist-info/entry_points.txt,sha256=vm47g4hoUbow4elcHr9yylYfj6IvAs10wSFKqwqTu6E,61
38
+ vim_eof_comment-0.5.2.dist-info/top_level.txt,sha256=TkaQ5vuhVzXaJnfUdcLJCQ81ILK2V6OtvX5-hIMZAc0,21
39
+ vim_eof_comment-0.5.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5