Skip to content

Commit eb033c1

Browse files
committed
code: simplify print method
1 parent ba14aa8 commit eb033c1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/util.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ function _global_options(argv) {
6060
}
6161

6262
/* Print data from process. */
63-
function _log(data) {
63+
function _print_data(data, prefix = '') {
6464
// After using `spawn` method, it will print two newline at the end of
6565
// message (Emacs + console.log). We simply remove 1 newline at the end
6666
// to prevent printing 2 newlines from one data.
67-
console.log(data.toString().replace(/\n$/, ''));
67+
console.log(prefix + data.toString().replace(/\n$/, ''));
6868
}
6969

7070
/**
@@ -87,12 +87,10 @@ async function e_call(argv, script, ...args) {
8787
console.log('~');
8888
let process = child_process.spawn('emacs', cmd);
8989

90-
process.stdout.on('data', function (data) { _log(data); });
91-
process.stderr.on('data', function (data) { _log(data); });
90+
process.stdout.on('data', function (data) { _print_data(data); });
91+
process.stderr.on('data', function (data) { _print_data(data); });
9292

93-
process.on('exit', function (code) {
94-
console.log('\nExit with code ' + code.toString());
95-
});
93+
process.on('exit', function (code) { _print_data(code, '\nExit with code '); });
9694
}
9795

9896
/*

0 commit comments

Comments
 (0)