Skip to content

Commit 0ed9001

Browse files
committed
Consistency edits
1 parent e79e103 commit 0ed9001

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/ntangle.nim

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import os, strformat, strutils, tables, terminal, sequtils, times
66
type
77
DebugVerbosity = enum dvNone, dvLow, dvHigh
88

9-
# const DebugVerbosityLevel = dvLow
10-
const DebugVerbosityLevel = dvNone
9+
const
10+
# DebugVerbosityLevel = dvLow
11+
DebugVerbosityLevel = dvNone
1112
template dbg(msg: string, verbosity = dvLow, prefix = "[DBG] ") =
1213
when DebugVerbosityLevel >= dvLow:
1314
case DebugVerbosityLevel
@@ -21,15 +22,15 @@ template dbg(msg: string, verbosity = dvLow, prefix = "[DBG] ") =
2122

2223
const
2324
tangledExt = {
24-
"emacs-lisp" : "el",
25-
"shell" : "sh",
26-
"bash" : "sh",
27-
"tcsh" : "csh",
28-
"rust" : "rs",
29-
"python" : "py",
30-
"python3" : "py",
31-
"ipython" : "py",
32-
"ipython3" : "py"
25+
"emacs-lisp": "el",
26+
"shell": "sh",
27+
"bash": "sh",
28+
"tcsh": "csh",
29+
"rust": "rs",
30+
"python": "py",
31+
"python3": "py",
32+
"ipython": "py",
33+
"ipython3": "py"
3334
}.toTable
3435
dbg "{tangledExt}"
3536

@@ -84,30 +85,28 @@ proc resetStateVars() =
8485
fileHeaderArgs.clear()
8586
headerArgsDefaults.clear()
8687
# Default tangle header args for all Org levels and languages.
87-
headerArgsDefaults[(0.Natural, "")] = HeaderArgs(tangle : "no",
88-
padline : true,
89-
shebang : "",
90-
mkdirp : false,
91-
permissions : {})
88+
headerArgsDefaults[(0.Natural, "")] = HeaderArgs(tangle: "no",
89+
padline: true,
90+
shebang: "",
91+
mkdirp: false,
92+
permissions: {})
9293

9394
proc parseFilePermissions(octals: string): set[FilePermission] =
9495
## Converts the input permissions octal string to a Nim set for FilePermission type.
9596
# https://devdocs.io/nim/os#FilePermission
96-
var perm: set[FilePermission]
9797
let
98-
readPerms = @[fpUserRead, fpGroupRead, fpOthersRead]
99-
writePerms = @[fpUserWrite, fpGroupWrite, fpOthersWrite]
100-
execPerms = @[fpUserExec, fpGroupExec, fpOthersExec]
98+
readPerms = [fpUserRead, fpGroupRead, fpOthersRead]
99+
writePerms = [fpUserWrite, fpGroupWrite, fpOthersWrite]
100+
execPerms = [fpUserExec, fpGroupExec, fpOthersExec]
101101
for idx, o in octals:
102102
if o != '0':
103103
if o in {'4', '5', '6', '7'}:
104-
perm = perm + {readPerms[idx]}
104+
result = result + {readPerms[idx]}
105105
if o in {'2', '3', '6', '7'}:
106-
perm = perm + {writePerms[idx]}
106+
result = result + {writePerms[idx]}
107107
if o in {'1', '3', '5', '7'}:
108-
perm = perm + {execPerms[idx]}
109-
dbg "permissions = {perm}"
110-
result = perm
108+
result = result + {execPerms[idx]}
109+
dbg "permissions = {result}"
111110

112111
proc parseTangleHeaderProperties(file: string, lnum: int, haObj: LangAndArgs) =
113112
## Org header arguments related to tangling. See (org) Extracting Source Code.
@@ -180,7 +179,8 @@ proc parseTangleHeaderProperties(file: string, lnum: int, haObj: LangAndArgs) =
180179
else:
181180
raise newException(OrgError, fmt("The '{argval}' value for ':{argkey}' is invalid. The only valid values are 'yes' and 'no'."))
182181
of "tangle-mode":
183-
let octalPerm = argval.split("#o", maxsplit=1)
182+
let
183+
octalPerm = argval.split("#o", maxsplit=1)
184184
if octalPerm.len != 2:
185185
raise newException(OrgError, fmt("Line {lnum} - The header argkey ':{argkey}' has invalid file permissions syntax: {argval}"))
186186
if octalPerm[1].len < 3:
@@ -282,10 +282,11 @@ proc lineAdjust(line: string, indent: int): string =
282282
result =
283283
if indent == 0:
284284
line & "\n"
285-
elif line.len <= 2 :
285+
elif line.len <= 2:
286286
line & "\n"
287287
else:
288-
var truncSafe = true
288+
var
289+
truncSafe = true
289290
for i, c in line[0 ..< indent]:
290291
dbg "line[{i}] = {c}"
291292
if c != ' ': # Don't truncate if the to-be-truncated portion is not all spaces
@@ -499,7 +500,8 @@ proc doOrgTangle(file: string) =
499500
if file.toLowerAscii.endsWith(".org"): # Ignore files with names not ending in ".org"
500501
resetStateVars()
501502
styledEcho("Parsing ", styleBright, file, resetStyle, " ..")
502-
var lnum = 1
503+
var
504+
lnum = 1
503505
for line in lines(file):
504506
dbg("", prefix=" ") # blank line
505507
dbg "{lnum}: {line}", dvHigh

0 commit comments

Comments
 (0)