aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2017-07-24 18:10:02 -0400
committerStefan Monnier2017-07-24 18:10:02 -0400
commit3d847fa9fd68592c50ea5e18c86b9f3eb5030654 (patch)
tree1f7f061eccffd3cf04c862b62c4d3e2cdb921ea2
parent69fb12a66b3d6b9bfb55d8bcd58bec2a8e7ca55b (diff)
downloademacs-3d847fa9fd68592c50ea5e18c86b9f3eb5030654.tar.gz
emacs-3d847fa9fd68592c50ea5e18c86b9f3eb5030654.zip
* lisp/progmodes/perl-mode.el: Add support for indented here docs
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): Recognize the new <<~ syntax for indented here docs. (perl-syntax-propertize-special-constructs): Adjust search of the end of here docs accordingly. * test/manual/indent/perl.perl: Add test for indented here docs.
-rw-r--r--lisp/progmodes/perl-mode.el43
-rwxr-xr-xtest/manual/indent/perl.perl8
2 files changed, 22 insertions, 29 deletions
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 3def37a2ea8..6197a53ee66 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -213,25 +213,6 @@
213 (regexp-opt perl--syntax-exp-intro-keywords) 213 (regexp-opt perl--syntax-exp-intro-keywords)
214 "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*"))) 214 "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*")))
215 215
216;; FIXME: handle here-docs and regexps.
217;; <<EOF <<"EOF" <<'EOF' (no space)
218;; see `man perlop'
219;; ?...?
220;; /.../
221;; m [...]
222;; m /.../
223;; q /.../ = '...'
224;; qq /.../ = "..."
225;; qx /.../ = `...`
226;; qr /.../ = precompiled regexp =~=~ m/.../
227;; qw /.../
228;; s /.../.../
229;; s <...> /.../
230;; s '...'...'
231;; tr /.../.../
232;; y /.../.../
233;;
234;; <file*glob>
235(defun perl-syntax-propertize-function (start end) 216(defun perl-syntax-propertize-function (start end)
236 (let ((case-fold-search nil)) 217 (let ((case-fold-search nil))
237 (goto-char start) 218 (goto-char start)
@@ -324,23 +305,25 @@
324 ((concat 305 ((concat
325 "\\(?:" 306 "\\(?:"
326 ;; << "EOF", << 'EOF', or << \EOF 307 ;; << "EOF", << 'EOF', or << \EOF
327 "<<[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)" 308 "<<\\(~\\)?[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)"
328 ;; The <<EOF case which needs perl--syntax-exp-intro-regexp, to 309 ;; The <<EOF case which needs perl--syntax-exp-intro-regexp, to
329 ;; disambiguate with the left-bitshift operator. 310 ;; disambiguate with the left-bitshift operator.
330 "\\|" perl--syntax-exp-intro-regexp "<<\\(?1:\\sw+\\)\\)" 311 "\\|" perl--syntax-exp-intro-regexp "<<\\(?2:\\sw+\\)\\)"
331 ".*\\(\n\\)") 312 ".*\\(\n\\)")
332 (3 (let* ((st (get-text-property (match-beginning 3) 'syntax-table)) 313 (4 (let* ((st (get-text-property (match-beginning 4) 'syntax-table))
333 (name (match-string 1))) 314 (name (match-string 2))
334 (goto-char (match-end 1)) 315 (indented (match-beginning 1)))
316 (goto-char (match-end 2))
335 (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))) 317 (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
336 ;; Leave the property of the newline unchanged. 318 ;; Leave the property of the newline unchanged.
337 st 319 st
338 (cons (car (string-to-syntax "< c")) 320 (cons (car (string-to-syntax "< c"))
339 ;; Remember the names of heredocs found on this line. 321 ;; Remember the names of heredocs found on this line.
340 (cons (pcase (aref name 0) 322 (cons (cons (pcase (aref name 0)
341 (`?\\ (substring name 1)) 323 (`?\\ (substring name 1))
342 ((or `?\" `?\' `?\`) (substring name 1 -1)) 324 ((or `?\" `?\' `?\`) (substring name 1 -1))
343 (_ name)) 325 (_ name))
326 indented)
344 (cdr st))))))) 327 (cdr st)))))))
345 ;; We don't call perl-syntax-propertize-special-constructs directly 328 ;; We don't call perl-syntax-propertize-special-constructs directly
346 ;; from the << rule, because there might be other elements (between 329 ;; from the << rule, because there might be other elements (between
@@ -383,7 +366,9 @@
383 (goto-char (nth 8 state))) 366 (goto-char (nth 8 state)))
384 (while (and names 367 (while (and names
385 (re-search-forward 368 (re-search-forward
386 (concat "^" (regexp-quote (pop names)) "\n") 369 (pcase-let ((`(,name . ,indented) (pop names)))
370 (concat "^" (if indented "[ \t]*")
371 (regexp-quote name) "\n"))
387 limit 'move)) 372 limit 'move))
388 (unless names 373 (unless names
389 (put-text-property (1- (point)) (point) 'syntax-table 374 (put-text-property (1- (point)) (point) 'syntax-table
diff --git a/test/manual/indent/perl.perl b/test/manual/indent/perl.perl
index f86a09b2733..06f32e7f090 100755
--- a/test/manual/indent/perl.perl
+++ b/test/manual/indent/perl.perl
@@ -53,6 +53,14 @@ EOF1
53bar 53bar
54EOF2 54EOF2
55 55
56print <<~"EOF1" . <<\EOF2 . s/he"llo/th'ere/;
57foo
58EOF2
59 bar
60 EOF1
61bar
62EOF2
63
56print $'; # This should not start a string! 64print $'; # This should not start a string!
57 65
58print "hello" for /./; 66print "hello" for /./;