Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ GNU Emacs 24以降では、[package][]機能を使って[MELPA][]からPHPモー

報告の際には `php-mode-version` コマンドを実行して、その出力をバグレポートに含めてください。問題を再現するための手がかりになります。

Settings
--------

### 個人設定

.emacsファイル(`~/.emacs.d/init.el`)にPHPモードでの設定を記述できます。

```lisp
(defun my-php-mode-init ()
(setq-local show-trailing-whitespace t)
(setq-local ac-disable-faces '(font-lock-comment-face font-lock-string-face))
(setq-local page-delimiter "\\_<\\(class\\|function\\|namespace\\)\\_>.+$")

;; If you feel phumped and phpcs annoying, invalidate them.
(when (boundp 'flycheck-disabled-checkers)
(add-to-list 'flycheck-disabled-checkers 'php-phpmd)
(add-to-list 'flycheck-disabled-checkers 'php-phpcs)))

(add-hook 'php-mode-hook #'my-php-mode-init)
```

### プロジェクトローカル設定

プロジェクトのトップディレクトリに`.dir-locals.el`を記述すると、プロジェクト単位の設定を追加することができます。このファイルはユーザー自身のEmacsにインストールされたパッケージに依存するため、バージョン管理の対象に含めないことを推奨します。

```lisp
((nil
(php-project-root . git)
(php-project-coding-style . psr2)))
```

実験的および作業中の機能
-------------------------------------

Expand Down
12 changes: 6 additions & 6 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ style from Drupal."
;; the file written to has no significance, only the buffer
(let ((tmp-filename (concat (make-temp-name temporary-file-directory) ".php")))
(dolist (mode '(pear wordpress symfony2))
(php-mode-custom-coding-style-set 'php-mode-coding-style 'drupal)
(php-mode-custom-coding-style-set 'php-mode-coding-style mode)
(php-set-style "drupal")
(php-set-style (symbol-name mode))
(should-not show-trailing-whitespace)
(php-mode-custom-coding-style-set 'php-mode-coding-style 'psr2)
(php-mode-custom-coding-style-set 'php-mode-coding-style mode)
(php-set-style "psr2")
(php-set-style (symbol-name mode))
(should-not show-trailing-whitespace)

(php-mode-custom-coding-style-set 'php-mode-coding-style 'drupal)
(php-set-style "drupal")
(write-file tmp-filename)
(should (looking-at-p "$"))))))

Expand Down Expand Up @@ -871,7 +871,7 @@ style from Drupal."
(ert-deftest php-mode-test-issue-200 ()
"Test highlighting and elimination of extraneous whitespace in PSR-2 mode"
(with-php-mode-test ("issue-200.php")
(php-mode-custom-coding-style-set 'php-mode-coding-style 'psr2)
(php-set-style "psr2")
(should show-trailing-whitespace)
(should (and (listp before-save-hook) (member 'delete-trailing-whitespace before-save-hook)))))

Expand Down
28 changes: 21 additions & 7 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

(require 'cl-lib)
(require 'mode-local)
(require 'php-project)

(eval-when-compile
(require 'regexp-opt)
Expand Down Expand Up @@ -374,14 +375,15 @@ This variable can take one of the following symbol values:
(const :tag "WordPress" wordpress)
(const :tag "Symfony2" symfony2)
(const :tag "PSR-2" psr2))
:set 'php-mode-custom-coding-style-set
:initialize 'custom-initialize-default)

(defun php-mode-custom-coding-style-set (sym value)
(when (eq major-mode 'php-mode)
(set sym value)
(set-default sym value)
(php-set-style (symbol-name value))))

(defcustom php-mode-enable-project-coding-style t
"When set to true override php-mode-coding-style by php-project-coding-style.

If you want to suppress styles from being overwritten by directory / file
local variables, set NIL."
:type 'boolean)

(defun php-mode-version ()
"Display string describing the version of PHP Mode."
Expand Down Expand Up @@ -1124,6 +1126,13 @@ After setting the stylevars run hooks according to STYLENAME

(put 'php-set-style 'interactive-form (interactive-form 'c-set-style))

(defun php-mode-set-style-delay ()
"Set the current `php-mode' buffer to use the style by custom or local variables."
(let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style)
php-mode-coding-style)))
(prog1 (php-set-style (symbol-name coding-style))
(remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))

(defun php-mode-debug ()
"Display informations useful for debugging PHP Mode."
(interactive)
Expand Down Expand Up @@ -1179,7 +1188,12 @@ After setting the stylevars run hooks according to STYLENAME
;; PHP vars are case-sensitive
(setq case-fold-search t)

(php-set-style (symbol-name php-mode-coding-style))
;; When php-mode-enable-project-coding-style is set, it is delayed by hook.
;; Since it depends on the timing at which the file local variable is set.
;; File local variables are set after initialization of major mode except `run-hook' is complete.
(if php-mode-enable-project-coding-style
(add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t)
(php-set-style (symbol-name php-mode-coding-style)))

(when (or php-mode-force-pear
(and (stringp buffer-file-name)
Expand Down
16 changes: 16 additions & 0 deletions php-project.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
;; Return root directory of current buffer file. The root directory is
;; determined by several marker file or directory.
;;
;; ## `.dir-locals.el' support
;;
;; - `php-project-coding-style'
;; - Symbol value of the coding style. (ex. `pear', `psr2')
;;
;;

;;; Code:
(require 'cl-lib)
Expand Down Expand Up @@ -64,6 +70,16 @@ SYMBOL
(make-variable-buffer-local 'php-project-root)
(put 'php-project-root 'safe-local-variable
#'(lambda (v) (assq v php-project-available-root-files))))

;;;###autoload
(progn
(defvar php-project-coding-style nil
"Symbol value of the coding style of the project that PHP major mode refers to.

Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
(make-variable-buffer-local 'php-project-coding-style)
(put 'php-project-coding-style 'safe-local-variable #'symbolp))


;; Functions

Expand Down