Skip to content

Commit

Permalink
- Conform to other languages definition.
Browse files Browse the repository at this point in the history
- Fix README
  • Loading branch information
tetsujin committed Aug 13, 2011
1 parent b01f150 commit 1761ede
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -30,13 +30,15 @@ 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; //

$bar = 2; //

### after ###

"$foo = 1";
$foo = "string"; // M-x arign-current
$looooooooong = 1; //

Expand All @@ -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
);
88 changes: 49 additions & 39 deletions php-align.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,68 +41,78 @@
;;; 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]\\|$\\)"))
(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")
(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-*\\)\\(&&\\|||\\|\\<and\\>\\|\\<or\\>\\)")
(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."
Expand Down

0 comments on commit 1761ede

Please sign in to comment.