diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-04 17:32:08 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-04 17:32:08 -0600 |
| commit | 541c61a403e01922a7569f5e23c25eba08fce427 (patch) | |
| tree | 4e923a8d58026658bb37d2eecf6855922a531cfe /wttrin-debug.el | |
| parent | 18b89fbdf3b5b13ccfd0d3a09f6bb2925addbab2 (diff) | |
refactor:debug: Rename and enhance wttrin debug functions
- Reorganized debugging utilities by renaming `debug-wttrin.el` to
`wttrin-debug.el` and adding new functions.
- The updated module now supports `debug-wttrin-mode-line` for
detailed mode-line diagnostics and introduces customizable mode-line
weather display with new configuration options.
- Additionally, extended debugging capabilities ensure concise
emoji-based weather info and tooltip data management, incorporated with auto-loaded conditional debug logic.
Diffstat (limited to 'wttrin-debug.el')
| -rw-r--r-- | wttrin-debug.el | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/wttrin-debug.el b/wttrin-debug.el new file mode 100644 index 0000000..55546d4 --- /dev/null +++ b/wttrin-debug.el @@ -0,0 +1,107 @@ +;;; wttrin-debug.el --- Debug functions for wttrin.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings +;; Author: Craig Jennings <c@cjennings.net> +;; Keywords: debug weather wttrin + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: + +;; This file contains debug functions for troubleshooting wttrin.el behavior. +;; It is only loaded when `wttrin-debug' is non-nil. +;; +;; Enable with: +;; (setq wttrin-debug t) +;; (require 'wttrin) +;; +;; Available debug functions: +;; - `debug-wttrin-show-raw' - View raw weather data with line numbers +;; - `debug-wttrin-mode-line' - Diagnose mode-line lighter issues +;; - `wttrin--debug-mode-line-info' - Auto-called when wttrin runs (if debug enabled) +;; +;; Interactive commands: +;; - M-x debug-wttrin-enable - Enable debug mode +;; - M-x debug-wttrin-disable - Disable debug mode +;; +;; When debug mode is enabled, raw weather data is automatically saved to +;; timestamped files in `temporary-file-directory' for bug reports. + +;;; Code: + +;; wttrin-debug.el is loaded by wttrin.el, so wttrin is already loaded +;; No need for (require 'wttrin) here + +;;;###autoload +(defun debug-wttrin-show-raw (location) + "Fetch and display raw wttr.in data for LOCATION with line numbers. +This is useful for debugging header parsing issues." + (interactive "sLocation: ") + (let ((raw-string (wttrin--get-cached-or-fetch location))) + (with-current-buffer (get-buffer-create "*wttrin-debug*") + (erase-buffer) + (insert raw-string) + (goto-char (point-min)) + (let ((line-num 1)) + (while (not (eobp)) + (beginning-of-line) + (insert (format "%2d: " line-num)) + (setq line-num (1+ line-num)) + (forward-line 1))) + (goto-char (point-min)) + (switch-to-buffer (current-buffer))))) + +;;;###autoload +(defun debug-wttrin-enable () + "Enable wttrin debug mode. +Raw weather data will be saved to timestamped files for bug reports." + (interactive) + (setq wttrin-debug t) + (message "Wttrin debug mode enabled. Raw data will be saved to: %s" temporary-file-directory)) + +;;;###autoload +(defun debug-wttrin-disable () + "Disable wttrin debug mode." + (interactive) + (setq wttrin-debug nil) + (message "Wttrin debug mode disabled")) + +;;;###autoload +(defun debug-wttrin-mode-line () + "Display detailed mode-line information for the wttrin buffer. +This is useful for diagnosing why the mode-line lighter isn't appearing." + (interactive) + (if-let ((buf (get-buffer "*wttr.in*"))) + (with-current-buffer buf + (let* ((has-custom-modeline (boundp 'cj/modeline-major-mode)) + (formatted-mode (when has-custom-modeline + (format-mode-line mode-name)))) + (with-output-to-temp-buffer "*wttrin-mode-debug*" + (princ (format "=== Wttrin Mode-Line Debug Info ===\n\n")) + (princ (format "Buffer: %s\n" (buffer-name))) + (princ (format "Major mode: %s\n" major-mode)) + (princ (format "mode-name variable: %S\n" mode-name)) + (princ (format "mode-name type: %s\n" (type-of mode-name))) + (princ (format "\nCustom modeline detected: %s\n" has-custom-modeline)) + (when has-custom-modeline + (princ (format "format-mode-line result: %S\n" formatted-mode))) + (princ (format "\nmode-line-format first 5 elements:\n")) + (let ((i 0)) + (dolist (elem mode-line-format) + (when (< i 5) + (princ (format " [%d] %S\n" i elem)) + (setq i (1+ i))))) + (princ (format "\nSpecial-mode parent: %s\n" + (get 'wttrin-mode 'derived-mode-parent))) + (princ (format "Is special-mode active: %s\n" + (derived-mode-p 'special-mode)))))) + (message "No *wttr.in* buffer exists. Run M-x wttrin first."))) + +(defun wttrin--debug-mode-line-info () + "Auto-generate mode-line diagnostic information. +This function is called automatically when wttrin runs if debug mode is enabled. +It creates the *wttrin-mode-debug* buffer with diagnostic information." + (debug-wttrin-mode-line)) + +(provide 'wttrin-debug) +;;; wttrin-debug.el ends here |
