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.

102 lines
4.3 KiB

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