emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/php-mode be716f0479 2/2: Merge pull request #727 from emac


From: ELPA Syncer
Subject: [nongnu] elpa/php-mode be716f0479 2/2: Merge pull request #727 from emacs-php/feature/use-function
Date: Sat, 11 Feb 2023 12:59:41 -0500 (EST)

branch: elpa/php-mode
commit be716f0479737baf2518b777c6015ffb124e949a
Merge: cf9481ccb7 d0949f1c17
Author: USAMI Kenta <tadsan@pixiv.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #727 from emacs-php/feature/use-function
    
    Add `use function` and `use const` to font-lock-keyword
---
 lisp/php-mode.el                            | 10 ++++++++
 tests/lang/import/import-constant.php       |  8 +++++++
 tests/lang/import/import-constant.php.faces | 31 ++++++++++++++++++++++++
 tests/lang/import/import-function.php       |  7 ++++++
 tests/lang/import/import-function.php.faces | 37 +++++++++++++++++++++++++++++
 tests/php-mode-test.el                      |  2 ++
 6 files changed, 95 insertions(+)

diff --git a/lisp/php-mode.el b/lisp/php-mode.el
index 179d5c9040..407745b3c3 100644
--- a/lisp/php-mode.el
+++ b/lisp/php-mode.el
@@ -1396,6 +1396,11 @@ for \\[find-tag] (which see)."
      ("\\_<\\(?:implements\\|extends\\)\\_>" . 'php-class-declaration-spec)
      ;; Namespace declaration
      ("\\_<namespace\\_>" . 'php-namespace-declaration)
+     ;; import constant statement
+     (,(rx symbol-start (group "use" (+ (syntax whitespace)) "const")
+           (+ (syntax whitespace)))
+      (1 'php-import-declaration)
+      (,(rx (group (+ (or (syntax word) (syntax symbol) "\\" "{" "}")))) nil 
nil (1 'php-constant-assign)))
      ;; import statement
      ("\\_<use\\_>" . 'php-import-declaration)
      ;; Class modifiers (abstract, final)
@@ -1478,6 +1483,11 @@ for \\[find-tag] (which see)."
    ;;   is usually overkill.
    `(
      ("\\<\\(@\\)" 1 'php-errorcontrol-op)
+     ;; import function statement
+     (,(rx symbol-start (group "use" (+ (syntax whitespace)) "function")
+           (+ (syntax whitespace)))
+      (1 'php-import-declaration)
+      (,(rx (group (+ (or (syntax word) (syntax symbol) "\\" "{" "}")))) nil 
nil (1 'php-function-name t)))
      ;; Highlight function calls
      ("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call)
      ;; Highlight all upper-cased symbols as constant
diff --git a/tests/lang/import/import-constant.php 
b/tests/lang/import/import-constant.php
new file mode 100644
index 0000000000..791e241a3c
--- /dev/null
+++ b/tests/lang/import/import-constant.php
@@ -0,0 +1,8 @@
+<?php
+namespace Foo;
+
+use const Foo\BAR;
+use const Foo\{BUZ, BUZBUZ};
+use const PHP_VERSION;
+
+const FOO = 'bar';
diff --git a/tests/lang/import/import-constant.php.faces 
b/tests/lang/import/import-constant.php.faces
new file mode 100644
index 0000000000..bef6797ee3
--- /dev/null
+++ b/tests/lang/import/import-constant.php.faces
@@ -0,0 +1,31 @@
+;; -*- mode: emacs-lisp -*-
+(("<?php" . php-php-tag)
+ ("\n")
+ ("namespace" . php-namespace-declaration)
+ (" ")
+ ("Foo" . font-lock-type-face)
+ (";\n\n")
+ ("use const" . php-import-declaration)
+ (" ")
+ ("Foo\\" . php-constant-assign)
+ ("BAR" . font-lock-type-face)
+ (";\n")
+ ("use const" . php-import-declaration)
+ (" ")
+ ("Foo" . font-lock-type-face)
+ ("\\{BUZ" . php-constant-assign)
+ (", ")
+ ("BUZBUZ}" . php-constant-assign)
+ (";\n")
+ ("use const" . php-import-declaration)
+ (" ")
+ ("PHP_VERSION" . font-lock-type-face)
+ (";\n\n")
+ ("const" . php-keyword)
+ (" ")
+ ("FOO" . font-lock-type-face)
+ (" ")
+ ("=" . php-assignment-op)
+ (" ")
+ ("'bar'" . php-string)
+ (";\n"))
diff --git a/tests/lang/import/import-function.php 
b/tests/lang/import/import-function.php
new file mode 100644
index 0000000000..0746c9b210
--- /dev/null
+++ b/tests/lang/import/import-function.php
@@ -0,0 +1,7 @@
+<?php
+namespace Foo;
+
+use function var_dump;
+use function is_array, is_string, is_dir;
+use function Safe\json_encode;
+use function Safe\{file_get_contents, json_decode};
diff --git a/tests/lang/import/import-function.php.faces 
b/tests/lang/import/import-function.php.faces
new file mode 100644
index 0000000000..e735da41a6
--- /dev/null
+++ b/tests/lang/import/import-function.php.faces
@@ -0,0 +1,37 @@
+;; -*- mode: emacs-lisp -*-
+(("<?php" . php-php-tag)
+ ("\n")
+ ("namespace" . php-namespace-declaration)
+ (" ")
+ ("Foo" . font-lock-type-face)
+ (";\n\n")
+ ("use" . php-import-declaration)
+ (" ")
+ ("function" . php-keyword)
+ (" ")
+ ("var_dump" . php-function-name)
+ (";\n")
+ ("use" . php-import-declaration)
+ (" ")
+ ("function" . php-keyword)
+ (" ")
+ ("is_array" . php-function-name)
+ (", ")
+ ("is_string" . php-function-name)
+ (", ")
+ ("is_dir" . php-function-name)
+ (";\n")
+ ("use" . php-import-declaration)
+ (" ")
+ ("function" . php-keyword)
+ (" ")
+ ("Safe\\json_encode" . php-function-name)
+ (";\n")
+ ("use" . php-import-declaration)
+ (" ")
+ ("function" . php-keyword)
+ (" ")
+ ("Safe\\{file_get_contents" . php-function-name)
+ (", ")
+ ("json_decode}" . php-function-name)
+ (";\n"))
diff --git a/tests/php-mode-test.el b/tests/php-mode-test.el
index 6e10a9914e..79db0b8a1b 100644
--- a/tests/php-mode-test.el
+++ b/tests/php-mode-test.el
@@ -683,6 +683,8 @@ Meant for `php-mode-test-issue-503'."
   (with-php-mode-test ("lang/doc-comment/return-type.php" :faces t))
   (with-php-mode-test ("lang/function/calls.php" :faces t))
   (with-php-mode-test ("lang/function/closure.php" :indent t :magic t :faces 
t))
+  (with-php-mode-test ("lang/import/import-constant.php" :faces t))
+  (with-php-mode-test ("lang/import/import-function.php" :faces t))
   (with-php-mode-test ("lang/try-cactch/multiple.php" :faces t))
   (with-php-mode-test ("lang/types/cast.php" :faces t))
   (with-php-mode-test ("lang/types/function.php" :faces t))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]