From 061a794165b9bfbb1bc57d1e54e438c622113be7 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 19 May 2021 21:16:36 +0900 Subject: [PATCH 1/3] Add `php-mode-syntax-propertize-extend-region-limit` for optimize syntax propertization --- CHANGELOG.md | 4 ++++ lisp/php-mode.el | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15274baf..3858b82f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Add `php-imenu-generic-expression-default` for default value or `php-imenu-generic-expression` * Add `php-imenu-generic-expression-legacy` for compatibility * Add `php-imenu-generic-expression-simple` for simple display + * Add custom variables + * Add `php-mode-syntax-propertize-extend-region-limit` for optimize syntax propertization + * The number of search characters used to find the starting point of Heredoc and Nowdoc ### Changed @@ -18,6 +21,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Reimoplement `php-syntax-propertize-function` using `syntax-propertize-rules` * Make propertize PHP 8 `#[Attribute]` always enabled * Changed grouping of `php-heredoc-start-re` + * Use limits on `php-mode-syntax-propertize-extend-region-limit` variable to find the starting point of Heredoc and Nowdoc * Re-organized `php-imenu-generic-expression` * Added `Import`, `Constants` and `Properties` * Removed `Anonymous Functions` diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 4301d411..57eb5a40 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -284,6 +284,15 @@ In that case set to `NIL'." :tag "PHP Mode Enable Project Local Variable" :type 'boolean) +(defcustom php-mode-syntax-propertize-extend-region-limit (* 100 syntax-propertize-chunk-size) + "Boundary value of the number of search characters to propertize syntax. + +Smaller values can improve performance with large buffers. +If the value is too small, the syntax will not be displayed properly." + :group 'php-mode + :tag "PHP Mode Syntax Propertize Extend Region Limit" + :type 'integer) + (defconst php-mode-cc-vertion (eval-when-compile c-version)) @@ -987,22 +996,24 @@ this ^ lineup" (defun php-syntax-propertize-extend-region (start end) "Extend the propertize region if START or END falls inside a PHP heredoc." - (let ((pair (cons start end))) + (let ((pair (cons start end)) + (limit (max syntax-propertize-chunk-size php-mode-syntax-propertize-extend-region-limit)) + new-start new-end maybe) (when (not (member pair php-mode--propertize-extend-region-current)) ;; re-search functions may trigger ;; syntax-propertize-extend-region-functions to be called again, which in ;; turn call this to be called again. (push pair php-mode--propertize-extend-region-current) (unwind-protect - (let (new-start new-end) + (progn (goto-char start) - (when (re-search-backward php-heredoc-start-re nil t) - (let ((maybe (point))) - (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) - (> (point) start)) - (setq new-start maybe)))) + (when (re-search-backward php-heredoc-start-re limit t) + (setq maybe (point)) + (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) + (> (point) start)) + (setq new-start maybe))) (goto-char end) - (when (re-search-backward php-heredoc-start-re nil t) + (when (re-search-backward php-heredoc-start-re limit t) (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) (when (> (point) end) (setq new-end (point))) From 805f5008cdd35026806bc9df77aa9378d05783fb Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 19 May 2021 21:16:51 +0900 Subject: [PATCH 2/3] Remove unnecessary matcher from c-basic-matchers-before for propertization --- lisp/php-mode.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 57eb5a40..31913893 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -576,7 +576,8 @@ might be to handle switch and goto labels differently." :test 'string-equal)))) (c-lang-defconst c-basic-matchers-before - php (cl-remove-if (lambda (elm) (and (listp elm) (equal (car elm) "\\s|"))) + php (cl-remove-if (lambda (elm) (or (and (consp elm) (equal (car elm) "\\s|")) + (functionp elm))) (c-lang-const c-basic-matchers-before php))) (c-lang-defconst c-basic-matchers-after From 9f16653581cee3fd21456b89f4981c91b9a5f06c Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 19 May 2021 22:39:27 +0900 Subject: [PATCH 3/3] Revert "Add `php-mode-syntax-propertize-extend-region-limit` for optimize syntax propertization" This reverts commit 061a794165b9bfbb1bc57d1e54e438c622113be7. --- CHANGELOG.md | 4 ---- lisp/php-mode.el | 27 ++++++++------------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3858b82f..15274baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,6 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Add `php-imenu-generic-expression-default` for default value or `php-imenu-generic-expression` * Add `php-imenu-generic-expression-legacy` for compatibility * Add `php-imenu-generic-expression-simple` for simple display - * Add custom variables - * Add `php-mode-syntax-propertize-extend-region-limit` for optimize syntax propertization - * The number of search characters used to find the starting point of Heredoc and Nowdoc ### Changed @@ -21,7 +18,6 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Reimoplement `php-syntax-propertize-function` using `syntax-propertize-rules` * Make propertize PHP 8 `#[Attribute]` always enabled * Changed grouping of `php-heredoc-start-re` - * Use limits on `php-mode-syntax-propertize-extend-region-limit` variable to find the starting point of Heredoc and Nowdoc * Re-organized `php-imenu-generic-expression` * Added `Import`, `Constants` and `Properties` * Removed `Anonymous Functions` diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 31913893..15579da8 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -284,15 +284,6 @@ In that case set to `NIL'." :tag "PHP Mode Enable Project Local Variable" :type 'boolean) -(defcustom php-mode-syntax-propertize-extend-region-limit (* 100 syntax-propertize-chunk-size) - "Boundary value of the number of search characters to propertize syntax. - -Smaller values can improve performance with large buffers. -If the value is too small, the syntax will not be displayed properly." - :group 'php-mode - :tag "PHP Mode Syntax Propertize Extend Region Limit" - :type 'integer) - (defconst php-mode-cc-vertion (eval-when-compile c-version)) @@ -997,24 +988,22 @@ this ^ lineup" (defun php-syntax-propertize-extend-region (start end) "Extend the propertize region if START or END falls inside a PHP heredoc." - (let ((pair (cons start end)) - (limit (max syntax-propertize-chunk-size php-mode-syntax-propertize-extend-region-limit)) - new-start new-end maybe) + (let ((pair (cons start end))) (when (not (member pair php-mode--propertize-extend-region-current)) ;; re-search functions may trigger ;; syntax-propertize-extend-region-functions to be called again, which in ;; turn call this to be called again. (push pair php-mode--propertize-extend-region-current) (unwind-protect - (progn + (let (new-start new-end) (goto-char start) - (when (re-search-backward php-heredoc-start-re limit t) - (setq maybe (point)) - (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) - (> (point) start)) - (setq new-start maybe))) + (when (re-search-backward php-heredoc-start-re nil t) + (let ((maybe (point))) + (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) + (> (point) start)) + (setq new-start maybe)))) (goto-char end) - (when (re-search-backward php-heredoc-start-re limit t) + (when (re-search-backward php-heredoc-start-re nil t) (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) (when (> (point) end) (setq new-end (point)))