From: Stefan Monnier Date: Fri, 14 Aug 2020 14:58:00 +0000 (-0400) Subject: * lisp/progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): Bug#42168 X-Git-Tag: emacs-28.0.90~6584^2~31 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7a7847d7ad558afb8452ff346a0356c5fc837f6e;p=emacs.git * lisp/progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): Bug#42168 * test/lisp/progmodes/cperl-mode-tests.el: Adjust for `perl-mode`. (cperl-test-ppss): Rename from `cperl-test-face` and change return value. (cperl-mode-test-bug-42168): Test the `syntax-ppss` state rather than the font-lock faces, so it works for both `perl-mode` and `cperl-mode`. --- diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index ff0b6a331bc..127b24cb890 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -214,7 +214,9 @@ (defconst perl--syntax-exp-intro-regexp (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)" (regexp-opt perl--syntax-exp-intro-keywords) - "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*"))) + "\\|[?:.,;|&*=!~({[]" + "\\|[^-+][-+]" ;Bug#42168: `+' is intro but `++' isn't! + "\\|\\(^\\)\\)[ \t\n]*"))) (defun perl-syntax-propertize-function (start end) (let ((case-fold-search nil)) diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index f39f1ba6580..be8b42d99a8 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -16,16 +16,17 @@ ;;; Code: -(defun cperl-test-face (text regexp) - "Returns the face of the first character matched by REGEXP in TEXT." +(defvar cperl-test-mode #'cperl-mode) + +(defun cperl-test-ppss (text regexp) + "Return the `syntax-ppss' of the first character matched by REGEXP in TEXT." (interactive) (with-temp-buffer - (insert text) - (cperl-mode) - (font-lock-ensure (point-min) (point-max)) - (goto-char (point-min)) - (re-search-forward regexp) - (get-text-property (match-beginning 0) 'face))) + (insert text) + (funcall cperl-test-mode) + (goto-char (point-min)) + (re-search-forward regexp) + (syntax-ppss))) (ert-deftest cperl-mode-test-bug-42168 () "Verify that '/' is a division after ++ or --, not a regexp. @@ -37,14 +38,14 @@ have a face property." ;; The next two Perl expressions have divisions. Perl "punctuation" ;; operators don't get a face. (let ((code "{ $a++ / $b }")) - (should (equal (cperl-test-face code "/" ) nil))) + (should (equal (nth 8 (cperl-test-ppss code "/")) nil))) (let ((code "{ $a-- / $b }")) - (should (equal (cperl-test-face code "/" ) nil))) + (should (equal (nth 8 (cperl-test-ppss code "/")) nil))) ;; The next two Perl expressions have regular expressions. The ;; delimiter of a RE is fontified with font-lock-constant-face. (let ((code "{ $a+ / $b } # /")) - (should (equal (cperl-test-face code "/" ) font-lock-constant-face))) + (should (equal (nth 8 (cperl-test-ppss code "/")) 7))) (let ((code "{ $a- / $b } # /")) - (should (equal (cperl-test-face code "/" ) font-lock-constant-face)))) + (should (equal (nth 8 (cperl-test-ppss code "/")) 7)))) ;;; cperl-mode-tests.el ends here