Nim: nimpretty generates broken formatting

Created on 7 Sep 2019  路  3Comments  路  Source: nim-lang/Nim

proc hid_open*(vendor_id: cushort; product_id: cushort; serial_number: cstring): ptr HidDevice {.
    importc: "hid_open", dynlib: hidapi.}

gets formatted into

proc hid_open*(vendor_id: cushort; product_id: cushort;
    serial_number: cstring): ptr HidDevice {.

importc: "hid_open", dynlib: hidapi.}
nimpretty

Most helpful comment

things (copy/paste/edit/format) would be so much easier without the 80 column limit causing hard line wrap. All modern editors allow soft-line-wrap when displaying long lines.

All 3 comments

things (copy/paste/edit/format) would be so much easier without the 80 column limit causing hard line wrap. All modern editors allow soft-line-wrap when displaying long lines.

The editors don't understand how to wrap them properly though. Not even nimpretty knows so how could they... ;-)

source code for strutils.isUpperAscii (after I removed the hard line wrap in proc signature):

proc isUpperAscii*(c: char): bool {.noSideEffect, procvar, rtl, extern: "nsuIsUpperAsciiChar".} =
  ## Checks whether or not `c` is an upper case character.
  ##
  ## This checks ASCII characters only.
  ## Use `Unicode module<unicode.html>`_ for UTF-8 support.
  ##
  ## See also:
  ## * `toUpperAscii proc<#toUpperAscii,char>`_
  runnableExamples:
    doAssert isUpperAscii('e') == false
    doAssert isUpperAscii('E') == true
    doAssert isUpperAscii('7') == false
  return c in {'A'..'Z'}

heres's sublimetext in 3 different editor widths (on my monitor, even with lots of panes/tabs open concurrently, I almost never go even near 80 columns (remnant from the 80's terminals), but even if I do, the soft line wrap is perfectly readable:

at ~ 40 colums editor width:
image
at ~ 82 colums editor width:
image
at > 120 colums editor width:
image

since this changes the rendering and not the source code, whatever heuristic is used doesn't even matter much and can be user-settable to user's liking instead of imposed by nimpretty

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hlaaftana picture hlaaftana  路  3Comments

ghost picture ghost  路  4Comments

wizzardx picture wizzardx  路  4Comments

juancarlospaco picture juancarlospaco  路  3Comments

zzz125 picture zzz125  路  4Comments