|
| 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 |
0 commit comments