Subject: Re: bug#68514: 30.0.50; minibuffer-choose-completion + elisp-c-a-p delete next sexp when completing after open paren

From: Stefan Monnier <[email-masked]>
Date: Wed, 17 Jan 2024 12:53:39 -0500

> This prevents completion from happening at all when point is right after
> an open paren and right before whitespace, which currently works, though
> it has this bug.

It "works" only in the sense that it shows completions, but the set of
possible completions is arguably too large (or small, depending on your
`completion-styles`) to be very useful, and the rest of the behavior is
broken because when you choose a completion it deletes the subsequent
sexp (because it's actually not completing on "" but on " <SEXP>").

> That doesn't seem like an improvement, and also it
> reverts 0db2126d7176b0bd1b13d4b0d1cd958c8cf55714 which explicitly did
> the opposite.

Then maybe...

        Stefan

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 00910fb67c7..da0cb96e1cf 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -657,12 +657,13 @@ elisp-completion-at-point
 		    (save-excursion
 		      (backward-sexp 1)
 		      (skip-chars-forward "`',‘#")
-		      (point))
+		      (min (point) pos))
 		  (scan-error pos)))
 	   (end
-	    (unless (or (eq beg (point-max))
-			(member (char-syntax (char-after beg))
-                                '(?\" ?\()))
+	    (cond
+	     ((and (< beg (point-max))
+		   (memq (char-syntax (char-after beg))
+		                   '(?w ?\\ ?_)))
 	      (condition-case nil
 		  (save-excursion
 		    (goto-char beg)
@@ -670,7 +671,11 @@ elisp-completion-at-point
                     (skip-chars-backward "'’")
 		    (when (>= (point) pos)
 		      (point)))
-		(scan-error pos))))
+		(scan-error pos)))
+             ((or (>= beg (point-max))
+                  (memq (char-syntax (char-after beg))
+		        '(?\) ?\s)))
+              beg)))
            ;; t if in function position.
            (funpos (eq (char-before beg) ?\())
            (quoted (elisp--form-quoted-p beg))