From: Harald Jörg Date: Mon, 19 Apr 2021 22:25:39 +0000 (+0200) Subject: cperl-mode: Avoid abbrev expansion in variable names X-Git-Tag: emacs-28.0.90~2797 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c4c9a60c1397f01f749e4aa3da8b85ad0bab20b6;p=emacs.git cperl-mode: Avoid abbrev expansion in variable names * 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. --- diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 7878e91096c..bff3e60e90e 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -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 diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index 107b359dc32..9867aa884c6 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -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