Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.3 KiB

5 years ago
  1. ;;; php-mode-debug.el --- Debug functions for PHP Mode -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2020 Friends of Emacs-PHP development
  3. ;; Author: USAMI Kenta <tadsan@zonu.me>
  4. ;; URL: https://github.com/emacs-php/php-mode
  5. ;; Keywords: maint
  6. ;; Version: 1.24.0
  7. ;; License: GPL-3.0-or-later
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; Provides functions to debugging php-mode work.
  20. ;;; Code:
  21. (require 'cc-mode)
  22. (require 'cus-edit)
  23. (require 'php-mode)
  24. (require 'package)
  25. (require 'pkg-info nil t)
  26. (declare-function pkg-info-version-info "pkg-info" (library &optional package show))
  27. (defun php-mode-debug--buffer (&optional command &rest args)
  28. "Return buffer for php-mode-debug, and execute `COMMAND' with `ARGS'."
  29. (with-current-buffer (get-buffer-create "*PHP Mode DEBUG*")
  30. (cl-case command
  31. (init (erase-buffer)
  32. (goto-address-mode))
  33. (top (goto-char (point-min)))
  34. (insert (goto-char (point-max))
  35. (apply #'insert args)))
  36. (current-buffer)))
  37. (defun php-mode-debug--message (format-string &rest args)
  38. "Write message `FORMAT-STRING' and `ARGS' to debug buffer, like `message'."
  39. (declare (indent 1))
  40. (php-mode-debug--buffer 'insert (apply #'format format-string args) "\n"))
  41. (defun php-mode-debug ()
  42. "Display informations useful for debugging PHP Mode."
  43. (interactive)
  44. (unless (eq major-mode 'php-mode)
  45. (user-error "Invoke this command only in php-mode buffer"))
  46. (php-mode-debug--buffer 'init)
  47. (php-mode-debug--message "Feel free to report on GitHub what you noticed!")
  48. (php-mode-debug--message "https://github.com/emacs-php/php-mode/issues/new")
  49. (php-mode-debug--message "")
  50. (php-mode-debug--message "Pasting the following information on the issue will help us to investigate the cause.")
  51. (php-mode-debug--message "```")
  52. (php-mode-debug--message "--- PHP-MODE DEBUG BEGIN ---")
  53. (php-mode-debug--message "versions: %s; %s; Cc Mode %s)" (emacs-version) (php-mode-version) c-version)
  54. (php-mode-debug--message "package-version: %s"
  55. (if (fboundp 'pkg-info)
  56. (pkg-info-version-info 'php-mode)
  57. (let ((pkg (and (boundp 'package-alist)
  58. (cadr (assq 'php-mode package-alist)))))
  59. (when (and pkg (member (package-desc-status pkg) '("unsigned" "dependency")))
  60. (package-version-join (package-desc-version pkg))))))
  61. (php-mode-debug--message "major-mode: %s" major-mode)
  62. (php-mode-debug--message "minor-modes: %s"
  63. (cl-loop for s in minor-mode-list
  64. unless (string-match-p "global" (symbol-name s))
  65. if (and (boundp s) (symbol-value s))
  66. collect s))
  67. (php-mode-debug--message "variables: %s"
  68. (cl-loop for v in '(indent-tabs-mode tab-width)
  69. collect (list v (symbol-value v))))
  70. (php-mode-debug--message "custom variables: %s"
  71. (cl-loop for (v type) in (custom-group-members 'php nil)
  72. if (eq type 'custom-variable)
  73. collect (list v (symbol-value v))))
  74. (php-mode-debug--message "c-indentation-style: %s" c-indentation-style)
  75. (php-mode-debug--message "c-style-variables: %s"
  76. (cl-loop for v in c-style-variables
  77. unless (memq v '(c-doc-comment-style c-offsets-alist))
  78. collect (list v (symbol-value v))))
  79. (php-mode-debug--message "c-doc-comment-style: %s" c-doc-comment-style)
  80. (php-mode-debug--message "c-offsets-alist: %s" c-offsets-alist)
  81. (php-mode-debug--message "buffer: %s" (list :length (save-excursion (goto-char (point-max)) (point))))
  82. (php-mode-debug--message "--- PHP-MODE DEBUG END ---")
  83. (php-mode-debug--message "```\n")
  84. (php-mode-debug--message "Thank you!")
  85. (pop-to-buffer (php-mode-debug--buffer 'top)))
  86. (provide 'php-mode-debug)
  87. ;;; php-mode-debug.el ends here