|
| 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