This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathweechat-core.el
101 lines (81 loc) · 3.38 KB
/
weechat-core.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; weechat-core --- Basic stuff for weechat.el ;; -*- lexical-binding: t -*-
;; Copyright (C) 2013 Moritz Ulrich
;; Author: Moritz Ulrich <[email protected]>
;; Rüdiger Sonderfeld <[email protected]>
;; Aristid Breitkreuz <[email protected]>
;; Keywords: irc chat network weechat
;; URL: https://github.com/the-kenny/weechat.el
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package provides a way to chat via WeeChat's relay protocol in
;; Emacs.
;; Please see README.org on how to use it.
;;; Code:
(require 'cl-lib)
(require 's)
(defgroup weechat nil
"WeeChat based IRC client for Emacs."
:link '(url-link "https://github.com/the-kenny/weechat.el")
:prefix "weechat-"
:group 'applications)
(defgroup weechat-relay nil
"WeeChat Relay Settings."
:link '(url-link "https://github.com/the-kenny/weechat.el")
:prefix "weechat-relay"
:group 'weechat)
(defcustom weechat-relay-log-buffer-name "*weechat-relay-log*"
"Buffer name to use as debug log.
Set to nil to disable logging."
:type 'string
:group 'weechat-relay)
(defcustom weechat-relay-log-level :info
"Minimum log level.
Might be one of :debug, :info, :warn, :error or nil."
:type '(choice (const :tag "Off" nil)
(const :tag "Error" :error)
(const :tag "Warnings" :warn)
(const :tag "Info" :info)
(const :tag "Debug" :debug))
:group 'weechat-relay)
(defun weechat-relay-log (text &optional level)
"Log `TEXT' to `weechat-relay-log-buffer-name' if enabled.
`LEVEL' might be one of :debug :info :warn :error. Defaults
to :info"
(let ((log-level-alist '((:debug . 0)
(:info . 1)
(:warn . 2)
(:error . 3))))
(when (and (>= (assoc-default (or level :info) log-level-alist)
(assoc-default weechat-relay-log-level log-level-alist))
weechat-relay-log-level
weechat-relay-log-buffer-name)
(with-current-buffer (get-buffer-create weechat-relay-log-buffer-name)
(let ((old-point (point)))
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(insert (s-trim text))
(newline)))
(goto-char old-point))))))
(defun weechat-warn (message &rest args)
"Display MESSAGE with `warn' and log it to `weechat-relay-log-buffer-name'."
(let ((str (apply 'format message args)))
(weechat-relay-log str :warn)
(display-warning 'weechat str)))
(defun weechat-message (format-string &rest args)
"Log MESSAGE with log-level :info and call `message'."
(let ((text (apply 'format format-string args)))
(weechat-relay-log text :info)
(message text)))
(provide 'weechat-core)
;;; weechat-core.el ends here