Skip to content

Commit 11abbfb

Browse files
authored
Merge pull request #427 from zonuexe/feature/php-project
New php-project.el
2 parents e96df88 + 6bedb4d commit 11abbfb

File tree

4 files changed

+97
-41
lines changed

4 files changed

+97
-41
lines changed

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
EMACS ?= emacs
2-
ELS = php-mode.el php-mode-test.el
2+
ELS = php-project.el php-mode.el php-mode-test.el
3+
AUTOLOADS = php-project-autoloads.el php-mode-autoloads.el
34
ELCS = $(ELS:.el=.elc)
45

56
%.elc: %.el
67
$(EMACS) -Q -batch -L . -f batch-byte-compile $<
78

89
all: autoloads $(ELCS)
910

10-
autoloads: php-mode-autoloads.el
11+
autoloads: $(AUTOLOADS)
1112

12-
php-mode-autoloads.el:
13+
$(AUTOLOADS): php-project.el php-mode.el
1314
$(EMACS) -Q -batch -L . --eval \
1415
"(progn \
15-
(require 'package) \
16-
(package-generate-autoloads \"php-mode\" default-directory))"
16+
(require 'package) \
17+
(package-generate-autoloads \"php-mode\" default-directory))"
1718

1819
clean:
19-
rm -f $(ELCS) php-mode-autoloads.el
20+
rm -f $(ELCS) $(AUTOLOADS)
2021

2122
# Runs all unit tests from php-mode-test.el and shows the results. The
2223
# script will exit with the status code zero if all tests pass. If any

php-mode-test.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
;;; Code:
3232

3333
(require 'php-mode)
34+
(require 'php-project)
3435
(require 'ert)
3536
(require 'cl-lib)
3637
(require 'imenu)
@@ -1075,6 +1076,10 @@ style from Drupal."
10751076
(search-forward variable)
10761077
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))))))
10771078

1079+
(ert-deftest php-project-root ()
1080+
(should (string= (abbreviate-file-name default-directory)
1081+
(php-project-get-root-dir))))
1082+
10781083
;;; php-mode-test.el ends here
10791084

10801085
;; Local Variables:

php-mode.el

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
(require 'etags)
8484
(require 'speedbar)
8585
(require 'imenu)
86+
(require 'php-project nil t)
8687

8788
(require 'cl-lib)
8889
(require 'mode-local)
@@ -388,30 +389,8 @@ This variable can take one of the following symbol values:
388389
(message "PHP Mode %s of %s"
389390
php-mode-version-number php-mode-modified))
390391

391-
(defvar php-available-project-root-files
392-
'((projectile ".projectile")
393-
(composer "composer.json" "composer.lock")
394-
(git ".git")
395-
(mercurial ".hg")
396-
(subversion ".svn")
397-
;; NOTICE: This method does not detect the top level of .editorconfig
398-
;; However, we can integrate it by adding the editorconfig.el's API.
399-
;;(editorconfig . ".editorconfig")
400-
))
401-
402392
;;;###autoload
403-
(progn
404-
(defvar php-project-root 'auto
405-
"Method of searching for the top level directory.
406-
407-
`auto' (default)
408-
Try to search file in order of `php-available-project-root-files'.
409-
410-
SYMBOL
411-
Key of `php-available-project-root-files'.")
412-
(make-variable-buffer-local 'php-project-root)
413-
(put 'php-project-root 'safe-local-variable
414-
#'(lambda (v) (assq v php-available-project-root-files))))
393+
(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0")
415394

416395
(defvar php-mode-map
417396
(let ((map (make-sparse-keymap)))
@@ -1743,18 +1722,6 @@ The output will appear in the buffer *PHP*."
17431722
(when (re-search-backward re-pattern nil t)
17441723
(match-string-no-properties 1))))
17451724

1746-
;;;###autoload
1747-
(defun php-project-get-root-dir ()
1748-
"Return path to current PHP project."
1749-
(let ((detect-method (if (stringp php-project-root)
1750-
(list php-project-root)
1751-
(if (eq php-project-root 'auto)
1752-
(cl-loop for m in php-available-project-root-files
1753-
append (cdr m))
1754-
(cdr-safe (assq php-project-root php-available-project-root-files))))))
1755-
(cl-loop for m in detect-method
1756-
thereis (locate-dominating-file default-directory m))))
1757-
17581725
;;;###autoload
17591726
(defun php-current-class ()
17601727
"Insert current class name if cursor in class context."

php-project.el

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
;;; php-project.el --- Project support for PHP application -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2018 Friends of Emacs-PHP development
4+
5+
;; Author: USAMI Kenta <tadsan@zonu.me>
6+
;; Keywords: tools, files
7+
;; URL: https://github.com/ejmr/php-mode
8+
;; Version: 1.18.4
9+
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
10+
;; License: GPL-3.0-or-later
11+
12+
;; This program is free software; you can redistribute it and/or modify
13+
;; it under the terms of the GNU General Public License as published by
14+
;; the Free Software Foundation, either version 3 of the License, or
15+
;; (at your option) any later version.
16+
17+
;; This program is distributed in the hope that it will be useful,
18+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
;; GNU General Public License for more details.
21+
22+
;; You should have received a copy of the GNU General Public License
23+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
25+
;;; Commentary:
26+
27+
;; Define project specific functions and variables for PHP application.
28+
;;
29+
;; ## API
30+
;;
31+
;; ### `php-project-get-root-dir()'
32+
;;
33+
;; Return root directory of current buffer file. The root directory is
34+
;; determined by several marker file or directory.
35+
;;
36+
37+
;;; Code:
38+
(require 'cl-lib)
39+
40+
;; Variables
41+
(defvar php-project-available-root-files
42+
'((projectile ".projectile")
43+
(composer "composer.json" "composer.lock")
44+
(git ".git")
45+
(mercurial ".hg")
46+
(subversion ".svn")
47+
;; NOTICE: This method does not detect the top level of .editorconfig
48+
;; However, we can integrate it by adding the editorconfig.el's API.
49+
;;(editorconfig . ".editorconfig")
50+
))
51+
52+
;; Buffer local variables
53+
54+
;;;###autoload
55+
(progn
56+
(defvar php-project-root 'auto
57+
"Method of searching for the top level directory.
58+
59+
`auto' (default)
60+
Try to search file in order of `php-project-available-root-files'.
61+
62+
SYMBOL
63+
Key of `php-project-available-root-files'.")
64+
(make-variable-buffer-local 'php-project-root)
65+
(put 'php-project-root 'safe-local-variable
66+
#'(lambda (v) (assq v php-project-available-root-files))))
67+
68+
;; Functions
69+
70+
;;;###autoload
71+
(defun php-project-get-root-dir ()
72+
"Return path to current PHP project."
73+
(let ((detect-method (if (stringp php-project-root)
74+
(list php-project-root)
75+
(if (eq php-project-root 'auto)
76+
(cl-loop for m in php-project-available-root-files
77+
append (cdr m))
78+
(cdr-safe (assq php-project-root php-project-available-root-files))))))
79+
(cl-loop for m in detect-method
80+
thereis (locate-dominating-file default-directory m))))
81+
82+
(provide 'php-project)
83+
;;; php-project.el ends here

0 commit comments

Comments
 (0)