Skip to content

Commit 1761ede

Browse files
committed
- Conform to other languages definition.
- Fix README
1 parent b01f150 commit 1761ede

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

Diff for: README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# About #
2+
CAUTION!! this is still experimental.
23

34
Support alignment (e.g. align, align-current) for PHP.
4-
CAUTION!! this is still experimental.
55

66
Put this file into your load-path.and the following code into your ~/.emacs
77

@@ -30,13 +30,15 @@ Put this file into your load-path.and the following code into your ~/.emacs
3030

3131
### before ###
3232

33+
"$foo = 1";
3334
$foo = "string"; // M-x arign-current
3435
$looooooooong = 1; //
3536

3637
$bar = 2; //
3738

3839
### after ###
3940

41+
"$foo = 1";
4042
$foo = "string"; // M-x arign-current
4143
$looooooooong = 1; //
4244

@@ -62,16 +64,16 @@ Put this file into your load-path.and the following code into your ~/.emacs
6264

6365
### before ###
6466
$vars = array(
65-
1, 2, 3, // one
66-
4, 5, 6, // two
67-
7, 8, 9,// three
68-
10, 11, 12, // M-x align-current
67+
1, 2, 3,
68+
4, 5, 6,
69+
7, 8, 9,
70+
10, 11, 12, // C-u M-x align-current
6971
);
7072

7173
### after ###
7274
$vars = array(
73-
1, 2, 3, // one
74-
4, 5, 6, // two
75-
7, 8, 9, // three
76-
10, 11, 12, // M-x align-current
75+
1, 2, 3,
76+
4, 5, 6,
77+
7, 8, 9,
78+
10, 11, 12, // C-u M-x align-current
7779
);

Diff for: php-align.el

+49-39
Original file line numberDiff line numberDiff line change
@@ -41,68 +41,78 @@
4141
;;; Code:
4242
(require 'php-mode)
4343
(require 'align)
44+
(require 'regexp-opt)
4445

4546
(defvar php-align-rules-list
4647
`((php-comma-delimiter
47-
(regexp . ",\\(\\s-*\\)[^\\(//\\) \t\n]")
48+
(regexp . ",\\(\\s-*\\)[^/ \t\n]")
4849
(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))))
5152
(php-assignment
5253
(regexp . ,(concat "[^=!^&*-+<>/.| \t\n]\\(\\s-*[=!^&%*-+<>/.|]*\\)=>?"
5354
"\\(\\s-*\\)\\([^= \t\n]\\|$\\)"))
5455
(group . (1 2))
5556
(modes . '(php-mode))
5657
(justify . t)
5758
(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+
))
6377

6478
(defvar php-align-region-separate
6579
(eval-when-compile
6680
(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+
"[ ;]"
97100
"\\)"
101+
"\\|"
102+
;; function or method call
103+
"\\(?:" "^\\s-*" "\\(?:" "\\w\\|[->\\: \t]" "\\)+" "(" "\\)"
98104
))
99105
"Regexp of a section of PHP for alignment.")
100106

101107
(defun php-align-setup ()
102108
"Setup alignment configuration for PHP code."
103109
(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))
105114

115+
;; Unused functions.
106116
(defsubst php-align-face-at-point-in-p (point face-list)
107117
"Return t if the face of the current POINT is an element of FACE-LIST.
108118
otherwise nil."

0 commit comments

Comments
 (0)