From 6d0d71de68c064aaa61633945deb24bfc973e1e2 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Sat, 3 Jan 2026 07:31:53 -0800 Subject: [PATCH] New IELM option to insert newline when inside sexp (bug#80123) * lisp/ielm.el (ielm-dynamic-return): Add new value `point' to user option. (ielm-return): Implement it (bug#80123). --- etc/NEWS | 7 +++++++ lisp/ielm.el | 27 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 2e110b19c31..fd73f26033e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2060,6 +2060,13 @@ When you kill the IELM process with 'C-c C-c', the input history is now saved to the file specified by 'ielm-history-file-name', just like when you exit the Emacs session or kill the IELM buffer. +--- +*** New value 'point' for user option 'ielm-dynamic-return' +When 'ielm-dynamic-return' is set to 'point', typing RET has dynamic +behavior based on if point is inside an sexp. While the point is inside +an sexp typing RET inserts a newline, otherwise the sexp is evaluated. +This is useful when the mode 'electric-pair-mode' is enabled. + ** DocView --- diff --git a/lisp/ielm.el b/lisp/ielm.el index 78c5ad31d3d..09a92f3f74a 100644 --- a/lisp/ielm.el +++ b/lisp/ielm.el @@ -97,9 +97,27 @@ customizes `ielm-prompt'.") (defcustom ielm-dynamic-return t "Controls whether \\\\[ielm-return] has intelligent behavior in IELM. -If non-nil, \\[ielm-return] evaluates input for complete sexps, or inserts a newline -and indents for incomplete sexps. If nil, always inserts newlines." - :type 'boolean) + +If nil, always insert newlines. + +If `point', insert newline if the point is in the middle of an sexp, +otherwise evaluate input. This is useful if you have +`electric-pair-mode' enabled. + +If any other non-nil value, insert newline for incomplete sexp input and +evaluate input for complete sexps. This is similar to the behavior in +text shells." + :type + '(radio + (const :tag "Always insert newline" nil) + (const + :tag + "Insert newline if point is in middle of sexp, otherwise evaluate input" + point) + (const + :tag + "Insert newline for incomplete sexp, otherwise evaluate input" + t))) (defcustom ielm-dynamic-multiline-inputs t "Force multiline inputs to start from column zero? @@ -248,7 +266,8 @@ simply inserts a newline." (if ielm-dynamic-return (let ((state (save-excursion - (end-of-line) + (unless (eq ielm-dynamic-return 'point) + (end-of-line)) (parse-partial-sexp (ielm-pm) (point))))) (if (and (< (car state) 1) (not (nth 3 state)))