[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 6ccb01a: Improved imenu, syntax-table and syn
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 6ccb01a: Improved imenu, syntax-table and syntax-coloring |
Date: |
Wed, 21 Aug 2019 01:10:57 -0400 (EDT) |
branch: externals/phps-mode
commit 6ccb01a57d156ef252ca6c57167425b23fa91a45
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Improved imenu, syntax-table and syntax-coloring
---
phps-mode-functions.el | 4 +-
phps-mode-lexer.el | 99 +++++++++++++++++++----------------------
phps-mode-syntax-table.el | 24 ++++------
phps-mode-test-functions.el | 7 ++-
phps-mode-test-syntax-table.el | 2 +
phps-mode.el | 53 ++++++++++++++++------
sample-php-files/class.php | 3 +-
sample-php-files/functions.php | 7 +--
sample-php-files/navigation.php | 46 +++++++++++++++++++
9 files changed, 156 insertions(+), 89 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 09bce05..7260d2f 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -269,7 +269,9 @@
(cond
- ((string= token "{")
+ ((or (string= token "{")
+ (equal token 'T_CURLY_OPEN)
+ (equal token 'T_DOLLAR_OPEN_CURLY_BRACES))
(setq imenu-nesting-level (1+ imenu-nesting-level)))
((string= token "}")
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index eba8222..de7a097 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -197,8 +197,16 @@
(when (boundp 'semantic-lex-end-point)
(setq semantic-lex-end-point position)))
-(defun phps-mode-lexer-COLOR_SYNTAX (token start end)
- "Syntax coloring for TOKEN from START to END."
+(defun phps-mode-lexer-set-region-syntax-color (start end properties)
+ "Do syntax coloring for region START to END with PROPERTIES."
+ (with-silent-modifications (set-text-properties start end properties)))
+
+(defun phps-mode-lexer-clear-region-syntax-color (start end)
+ "Clear region of syntax coloring from START to END."
+ (with-silent-modifications (set-text-properties start end nil)))
+
+(defun phps-mode-lexer-get-token-syntax-color (token)
+ "Return syntax color for TOKEN."
;; Syntax coloring
;; see
https://www.gnu.org/software/emacs/manual/html_node/elisp/Faces-for-Font-Lock.html#Faces-for-Font-Lock
;; (message "Color token %s %s %s" token start end)
@@ -207,29 +215,28 @@
((or
(string= token 'T_VARIABLE)
(string= token 'T_STRING_VARNAME))
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-variable-name-face))
+ (list 'font-lock-face 'font-lock-variable-name-face))
((string= token 'T_INLINE_HTML)
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-comment-delimiter-face)
-
;; Optional support for mmm-mode below
- (if (and (boundp 'phps-mode-inline-mmm-submode)
- phps-mode-inline-mmm-submode
- (fboundp 'mmm-make-region))
- (progn
- ;; (message "Added mmm-submode '%s' from %s - %s"
phps-mode-inline-mmm-submode start end)
- (dolist (overlay (overlays-in start end))
- (delete-overlay overlay))
- ;; (mmm-make-region phps-mode-inline-mmm-submode start end)
- )
- ))
+ ;; (if (and (boundp 'phps-mode-inline-mmm-submode)
+ ;; phps-mode-inline-mmm-submode
+ ;; (fboundp 'mmm-make-region))
+ ;; (progn
+ ;; ;; (message "Added mmm-submode '%s' from %s - %s"
phps-mode-inline-mmm-submode start end)
+
+ ;; ;; (mmm-make-region phps-mode-inline-mmm-submode start end)
+ ;; )
+ ;; )
+
+ (list 'font-lock-face 'font-lock-comment-delimiter-face))
((string= token 'T_COMMENT)
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-comment-face))
+ (list 'font-lock-face 'font-lock-comment-face))
((string= token 'T_DOC_COMMENT)
- (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-doc-face))
+ (list 'font-lock-face 'font-lock-doc-face))
((or
(string= token 'T_STRING)
@@ -237,9 +244,8 @@
(string= token 'T_ENCAPSED_AND_WHITESPACE)
(string= token 'T_NUM_STRING)
(string= token 'T_DNUMBER)
- (string= token 'T_LNUMBER)
- )
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-string-face))
+ (string= token 'T_LNUMBER))
+ (list 'font-lock-face 'font-lock-string-face))
((or
(string= token 'T_DOLLAR_OPEN_CURLY_BRACES)
@@ -313,7 +319,7 @@
(string= token 'T_ARRAY)
(string= token 'T_CALLABLE)
)
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-keyword-face))
+ (list 'font-lock-face 'font-lock-keyword-face))
((or
(string= token 'T_OPEN_TAG)
@@ -371,31 +377,32 @@
(string= token 'T_BOOL_CAST)
(string= token 'T_UNSET_CAST)
)
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-constant-face))
+ (list 'font-lock-face 'font-lock-constant-face))
((string= token 'T_ERROR)
- (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-warning-face))
+ (list 'font-lock-face 'font-lock-warning-face))
- (t (overlay-put (make-overlay start end) 'font-lock-face
'font-lock-constant-face)))
- )
+ (t (list 'font-lock-face 'font-lock-constant-face))
+ ))
(defun phps-mode-lexer-RETURN_TOKEN (token start end)
- "Push TOKEN to list with START and END."
- (phps-mode-lexer-COLOR_SYNTAX token start end)
+"Push TOKEN to list with START and END."
+(phps-mode-lexer-set-region-syntax-color
+ start end (phps-mode-lexer-get-token-syntax-color token))
- ;; (when (and
- ;; phps-mode-lexer-prepend_trailing_brace
- ;; (> end (- (point-max) 2)))
- ;; ;; (message "Adding trailing brace")
- ;; (setq phps-mode-lexer-prepend_trailing_brace nil)
- ;; (phps-mode-lexer-RETURN_TOKEN "}" (- end 1) end))
+;; (when (and
+;; phps-mode-lexer-prepend_trailing_brace
+;; (> end (- (point-max) 2)))
+;; ;; (message "Adding trailing brace")
+;; (setq phps-mode-lexer-prepend_trailing_brace nil)
+;; (phps-mode-lexer-RETURN_TOKEN "}" (- end 1) end))
- ;; (message "Added token %s (%s-%s)" token start end)
+;; (message "Added token %s (%s-%s)" token start end)
- ;; Push token start, end, lexer state and state stack to variable
- (push (list start end phps-mode-lexer-STATE phps-mode-lexer-state_stack)
phps-mode-lexer-states)
+;; Push token start, end, lexer state and state stack to variable
+(push (list start end phps-mode-lexer-STATE phps-mode-lexer-state_stack)
phps-mode-lexer-states)
- (semantic-lex-push-token (semantic-lex-token token start end)))
+(semantic-lex-push-token (semantic-lex-token token start end)))
;; TODO Figure out what this does
(defun phps-mode-lexer-SKIP_TOKEN (_token _start _end)
@@ -1607,7 +1614,7 @@
;; Does lexer start from the beginning of buffer?
(when (and (eq start 1)
end)
- (delete-all-overlays)
+ (phps-mode-lexer-clear-region-syntax-color (point-min) (point-max))
(setq phps-mode-lexer-states nil)
(phps-mode-lexer-BEGIN phps-mode-lexer-ST_INITIAL)))
@@ -1719,9 +1726,8 @@
(throw 'stop-iteration nil)))))
(setq old-tokens (nreverse old-tokens))
- ;; Delete all overlays from point of change to end of buffer
- (dolist (overlay (overlays-in previous-token-end (point-max)))
- (delete-overlay overlay))
+ ;; Delete all syntax coloring from point of change to end of
buffer
+ (phps-mode-lexer-clear-region-syntax-color previous-token-end
(point-max))
(let* ((new-tokens (semantic-lex previous-token-start
(point-max)))
(appended-tokens (append old-tokens new-tokens)))
@@ -1744,17 +1750,6 @@
phps-mode-lexer-lex-analyzer
semantic-lex-default-action)
-(defun phps-mode-lexer-init ()
- "Initialize lexer."
- (when (and (boundp 'semantic-lex-syntax-table)
- (boundp 'phps-mode-syntax-table))
- (setq semantic-lex-syntax-table phps-mode-syntax-table))
- (when (boundp 'semantic-lex-analyzer)
- (setq semantic-lex-analyzer 'phps-mode-lexer-lex))
- (add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup)
- (setq-local phps-mode-lexer-tokens nil)
- (phps-mode-lexer-run))
-
(provide 'phps-mode-lexer)
;;; phps-mode-lexer.el ends here
diff --git a/phps-mode-syntax-table.el b/phps-mode-syntax-table.el
index 636c71c..8e55da9 100644
--- a/phps-mode-syntax-table.el
+++ b/phps-mode-syntax-table.el
@@ -99,26 +99,20 @@
;; Treat back-quoted string as string quote
(modify-syntax-entry ?` "\"" phps-mode-syntax-table)
- phps-mode-syntax-table)
- "Syntax table for phps-mode.")
-(defun phps-mode-syntax-table-init ()
- "Apply syntax table."
- (set-syntax-table phps-mode-syntax-table)
+ ;; GENERIC COMMENT FENCE
- ;; NOTE: These are required for wrapping region functionality
- (transient-mark-mode)
- (electric-pair-local-mode)
+ ;; Double slash starts comment type b
+ (modify-syntax-entry ?/ ". 124b" phps-mode-syntax-table)
+ (modify-syntax-entry ?* ". 23" phps-mode-syntax-table)
- (when (boundp 'electric-pair-pairs)
+ ;; Newline end comment type b
+ (modify-syntax-entry ?\n "> b" phps-mode-syntax-table)
+ (modify-syntax-entry ?\r "> b" phps-mode-syntax-table)
- ;; Add back-quotes to electric pair list
- (unless (assoc 96 electric-pair-pairs)
- (push '(96 . 96) electric-pair-pairs))
- ;; Add single-quotes to electric-pair characters
- (unless (assoc 39 electric-pair-pairs)
- (push '(39 . 39) electric-pair-pairs))))
+ phps-mode-syntax-table)
+ "Syntax table for phps-mode.")
(provide 'phps-mode-syntax-table)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index ded3512..95db78f 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -884,7 +884,12 @@
(phps-mode-test-with-buffer
"<?php\nclass myClass\n{\n\n public function myFunction1()\n {\n
echo \"my string with variable {$variable} inside it\";\n }\n\n public
function myFunction2()\n {\n }\n\n}"
"Imenu with double quoted string with variable inside it"
- (should (equal (phps-mode-functions-get-imenu) '(("myClass" ("myFunction1"
. 44)) ("myFunction2" . 153)))))
+ (should (equal (phps-mode-functions-get-imenu) '(("myClass" ("myFunction1"
. 44) ("myFunction2" . 153))))))
+
+ (phps-mode-test-with-buffer
+ "<?php\n\nnamespace MyNamespace;\n\nclass MyClass\n{\n\n /**\n *\n
*/\n public function __construct()\n {\n if ($test) {\n
}\n }\n\n /**\n *\n */\n public function myFunction1()\n
{\n $this->addMessage(\"My random {$message} here\" . ($random > 1 ?
\"A\" : \"\") . \" was here.\");\n }\n \n /**\n *\n */\n
public function myFunction2()\n {\n }\n\n /**\n * It's good\n
*/\n public function my [...]
+ "Imenu with double quoted string with variable inside it and concatenated
string"
+ (should (equal (phps-mode-functions-get-imenu) '(("MyNamespace" ("MyClass"
("__construct" . 92) ("myFunction1" . 193) ("myFunction2" . 365) ("myFunction3"
. 445) ("myFunction4" . 515)))))))
)
diff --git a/phps-mode-test-syntax-table.el b/phps-mode-test-syntax-table.el
index b4b81db..b512fc7 100644
--- a/phps-mode-test-syntax-table.el
+++ b/phps-mode-test-syntax-table.el
@@ -29,6 +29,8 @@
(require 'phps-mode-functions)
(require 'phps-mode-test)
+;; TODO Should test `forward-sexp', `forward-word', `forward-list' as well
+
(defun phps-mode-test-syntax-table-quote-region ()
"Test double quotes, single quotes, curly bracket, square bracket, round
bracket, back-quotes on regions."
diff --git a/phps-mode.el b/phps-mode.el
index 7535f62..607ac2a 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -2,11 +2,11 @@
;; Copyright (C) 2018-2019 Free Software Foundation, Inc.
-;; Author: Christian Johansson <github.com/cjohansson>
+;; Author: Christian Johansson <address@hidden>
;; Maintainer: Christian Johansson <address@hidden>
;; Created: 3 Mar 2018
-;; Modified: 16 Aug 2019
-;; Version: 0.2.4
+;; Modified: 21 Aug 2019
+;; Version: 0.2.6
;; Keywords: tools, convenience
;; URL: https://github.com/cjohansson/emacs-phps-mode
@@ -64,13 +64,14 @@
"Major mode for PHP with Semantic integration."
;; TODO Check whether PSR-2 requires final newlines or not
- (setq-local require-final-newline nil)
+ (setq-local require-final-newline t)
- ;; TODO Verify this setting
- (setq-local parse-sexp-ignore-comments nil)
+ ;; Skip comments when navigating via syntax-table
+ (setq-local parse-sexp-ignore-comments t)
;; Key-map
;; prog-mode will create the key-map and we just modify it here.
+ ;; should break this out to stand-alone variable
(when (and phps-mode-map
(not phps-mode-map-applied))
(define-key phps-mode-map (kbd "C-c /") #'comment-region)
@@ -79,7 +80,13 @@
(use-local-map phps-mode-map)
;; Syntax table
- (phps-mode-syntax-table-init)
+ (set-syntax-table phps-mode-syntax-table)
+
+ ;; NOTE: These are required for wrapping region functionality
+ (transient-mark-mode)
+
+ ;; TODO Add this as a setting similar to php-mode
+ (electric-pair-local-mode)
;; Font lock
;; This makes it possible to have full control over syntax coloring from the
lexer
@@ -90,7 +97,8 @@
;; (phps-mode-flymake-init)
;; Flycheck
- ;; Add support for flycheck PHP checkers: PHP, PHPMD and PHPCS here, do it
once but only if flycheck is available
+ ;; Add support for flycheck PHP checkers: PHP, PHPMD and PHPCS here
+ ;; Do it once but only if flycheck is available
(when (and (fboundp 'flycheck-add-mode)
(not phps-mode-flycheck-applied))
(flycheck-add-mode 'php 'phps-mode)
@@ -99,7 +107,7 @@
(setq phps-mode-flycheck-applied t))
;; Custom indentation
- ;; NOTE Indent-region will call this on each line of region
+ ;; Indent-region will call this on each line of selected region
(setq-local indent-line-function #'phps-mode-functions-indent-line)
;; Custom Imenu
@@ -135,16 +143,33 @@
(add-hook 'after-change-functions #'phps-mode-functions-after-change)
;; Lexer
- (phps-mode-lexer-init)
+ (if (and (boundp 'semantic-lex-syntax-table)
+ (boundp 'phps-mode-syntax-table))
+ (setq-local semantic-lex-syntax-table phps-mode-syntax-table)
+ (signal 'error "Semantic or regular syntax-table for PHPs-mode missing!"))
+
+ ;; Semantic
+ (if (boundp 'semantic-lex-analyzer)
+ (setq-local semantic-lex-analyzer #'phps-mode-lexer-lex)
+ (signal 'error "Semantic semantic-lex-analyzer missing!"))
+
+ ;; Set semantic-lex initializer function
+ (add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup)
+
+ ;; Reset tokens
+ (setq-local phps-mode-lexer-tokens nil)
+
+ ;; Initial run of lexer
+ (phps-mode-lexer-run)
+
+ ;; Run semantic functions for new buffer
+ (semantic-new-buffer-fcn)
;; Wisent LALR parser TODO
;; (phps-mode-tags-init)
;; Add compatibility for plug-ins here
- (run-hooks 'phps-mode-hook)
-
- ;; Run semantic functions for new buffer
- (semantic-new-buffer-fcn))
+ (run-hooks 'phps-mode-hook))
(provide 'phps-mode)
;;; phps-mode.el ends here
diff --git a/sample-php-files/class.php b/sample-php-files/class.php
index 891b7e7..d555b4b 100644
--- a/sample-php-files/class.php
+++ b/sample-php-files/class.php
@@ -2,7 +2,7 @@
/**
* Some comments here
* @todo was here
- **/
+ */
class MyClass
{
@@ -39,6 +39,7 @@ class MyClass
$this->var = 'abc';
$this->var = '\\';
+ $this->var2 = "abc{$this->var} is good";
}
public function heres_more_information() {
diff --git a/sample-php-files/functions.php b/sample-php-files/functions.php
index 76199ea..36277c2 100644
--- a/sample-php-files/functions.php
+++ b/sample-php-files/functions.php
@@ -2,10 +2,7 @@
/**
* @param string $myArg1
- * @param string $myArg2
-
-
-
+ * @param string $myArg2
*/
function myFunctionA($myArg1, $myArg2)
{
@@ -26,4 +23,4 @@ function myFunctionB($myArg3) {
More stuff
</p>
</div>
-</body>
\ No newline at end of file
+</body>
diff --git a/sample-php-files/navigation.php b/sample-php-files/navigation.php
new file mode 100644
index 0000000..b9f3c91
--- /dev/null
+++ b/sample-php-files/navigation.php
@@ -0,0 +1,46 @@
+<?php
+
+function myFunctionE()
+{
+}
+
+function myFunctionF()
+{
+}
+
+// Comment's breaking navgiation?
+function myFunctionA()
+{
+}
+
+function myFunctionB()
+{
+}
+
+function myFunctionC()
+{
+}
+
+function myFunctionD()
+{
+}
+
+/* Does comment's break navgitation? */
+
+function myFunctionG()
+{
+}
+
+function myFunctionH()
+{
+}
+
+/** Does comment's break navgitation? **/
+
+function myFunctionI()
+{
+}
+
+function myFunctionJ()
+{
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/phps-mode 6ccb01a: Improved imenu, syntax-table and syntax-coloring,
Christian Johansson <=