]> git.eshelyaron.com Git - emacs.git/commitdiff
cperl-mode: Avoid abbrev expansion in variable names
authorHarald Jörg <haj@posteo.de>
Mon, 19 Apr 2021 22:25:39 +0000 (00:25 +0200)
committerStefan Kangas <stefan@marxist.se>
Tue, 20 Apr 2021 20:47:13 +0000 (22:47 +0200)
* lisp/progmodes/cperl-mode.el (cperl-electric-else): Don't expand
scalar variables like '$continue' as keywords.  (Bug#47902)
* test/lisp/progmodes/cperl-mode-tests.el
(cperl-test-hyperactive-electric-else): Verify that keywords are
expanded but variable names aren't.

lisp/progmodes/cperl-mode.el
test/lisp/progmodes/cperl-mode-tests.el

index 7878e91096c62d85059734893ca0fe68b0cde34b..bff3e60e90e7fa78428e6805b4a764f71464d918 100644 (file)
@@ -2224,7 +2224,7 @@ Help message may be switched off by setting `cperl-message-electric-keyword'
 to nil."
   (let ((beg (point-at-bol)))
     (and (save-excursion
-          (backward-sexp 1)
+           (skip-chars-backward "[:alpha:]")
           (cperl-after-expr-p nil "{;:"))
         (save-excursion
           (not
index 107b359dc32e097a6a4f1b81638a33e317095646..9867aa884c67fe709e1c61015a1ebd4e087548d2 100644 (file)
@@ -495,4 +495,33 @@ as that quote like operator."
                          'font-lock-constant-face
                        font-lock-string-face))))))
 
+(ert-deftest cperl-test-hyperactive-electric-else ()
+  "Demonstrate cperl-electric-else behavior.
+If `cperl-electric-keywords' is true, keywords like \"else\" and
+\"continue\" are expanded by a following empty block, with the
+cursor in the appropriate position to write that block.  This,
+however, must not happen when the keyword occurs in a variable
+\"$else\" or \"$continue\"."
+  (skip-unless (eq cperl-test-mode #'cperl-mode))
+  ;; `self-insert-command' takes a second argument only since Emacs 27
+  (skip-unless (not (< emacs-major-version 27)))
+  (with-temp-buffer
+    (setq cperl-electric-keywords t)
+    (cperl-mode)
+    (insert "continue")
+    (self-insert-command 1 ?\ )
+    (indent-region (point-min) (point-max))
+    (goto-char (point-min))
+    ;; cperl-mode creates a block here
+    (should (search-forward-regexp "continue {\n[[:blank:]]+\n}")))
+  (with-temp-buffer
+    (setq cperl-electric-keywords t)
+    (cperl-mode)
+    (insert "$continue")
+    (self-insert-command 1 ?\ )
+    (indent-region (point-min) (point-max))
+    (goto-char (point-min))
+    ;; No block should have been created here
+    (should-not (search-forward-regexp "{" nil t))))
+
 ;;; cperl-mode-tests.el ends here