]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/perl-mode.el: Add support for indented here docs
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 24 Jul 2017 22:10:02 +0000 (18:10 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 24 Jul 2017 22:10:02 +0000 (18:10 -0400)
* 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.

lisp/progmodes/perl-mode.el
test/manual/indent/perl.perl

index 3def37a2ea8ae140ce61aa04ac985856c8291341..6197a53ee66db9650a7776b1ba71193f03788688 100644 (file)
             (regexp-opt perl--syntax-exp-intro-keywords)
             "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*")))
 
-;; FIXME: handle here-docs and regexps.
-;; <<EOF <<"EOF" <<'EOF' (no space)
-;; see `man perlop'
-;; ?...?
-;; /.../
-;; m [...]
-;; m /.../
-;; q /.../ = '...'
-;; qq /.../ = "..."
-;; qx /.../ = `...`
-;; qr /.../ = precompiled regexp =~=~ m/.../
-;; qw /.../
-;; s /.../.../
-;; s <...> /.../
-;; s '...'...'
-;; tr /.../.../
-;; y /.../.../
-;;
-;; <file*glob>
 (defun perl-syntax-propertize-function (start end)
   (let ((case-fold-search nil))
     (goto-char start)
       ((concat
         "\\(?:"
         ;; << "EOF", << 'EOF', or << \EOF
-        "<<[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)"
+        "<<\\(~\\)?[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)"
         ;; The <<EOF case which needs perl--syntax-exp-intro-regexp, to
         ;; disambiguate with the left-bitshift operator.
-        "\\|" perl--syntax-exp-intro-regexp "<<\\(?1:\\sw+\\)\\)"
+        "\\|" perl--syntax-exp-intro-regexp "<<\\(?2:\\sw+\\)\\)"
         ".*\\(\n\\)")
-       (3 (let* ((st (get-text-property (match-beginning 3) 'syntax-table))
-                 (name (match-string 1)))
-            (goto-char (match-end 1))
+       (4 (let* ((st (get-text-property (match-beginning 4) 'syntax-table))
+                 (name (match-string 2))
+                 (indented (match-beginning 1)))
+            (goto-char (match-end 2))
             (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
                 ;; Leave the property of the newline unchanged.
                 st
               (cons (car (string-to-syntax "< c"))
                     ;; Remember the names of heredocs found on this line.
-                    (cons (pcase (aref name 0)
-                            (`?\\ (substring name 1))
-                            ((or `?\" `?\' `?\`) (substring name 1 -1))
-                            (_ name))
+                    (cons (cons (pcase (aref name 0)
+                                  (`?\\ (substring name 1))
+                                  ((or `?\" `?\' `?\`) (substring name 1 -1))
+                                  (_ name))
+                                indented)
                           (cdr st)))))))
       ;; We don't call perl-syntax-propertize-special-constructs directly
       ;; from the << rule, because there might be other elements (between
           (goto-char (nth 8 state)))
         (while (and names
                     (re-search-forward
-                     (concat "^" (regexp-quote (pop names)) "\n")
+                     (pcase-let ((`(,name . ,indented) (pop names)))
+                       (concat "^" (if indented "[ \t]*")
+                               (regexp-quote name) "\n"))
                      limit 'move))
           (unless names
             (put-text-property (1- (point)) (point) 'syntax-table
index f86a09b2733c363bb2165f15a8a71f32a4dae149..06f32e7f090dbf28edecbfd8373a7522422b762a 100755 (executable)
@@ -53,6 +53,14 @@ EOF1
 bar
 EOF2
 
+print <<~"EOF1" . <<\EOF2 . s/he"llo/th'ere/;
+foo
+EOF2
+   bar
+   EOF1
+bar
+EOF2
+
 print $'; # This should not start a string!
 
 print "hello" for /./;