diff options
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 61 | ||||
| -rw-r--r-- | test/automated/ruby-mode-tests.el | 8 |
2 files changed, 39 insertions, 30 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index fa94992ab79..1395828cff9 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -1901,7 +1901,10 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1901 | (ruby-syntax-propertize-heredoc end)))) | 1901 | (ruby-syntax-propertize-heredoc end)))) |
| 1902 | ;; Handle percent literals: %w(), %q{}, etc. | 1902 | ;; Handle percent literals: %w(), %q{}, etc. |
| 1903 | ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) | 1903 | ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) |
| 1904 | (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) | 1904 | (1 (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 1)))) |
| 1905 | ;; Not inside a string, a comment, or a percent literal. | ||
| 1906 | (ruby-syntax-propertize-percent-literal end) | ||
| 1907 | (string-to-syntax "|"))))) | ||
| 1905 | (point) end))) | 1908 | (point) end))) |
| 1906 | 1909 | ||
| 1907 | (define-obsolete-function-alias | 1910 | (define-obsolete-function-alias |
| @@ -1944,35 +1947,33 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1944 | 1947 | ||
| 1945 | (defun ruby-syntax-propertize-percent-literal (limit) | 1948 | (defun ruby-syntax-propertize-percent-literal (limit) |
| 1946 | (goto-char (match-beginning 2)) | 1949 | (goto-char (match-beginning 2)) |
| 1947 | ;; Not inside a simple string or comment. | 1950 | (let* ((op (char-after)) |
| 1948 | (when (eq t (nth 3 (syntax-ppss))) | 1951 | (ops (char-to-string op)) |
| 1949 | (let* ((op (char-after)) | 1952 | (cl (or (cdr (aref (syntax-table) op)) |
| 1950 | (ops (char-to-string op)) | 1953 | (cdr (assoc op '((?< . ?>)))))) |
| 1951 | (cl (or (cdr (aref (syntax-table) op)) | 1954 | parse-sexp-lookup-properties) |
| 1952 | (cdr (assoc op '((?< . ?>)))))) | 1955 | (save-excursion |
| 1953 | parse-sexp-lookup-properties) | 1956 | (condition-case nil |
| 1954 | (save-excursion | 1957 | (progn |
| 1955 | (condition-case nil | 1958 | (if cl ; Paired delimiters. |
| 1956 | (progn | 1959 | ;; Delimiter pairs of the same kind can be nested |
| 1957 | (if cl ; Paired delimiters. | 1960 | ;; inside the literal, as long as they are balanced. |
| 1958 | ;; Delimiter pairs of the same kind can be nested | 1961 | ;; Create syntax table that ignores other characters. |
| 1959 | ;; inside the literal, as long as they are balanced. | 1962 | (with-syntax-table (make-char-table 'syntax-table nil) |
| 1960 | ;; Create syntax table that ignores other characters. | 1963 | (modify-syntax-entry op (concat "(" (char-to-string cl))) |
| 1961 | (with-syntax-table (make-char-table 'syntax-table nil) | 1964 | (modify-syntax-entry cl (concat ")" ops)) |
| 1962 | (modify-syntax-entry op (concat "(" (char-to-string cl))) | 1965 | (modify-syntax-entry ?\\ "\\") |
| 1963 | (modify-syntax-entry cl (concat ")" ops)) | 1966 | (save-restriction |
| 1964 | (modify-syntax-entry ?\\ "\\") | 1967 | (narrow-to-region (point) limit) |
| 1965 | (save-restriction | 1968 | (forward-list))) ; skip to the paired character |
| 1966 | (narrow-to-region (point) limit) | 1969 | ;; Single character delimiter. |
| 1967 | (forward-list))) ; skip to the paired character | 1970 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" |
| 1968 | ;; Single character delimiter. | 1971 | (regexp-quote ops)) limit nil)) |
| 1969 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" | 1972 | ;; Found the closing delimiter. |
| 1970 | (regexp-quote ops)) limit nil)) | 1973 | (put-text-property (1- (point)) (point) 'syntax-table |
| 1971 | ;; Found the closing delimiter. | 1974 | (string-to-syntax "|"))) |
| 1972 | (put-text-property (1- (point)) (point) 'syntax-table | 1975 | ;; Unclosed literal, do nothing. |
| 1973 | (string-to-syntax "|"))) | 1976 | ((scan-error search-failed)))))) |
| 1974 | ;; Unclosed literal, do nothing. | ||
| 1975 | ((scan-error search-failed))))))) | ||
| 1976 | 1977 | ||
| 1977 | (defun ruby-syntax-propertize-expansion () | 1978 | (defun ruby-syntax-propertize-expansion () |
| 1978 | ;; Save the match data to a text property, for font-locking later. | 1979 | ;; Save the match data to a text property, for font-locking later. |
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index da8d77c5157..7073f7a04e2 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el | |||
| @@ -461,6 +461,14 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 461 | (ruby-assert-face "%S{foo}" 4 nil) | 461 | (ruby-assert-face "%S{foo}" 4 nil) |
| 462 | (ruby-assert-face "%R{foo}" 4 nil)) | 462 | (ruby-assert-face "%R{foo}" 4 nil)) |
| 463 | 463 | ||
| 464 | (ert-deftest ruby-no-nested-percent-literals () | ||
| 465 | (ruby-with-temp-buffer "a = %w[b %()]" | ||
| 466 | (syntax-propertize (point)) | ||
| 467 | (should (null (nth 8 (syntax-ppss)))) | ||
| 468 | (should (eq t (nth 3 (syntax-ppss (1- (point-max)))))) | ||
| 469 | (search-backward "[") | ||
| 470 | (should (eq t (nth 3 (syntax-ppss)))))) | ||
| 471 | |||
| 464 | (ert-deftest ruby-add-log-current-method-examples () | 472 | (ert-deftest ruby-add-log-current-method-examples () |
| 465 | (let ((pairs '(("foo" . "#foo") | 473 | (let ((pairs '(("foo" . "#foo") |
| 466 | ("C.foo" . ".foo") | 474 | ("C.foo" . ".foo") |