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

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

[elpa] externals/phps-mode 54ad285: Improved token-blind indentation aft


From: Christian Johansson
Subject: [elpa] externals/phps-mode 54ad285: Improved token-blind indentation after assignments
Date: Sat, 25 Apr 2020 16:56:56 -0400 (EDT)

branch: externals/phps-mode
commit 54ad285910c01e06c68a225ce1883d8c78ba83e0
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Improved token-blind indentation after assignments
---
 admin/phps-mode-automation-header.wy | 32 ++++++++++++++++----------------
 admin/phps-mode-automation.el        |  6 +++---
 phps-mode-lex-analyzer.el            | 20 ++++++++++++--------
 phps-mode-wy-macros.el               | 32 ++++++++++++++++----------------
 phps-mode.el                         |  4 ++--
 test/phps-mode-test-lex-analyzer.el  | 27 +++++++++++++++++++++++++++
 6 files changed, 76 insertions(+), 45 deletions(-)

diff --git a/admin/phps-mode-automation-header.wy 
b/admin/phps-mode-automation-header.wy
index 8726788..7e6fcf9 100644
--- a/admin/phps-mode-automation-header.wy
+++ b/admin/phps-mode-automation-header.wy
@@ -37,20 +37,20 @@
 %languagemode phps-mode
 
 %use-macros phps-mode-wy-macros {
-             zend_add_class_modifier
-             zend_add_member_modifier
-             zend_append_str
-             zend_ast_create
-             zend_ast_create_assign_op
-             zend_ast_create_binary_op
-             zend_ast_create_cast
-             zend_ast_create_decl
-             zend_ast_create_ex
-             zend_ast_create_list
-             zend_ast_create_zval_from_str
-             zend_ast_get_str
-             zend_ast_list_add
-             zend_ast_list_rtrim
-             zend_handle_encoding_declaration
-             zend_negate_num_string
+             phps-mode-wy-macros--zend_add_class_modifier
+             phps-mode-wy-macros--zend_add_member_modifier
+             phps-mode-wy-macros--zend_append_str
+             phps-mode-wy-macros--zend_ast_create
+             phps-mode-wy-macros--zend_ast_create_assign_op
+             phps-mode-wy-macros--zend_ast_create_binary_op
+             phps-mode-wy-macros--zend_ast_create_cast
+             phps-mode-wy-macros--zend_ast_create_decl
+             phps-mode-wy-macros--zend_ast_create_ex
+             phps-mode-wy-macros--zend_ast_create_list
+             phps-mode-wy-macros--zend_ast_create_zval_from_str
+             phps-mode-wy-macros--zend_ast_get_str
+             phps-mode-wy-macros--zend_ast_list_add
+             phps-mode-wy-macros--zend_ast_list_rtrim
+             phps-mode-wy-macros--zend_handle_encoding_declaration
+             phps-mode-wy-macros--zend_negate_num_string
 }
diff --git a/admin/phps-mode-automation.el b/admin/phps-mode-automation.el
index c84b658..316d33e 100644
--- a/admin/phps-mode-automation.el
+++ b/admin/phps-mode-automation.el
@@ -40,9 +40,9 @@
 
   ;; Generate grammar
   (message "Generating Wisent grammar..")
-  (if (fboundp 'emacs-wisent-grammar-converter-generate-grammar-from-filename)
-      (emacs-wisent-grammar-converter-generate-grammar-from-filename
-       php-yacc-file wisent-destination header)
+  (if (fboundp 'emacs-wisent-grammar-converter--generate-grammar-from-filename)
+      (emacs-wisent-grammar-converter--generate-grammar-from-filename
+       php-yacc-file wisent-destination header "phps-mode-wy-macros--")
     (display-warning 'warning "Missing emacs-wisent-grammar-converter!"))
   (message "Automation completed"))
 
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 8b74245..c367dc0 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -2021,7 +2021,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                    (line-starts-with-closing-bracket 
(phps-mode-lex-analyzer--string-starts-with-closing-bracket-p line-string))
                    (line-ends-with-assignment 
(phps-mode-lex-analyzer--string-ends-with-assignment-p line-string))
                    (line-ends-with-opening-bracket 
(phps-mode-lex-analyzer--string-ends-with-opening-bracket-p line-string))
-                   (line-ends-with-semicolon 
(phps-mode-lex-analyzer--string-ends-with-semicolon-p line-string))
+                   (line-ends-with-terminus 
(phps-mode-lex-analyzer--string-ends-with-terminus-p line-string))
                    (bracket-level 
(phps-mode-lex-analyzer--get-string-brackets-count line-string)))
               (setq new-indentation old-indentation)
               (goto-char point)
@@ -2048,21 +2048,25 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                          (< bracket-level 0))
                 (setq new-indentation (+ new-indentation tab-width)))
 
-              (when line-ends-with-semicolon
+              (when line-ends-with-terminus
                 ;; Back-trace buffer from previous line
                 ;; Determine if semi-colon ended an assignment or not
                 (forward-line (* -1 move-length))
+                (end-of-line)
+                (forward-char -1)
                 (let ((not-found t)
                       (is-assignment nil))
                   (while (and
                           not-found
-                          (search-backward-regexp "\\(;\\|:\\|)\\|=\\)" nil t))
+                          (search-backward-regexp "\\(;\\|,\\|:\\|)\\|=\\)" 
nil t))
                     (let ((match (buffer-substring-no-properties 
(match-beginning 0) (match-end 0))))
                       (setq is-assignment (string= match "="))
                       (setq not-found nil)))
-                  ;; If it ended an assignment, decrease indentation
+                  ;; If it ended an assignment on a previous line, decrease 
indentation
                   (when (and is-assignment
-                             (> bracket-level -1))
+                             (> bracket-level -1)
+                             (not
+                              (= line-number (line-number-at-pos))))
                     ;; NOTE stuff like $var = array(\n    4\n);\n
                     ;; will end assignment but also decrease bracket-level
                     (setq new-indentation (- new-indentation tab-width))))
@@ -2122,11 +2126,11 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
 (defun phps-mode-lex-analyzer--string-ends-with-assignment-p (string)
   "Get bracket count for STRING."
-  (string-match-p "=[\t ]*$" string))
+  (string-match-p "=>?[\t ]*$" string))
 
-(defun phps-mode-lex-analyzer--string-ends-with-semicolon-p (string)
+(defun phps-mode-lex-analyzer--string-ends-with-terminus-p (string)
   "Get bracket count for STRING."
-  (string-match-p ";[\t ]*$" string))
+  (string-match-p "\\(;\\|,\\)[\t ]*$" string))
 
 (defun phps-mode-lex-analyzer--cancel-idle-timer ()
   "Cancel idle timer."
diff --git a/phps-mode-wy-macros.el b/phps-mode-wy-macros.el
index 09dc59d..cb93e51 100644
--- a/phps-mode-wy-macros.el
+++ b/phps-mode-wy-macros.el
@@ -36,74 +36,74 @@
       (puthash subject value phps-mode-wy-macros--CG-data)
     (gethash subject phps-mode-wy-macros--CG-data)))
 
-(defun zend_add_class_modifier (_class _modifier)
+(defun phps-mode-wy-macros--zend_add_class_modifier (_class _modifier)
   "Add CLASS MODIFIER."
   )
 
-(defun zend_add_member_modifier (_member _modifier)
+(defun phps-mode-wy-macros--zend_add_member_modifier (_member _modifier)
   "Add MEMBER MODIFIER."
   )
 
-(defun zend_ast_create (_a _b _c _d)
+(defun phps-mode-wy-macros--zend_ast_create (_a _b _c _d)
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_assign_op (_operator _a _b)
+(defun phps-mode-wy-macros--zend_ast_create_assign_op (_operator _a _b)
   "Assign A value of B via OPERATOR."
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_binary_op (_operator _a _b)
+(defun phps-mode-wy-macros--zend_ast_create_binary_op (_operator _a _b)
   "Perform binary OPERATOR on A and B."
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_cast (_operator _subject)
+(defun phps-mode-wy-macros--zend_ast_create_cast (_operator _subject)
   "Cast SUBJECT with OPERATOR."
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_decl (_a _b _c _d _e _f _g _h)
+(defun phps-mode-wy-macros--zend_ast_create_decl (_a _b _c _d _e _f _g _h)
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_ex (_a _b _c _d)
+(defun phps-mode-wy-macros--zend_ast_create_ex (_a _b _c _d)
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_list (_a _b _c)
+(defun phps-mode-wy-macros--zend_ast_create_list (_a _b _c)
   ;; TODO Understand this
   )
 
-(defun zend_ast_create_zval_from_str (_subject)
+(defun phps-mode-wy-macros--zend_ast_create_zval_from_str (_subject)
   "Create zval from SUBJECT."
   ;; TODO Understand this
   )
 
-(defun zend_ast_get_str (_subject)
+(defun phps-mode-wy-macros--zend_ast_get_str (_subject)
   "Get string from SUBJECT."
   ;; TODO Understand this
   )
 
-(defun zend_lex_tstring(_subject)
+(defun phps-mode-wy-macros--zend_lex_tstring(_subject)
   ;; TODO Understand this
   )
 
-(defun zend_ast_list_add (_list _item)
+(defun phps-mode-wy-macros--zend_ast_list_add (_list _item)
   "Add ITEM to LIST."
   ;; TODO Understand this
   )
 
-(defun zend_ast_list_rtrim (_subject)
+(defun phps-mode-wy-macros--zend_ast_list_rtrim (_subject)
   "Perform a right trim on SUBJECT."
   ;; TODO Understand this
   )
 
-(defun zend_handle_encoding_declaration (_subject)
+(defun phps-mode-wy-macros--zend_handle_encoding_declaration (_subject)
   ;; TODO Understand this
   )
 
-(defun zend_negate_num_string (_subject)
+(defun phps-mode-wy-macros--zend_negate_num_string (_subject)
   "Negate num string on SUBJECT."
   ;; TODO Understand this
   )
diff --git a/phps-mode.el b/phps-mode.el
index f9758d6..f9b4c3a 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
 ;; Author: Christian Johansson <address@hidden>
 ;; Maintainer: Christian Johansson <address@hidden>
 ;; Created: 3 Mar 2018
-;; Modified: 16 Apr 2020
-;; Version: 0.3.42
+;; Modified: 25 Apr 2020
+;; Version: 0.3.43
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-lex-analyzer.el 
b/test/phps-mode-test-lex-analyzer.el
index 9e6d617..6514b26 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -312,6 +312,33 @@
             (phps-mode-lex-analyzer--alternative-indentation)
             4)))
 
+  (phps-mode-test--with-buffer
+   "<?php\n\n$var = array(\n    '123' =>\n        'def',\n);"
+   "Token-blind indentation on lines after lines ending with T_DOUBLE_ARROW"
+   (goto-char 43)
+   (should (equal
+            (phps-mode-lex-analyzer--alternative-indentation)
+            8))
+   (goto-char 50)
+   (should (equal
+            (phps-mode-lex-analyzer--alternative-indentation)
+            0)))
+
+  (phps-mode-test--with-buffer
+   "<?php\n$var = array(\n    '123' => true,\n    \n);"
+   "Line after comma ended double arrow assignment"
+   (goto-char 44)
+   (should (equal
+            (phps-mode-lex-analyzer--alternative-indentation)
+            4)))
+
+  (phps-mode-test--with-buffer
+   "<?php\nfunction myFunction(\n    $arg = true,\n    $arg2 = false\n) {\n    
\n}"
+   "Line after function argument with default value"
+   (goto-char 49)
+   (should (equal
+            (phps-mode-lex-analyzer--alternative-indentation)
+            4)))
   )
 
 (defun phps-mode-test-lex-analyzer--move-lines-indent ()



reply via email to

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