diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2015-06-15 17:10:06 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2015-06-15 17:10:06 -0400 |
commit | f784272f7381dfd1fc1e6ba2c3c79cd1b7a9c5cd (patch) | |
tree | 5a0ff1dcff3763633edc0ff586dab519554bad5b /lisp/progmodes/perl-mode.el | |
parent | e58a815339fe77f184da8e71e3b932a46b2c0433 (diff) | |
download | emacs-f784272f7381dfd1fc1e6ba2c3c79cd1b7a9c5cd.tar.gz |
* lisp/progmodes/perl-mode.el: Refine handling of /re/ and y/abc/def/
(perl--syntax-exp-intro-keywords): New var.
(perl--syntax-exp-intro-regexp, perl-syntax-propertize-function): Use it.
(bug#20800).
Diffstat (limited to 'lisp/progmodes/perl-mode.el')
-rw-r--r-- | lisp/progmodes/perl-mode.el | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index a64944f0dc5..3521a139809 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -204,10 +204,13 @@ '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>))) (eval-and-compile + (defconst perl--syntax-exp-intro-keywords + '("split" "if" "unless" "until" "while" "print" + "grep" "map" "not" "or" "and" "for" "foreach")) + (defconst perl--syntax-exp-intro-regexp (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)" - (regexp-opt '("split" "if" "unless" "until" "while" "print" - "grep" "map" "not" "or" "and" "for" "foreach")) + (regexp-opt perl--syntax-exp-intro-keywords) "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*"))) ;; FIXME: handle here-docs and regexps. @@ -278,8 +281,13 @@ (forward-comment (- (point-max))) (put-text-property (point) (match-end 2) 'syntax-multiline t) - (not (memq (char-before) - '(?? ?: ?. ?, ?\; ?= ?! ?~ ?\( ?\[))))) + (not (or (and (eq ?w (char-syntax (preceding-char))) + (let ((end (point))) + (backward-sexp 1) + (member (buffer-substring (point) end) + perl--syntax-exp-intro-keywords))) + (memq (char-before) + '(?? ?: ?. ?, ?\; ?= ?! ?~ ?\( ?\[)))))) nil ;; A division sign instead of a regexp-match. (put-text-property (match-beginning 2) (match-end 2) 'syntax-table (string-to-syntax "\"")) @@ -297,13 +305,19 @@ (looking-at-p "sub[ \t\n]")) ;; This is defining a function. nil - (put-text-property (match-beginning 3) (match-end 3) - 'syntax-table - (if (assoc (char-after (match-beginning 3)) - perl-quote-like-pairs) - (string-to-syntax "|") - (string-to-syntax "\""))) - (perl-syntax-propertize-special-constructs end))))) + (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 1)))) + ;; Don't add this syntax-table property if + ;; within a string, which would misbehave in cases such as + ;; $a = "foo y \"toto\" bar" where we'd end up changing the + ;; syntax of the backslash and hence de-escaping the embedded + ;; double quote. + (put-text-property (match-beginning 3) (match-end 3) + 'syntax-table + (if (assoc (char-after (match-beginning 3)) + perl-quote-like-pairs) + (string-to-syntax "|") + (string-to-syntax "\""))) + (perl-syntax-propertize-special-constructs end)))))) ;; Here documents. ((concat "\\(?:" |