nimfix supports specialized '.nimfix' modules
This commit is contained in:
parent
7333237be6
commit
c53a27f0dc
4 changed files with 31 additions and 18 deletions
|
|
@ -337,6 +337,16 @@ proc findFile*(f: string): string {.procvar.} =
|
|||
|
||||
proc findModule*(modulename, currentModule: string): string =
|
||||
# returns path to module
|
||||
when defined(nimfix):
|
||||
# '.nimfix' modules are preferred over '.nim' modules so that specialized
|
||||
# versions can be kept for 'nimfix'.
|
||||
block:
|
||||
let m = addFileExt(modulename, "nimfix")
|
||||
let currentPath = currentModule.splitFile.dir
|
||||
result = currentPath / m
|
||||
if not existsFile(result):
|
||||
result = findFile(m)
|
||||
if existsFile(result): return result
|
||||
let m = addFileExt(modulename, NimExt)
|
||||
let currentPath = currentModule.splitFile.dir
|
||||
result = currentPath / m
|
||||
|
|
|
|||
|
|
@ -31,20 +31,20 @@ type
|
|||
proc overwriteFiles*() =
|
||||
let doStrip = options.getConfigVar("pretty.strip").normalize == "on"
|
||||
for i in 0 .. high(gSourceFiles):
|
||||
if not gSourceFiles[i].dirty: continue
|
||||
let newFile = if gOverWrite: gSourceFiles[i].fullpath
|
||||
else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim")
|
||||
try:
|
||||
var f = open(newFile, fmWrite)
|
||||
for line in gSourceFiles[i].lines:
|
||||
if doStrip:
|
||||
f.write line.strip(leading = false, trailing = true)
|
||||
else:
|
||||
f.write line
|
||||
f.write("\L")
|
||||
f.close
|
||||
except IOError:
|
||||
rawMessage(errCannotOpenFile, newFile)
|
||||
if gSourceFiles[i].dirty and not gSourceFiles[i].isNimfixFile:
|
||||
let newFile = if gOverWrite: gSourceFiles[i].fullpath
|
||||
else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim")
|
||||
try:
|
||||
var f = open(newFile, fmWrite)
|
||||
for line in gSourceFiles[i].lines:
|
||||
if doStrip:
|
||||
f.write line.strip(leading = false, trailing = true)
|
||||
else:
|
||||
f.write line
|
||||
f.write("\L")
|
||||
f.close
|
||||
except IOError:
|
||||
rawMessage(errCannotOpenFile, newFile)
|
||||
|
||||
proc `=~`(s: string, a: openArray[string]): bool =
|
||||
for x in a:
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@
|
|||
#
|
||||
|
||||
import ast, msgs, strutils, idents
|
||||
from os import splitFile
|
||||
|
||||
type
|
||||
TSourceFile* = object
|
||||
lines*: seq[string]
|
||||
dirty*: bool
|
||||
dirty*, isNimfixFile*: bool
|
||||
fullpath*: string
|
||||
|
||||
var
|
||||
|
|
@ -26,7 +27,8 @@ proc loadFile*(info: TLineInfo) =
|
|||
gSourceFiles[i].lines = @[]
|
||||
let path = info.toFullPath
|
||||
gSourceFiles[i].fullpath = path
|
||||
# we want to die here for EIO:
|
||||
gSourceFiles[i].isNimfixFile = path.splitFile.ext == "nimfix"
|
||||
# we want to die here for IOError:
|
||||
for line in lines(path):
|
||||
gSourceFiles[i].lines.add(line)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue