diff options
| author | Stefan Monnier | 2005-10-20 19:43:44 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-10-20 19:43:44 +0000 |
| commit | 9d37a5c0f54bfadc33017697b2579aa0554d0b23 (patch) | |
| tree | 76913cbfdfa4d943a4c13560d96c476ec62fba9d | |
| parent | 4bfa31bac081488a27664d11a3a3891f1631330d (diff) | |
| download | emacs-9d37a5c0f54bfadc33017697b2579aa0554d0b23.tar.gz emacs-9d37a5c0f54bfadc33017697b2579aa0554d0b23.zip | |
(sh-escaped-line-re): New var.
(sh-here-doc-open-re, sh-font-lock-close-heredoc): Use it.
(sh-font-lock-open-heredoc): Try to properly handle heredoc starters
whose line is either continued or ends with a comment.
| -rw-r--r-- | lisp/progmodes/sh-script.el | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index b8c425428b5..6d4572a43f8 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -869,7 +869,15 @@ See `sh-feature'.") | |||
| 869 | (defconst sh-st-symbol (string-to-syntax "_")) | 869 | (defconst sh-st-symbol (string-to-syntax "_")) |
| 870 | (defconst sh-here-doc-syntax (string-to-syntax "|")) ;; generic string | 870 | (defconst sh-here-doc-syntax (string-to-syntax "|")) ;; generic string |
| 871 | 871 | ||
| 872 | (defconst sh-here-doc-open-re "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\).*\\(\n\\)") | 872 | (defconst sh-escaped-line-re |
| 873 | ;; Should match until the real end-of-continued line, but if that is not | ||
| 874 | ;; possible (because we bump into EOB or the search bound), then we should | ||
| 875 | ;; match until the search bound. | ||
| 876 | "\\(?:\\(?:.*[^\\\n]\\)?\\(?:\\\\\\\\\\)*\\\\\n\\)*.*") | ||
| 877 | |||
| 878 | (defconst sh-here-doc-open-re | ||
| 879 | (concat "<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\)+\\)" | ||
| 880 | sh-escaped-line-re "\\(\n\\)")) | ||
| 873 | 881 | ||
| 874 | (defvar sh-here-doc-markers nil) | 882 | (defvar sh-here-doc-markers nil) |
| 875 | (make-variable-buffer-local 'sh-here-doc-markers) | 883 | (make-variable-buffer-local 'sh-here-doc-markers) |
| @@ -883,7 +891,9 @@ If non-nil INDENTED indicates that the EOF was indented." | |||
| 883 | ;; A rough regexp that should find the opening <<EOF back. | 891 | ;; A rough regexp that should find the opening <<EOF back. |
| 884 | (sre (concat "<<\\(-?\\)\\s-*['\"\\]?" | 892 | (sre (concat "<<\\(-?\\)\\s-*['\"\\]?" |
| 885 | ;; Use \s| to cheaply check it's an open-heredoc. | 893 | ;; Use \s| to cheaply check it's an open-heredoc. |
| 886 | eof-re "['\"]?\\([ \t|;&)<>].*\\)?\\s|")) | 894 | eof-re "['\"]?\\([ \t|;&)<>]" |
| 895 | sh-escaped-line-re | ||
| 896 | "\\)?\\s|")) | ||
| 887 | ;; A regexp that will find other EOFs. | 897 | ;; A regexp that will find other EOFs. |
| 888 | (ere (concat "^" (if indented "[ \t]*") eof-re "\n")) | 898 | (ere (concat "^" (if indented "[ \t]*") eof-re "\n")) |
| 889 | (start (save-excursion | 899 | (start (save-excursion |
| @@ -922,7 +932,8 @@ If non-nil INDENTED indicates that the EOF was indented." | |||
| 922 | START is the position of <<. | 932 | START is the position of <<. |
| 923 | STRING is the actual word used as delimiter (f.ex. \"EOF\"). | 933 | STRING is the actual word used as delimiter (f.ex. \"EOF\"). |
| 924 | INDENTED is non-nil if the here document's content (and the EOF mark) can | 934 | INDENTED is non-nil if the here document's content (and the EOF mark) can |
| 925 | be indented (i.e. a <<- was used rather than just <<)." | 935 | be indented (i.e. a <<- was used rather than just <<). |
| 936 | Point is at the beginning of the next line." | ||
| 926 | (unless (or (memq (char-before start) '(?< ?>)) | 937 | (unless (or (memq (char-before start) '(?< ?>)) |
| 927 | (sh-in-comment-or-string start)) | 938 | (sh-in-comment-or-string start)) |
| 928 | ;; We're looking at <<STRING, so we add "^STRING$" to the syntactic | 939 | ;; We're looking at <<STRING, so we add "^STRING$" to the syntactic |
| @@ -933,6 +944,20 @@ be indented (i.e. a <<- was used rather than just <<)." | |||
| 933 | (setq sh-here-doc-re | 944 | (setq sh-here-doc-re |
| 934 | (concat sh-here-doc-open-re "\\|^\\([ \t]*\\)" | 945 | (concat sh-here-doc-open-re "\\|^\\([ \t]*\\)" |
| 935 | (regexp-opt sh-here-doc-markers t) "\\(\n\\)")))) | 946 | (regexp-opt sh-here-doc-markers t) "\\(\n\\)")))) |
| 947 | (let ((ppss (save-excursion (syntax-ppss (1- (point)))))) | ||
| 948 | (if (nth 4 ppss) | ||
| 949 | ;; The \n not only starts the heredoc but also closes a comment. | ||
| 950 | ;; Let's close the comment just before the \n. | ||
| 951 | (put-text-property (1- (point)) (point) 'syntax-table '(12))) ;">" | ||
| 952 | (if (or (nth 5 ppss) (> (count-lines start (point)) 1)) | ||
| 953 | ;; If the sh-escaped-line-re part of sh-here-doc-re has matched | ||
| 954 | ;; several lines, make sure we refontify them together. | ||
| 955 | ;; Furthermore, if (nth 5 ppss) is non-nil (i.e. the \n is | ||
| 956 | ;; escaped), it means the right \n is actually further down. | ||
| 957 | ;; Don't bother fixing it now, but place a multiline property so | ||
| 958 | ;; that when jit-lock-context-* refontifies the rest of the | ||
| 959 | ;; buffer, it also refontifies the current line with it. | ||
| 960 | (put-text-property start (point) 'font-lock-multiline t))) | ||
| 936 | sh-here-doc-syntax)) | 961 | sh-here-doc-syntax)) |
| 937 | 962 | ||
| 938 | (defun sh-font-lock-here-doc (limit) | 963 | (defun sh-font-lock-here-doc (limit) |