google / vimdoc

Helpfile generation for vim
Apache License 2.0
290 stars 37 forks source link

Generate unix fileformat txt file in windows #108

Closed wsdjeg closed 5 years ago

wsdjeg commented 5 years ago

In windows, when run python -m vimdoc . the txt file is generated, but the fileformate is changed to dos, is it possible to generate unix fireformate file?

https://stackoverflow.com/questions/6159900/correct-way-to-write-line-to-file

https://www.datacamp.com/community/tutorials/reading-writing-files-python

maybe this func need to be changed

  def WriteLine(self, text='', right='', indent=0, leader=None, fill=' '):
    """Writes one line of output, breaking it up as needed."""
    if leader is not None:
      initial_indent = (indent * self.TAB) + leader
      subsequent_indent = (indent + 1) * self.TAB
    else:
      initial_indent = indent * self.TAB
      subsequent_indent = indent * self.TAB
    wrapper = textwrap.TextWrapper(
        width=self.WIDTH,
        initial_indent=initial_indent,
        subsequent_indent=subsequent_indent,
        break_on_hyphens=False)
    lines = wrapper.wrap(text)
    # wrap returns empty list for ''. See http://bugs.python.org/issue15510.
    lines = lines or ['']
    lastlen = len(lines[-1])
    rightlen = len(right)
    assert rightlen <= self.WIDTH
    if right and lastlen + rightlen + 1 > self.WIDTH:
      lines.append('')
      lastlen = 0
    if right:
      padding = self.WIDTH - lastlen - rightlen
      assert padding >= 0
      lines[-1] += (fill * padding) + right
    for line in lines:
     self.Print(line)
wsdjeg commented 5 years ago

Before this is fixed, user can use this script:

https://gist.github.com/jonlabelle/dd8c3caa7808cbe4cfe0a47ee4881059

just run crlf.py -u help_file.txt

dbarnett commented 5 years ago

Hmm, so does vim not properly display help files with DOS-style line endings?

wsdjeg commented 5 years ago

yeah. but it cause many diff when use git.

see https://github.com/SpaceVim/SpaceVim/pull/2282

dbarnett commented 5 years ago

Created PR #109 that should fix it. Can you try it out locally and confirm?

wsdjeg commented 5 years ago

OK,I will test it tonight. thanks for your work.

wsdjeg commented 5 years ago

@dbarnett thanks, just confirm, it works well for me.