1 ;;; geiser-log.el -- logging utilities
3 ;; Copyright (C) 2009, 2010, 2012, 2019 Jose Antonio Ortega Ruiz
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the Modified BSD License. You should
7 ;; have received a copy of the license along with this program. If
8 ;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
10 ;; Start date: Sat Feb 07, 2009 12:07
14 ;; Some utilities for maintaining a simple log buffer, mainly for
15 ;; debugging purposes.
20 (require 'geiser-custom
)
21 (require 'geiser-popup
)
22 (require 'geiser-base
)
29 (geiser-custom--defcustom geiser-log-autoscroll-buffer-p nil
30 "Set this so than the buffer *geiser messages* always shows the last message"
34 (defvar geiser-log--buffer-name
"*geiser messages*"
35 "Name of the Geiser log buffer.")
37 (defvar geiser-log--max-buffer-size
32000
38 "Maximum size of the Geiser messages log.")
40 (defvar geiser-log--max-message-size
2048
41 "Maximum size of individual Geiser log messages.")
43 (defvar geiser-log-verbose-p nil
44 "Log purely informational messages. Useful for debugging.")
46 (defvar geiser-log-verbose-debug-p nil
47 "Log very verbose informational messages. Useful only for debugging.")
50 (defvar geiser-log--inhibit-p nil
51 "Set this to t to inhibit all log messages")
54 ;;; Log buffer and mode:
56 (defvar geiser-messages-mode-map
57 (let ((map (make-sparse-keymap)))
58 (define-key map
"c" 'geiser-log-clear
)
59 (define-key map
"Q" 'geiser-log--deactivate
)
62 (define-derived-mode geiser-messages-mode fundamental-mode
"Geiser Messages"
63 "Simple mode for Geiser log messages buffer."
65 (add-hook 'after-change-functions
67 (let ((inhibit-read-only t
))
68 (when (> b geiser-log--max-buffer-size
)
69 (delete-region (point-min) b
))))
71 ;; Maybe this feature would better be implemented as a revert-buffer function?
72 (add-hook 'after-change-functions
74 (when geiser-log-autoscroll-buffer-p
75 (let ((my-window (get-buffer-window (geiser-log--buffer) t
)))
76 (when (window-live-p my-window
)
77 (set-window-point my-window
(point))))))
79 (setq buffer-read-only t
))
81 (geiser-popup--define log geiser-log--buffer-name geiser-messages-mode
)
84 ;;; Logging functions:
86 (defun geiser-log--msg (type &rest args
)
87 (unless geiser-log--inhibit-p
88 (geiser-log--with-buffer
89 (goto-char (point-max))
90 (insert (geiser--shorten-str (format "\n%s: %s\n" type
92 geiser-log--max-message-size
)))))
94 (defsubst geiser-log--warn
(&rest args
)
95 (apply 'geiser-log--msg
'WARNING args
))
97 (defsubst geiser-log--error
(&rest args
)
98 (apply 'geiser-log--msg
'ERROR args
))
100 (defsubst geiser-log--info
(&rest args
)
101 (when geiser-log-verbose-p
102 (apply 'geiser-log--msg
'INFO args
) ""))
104 (defsubst geiser-log--debug
(&rest args
)
105 (when geiser-log-verbose-debug-p
106 (apply 'geiser-log--msg
'DEBUG args
) ""))
111 (defun geiser-show-logs (&optional arg
)
112 "Show Geiser log messages.
113 With prefix, activates all logging levels."
115 (when arg
(setq geiser-log-verbose-p t
))
116 (geiser-log--pop-to-buffer))
118 (defun geiser-log-clear ()
121 (geiser-log--with-buffer (delete-region (point-min) (point-max))))
123 (defun geiser-log-toggle-verbose ()
124 "Toggle verbose logs"
126 (setq geiser-log-verbose-p
(not geiser-log-verbose-p
))
127 (message "Geiser verbose logs %s"
128 (if geiser-log-verbose-p
"enabled" "disabled")))
130 (defun geiser-log--deactivate ()
132 (setq geiser-log-verbose-p nil
)
133 (when (eq (current-buffer) (geiser-log--buffer)) (View-quit)))
136 (provide 'geiser-log
)