Skip to content

Commit 33f6fdf

Browse files
committed
Fix duplicated output when evaluating selections
If the expression being evaluated is already enclosed by a message call, there's no point wrapping it in one. Doing so displays the result twice.
1 parent 1de3cda commit 33f6fdf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ class EmacsLisp{
5151
* Evaluate a string of Emacs Lisp code.
5252
*
5353
* @example eval("(+ 5 5)") -> "10"
54-
* @param {String} text
54+
* @param {String} expr
5555
* @return {Promise} Resolves with collected output.
5656
*/
57-
eval(text){
57+
eval(expr){
5858
return new Promise((resolve, reject) => {
59-
const emacs = childProcess.spawn("emacs", [
60-
"--batch",
61-
"--eval",
62-
`(message "%s" ${text})`
63-
]);
59+
expr = expr.replace(/\r(?=\n)/g, "");
60+
if(!/^\s*\(message\s+".+?%.+?"\s(?:.|\n)+\)\s*$/.test(expr))
61+
expr = `(message "%s" ${expr})`;
62+
const emacs = childProcess.spawn("emacs", ["--batch", "--eval", expr]);
6463

6564
let output = "";
6665
emacs.stderr.on("data", data => {

0 commit comments

Comments
 (0)