aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Jörg2025-01-13 12:24:40 +0100
committerHarald Jörg2025-01-13 12:24:40 +0100
commitb74ac4af9408230645f1edb56c410b7a80bb41d2 (patch)
tree1870231f83a14e87e65d69cc5d44d96e2c784bd8
parentd66b8d4becb6804d3bd912a000dc64ccfdbe6810 (diff)
downloademacs-b74ac4af9408230645f1edb56c410b7a80bb41d2.tar.gz
emacs-b74ac4af9408230645f1edb56c410b7a80bb41d2.zip
; cperl-mode.el: Allow bare $ in a signature (Bug#74245)
* lisp/progmodes/cperl-mode.el (cperl--signature-rx): Allow bare sigils for unused parameters in signatures. (cperl-find-pods-heres): Avoid $) at the end of a signature being treated as the punctuation variable $) by treating this dollar as punctuation * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-signature-rx): Add ($first,$) as a valid signature, remove ($) from the list of invalid signatures.
-rw-r--r--lisp/progmodes/cperl-mode.el26
-rw-r--r--test/lisp/progmodes/cperl-mode-tests.el3
2 files changed, 19 insertions, 10 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index ed8527f0039..38015ed2acd 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -1352,13 +1352,14 @@ prototypes from signatures.")
1352 (optional 1352 (optional
1353 (sequence 1353 (sequence
1354 (0+ (sequence ,cperl--ws*-rx 1354 (0+ (sequence ,cperl--ws*-rx
1355 ,cperl--basic-scalar-rx 1355 (or ,cperl--basic-scalar-rx "$")
1356 ,cperl--ws*-rx 1356 ,cperl--ws*-rx
1357 ",")) 1357 ","))
1358 ,cperl--ws*-rx 1358 ,cperl--ws*-rx
1359 (or ,cperl--basic-scalar-rx 1359 (or ,cperl--basic-scalar-rx
1360 ,cperl--basic-array-rx 1360 ,cperl--basic-array-rx
1361 ,cperl--basic-hash-rx))) 1361 ,cperl--basic-hash-rx
1362 "$" "%" "@")))
1362 (optional (sequence ,cperl--ws*-rx) "," ) 1363 (optional (sequence ,cperl--ws*-rx) "," )
1363 ,cperl--ws*-rx 1364 ,cperl--ws*-rx
1364 ")") 1365 ")")
@@ -4355,8 +4356,8 @@ recursive calls in starting lines of here-documents."
4355 (opt (group (eval cperl--normal-identifier-rx))) ; #13 4356 (opt (group (eval cperl--normal-identifier-rx))) ; #13
4356 (eval cperl--ws*-rx) 4357 (eval cperl--ws*-rx)
4357 (group (or (group (eval cperl--prototype-rx)) ; #14,#15 4358 (group (or (group (eval cperl--prototype-rx)) ; #14,#15
4358 ;; (group (eval cperl--signature-rx)) ; #16 4359 (group (eval cperl--signature-rx)) ; #16
4359 (group unmatchable) ; #16 4360 ;; (group unmatchable) ; #16
4360 (group (or anything buffer-end)))))) ; #17 4361 (group (or anything buffer-end)))))) ; #17
4361 "\\|" 4362 "\\|"
4362 ;; -------- weird variables, capture group 18 4363 ;; -------- weird variables, capture group 18
@@ -5251,7 +5252,7 @@ recursive calls in starting lines of here-documents."
5251 ;; match-string 13: Name of the subroutine (optional) 5252 ;; match-string 13: Name of the subroutine (optional)
5252 ;; match-string 14: Indicator for proto/attr/signature 5253 ;; match-string 14: Indicator for proto/attr/signature
5253 ;; match-string 15: Prototype 5254 ;; match-string 15: Prototype
5254 ;; match-string 16: unused 5255 ;; match-string 16: Subroutine signature
5255 ;; match-string 17: Distinguish declaration/definition 5256 ;; match-string 17: Distinguish declaration/definition
5256 (setq b1 (match-beginning 13) e1 (match-end 13)) 5257 (setq b1 (match-beginning 13) e1 (match-end 13))
5257 (if (memq (char-after (1- b)) 5258 (if (memq (char-after (1- b))
@@ -5267,9 +5268,18 @@ recursive calls in starting lines of here-documents."
5267 (forward-comment (buffer-size)) 5268 (forward-comment (buffer-size))
5268 (cperl-find-sub-attrs st-l b1 e1 b)) 5269 (cperl-find-sub-attrs st-l b1 e1 b))
5269 ;; treat attributes without prototype and incomplete stuff 5270 ;; treat attributes without prototype and incomplete stuff
5270 (goto-char (match-beginning 17)) 5271 (if (match-beginning 16) ; a complete subroutine signature
5271 (cperl-find-sub-attrs st-l b1 e1 b)))) 5272 ;; A signature ending in "$)" must not be
5272 ;; 1+6+2+1+1+6+1=18 extra () before this: 5273 ;; mistaken as the punctuation variable $) which
5274 ;; messes up balance of parens (Bug#74245).
5275 (progn
5276 (when (= (char-after (- (match-end 16) 2)) ?$)
5277 (put-text-property (- (match-end 16) 2) (1- (match-end 16))
5278 'syntax-table cperl-st-punct))
5279 (goto-char (match-end 16)))
5280 (goto-char (match-beginning 17))
5281 (cperl-find-sub-attrs st-l b1 e1 b)))))
5282 ;; 1+6+2+1+1+6+1=18 extra () before this:
5273 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'") 5283 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
5274 ((match-beginning 19) ; old $abc'efg syntax 5284 ((match-beginning 19) ; old $abc'efg syntax
5275 (setq bb (match-end 0)) 5285 (setq bb (match-end 0))
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index 1f3c0ca3213..958ffe38a8b 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -622,10 +622,9 @@ Also includes valid cases with whitespace in strange places."
622 "Test subroutine signatures." 622 "Test subroutine signatures."
623 (skip-unless (eq cperl-test-mode #'cperl-mode)) 623 (skip-unless (eq cperl-test-mode #'cperl-mode))
624 (let ((valid 624 (let ((valid
625 '("()" "( )" "($self, %params)" "(@params)")) 625 '("()" "( )" "($self, %params)" "(@params)" "($first,$)"))
626 (invalid 626 (invalid
627 '("$self" ; missing paren 627 '("$self" ; missing paren
628 "($)" ; a subroutine signature
629 "($!)" ; globals not permitted in a signature 628 "($!)" ; globals not permitted in a signature
630 "(@par,%options)" ; two slurpy parameters 629 "(@par,%options)" ; two slurpy parameters
631 "{$self}"))) ; wrong type of paren 630 "{$self}"))) ; wrong type of paren