diff options
| author | Dmitry Gutov | 2020-12-31 20:59:00 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2020-12-31 20:59:00 +0200 |
| commit | 761d3f3cdcfd86248608254a3391405ddbb299e3 (patch) | |
| tree | 64d0dcacbf431acd639e698341ab156c7125119a | |
| parent | 0e41e89d7e9787c5ca3446af01b3c3afa433bb9b (diff) | |
| download | emacs-761d3f3cdcfd86248608254a3391405ddbb299e3.tar.gz emacs-761d3f3cdcfd86248608254a3391405ddbb299e3.zip | |
ruby-mode: Optimize expression expansion too
This speeds up syntax-propertize almost 2x.
* lisp/progmodes/ruby-mode.el (ruby-syntax-propertize):
Optimize expression expansion too.
(ruby-syntax-propertize-expansion, ruby-font-lock-keywords)
(ruby-expression-expansion-re): Update to match.
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 9aebb29333b..08df99ef88b 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -101,7 +101,7 @@ | |||
| 101 | "Regexp to match the beginning of a heredoc.") | 101 | "Regexp to match the beginning of a heredoc.") |
| 102 | 102 | ||
| 103 | (defconst ruby-expression-expansion-re | 103 | (defconst ruby-expression-expansion-re |
| 104 | "\\(?:[^\\]\\|\\=\\)\\(\\\\\\\\\\)*\\(#\\({[^}\n\\]*\\(\\\\.[^}\n\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\|\\$[^a-zA-Z \n]\\)\\)")) | 104 | "#\\({[^}\n\\]*\\(\\\\.[^}\n\\]*\\)*}\\|\\(?:\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\|\\$[^a-zA-Z \n]\\)")) |
| 105 | 105 | ||
| 106 | (defun ruby-here-doc-end-match () | 106 | (defun ruby-here-doc-end-match () |
| 107 | "Return a regexp to find the end of a heredoc. | 107 | "Return a regexp to find the end of a heredoc. |
| @@ -1914,7 +1914,13 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1914 | ;; Expression expansions in strings. We're handling them | 1914 | ;; Expression expansions in strings. We're handling them |
| 1915 | ;; here, so that the regexp rule never matches inside them. | 1915 | ;; here, so that the regexp rule never matches inside them. |
| 1916 | (ruby-expression-expansion-re | 1916 | (ruby-expression-expansion-re |
| 1917 | (0 (ignore (ruby-syntax-propertize-expansion)))) | 1917 | (0 (ignore |
| 1918 | (if (save-excursion | ||
| 1919 | (goto-char (match-beginning 0)) | ||
| 1920 | ;; The hash character is not escaped. | ||
| 1921 | (cl-evenp (skip-chars-backward "\\\\"))) | ||
| 1922 | (ruby-syntax-propertize-expansion) | ||
| 1923 | (goto-char (match-beginning 1)))))) | ||
| 1918 | ("^=en\\(d\\)\\_>" (1 "!")) | 1924 | ("^=en\\(d\\)\\_>" (1 "!")) |
| 1919 | ("^\\(=\\)begin\\_>" (1 "!")) | 1925 | ("^\\(=\\)begin\\_>" (1 "!")) |
| 1920 | ;; Handle here documents. | 1926 | ;; Handle here documents. |
| @@ -2004,8 +2010,8 @@ It will be properly highlighted even when the call omits parens.") | |||
| 2004 | (defun ruby-syntax-propertize-expansion () | 2010 | (defun ruby-syntax-propertize-expansion () |
| 2005 | ;; Save the match data to a text property, for font-locking later. | 2011 | ;; Save the match data to a text property, for font-locking later. |
| 2006 | ;; Set the syntax of all double quotes and backticks to punctuation. | 2012 | ;; Set the syntax of all double quotes and backticks to punctuation. |
| 2007 | (let* ((beg (match-beginning 2)) | 2013 | (let* ((beg (match-beginning 0)) |
| 2008 | (end (match-end 2)) | 2014 | (end (match-end 0)) |
| 2009 | (state (and beg (save-excursion (syntax-ppss beg))))) | 2015 | (state (and beg (save-excursion (syntax-ppss beg))))) |
| 2010 | (when (ruby-syntax-expansion-allowed-p state) | 2016 | (when (ruby-syntax-expansion-allowed-p state) |
| 2011 | (put-text-property beg (1+ beg) 'ruby-expansion-match-data | 2017 | (put-text-property beg (1+ beg) 'ruby-expansion-match-data |
| @@ -2232,7 +2238,7 @@ It will be properly highlighted even when the call omits parens.") | |||
| 2232 | (1 font-lock-builtin-face)) | 2238 | (1 font-lock-builtin-face)) |
| 2233 | ;; Expression expansion. | 2239 | ;; Expression expansion. |
| 2234 | (ruby-match-expression-expansion | 2240 | (ruby-match-expression-expansion |
| 2235 | 2 font-lock-variable-name-face t) | 2241 | 0 font-lock-variable-name-face t) |
| 2236 | ;; Negation char. | 2242 | ;; Negation char. |
| 2237 | ("\\(?:^\\|[^[:alnum:]_]\\)\\(!+\\)[^=~]" | 2243 | ("\\(?:^\\|[^[:alnum:]_]\\)\\(!+\\)[^=~]" |
| 2238 | 1 font-lock-negation-char-face) | 2244 | 1 font-lock-negation-char-face) |