Subject: bug#47652: 28.0.50; completion-at-point fails in verilog-mode

From: Simon McFarlane <[email-masked]>
Date: Thu, 8 Apr 2021 21:04:15 -0700

Hi,

After a very pleasant evening with Edebug (seriously, debugging Emacs is such a smooth experience) I found what I believe to be the culprit and have attached a patch that fixes the issue for me. This is my first time contributing to Emacs so I apologize if I've violated the mailing list convention or etiquette.

Happy to make adjustments if my patch isn't quite right.

Thanks,
Simon
>From 5f80b93f0456a94efc9cf027b5f920cb63e13f38 Mon Sep 17 00:00:00 2001
From: Simon McFarlane <[email-masked]>
Date: Thu, 8 Apr 2021 20:57:53 -0700
Subject: [PATCH] verilog-mode: add save-excursion to fix completion-at-word
 mangling cursor

---
 lisp/progmodes/verilog-mode.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el
index a7f72950b1..bc4f101c0a 100644
--- a/lisp/progmodes/verilog-mode.el
+++ b/lisp/progmodes/verilog-mode.el
@@ -7630,27 +7630,27 @@ nil otherwise."
       (let ((state (car (verilog-calculate-indent))))
 	(cond ((eq state 'defun)
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'module)
+	       (save-excursion (verilog-func-completion 'module))
 	       (verilog-keyword-completion verilog-defun-keywords))
 
 	      ((eq state 'behavioral)
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'module)
+	       (save-excursion (verilog-func-completion 'module))
 	       (verilog-keyword-completion verilog-defun-keywords))
 
 	      ((eq state 'block)
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'tf)
+	       (save-excursion (verilog-func-completion 'tf))
 	       (verilog-keyword-completion verilog-block-keywords))
 
 	      ((eq state 'case)
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'tf)
+	       (save-excursion (verilog-func-completion 'tf))
 	       (verilog-keyword-completion verilog-case-keywords))
 
 	      ((eq state 'tf)
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'tf)
+	       (save-excursion (verilog-func-completion 'tf))
 	       (verilog-keyword-completion verilog-tf-keywords))
 
 	      ((eq state 'cpp)
@@ -7662,7 +7662,7 @@ nil otherwise."
 
 	      (t;--Anywhere else
 	       (save-excursion (verilog-var-completion))
-	       (verilog-func-completion 'both)
+	       (save-excursion (verilog-func-completion 'both))
 	       (verilog-keyword-completion verilog-separator-keywords))))
 
       ;; Now we have built a list of all matches. Give response to caller
-- 
2.31.1