1 ;;; riece-misc.el --- miscellaneous functions (not inlined)
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (require 'riece-options)
28 (require 'riece-coding)
29 (require 'riece-identity)
30 (require 'riece-version)
31 (require 'riece-channel)
32 (require 'riece-server)
35 (defun riece-get-buffer-create (name)
36 (let ((buffer (get-buffer-create name)))
37 (unless (memq buffer riece-buffer-list)
38 (setq riece-buffer-list (cons buffer riece-buffer-list)))
41 (defun riece-scan-property-region (property start end function)
44 ;; Search for the beginning of the property region.
45 (unless (get-text-property start property)
46 (setq start (next-single-property-change start property nil end)))
49 ;; Search for the end of the property region.
50 (let ((region-end (next-single-property-change start property nil end)))
51 (if (= region-end end)
53 (funcall function start region-end)
54 (setq start region-end)))))
56 (defun riece-insert (buffers string)
57 (unless (listp buffers)
58 (setq buffers (list buffers)))
60 (run-hooks 'riece-before-insert-functions)
62 (set-buffer (riece-get-buffer-create (car buffers)))
63 (let ((inhibit-read-only t)
65 (start (goto-char (point-max))))
66 (insert (format-time-string "%H:%M") " " string)
67 (if (and (not (riece-frozen (current-buffer)))
68 (get-buffer-window (current-buffer)))
69 (set-window-point (get-buffer-window (current-buffer))
71 (run-hook-with-args 'riece-after-insert-functions start (point))))
72 (setq buffers (cdr buffers))))
74 (defun riece-insert-change (buffer message)
75 (riece-insert buffer (concat riece-change-prefix message)))
77 (defun riece-insert-notice (buffer message)
78 (riece-insert buffer (concat riece-notice-prefix message)))
80 (defun riece-insert-wallops (buffer message)
81 (riece-insert buffer (concat riece-wallops-prefix message)))
83 (defun riece-insert-error (buffer message)
84 (riece-insert buffer (concat riece-error-prefix message)))
86 (defun riece-insert-info (buffer message)
87 (riece-insert buffer (concat riece-info-prefix message)))
89 (defun riece-frozen (buffer)
90 (with-current-buffer buffer
93 (defun riece-own-frozen (buffer)
94 (with-current-buffer buffer
95 (eq riece-freeze 'own)))
97 (defun riece-channel-p (string)
98 "Return t if STRING is a channel.
99 \(i.e. it matches `riece-channel-regexp')"
100 (string-match (concat "^" riece-channel-regexp) string))
102 (defun riece-current-nickname ()
103 "Return the current nickname."
104 (riece-with-server-buffer (riece-identity-server riece-current-channel)
105 (if riece-real-nickname
106 (riece-make-identity riece-real-nickname riece-server-name))))
108 (defun riece-split-parameters (string)
109 (if (eq ?: (aref string 0))
110 (list (substring string 1))
113 (while (string-match "^\\([^ ]+\\) +" string)
114 (setq parameters (nconc parameters (list (match-string 1 string)))
115 string (substring string (match-end 0)))
116 (and (not (equal "" string)) (eq ?: (aref string 0))
117 (setq string (substring string 1))
119 (or (equal "" string)
120 (setq parameters (nconc parameters (list string))))
123 (defun riece-concat-channel-topic (target string)
124 (riece-with-server-buffer (riece-identity-server target)
125 (let ((topic (riece-channel-get-topic (riece-identity-prefix target))))
129 (concat string ": " topic)))))
131 (defun riece-concat-channel-modes (target string)
132 (riece-with-server-buffer (riece-identity-server target)
133 (let ((modes (riece-channel-get-modes (riece-identity-prefix target))))
135 (concat string " [" (apply #'string modes) "]")
138 (defun riece-concat-message (string message)
139 (if (or (null message)
142 (concat string " (" message ")")))
144 (defun riece-concat-server-name (string)
145 (if (equal riece-server-name "")
147 (concat string " (from " riece-server-name ")")))
149 (defun riece-prefix-user-at-host (prefix)
150 (if (string-match "!" prefix)
151 (substring prefix (match-end 0))
154 (defun riece-prefix-nickname (prefix)
155 (if (string-match "!" prefix)
156 (substring prefix 0 (match-beginning 0))
159 (defun riece-parse-user-at-host (user-at-host)
160 (if (memq (aref user-at-host 0) '(?^ ?= ?~ ?- ?+))
162 (if (memq (aref user-at-host 0) '(?^ ?=))
163 (setq riece-user-at-host-type 'fake)
164 (if (memq (aref user-at-host 0) '(?~ ?-))
165 (setq riece-user-at-host-type 'not-verified)
166 (if (eq (aref user-at-host 0) ?+)
167 (setq riece-user-at-host-type 'ok))))
168 (substring user-at-host 1))
169 (setq riece-user-at-host-type 'ok)
172 (defun riece-strip-user-at-host (user-at-host)
173 (if (memq (aref user-at-host 0) '(?^ ?= ?~ ?- ?+))
174 (substring user-at-host 1)
177 (defun riece-get-users-on-server ()
178 (riece-with-server-buffer (riece-identity-server riece-current-channel)
182 (unless (riece-channel-p (symbol-name atom))
183 (setq users (cons (symbol-name atom) users))))
185 (if (member riece-real-nickname users)
187 (cons riece-real-nickname users)))))
189 (provide 'riece-misc)
191 ;;; riece-misc.el ends here