|
41 | 41 | ;;; Code:
|
42 | 42 | (require 'php-mode)
|
43 | 43 | (require 'align)
|
| 44 | +(require 'regexp-opt) |
44 | 45 |
|
45 | 46 | (defvar php-align-rules-list
|
46 | 47 | `((php-comma-delimiter
|
47 |
| - (regexp . ",\\(\\s-*\\)[^\\(//\\) \t\n]") |
| 48 | + (regexp . ",\\(\\s-*\\)[^/ \t\n]") |
48 | 49 | (repeat . t)
|
49 |
| - (valid . (lambda() (not (php-align-point-is-string-p)))) |
50 |
| - (modes . '(php-mode))) |
| 50 | + (modes . '(php-mode)) |
| 51 | + (run-if . ,(function (lambda () current-prefix-arg)))) |
51 | 52 | (php-assignment
|
52 | 53 | (regexp . ,(concat "[^=!^&*-+<>/.| \t\n]\\(\\s-*[=!^&%*-+<>/.|]*\\)=>?"
|
53 | 54 | "\\(\\s-*\\)\\([^= \t\n]\\|$\\)"))
|
54 | 55 | (group . (1 2))
|
55 | 56 | (modes . '(php-mode))
|
56 | 57 | (justify . t)
|
57 | 58 | (tab-stop . nil))
|
58 |
| - (php-single-line-comment |
59 |
| - (regexp . "\\(\\s-*\\)//") |
60 |
| - (modes . '(php-mode))) |
61 |
| - ) |
62 |
| - "Definition of `align-rules-list' for PHP") |
| 59 | + (php-comment |
| 60 | + (regexp . "\\(\\s-*\\)\\(//.*\\|/\\*.*\\*/\\s-*\\)$") |
| 61 | + (modes . (php-mode)) |
| 62 | + (column . comment-column) |
| 63 | + (valid . ,(function |
| 64 | + (lambda () |
| 65 | + (save-excursion |
| 66 | + (goto-char (match-beginning 1)) |
| 67 | + (not (bolp))))))) |
| 68 | + (php-chain-logic |
| 69 | + (regexp . "\\(\\s-*\\)\\(&&\\|||\\|\\<and\\>\\|\\<or\\>\\)") |
| 70 | + (modes . (php-mode)) |
| 71 | + (valid . ,(function |
| 72 | + (lambda () |
| 73 | + (save-excursion |
| 74 | + (goto-char (match-end 2)) |
| 75 | + (looking-at "\\s-*\\(/[*/]\\|$\\)")))))) |
| 76 | + )) |
63 | 77 |
|
64 | 78 | (defvar php-align-region-separate
|
65 | 79 | (eval-when-compile
|
66 | 80 | (concat
|
67 |
| - "\\(" ; * blank line |
68 |
| - "^\\s-*$" |
69 |
| - "\\)\\|\\(" ; * comment start or end line |
70 |
| - "^\\s-*\\(/[/*]\\|\\*/\\)" |
71 |
| - "\\)\\|\\(" ; * end of line are '[', '(', '{', '}', '/*' |
72 |
| - "\\([[({}]\\|/\\*+\\)\\s-*$" |
73 |
| - "\\)\\|\\(" ; * beginning of line are ')', '}', ']' |
74 |
| - "^\\s-*[)}]][ \t,;]?\\s-*$" ; and trailing character are ',', ';' |
75 |
| - "\\)\\|\\(" ; * beginning of line are some PHP keywrods |
76 |
| - "^\\s-*" |
77 |
| - "\\(" |
78 |
| - "for\\|" |
79 |
| - "foreach\\|" |
80 |
| - "while\\|" |
81 |
| - "if\\|" |
82 |
| - "else\\|" |
83 |
| - "switch\\|" |
84 |
| - "case\\|" |
85 |
| - "break\\|" |
86 |
| - "continue\\|" |
87 |
| - "declare\\|" |
88 |
| - "do" |
89 |
| - "\\)" |
90 |
| - "[ ;]" |
91 |
| - "\\)\\|\\(" ; * function or method call |
92 |
| - "^\\s-*" |
93 |
| - "\\(" |
94 |
| - "\\w\\|[->\\: \t]" |
95 |
| - "\\)+" |
96 |
| - "(" |
| 81 | + ;; blank line |
| 82 | + "\\(?:" "^\\s-*$" "\\)" |
| 83 | + "\\|" |
| 84 | + ;; comment start or end line |
| 85 | + "\\(?:" "^\\s-*\\(?:/[/*]\\|\\*/\\)" "\\)" |
| 86 | + "\\|" |
| 87 | + ;; end of line are '[', '(', '{', '}', '/*' |
| 88 | + "\\(?:" "\\(?:[[({}]\\|/\\*+\\)\\s-*$" "\\)" |
| 89 | + "\\|" |
| 90 | + ;; beginning of line are ')', '}', ']' and trailing character are ',', ';' |
| 91 | + "\\(?:" "^\\s-*[)}]][ \t,;]?\\s-*$" "\\)" |
| 92 | + "\\|" |
| 93 | + ;; beginning of line are some PHP keywrods |
| 94 | + "\\(?:" |
| 95 | + "^\\s-*" |
| 96 | + (regexp-opt |
| 97 | + '("for" "foreach" "while" "if" "else" "switch" "case" "break" "continue" |
| 98 | + "try" "catch" "declare" "do" "return" "namespace" "use")) |
| 99 | + "[ ;]" |
97 | 100 | "\\)"
|
| 101 | + "\\|" |
| 102 | + ;; function or method call |
| 103 | + "\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)" |
98 | 104 | ))
|
99 | 105 | "Regexp of a section of PHP for alignment.")
|
100 | 106 |
|
101 | 107 | (defun php-align-setup ()
|
102 | 108 | "Setup alignment configuration for PHP code."
|
103 | 109 | (set (make-local-variable 'align-mode-rules-list) php-align-rules-list)
|
104 |
| - (set (make-local-variable 'align-region-separate) php-align-region-separate)) |
| 110 | + (set (make-local-variable 'align-region-separate) php-align-region-separate) |
| 111 | + (add-to-list 'align-open-comment-modes 'php-mode) |
| 112 | + (add-to-list 'align-dq-string-modes 'php-mode) |
| 113 | + (add-to-list 'align-sq-string-modes 'php-mode)) |
105 | 114 |
|
| 115 | +;; Unused functions. |
106 | 116 | (defsubst php-align-face-at-point-in-p (point face-list)
|
107 | 117 | "Return t if the face of the current POINT is an element of FACE-LIST.
|
108 | 118 | otherwise nil."
|
|
0 commit comments