aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-25 13:08:33 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-25 13:08:33 +0100
commitd7ce2174f12d1b7730a015100ca0fef457ad4d72 (patch)
treebbd7bc1a76689bdb0c0e1b731db7834520d58ac4 /src
parent22abd1b12b66e75f75fe01dc33abaa7d74597b3c (diff)
downloadchawan-d7ce2174f12d1b7730a015100ca0fef457ad4d72.tar.gz
ips/editor: don't write file for empty input, check for conflicting files
Diffstat (limited to 'src')
-rw-r--r--src/ips/editor.nim19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/ips/editor.nim b/src/ips/editor.nim
index bfa88cb5..4361c39f 100644
--- a/src/ips/editor.nim
+++ b/src/ips/editor.nim
@@ -24,8 +24,6 @@ func formatEditorName(editor, file: string, line: int): string =
continue
result &= editor[i]
inc i
- if editor.len == 0:
- result = "vi"
if not filefound:
if result[^1] != ' ':
result &= ' '
@@ -48,12 +46,19 @@ proc openInEditor*(term: Terminal, config: Config, input: var string): bool =
let tmpdir = config.tmpdir
if not dirExists(tmpdir):
createDir(tmpdir)
- let tmpf = tmpdir / "chatmp" & $tmpf_seq
+ var tmpf = tmpdir / "chatmp" & $tmpf_seq
+ while fileExists(tmpf):
+ inc tmpf_seq
+ tmpf = tmpdir / "chatmp" & $tmpf_seq
inc tmpf_seq
- writeFile(tmpf, input)
+ if input != "":
+ writeFile(tmpf, input)
if openEditor(term, config, tmpf):
- input = readFile(tmpf)
- removeFile(tmpf)
- return true
+ if fileExists(tmpf):
+ input = readFile(tmpf)
+ removeFile(tmpf)
+ return true
+ else:
+ return false
except IOError:
discard