Skip to content

Commit fa4a54f

Browse files
authored
Merge pull request #512 from emacs-php/split/php-mode-util
Split php.el and php-mode-debug.el
2 parents 1e16e20 + 699a900 commit fa4a54f

File tree

6 files changed

+294
-219
lines changed

6 files changed

+294
-219
lines changed

Cask

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(package "php-mode" "1.21.2" "Major mode for editing PHP code")
22
(source melpa)
33

4+
(package-file "php.el")
45
(package-file "php-mode.el")
56
(package-file "php-project.el")
7+
(package-file "php-mode-debug.el")
68

79
(development
810
(depends-on "pkg-info")

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
EMACS ?= emacs
2-
ELS = php-project.el php-mode.el php-mode-test.el
2+
ELS = php.el php-project.el php-mode.el php-mode-debug.el php-mode-test.el
33
AUTOLOADS = php-project-autoloads.el php-mode-autoloads.el
44
ELCS = $(ELS:.el=.elc)
55

@@ -10,7 +10,7 @@ all: autoloads $(ELCS)
1010

1111
autoloads: $(AUTOLOADS)
1212

13-
$(AUTOLOADS): php-project.el php-mode.el
13+
$(AUTOLOADS): php.el php-project.el php-mode-debug.el php-mode.el
1414
$(EMACS) -Q -batch -L . --eval \
1515
"(progn \
1616
(require 'package) \
@@ -24,7 +24,7 @@ clean:
2424
dev:
2525
cp etc/git/prepare-commit-msg .git/hooks/prepare-commit-msg
2626
chmod u+x .git/hooks/prepare-commit-msg
27-
27+
2828
# Runs all unit tests from php-mode-test.el and shows the results. The
2929
# script will exit with the status code zero if all tests pass. If any
3030
# test fails the script exits with a non-zero status and shows

php-mode-debug.el

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
;;; php-mode-debug.el --- Debug functions for PHP Mode -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2018-2019 Friends of Emacs-PHP development
4+
5+
;; Author: USAMI Kenta <tadsan@zonu.me>
6+
;; URL: https://github.com/emacs-php/php-mode
7+
;; Keywords: maint
8+
;; Version: 1.21.2
9+
;; Package-Requires: ((emacs "24.3") (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+
;; Provides functions to debugging php-mode work.
28+
29+
;;; Code:
30+
(require 'cc-mode)
31+
(require 'cus-edit)
32+
(require 'php-mode)
33+
(require 'package)
34+
(require 'pkg-info nil t)
35+
36+
(declare-function pkg-info-version-info "pkg-info" (library &optional package show))
37+
38+
(defun php-mode-debug--buffer (&optional command &rest args)
39+
"Return buffer for php-mode-debug, and execute `COMMAND' with `ARGS'."
40+
(with-current-buffer (get-buffer-create "*PHP Mode DEBUG*")
41+
(cl-case command
42+
(init (erase-buffer)
43+
(goto-address-mode))
44+
(top (goto-char (point-min)))
45+
(insert (goto-char (point-max))
46+
(apply #'insert args)))
47+
(current-buffer)))
48+
49+
(defun php-mode-debug--message (format-string &rest args)
50+
"Write message `FORMAT-STRING' and `ARGS' to debug buffer, like `message'."
51+
(declare (indent 1))
52+
(php-mode-debug--buffer 'insert (apply #'format format-string args) "\n"))
53+
54+
(defun php-mode-debug ()
55+
"Display informations useful for debugging PHP Mode."
56+
(interactive)
57+
(php-mode-debug--buffer 'init)
58+
(php-mode-debug--message "Feel free to report on GitHub what you noticed!")
59+
(php-mode-debug--message "https://github.com/emacs-php/php-mode/issues/new")
60+
(php-mode-debug--message "")
61+
(php-mode-debug--message "Pasting the following information on the issue will help us to investigate the cause.")
62+
(php-mode-debug--message "```")
63+
(php-mode-debug--message "--- PHP-MODE DEBUG BEGIN ---")
64+
(php-mode-debug--message "versions: %s; %s" (emacs-version) (php-mode-version))
65+
(php-mode-debug--message "package-version: %s"
66+
(if (fboundp 'pkg-info)
67+
(pkg-info-version-info 'php-mode)
68+
(let ((pkg (and (boundp 'package-alist)
69+
(cadr (assq 'php-mode package-alist)))))
70+
(when (and pkg (member (package-desc-status pkg) '("unsigned" "dependency")))
71+
(package-version-join (package-desc-version pkg))))))
72+
73+
(php-mode-debug--message "major-mode: %s" major-mode)
74+
(php-mode-debug--message "minor-modes: %s"
75+
(cl-loop for s in minor-mode-list
76+
unless (string-match-p "global" (symbol-name s))
77+
if (and (boundp s) (symbol-value s))
78+
collect s))
79+
(php-mode-debug--message "variables: %s"
80+
(cl-loop for v in '(indent-tabs-mode tab-width)
81+
collect (list v (symbol-value v))))
82+
(php-mode-debug--message "custom variables: %s"
83+
(cl-loop for (v type) in (custom-group-members 'php nil)
84+
if (eq type 'custom-variable)
85+
collect (list v (symbol-value v))))
86+
(php-mode-debug--message "c-indentation-style: %s" c-indentation-style)
87+
(php-mode-debug--message "c-style-variables: %s"
88+
(cl-loop for v in c-style-variables
89+
unless (memq v '(c-doc-comment-style c-offsets-alist))
90+
collect (list v (symbol-value v))))
91+
(php-mode-debug--message "c-doc-comment-style: %s" c-doc-comment-style)
92+
(php-mode-debug--message "c-offsets-alist: %s" c-offsets-alist)
93+
(php-mode-debug--message "--- PHP-MODE DEBUG END ---")
94+
(php-mode-debug--message "```\n")
95+
(php-mode-debug--message "Thank you!")
96+
(pop-to-buffer (php-mode-debug--buffer 'top)))
97+
98+
(provide 'php-mode-debug)
99+
;;; php-mode-debug.el ends here

php-mode-test.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
;; with Emacs >= 24.1.
3131

3232
;;; Code:
33-
33+
(require 'php)
3434
(require 'php-mode)
35+
(require 'php-mode-debug)
3536
(require 'php-project)
3637
(require 'ert)
3738
(require 'cl-lib)

0 commit comments

Comments
 (0)