[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode b8e9449 247/405: Refactored Imenu to use a pe
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode b8e9449 247/405: Refactored Imenu to use a persistent variable per buffer |
Date: |
Sat, 13 Jul 2019 10:00:25 -0400 (EDT) |
branch: externals/phps-mode
commit b8e94497740ac0245cc9668657e35ca6aa08632e
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Refactored Imenu to use a persistent variable per buffer
---
phps-mode-functions.el | 40 +++++++++++++++++++++++-----------------
phps-mode-lexer.el | 4 ++++
phps-mode-test-functions.el | 14 +++++++-------
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 04c36ae..74de4bc 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -34,6 +34,9 @@
(defvar phps-mode-functions-lines-indent nil
"The indentation of each line in buffer, nil if none.")
+(defvar phps-mode-functions-imenu nil
+ "The Imenu alist for current buffer, nil if none.")
+
(defvar phps-mode-functions-verbose nil
"Verbose messaging, default nil.")
@@ -568,8 +571,7 @@
(defun phps-mode-functions-indent-line ()
"Indent line."
;; Set lines indent if not set
- (unless (and (boundp 'phps-mode-functions-lines-indent)
- phps-mode-functions-lines-indent)
+ (unless phps-mode-functions-lines-indent
(setq phps-mode-functions-lines-indent
(phps-mode-functions-get-lines-indent)))
(when phps-mode-functions-lines-indent
@@ -618,7 +620,7 @@
;; (message "phps-mode-functions-after-change %s %s %s" start stop length)
))
-(defun phps-mode-functions-imenu-create-index-function ()
+(defun phps-mode-functions--imenu-create-index-function ()
"Create index for imenu."
(let ((index '()))
@@ -632,7 +634,6 @@
(in-class-name nil)
(in-function-declaration nil)
(in-function-name nil)
- (open-function-level nil)
(nesting-level 0))
(dolist (token tokens)
(let ((token-symbol (car token))
@@ -695,7 +696,6 @@
(cond
((string= token-symbol "{")
- (setq open-function-level nesting-level)
(setq in-function-name nil)
(setq in-function-declaration nil))
@@ -713,23 +713,28 @@
(setq index-name (concat in-namespace-name "\\"
index-name)))
(push `(,index-name . ,index-pos) index)))))
- (t
- (cond
+ (t (cond
- ((equal token-symbol 'T_NAMESPACE)
- (setq in-namespace-name nil)
- (setq in-namespace-declaration t))
+ ((equal token-symbol 'T_NAMESPACE)
+ (setq in-namespace-name nil)
+ (setq in-namespace-declaration t))
- ((equal token-symbol 'T_CLASS)
- (setq in-class-name nil)
- (setq in-class-declaration t))
+ ((equal token-symbol 'T_CLASS)
+ (setq in-class-name nil)
+ (setq in-class-declaration t))
- ((equal token-symbol 'T_FUNCTION)
- (setq in-function-name nil)
- (setq in-function-declaration t)))))))))
+ ((equal token-symbol 'T_FUNCTION)
+ (setq in-function-name nil)
+ (setq in-function-declaration t)))))))))
(nreverse index)))
+(defun phps-mode-functions-get-imenu ()
+ "Get Imenu for current buffer."
+ (unless phps-mode-functions-imenu
+ (setq phps-mode-functions-imenu
(phps-mode-functions--imenu-create-index-function)))
+ phps-mode-functions-imenu)
+
(defun phps-mode-functions-init ()
"PHP specific init-cleanup routines."
@@ -737,7 +742,7 @@
(set (make-local-variable 'indent-line-function)
#'phps-mode-functions-indent-line)
;; Support Imenu
- (set (make-local-variable 'imenu-create-index-function)
#'phps-mode-functions-imenu-create-index-function)
+ (set (make-local-variable 'imenu-create-index-function)
#'phps-mode-functions-get-imenu)
(when (and (boundp 'phps-mode-use-psr-2)
phps-mode-use-psr-2)
@@ -752,6 +757,7 @@
(set (make-local-variable 'phps-mode-functions-buffer-changes-start) nil)
(set (make-local-variable 'phps-mode-functions-lines-indent) nil)
+ (set (make-local-variable 'phps-mode-functions-imenu) nil)
(add-hook 'after-change-functions #'phps-mode-functions-after-change))
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 9733cc5..971dc77 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -1283,6 +1283,10 @@ ANY_CHAR'
phps-mode-functions-lines-indent)
(setq phps-mode-functions-lines-indent nil))
+ ;; Reset imenu index
+ (when (and (boundp 'phps-mode-functions-imenu)
+ phps-mode-functions-imenu)
+ (setq phps-mode-functions-imenu nil))
(setq phps-mode-lexer-states nil)
(phps-mode-lexer-BEGIN phps-mode-lexer-ST_INITIAL)))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index b69ae50..039a606 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -589,37 +589,37 @@
(phps-mode-test-with-buffer
"<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n"
"Imenu function-oriented file"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("myFunctionA()" . 16) ("myFunctionB()" . 42)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("myFunctionA()" . 16)
("myFunctionB()" . 42)))))
(phps-mode-test-with-buffer
"<?php\nclass myClass {\n public function myFunctionA() {}\n
protected function myFunctionB() {}\n}\n"
"Imenu object-oriented file"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("myClass" . 13) ("myClass->myFunctionA()" . 43) ("myClass->myFunctionB()" .
83)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("myClass" . 13)
("myClass->myFunctionA()" . 43) ("myClass->myFunctionB()" . 83)))))
(phps-mode-test-with-buffer
"<?php\nnamespace myNamespace {\n class myClass {\n public
function myFunctionA() {}\n protected function myFunctionB() {}\n
}\n}\n"
"Imenu object-oriented file with namespace, class and function"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 41)
("\\myNamespace\\myClass->myFunctionA()" . 75)
("\\myNamespace\\myClass->myFunctionB()" . 119)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17)
("\\myNamespace\\myClass" . 41) ("\\myNamespace\\myClass->myFunctionA()" . 75)
("\\myNamespace\\myClass->myFunctionB()" . 119)))))
(phps-mode-test-with-buffer
"<?php\nnamespace myNamespace;\nclass myClass {\n public function
myFunctionA() {}\n protected function myFunctionB() {}\n}\n"
"Imenu object-oriented file with bracket-less namespace, class and function"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 36)
("\\myNamespace\\myClass->myFunctionA()" . 66)
("\\myNamespace\\myClass->myFunctionB()" . 106)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17)
("\\myNamespace\\myClass" . 36) ("\\myNamespace\\myClass->myFunctionA()" . 66)
("\\myNamespace\\myClass->myFunctionB()" . 106)))))
(phps-mode-test-with-buffer
"<?php\nnamespace myNamespace {\n class myClass extends myAbstract {\n
public function myFunctionA() {}\n protected function myFunctionB()
{}\n }\n}\n"
"Imenu object-oriented file with namespace, class that extends and
functions"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 41)
("\\myNamespace\\myClass->myFunctionA()" . 94)
("\\myNamespace\\myClass->myFunctionB()" . 138)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17)
("\\myNamespace\\myClass" . 41) ("\\myNamespace\\myClass->myFunctionA()" . 94)
("\\myNamespace\\myClass->myFunctionB()" . 138)))))
(phps-mode-test-with-buffer
"<?php\nnamespace myNamespace;\nclass myClass extends myAbstract implements
myInterface {\n public function myFunctionA() {}\n protected function
myFunctionB() {}\n}\n"
"Imenu object-oriented file with bracket-less namespace, class that extends
and implements and functions"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 36)
("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 148)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17)
("\\myNamespace\\myClass" . 36) ("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 148)))))
(phps-mode-test-with-buffer
"<?php\nnamespace myNamespace;\nclass myClass extends myAbstract implements
myInterface {\n public function myFunctionA($myArg = null) {}\n protected
function myFunctionB($myArg = 'abc') {}\n}\n"
"Imenu object-oriented file with bracket-less namespace, class that extends
and implements and functions with optional arguments"
- (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 36)
("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 161)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17)
("\\myNamespace\\myClass" . 36) ("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 161)))))
)
- [elpa] externals/phps-mode b2a5700 218/405: Fixed indentation for multi-line optional function arguments, (continued)
- [elpa] externals/phps-mode b2a5700 218/405: Fixed indentation for multi-line optional function arguments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f7186a1 239/405: Preparations for hierarchical imenu, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 43bf350 216/405: Added tests for token-less lines, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0de10fa 235/405: Passes first test for imenu, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f791cee 234/405: Started on unit tests for imenu-index generation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b56a15c 233/405: Removed debugging output, updated todo items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 73784d0 225/405: Cleaned up tests for indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f7e7c74 219/405: Work on indentation for switch-case, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c2af31e 240/405: Imenu support now shows hierarchical information, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 55953de 232/405: Lexer now doesn't find keywords in function names, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b8e9449 247/405: Refactored Imenu to use a persistent variable per buffer,
Stefan Monnier <=
- [elpa] externals/phps-mode 67b8701 244/405: Decreased length of imenu items to prevent truncation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e78d8ed 248/405: Clean-up of indentation code, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c2db7d3 250/405: Preparations for integration test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 11309b8 256/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode fcc920f 258/405: More preparations for merging indent and Imenu into one function, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 41c12c1 251/405: Updated paths for byte-compilation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0e927e8 252/405: Fixed compilation command in makefile, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6593242 257/405: Preparations for doing indentation and imenu in one pass, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 318001e 259/405: Merged Imenu and indentation generation into one iteration of tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5bb45ce 253/405: Added lexer test for properties inside heredoc, Stefan Monnier, 2019/07/13