From 637e7ebc8c7d88c5054136f1dab5c8cc4f203305 Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sat, 13 Aug 2011 20:07:33 +0900 Subject: [PATCH 01/23] initial commit. --- README.md | 74 +++++++++++++++++++++++++++++++ php-align.el | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 README.md create mode 100644 php-align.el diff --git a/README.md b/README.md new file mode 100644 index 00000000..3bd4898d --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +# About # + +Support alignment (e.g. `align', `align-current') for PHP. +CAUTION!! this is still experimental. + +Put this file into your load-path.and the following code into your ~/.emacs + + (add-hook 'php-mode-hook + (require 'php-align) + (lambda () (php-align-setup))) + +# Examples # + +## 1. ## + +### before ### + + $foo = "string"; // M-x arign-current + $looooooooong = 1; // + +### after ### + + $foo = "string"; // M-x arign-current + $looooooooong = 1; // + +## 2. ## + +### before ### + + $foo = "string"; // M-x arign-current + $looooooooong = 1; // + + $bar = 2; // + +### after ### + + $foo = "string"; // M-x arign-current + $looooooooong = 1; // + + $bar = 2; // + +## 3. ## + +### before ### + $variable = 1; + $vars = array(); // M-x align-current + if ($variable == $vars) { + + } + +### after ### + $variable = 1; + $vars = array(); // M-x align-current + if ($variable == $vars) { + + } + +## 4. ## + +### before ### + $vars = array( + 1, 2, 3, // one + 4, 5, 6, // two + 7, 8, 9,// three + 10, 11, 12, // M-x align-current + ); + +### after ### + $vars = array( + 1, 2, 3, // one + 4, 5, 6, // two + 7, 8, 9, // three + 10, 11, 12, // M-x align-current + ); \ No newline at end of file diff --git a/php-align.el b/php-align.el new file mode 100644 index 00000000..bd15f8ff --- /dev/null +++ b/php-align.el @@ -0,0 +1,121 @@ +;;; php-align.el --- Setup alignment configuration for PHP. + +;; Copyright (C) 2011 tetsujin (Yusuke Segawa) + +;; Author: tetsujin (Yusuke Segawa) +;; Keywords: php languages convenience align +;; URL: https://github.com/tetsujin/emacs-php-align +;; Version: 0.0.1 + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: +;; This extension provides alignment for PHP. +;; Note that you must have Font Lock mode enabled. +;; +;; If you don't have php-mode then get from https://github.com/rradonic/php-mode +;; This php-mode has various improvements than original it. +;; +;; Put this file into your load-path.and the following code into your ~/.emacs +;; (add-hook 'php-mode-hook +;; (require 'php-align) +;; (lambda () (php-align-setup))) + +;;; TODO: +;; - Add test codes using el-expectations. + +;;; Code: +(require 'php-mode) +(require 'align) + +(defvar php-align-rules-list + `((php-comma-delimiter + (regexp . ",\\(\\s-*\\)[^\\(//\\) \t\n]") + (repeat . t) + (valid . (lambda() (not (php-align-point-is-string-p)))) + (modes . '(php-mode))) + (php-assignment + (regexp . ,(concat "[^=!^&*-+<>/.| \t\n]\\(\\s-*[=!^&%*-+<>/.|]*\\)=>?" + "\\(\\s-*\\)\\([^= \t\n]\\|$\\)")) + (group . (1 2)) + (modes . '(php-mode)) + (justify . t) + (tab-stop . nil)) + (php-single-line-comment + (regexp . "\\(\\s-*\\)//") + (modes . '(php-mode))) + ) + "Definition of `align-rules-list' for PHP") + +(defvar php-align-region-separate + (eval-when-compile + (concat + "\\(" ; * blank line + "^\\s-*$" + "\\)\\|\\(" ; * comment start or end line + "^\\s-*\\(/[/*]\\|\\*/\\)" + "\\)\\|\\(" ; * end of line are '[', '(', '{', '}', '/*' + "\\([[({}]\\|/\\*+\\)\\s-*$" + "\\)\\|\\(" ; * beginning of line are ')', '}', ']' + "^\\s-*[)}]][ \t,;]?\\s-*$" ; and trailing character are ',', ';' + "\\)\\|\\(" ; * beginning of line are some PHP keywrods + "^\\s-*" + "\\(" + "for\\|" + "foreach\\|" + "while\\|" + "if\\|" + "else\\|" + "switch\\|" + "case\\|" + "break\\|" + "continue\\|" + "declare\\|" + "do" + "\\)" + "[ ;]" + "\\)\\|\\(" ; * function or method call + "^\\s-*" + "\\(" + "\\w\\|[->\\: \t]" + "\\)+" + "(" + "\\)" + )) + "Regexp of a section of PHP for alignment.") + +(defun php-align-setup () + "Setup alignment configuration for PHP code." + (set (make-local-variable 'align-mode-rules-list) php-align-rules-list) + (set (make-local-variable 'align-region-separate) php-align-region-separate)) + +(defsubst php-align-face-at-point-in-p (point face-list) + "Return t if the face of the current POINT is an element of FACE-LIST. + otherwise nil." + (consp (memq (get-text-property point 'face) face-list))) + +(defun php-align-point-is-comment-p () + "Return t if the face of the current position is on the comment syntax." + (php-align-face-at-point-in-p (point) '(font-lock-comment-face))) + +(defun php-align-point-is-string-p () + "Return t if the face of the current position is on the string syntax." + (php-align-face-at-point-in-p (point) '(font-lock-string-face))) + +;; Provide: +(provide 'php-align) + +;;; php-align.el ends here \ No newline at end of file From e9f5f158e124e235895775e7800b953d5e44a65a Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sat, 13 Aug 2011 20:12:28 +0900 Subject: [PATCH 02/23] comment fix --- README.md | 7 ++++--- php-align.el | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3bd4898d..e07e8b02 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ CAUTION!! this is still experimental. Put this file into your load-path.and the following code into your ~/.emacs - (add-hook 'php-mode-hook - (require 'php-align) - (lambda () (php-align-setup))) +(add-hook 'php-mode-hook + (lambda () + (require 'php-align) + (php-align-setup))) # Examples # diff --git a/php-align.el b/php-align.el index bd15f8ff..07e96f6c 100644 --- a/php-align.el +++ b/php-align.el @@ -1,4 +1,4 @@ -;;; php-align.el --- Setup alignment configuration for PHP. +;;; php-align.el --- Alignment configuration for PHP. ;; Copyright (C) 2011 tetsujin (Yusuke Segawa) @@ -31,8 +31,9 @@ ;; ;; Put this file into your load-path.and the following code into your ~/.emacs ;; (add-hook 'php-mode-hook -;; (require 'php-align) -;; (lambda () (php-align-setup))) +;; (lambda () +;; (require 'php-align) +;; (php-align-setup))) ;;; TODO: ;; - Add test codes using el-expectations. From e7eec998098c5d116411d2b6db1e0b558656c94a Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sat, 13 Aug 2011 20:16:28 +0900 Subject: [PATCH 03/23] modified README --- README.md | 69 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index e07e8b02..43130629 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,10 @@ Support alignment (e.g. `align', `align-current') for PHP. CAUTION!! this is still experimental. Put this file into your load-path.and the following code into your ~/.emacs - -(add-hook 'php-mode-hook - (lambda () - (require 'php-align) - (php-align-setup))) + (add-hook 'php-mode-hook + (lambda () + (require 'php-align) + (php-align-setup))) # Examples # @@ -16,60 +15,60 @@ Put this file into your load-path.and the following code into your ~/.emacs ### before ### - $foo = "string"; // M-x arign-current - $looooooooong = 1; // + $foo = "string"; // M-x arign-current + $looooooooong = 1; // ### after ### - $foo = "string"; // M-x arign-current - $looooooooong = 1; // + $foo = "string"; // M-x arign-current + $looooooooong = 1; // ## 2. ## ### before ### - $foo = "string"; // M-x arign-current - $looooooooong = 1; // + $foo = "string"; // M-x arign-current + $looooooooong = 1; // - $bar = 2; // + $bar = 2; // ### after ### - $foo = "string"; // M-x arign-current - $looooooooong = 1; // + $foo = "string"; // M-x arign-current + $looooooooong = 1; // - $bar = 2; // + $bar = 2; // ## 3. ## ### before ### - $variable = 1; - $vars = array(); // M-x align-current - if ($variable == $vars) { + $variable = 1; + $vars = array(); // M-x align-current + if ($variable == $vars) { - } + } ### after ### - $variable = 1; - $vars = array(); // M-x align-current - if ($variable == $vars) { + $variable = 1; + $vars = array(); // M-x align-current + if ($variable == $vars) { - } + } ## 4. ## ### before ### - $vars = array( - 1, 2, 3, // one - 4, 5, 6, // two - 7, 8, 9,// three - 10, 11, 12, // M-x align-current - ); + $vars = array( + 1, 2, 3, // one + 4, 5, 6, // two + 7, 8, 9,// three + 10, 11, 12, // M-x align-current + ); ### after ### - $vars = array( - 1, 2, 3, // one - 4, 5, 6, // two - 7, 8, 9, // three - 10, 11, 12, // M-x align-current - ); \ No newline at end of file + $vars = array( + 1, 2, 3, // one + 4, 5, 6, // two + 7, 8, 9, // three + 10, 11, 12, // M-x align-current + ); \ No newline at end of file From 756e2c732a12fe344568d4104c6a7b1a971e37a5 Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sat, 13 Aug 2011 20:18:00 +0900 Subject: [PATCH 04/23] modified README --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 43130629..4de5274d 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,13 @@ Support alignment (e.g. `align', `align-current') for PHP. CAUTION!! this is still experimental. Put this file into your load-path.and the following code into your ~/.emacs - (add-hook 'php-mode-hook - (lambda () - (require 'php-align) - (php-align-setup))) + + +(add-hook 'php-mode-hook + (lambda () + (require 'php-align) + (php-align-setup))) + # Examples # From b01f150797a420b14c25df8c7df19f109c33e9be Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sat, 13 Aug 2011 20:18:50 +0900 Subject: [PATCH 05/23] README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4de5274d..c5bc37b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # About # -Support alignment (e.g. `align', `align-current') for PHP. +Support alignment (e.g. align, align-current) for PHP. CAUTION!! this is still experimental. Put this file into your load-path.and the following code into your ~/.emacs From 1761ede04060acc723c9c297794846c1213d241c Mon Sep 17 00:00:00 2001 From: tetsujin Date: Sun, 14 Aug 2011 03:23:51 +0900 Subject: [PATCH 06/23] - Conform to other languages definition. - Fix README --- README.md | 20 ++++++------ php-align.el | 88 +++++++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index c5bc37b0..696f3e79 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # About # +CAUTION!! this is still experimental. Support alignment (e.g. align, align-current) for PHP. -CAUTION!! this is still experimental. Put this file into your load-path.and the following code into your ~/.emacs @@ -30,6 +30,7 @@ Put this file into your load-path.and the following code into your ~/.emacs ### before ### + "$foo = 1"; $foo = "string"; // M-x arign-current $looooooooong = 1; // @@ -37,6 +38,7 @@ Put this file into your load-path.and the following code into your ~/.emacs ### after ### + "$foo = 1"; $foo = "string"; // M-x arign-current $looooooooong = 1; // @@ -62,16 +64,16 @@ Put this file into your load-path.and the following code into your ~/.emacs ### before ### $vars = array( - 1, 2, 3, // one - 4, 5, 6, // two - 7, 8, 9,// three - 10, 11, 12, // M-x align-current + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10, 11, 12, // C-u M-x align-current ); ### after ### $vars = array( - 1, 2, 3, // one - 4, 5, 6, // two - 7, 8, 9, // three - 10, 11, 12, // M-x align-current + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10, 11, 12, // C-u M-x align-current ); \ No newline at end of file diff --git a/php-align.el b/php-align.el index 07e96f6c..0e15d0ec 100644 --- a/php-align.el +++ b/php-align.el @@ -41,13 +41,14 @@ ;;; Code: (require 'php-mode) (require 'align) +(require 'regexp-opt) (defvar php-align-rules-list `((php-comma-delimiter - (regexp . ",\\(\\s-*\\)[^\\(//\\) \t\n]") + (regexp . ",\\(\\s-*\\)[^/ \t\n]") (repeat . t) - (valid . (lambda() (not (php-align-point-is-string-p)))) - (modes . '(php-mode))) + (modes . '(php-mode)) + (run-if . ,(function (lambda () current-prefix-arg)))) (php-assignment (regexp . ,(concat "[^=!^&*-+<>/.| \t\n]\\(\\s-*[=!^&%*-+<>/.|]*\\)=>?" "\\(\\s-*\\)\\([^= \t\n]\\|$\\)")) @@ -55,54 +56,63 @@ (modes . '(php-mode)) (justify . t) (tab-stop . nil)) - (php-single-line-comment - (regexp . "\\(\\s-*\\)//") - (modes . '(php-mode))) - ) - "Definition of `align-rules-list' for PHP") + (php-comment + (regexp . "\\(\\s-*\\)\\(//.*\\|/\\*.*\\*/\\s-*\\)$") + (modes . (php-mode)) + (column . comment-column) + (valid . ,(function + (lambda () + (save-excursion + (goto-char (match-beginning 1)) + (not (bolp))))))) + (php-chain-logic + (regexp . "\\(\\s-*\\)\\(&&\\|||\\|\\\\|\\\\)") + (modes . (php-mode)) + (valid . ,(function + (lambda () + (save-excursion + (goto-char (match-end 2)) + (looking-at "\\s-*\\(/[*/]\\|$\\)")))))) + )) (defvar php-align-region-separate (eval-when-compile (concat - "\\(" ; * blank line - "^\\s-*$" - "\\)\\|\\(" ; * comment start or end line - "^\\s-*\\(/[/*]\\|\\*/\\)" - "\\)\\|\\(" ; * end of line are '[', '(', '{', '}', '/*' - "\\([[({}]\\|/\\*+\\)\\s-*$" - "\\)\\|\\(" ; * beginning of line are ')', '}', ']' - "^\\s-*[)}]][ \t,;]?\\s-*$" ; and trailing character are ',', ';' - "\\)\\|\\(" ; * beginning of line are some PHP keywrods - "^\\s-*" - "\\(" - "for\\|" - "foreach\\|" - "while\\|" - "if\\|" - "else\\|" - "switch\\|" - "case\\|" - "break\\|" - "continue\\|" - "declare\\|" - "do" - "\\)" - "[ ;]" - "\\)\\|\\(" ; * function or method call - "^\\s-*" - "\\(" - "\\w\\|[->\\: \t]" - "\\)+" - "(" + ;; blank line + "\\(?:" "^\\s-*$" "\\)" + "\\|" + ;; comment start or end line + "\\(?:" "^\\s-*\\(?:/[/*]\\|\\*/\\)" "\\)" + "\\|" + ;; end of line are '[', '(', '{', '}', '/*' + "\\(?:" "\\(?:[[({}]\\|/\\*+\\)\\s-*$" "\\)" + "\\|" + ;; beginning of line are ')', '}', ']' and trailing character are ',', ';' + "\\(?:" "^\\s-*[)}]][ \t,;]?\\s-*$" "\\)" + "\\|" + ;; beginning of line are some PHP keywrods + "\\(?:" + "^\\s-*" + (regexp-opt + '("for" "foreach" "while" "if" "else" "switch" "case" "break" "continue" + "try" "catch" "declare" "do" "return" "namespace" "use")) + "[ ;]" "\\)" + "\\|" + ;; function or method call + "\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)" )) "Regexp of a section of PHP for alignment.") (defun php-align-setup () "Setup alignment configuration for PHP code." (set (make-local-variable 'align-mode-rules-list) php-align-rules-list) - (set (make-local-variable 'align-region-separate) php-align-region-separate)) + (set (make-local-variable 'align-region-separate) php-align-region-separate) + (add-to-list 'align-open-comment-modes 'php-mode) + (add-to-list 'align-dq-string-modes 'php-mode) + (add-to-list 'align-sq-string-modes 'php-mode)) +;; Unused functions. (defsubst php-align-face-at-point-in-p (point face-list) "Return t if the face of the current POINT is an element of FACE-LIST. otherwise nil." From 552ea1bc3d056c59956bfd62ed4fabb90433c04a Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:09:45 +0900 Subject: [PATCH 07/23] Move php-align.el to root directory --- php-align/php-align.el => php-align.el | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename php-align/php-align.el => php-align.el (100%) diff --git a/php-align/php-align.el b/php-align.el similarity index 100% rename from php-align/php-align.el rename to php-align.el From fd764ebc4fe042d8edd13d795ee3d48321a6e968 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:14:37 +0900 Subject: [PATCH 08/23] Remove unused functions --- php-align.el | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/php-align.el b/php-align.el index 0e15d0ec..0612bed9 100644 --- a/php-align.el +++ b/php-align.el @@ -112,21 +112,5 @@ (add-to-list 'align-dq-string-modes 'php-mode) (add-to-list 'align-sq-string-modes 'php-mode)) -;; Unused functions. -(defsubst php-align-face-at-point-in-p (point face-list) - "Return t if the face of the current POINT is an element of FACE-LIST. - otherwise nil." - (consp (memq (get-text-property point 'face) face-list))) - -(defun php-align-point-is-comment-p () - "Return t if the face of the current position is on the comment syntax." - (php-align-face-at-point-in-p (point) '(font-lock-comment-face))) - -(defun php-align-point-is-string-p () - "Return t if the face of the current position is on the string syntax." - (php-align-face-at-point-in-p (point) '(font-lock-string-face))) - -;; Provide: (provide 'php-align) - -;;; php-align.el ends here \ No newline at end of file +;;; php-align.el ends here From 27257bd9c5c5fa4a3ab0a09933bee94e757a629f Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:16:55 +0900 Subject: [PATCH 09/23] align --- php-align.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/php-align.el b/php-align.el index 0612bed9..df4ac863 100644 --- a/php-align.el +++ b/php-align.el @@ -72,8 +72,7 @@ (lambda () (save-excursion (goto-char (match-end 2)) - (looking-at "\\s-*\\(/[*/]\\|$\\)")))))) - )) + (looking-at "\\s-*\\(/[*/]\\|$\\)")))))))) (defvar php-align-region-separate (eval-when-compile @@ -100,8 +99,7 @@ "\\)" "\\|" ;; function or method call - "\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)" - )) + "\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)")) "Regexp of a section of PHP for alignment.") (defun php-align-setup () From 8395a4f342c3d24ffafd45161c592b3b95c3fd37 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:16:30 +0900 Subject: [PATCH 10/23] Modify headers and license notation --- php-align.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/php-align.el b/php-align.el index df4ac863..1c4747ca 100644 --- a/php-align.el +++ b/php-align.el @@ -1,4 +1,4 @@ -;;; php-align.el --- Alignment configuration for PHP. +;;; php-align.el --- Alignment configuration for PHP -*- lexical-binding: t; -*- ;; Copyright (C) 2011 tetsujin (Yusuke Segawa) @@ -6,23 +6,24 @@ ;; Keywords: php languages convenience align ;; URL: https://github.com/tetsujin/emacs-php-align ;; Version: 0.0.1 +;; Package-Requires: ((emacs "24.3")) +;; License: GPL-3.0-or-later -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software: you can redistribute it and/or modify +;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. -;; GNU Emacs is distributed in the hope that it will be useful, +;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs. If not, see . +;; along with this program. If not, see . ;;; Commentary: + ;; This extension provides alignment for PHP. ;; Note that you must have Font Lock mode enabled. ;; From c10143154376d604df6eabd413db1db59cf92da6 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:20:03 +0900 Subject: [PATCH 11/23] Remove unnecessary (require 'php-mode) --- php-align.el | 1 - 1 file changed, 1 deletion(-) diff --git a/php-align.el b/php-align.el index 1c4747ca..0eaf2f24 100644 --- a/php-align.el +++ b/php-align.el @@ -40,7 +40,6 @@ ;; - Add test codes using el-expectations. ;;; Code: -(require 'php-mode) (require 'align) (require 'regexp-opt) From bdc9881fcf62931a453626755b08f518743999a6 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:23:08 +0900 Subject: [PATCH 12/23] Add autoload cookie to php-align-setup --- php-align.el | 1 + 1 file changed, 1 insertion(+) diff --git a/php-align.el b/php-align.el index 0eaf2f24..cb3e8437 100644 --- a/php-align.el +++ b/php-align.el @@ -102,6 +102,7 @@ "\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)")) "Regexp of a section of PHP for alignment.") +;;;###autoload (defun php-align-setup () "Setup alignment configuration for PHP code." (set (make-local-variable 'align-mode-rules-list) php-align-rules-list) From caedb99c007d3a1e5f63b34a8456c047d52f1c8e Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:23:46 +0900 Subject: [PATCH 13/23] Add php-align to Makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5dc3f21e..682675df 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ EMACS ?= emacs -ELS = php.el php-face.el php-project.el php-mode.el php-mode-debug.el +ELS = php.el php-align.el php-face.el php-project.el php-mode.el php-mode-debug.el AUTOLOADS = php-mode-autoloads.el ELCS = $(ELS:.el=.elc) @@ -21,7 +21,7 @@ AUTHORS.md: AUTHORS.md.in autoloads: $(AUTOLOADS) -$(AUTOLOADS): php.el php-face.el php-project.el php-mode-debug.el php-mode.el +$(AUTOLOADS): php.el php-align.el php-face.el php-project.el php-mode-debug.el php-mode.el $(EMACS) -Q -batch -L . --eval \ "(progn \ (require 'package) \ From ffea5b24ae2114a99178b54de32936301f3cb243 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:23:59 +0900 Subject: [PATCH 14/23] Add tetsujin (the author of php-align.el) to AUTHORS --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index e873d9b5..6a9e4335 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -74,6 +74,7 @@ Names Sorted Alphabetically: - phil-s - takeokunn - tangxinfa +- tetsujin - tijsmallaerts - zapad - 顾伟刚 From 5ce33cafb881776c053d309fb93b5592da9af522 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:41:58 +0900 Subject: [PATCH 15/23] Update README --- php-align/README.md | 49 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/php-align/README.md b/php-align/README.md index 696f3e79..5d37010d 100644 --- a/php-align/README.md +++ b/php-align/README.md @@ -1,68 +1,72 @@ -# About # +# php-align.el + CAUTION!! this is still experimental. -Support alignment (e.g. align, align-current) for PHP. +Support alignment (e.g. `align`, `align-current`) for PHP. Put this file into your load-path.and the following code into your ~/.emacs - +```el (add-hook 'php-mode-hook (lambda () (require 'php-align) (php-align-setup))) - +``` -# Examples # +## Examples -## 1. ## +### 1. -### before ### +#### before - $foo = "string"; // M-x arign-current + $foo = "string"; // M-x align-current $looooooooong = 1; // -### after ### +#### after - $foo = "string"; // M-x arign-current + $foo = "string"; // M-x align-current $looooooooong = 1; // -## 2. ## +### 2. -### before ### +#### before "$foo = 1"; - $foo = "string"; // M-x arign-current + $foo = "string"; // M-x align-current $looooooooong = 1; // $bar = 2; // -### after ### +#### after "$foo = 1"; - $foo = "string"; // M-x arign-current + $foo = "string"; // M-x align-current $looooooooong = 1; // $bar = 2; // -## 3. ## +### 3. + +#### before -### before ### $variable = 1; $vars = array(); // M-x align-current if ($variable == $vars) { } -### after ### +#### after + $variable = 1; $vars = array(); // M-x align-current if ($variable == $vars) { } -## 4. ## +### 4. + +#### before -### before ### $vars = array( 1, 2, 3, 4, 5, 6, @@ -70,10 +74,11 @@ Put this file into your load-path.and the following code into your ~/.emacs 10, 11, 12, // C-u M-x align-current ); -### after ### +#### after + $vars = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, // C-u M-x align-current - ); \ No newline at end of file + ); From cb8aa164c4e0ca4e2bebc5a80996ed37e03a3f41 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:42:57 +0900 Subject: [PATCH 16/23] Use setq-local instead of make-local-variable --- php-align.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-align.el b/php-align.el index cb3e8437..5ee709d9 100644 --- a/php-align.el +++ b/php-align.el @@ -105,8 +105,8 @@ ;;;###autoload (defun php-align-setup () "Setup alignment configuration for PHP code." - (set (make-local-variable 'align-mode-rules-list) php-align-rules-list) - (set (make-local-variable 'align-region-separate) php-align-region-separate) + (setq-local align-mode-rules-list php-align-rules-list) + (setq-local align-region-separate php-align-region-separate) (add-to-list 'align-open-comment-modes 'php-mode) (add-to-list 'align-dq-string-modes 'php-mode) (add-to-list 'align-sq-string-modes 'php-mode)) From b0711d7648b2c504da2ebd6d554f14cec5c8e832 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 10:48:24 +0900 Subject: [PATCH 17/23] Use fence notation --- php-align/README.md | 80 +++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/php-align/README.md b/php-align/README.md index 5d37010d..214671a5 100644 --- a/php-align/README.md +++ b/php-align/README.md @@ -19,66 +19,82 @@ Put this file into your load-path.and the following code into your ~/.emacs #### before - $foo = "string"; // M-x align-current - $looooooooong = 1; // +```php +$foo = "string"; // M-x align-current +$looooooooong = 1; // +``` #### after - $foo = "string"; // M-x align-current - $looooooooong = 1; // +```php +$foo = "string"; // M-x align-current +$looooooooong = 1; // +``` ### 2. #### before - "$foo = 1"; - $foo = "string"; // M-x align-current - $looooooooong = 1; // +```php +"$foo = 1"; +$foo = "string"; // M-x align-current +$looooooooong = 1; // - $bar = 2; // +$bar = 2; // +``` #### after - "$foo = 1"; - $foo = "string"; // M-x align-current - $looooooooong = 1; // +```php +"$foo = 1"; +$foo = "string"; // M-x align-current +$looooooooong = 1; // - $bar = 2; // +$bar = 2; // +``` ### 3. #### before - $variable = 1; - $vars = array(); // M-x align-current - if ($variable == $vars) { +```php +$variable = 1; +$vars = array(); // M-x align-current +if ($variable == $vars) { - } +} +``` #### after - $variable = 1; - $vars = array(); // M-x align-current - if ($variable == $vars) { +```php +$variable = 1; +$vars = array(); // M-x align-current +if ($variable == $vars) { - } +} +``` ### 4. #### before - $vars = array( - 1, 2, 3, - 4, 5, 6, - 7, 8, 9, - 10, 11, 12, // C-u M-x align-current - ); +```php +$vars = array( + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10, 11, 12, // C-u M-x align-current +); +``` #### after - $vars = array( - 1, 2, 3, - 4, 5, 6, - 7, 8, 9, - 10, 11, 12, // C-u M-x align-current - ); +```php +$vars = array( + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10, 11, 12, // C-u M-x align-current +); +``` From b02c2c2f058f0c2366bb0262dac6a1ed8ef7f4d6 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 19:21:38 +0900 Subject: [PATCH 18/23] Impl php-align-mode --- php-align.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/php-align.el b/php-align.el index 5ee709d9..9ff6a14f 100644 --- a/php-align.el +++ b/php-align.el @@ -105,8 +105,17 @@ ;;;###autoload (defun php-align-setup () "Setup alignment configuration for PHP code." - (setq-local align-mode-rules-list php-align-rules-list) + (php-align-mode 1)) + +(defvar php-align-mode-lighter " PHP-Align") + +;;;###autoload +(define-minor-mode php-align-mode + "Alignment lines for PHP script." + :lighter php-align-mode-lighter (setq-local align-region-separate php-align-region-separate) + (setq-local align-mode-rules-list nil) + (setq-local align-region-separate nil) (add-to-list 'align-open-comment-modes 'php-mode) (add-to-list 'align-dq-string-modes 'php-mode) (add-to-list 'align-sq-string-modes 'php-mode)) From b3b61383a30acd7e95b86085708af290fceb2d73 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 19:22:14 +0900 Subject: [PATCH 19/23] Impl restore align-mode-rules-list on turn off mode --- php-align.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/php-align.el b/php-align.el index 9ff6a14f..eb20d1ea 100644 --- a/php-align.el +++ b/php-align.el @@ -113,12 +113,16 @@ (define-minor-mode php-align-mode "Alignment lines for PHP script." :lighter php-align-mode-lighter - (setq-local align-region-separate php-align-region-separate) - (setq-local align-mode-rules-list nil) - (setq-local align-region-separate nil) (add-to-list 'align-open-comment-modes 'php-mode) (add-to-list 'align-dq-string-modes 'php-mode) - (add-to-list 'align-sq-string-modes 'php-mode)) + (add-to-list 'align-sq-string-modes 'php-mode) + + (if php-align-mode + (progn + (setq-local align-mode-rules-list php-align-rules-list) + (setq-local align-region-separate php-align-region-separate)) + (setq-local align-mode-rules-list nil) + (setq-local align-region-separate nil))) (provide 'php-align) ;;; php-align.el ends here From 06c68d8df64f94b3d97d3ca7c5edf2980df1208e Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 19:36:36 +0900 Subject: [PATCH 20/23] Add php-project-align-lines variable --- php-align.el | 4 +++- php-project.el | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/php-align.el b/php-align.el index eb20d1ea..fa8af227 100644 --- a/php-align.el +++ b/php-align.el @@ -42,6 +42,7 @@ ;;; Code: (require 'align) (require 'regexp-opt) +(require 'php-project) (defvar php-align-rules-list `((php-comma-delimiter @@ -105,7 +106,8 @@ ;;;###autoload (defun php-align-setup () "Setup alignment configuration for PHP code." - (php-align-mode 1)) + (when php-project-align-lines + (php-align-mode 1))) (defvar php-align-mode-lighter " PHP-Align") diff --git a/php-project.el b/php-project.el index 99c3a898..f82b4e87 100644 --- a/php-project.el +++ b/php-project.el @@ -152,6 +152,10 @@ defines constants, and sets the class loaders.") Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.") (put 'php-project-coding-style 'safe-local-variable #'symbolp) + (defvar-local php-project-align-lines t + "If T, automatically turn on `php-align-mode' by `php-align-setup'.") + (put 'php-project-align-lines 'safe-local-variable #'booleanp) + (defvar-local php-project-php-file-as-template 'auto " `auto' (default) From 56c7b89552f57e9e019b58fd894f79c8d86a6685 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 19:45:53 +0900 Subject: [PATCH 21/23] Modify php-align comment --- php-align.el | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/php-align.el b/php-align.el index fa8af227..68833f13 100644 --- a/php-align.el +++ b/php-align.el @@ -27,14 +27,9 @@ ;; This extension provides alignment for PHP. ;; Note that you must have Font Lock mode enabled. ;; -;; If you don't have php-mode then get from https://github.com/rradonic/php-mode -;; This php-mode has various improvements than original it. -;; ;; Put this file into your load-path.and the following code into your ~/.emacs -;; (add-hook 'php-mode-hook -;; (lambda () -;; (require 'php-align) -;; (php-align-setup))) +;; +;; (add-hook 'php-mode-hook #'php-align-setup) ;;; TODO: ;; - Add test codes using el-expectations. From 62b7933d29b5926eafecba34e97bad8a62086dd8 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 20:39:35 +0900 Subject: [PATCH 22/23] Add link to emacs-php/php-mode project page --- php-align.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/php-align.el b/php-align.el index 68833f13..a4e8754d 100644 --- a/php-align.el +++ b/php-align.el @@ -1,11 +1,13 @@ ;;; php-align.el --- Alignment configuration for PHP -*- lexical-binding: t; -*- ;; Copyright (C) 2011 tetsujin (Yusuke Segawa) +;; Copyright (C) 2020 Friends of Emacs-PHP development ;; Author: tetsujin (Yusuke Segawa) +;; Maintainer: USAMI Kenta ;; Keywords: php languages convenience align -;; URL: https://github.com/tetsujin/emacs-php-align -;; Version: 0.0.1 +;; Homepage: https://github.com/emacs-php/php-mode +;; Version: 1.22.2 ;; Package-Requires: ((emacs "24.3")) ;; License: GPL-3.0-or-later From 8eccc3b203a34f53c323d37cd7c8e7258be25b5b Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Mar 2020 20:41:04 +0900 Subject: [PATCH 23/23] Modify setup php-align --- php-align/README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/php-align/README.md b/php-align/README.md index 214671a5..0e8000be 100644 --- a/php-align/README.md +++ b/php-align/README.md @@ -7,10 +7,7 @@ Support alignment (e.g. `align`, `align-current`) for PHP. Put this file into your load-path.and the following code into your ~/.emacs ```el -(add-hook 'php-mode-hook - (lambda () - (require 'php-align) - (php-align-setup))) +(add-hook 'php-mode-hook #'php-align-setup) ``` ## Examples