[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 0de10fa 235/405: Passes first test for imenu
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 0de10fa 235/405: Passes first test for imenu |
Date: |
Sat, 13 Jul 2019 10:00:22 -0400 (EDT) |
branch: externals/phps-mode
commit 0de10fafd1ae10974343fd05d890b23544ff28af
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Passes first test for imenu
---
phps-mode-functions.el | 60 +++++++++++++++++++++++++++++++++++++++++++--
phps-mode-test-functions.el | 7 +++---
2 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index eba4714..798aee0 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -623,9 +623,65 @@
"Create index for imenu."
(let ((index '()))
- ;; TODO Iterate namespaces, classes and functions and add to index
+ (when (boundp 'phps-mode-lexer-tokens)
+ (let ((tokens phps-mode-lexer-tokens)
+ (in-namespace-declaration nil)
+ (in-class-declaration nil)
+ (in-function-declaration nil))
+ (dolist (token tokens)
+ (let ((token-symbol (car token))
+ (token-start (car (cdr token)))
+ (token-end (cdr (cdr token))))
+ (cond
- index))
+ (in-namespace-declaration
+ (cond
+
+ ((or (string= token-symbol "{")
+ (string= token-symbol ";"))
+ (setq in-namespace-declaration nil))
+
+ ((equal token-symbol 'T_STRING)
+ (let ((index-name (format "namespace %s"
(buffer-substring-no-properties token-start token-end)))
+ (index-pos token-start))
+ (push `(,index-name . ,index-pos) index)))))
+
+ (in-class-declaration
+ (cond
+
+ ((string= token-symbol "{")
+ (setq in-class-declaration nil))
+
+ ((equal token-symbol 'T_STRING)
+ (let ((index-name (format "class %s"
(buffer-substring-no-properties token-start token-end)))
+ (index-pos token-start))
+ (push `(,index-name . ,index-pos) index)))))
+
+ (in-function-declaration
+ (cond
+
+ ((or (string= token-symbol "{")
+ (string= token-symbol ";"))
+ (setq in-function-declaration nil))
+
+ ((equal token-symbol 'T_STRING)
+ (let ((index-name (format "function %s"
(buffer-substring-no-properties token-start token-end)))
+ (index-pos token-start))
+ (push `(,index-name . ,index-pos) index)))))
+
+ (t
+ (cond
+
+ ((equal token-symbol 'T_NAMESPACE)
+ (setq in-namespace-declaration t))
+
+ ((equal token-symbol 'T_CLASS)
+ (setq in-class-declaration t))
+
+ ((equal token-symbol 'T_FUNCTION)
+ (setq in-function-declaration t)))))))))
+
+ (nreverse index)))
(defun phps-mode-functions-init ()
"PHP specific init-cleanup routines."
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 1de7fdf..c889176 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -584,12 +584,13 @@
)
(defun phps-mode-test-functions-imenu ()
- "Test for imenu"
+ "Test for imenu."
+
(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) ("myFunction B" . 42))))
- )
+ (should (equal (phps-mode-functions-imenu-create-index-function)
'(("function myFunctionA" . 16) ("function myFunctionB" . 42)))))
+
)
;; TODO Add tests for all examples here: https://www.php-fig.org/psr/psr-2/
- [elpa] externals/phps-mode 75c4af4 214/405: Fixed indentation for lines wrapped in scripting open/close, (continued)
- [elpa] externals/phps-mode 75c4af4 214/405: Fixed indentation for lines wrapped in scripting open/close, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d754163 221/405: More work on multi-line token-less lines, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8947e6e 202/405: Conceptual work on indentation-calculation for multi-line assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode fc2e8b7 212/405: Added logic to indent token-less lines as well, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8707777 237/405: Updated README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2d4646f 203/405: Work on inline control structure indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 202827b 198/405: New indentation algorithm now supports inline control structures, Stefan Monnier, 2019/07/13
- [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 <=
- [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, 2019/07/13
- [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