- (concat (rcirc-facify (format-time-string rcirc-time-format (current-time))
- 'rcirc-timestamp)
- (cond ((or (string= response "PRIVMSG")
- (string= response "NOTICE")
- (string= response "ACTION"))
- (let (first middle end)
- (cond ((string= response "PRIVMSG")
- (setq first "<" middle "> "))
- ((string= response "NOTICE")
- (when sender
- (setq first "-" middle "- ")))
- (t
- (setq first "[" middle " " end "]")))
- (concat first
- (rcirc-facify (rcirc-user-nick sender)
- (if (string= sender
- (rcirc-nick process))
- 'rcirc-my-nick
- 'rcirc-other-nick))
- middle
- (rcirc-mangle-text process text)
- end)))
- ((string= response "COMMAND")
- text)
- ((string= response "ERROR")
- (propertize (concat "!!! " text)
- 'face 'font-lock-warning-face))
- (t
- (rcirc-mangle-text
- process
- (concat (rcirc-facify "*** " 'rcirc-server-prefix)
- (rcirc-facify
- (concat
- (when (not (string= sender (rcirc-server process)))
- (concat (rcirc-user-nick sender) " "))
- (when (zerop (string-to-number response))
- (concat response " "))
- text)
- 'rcirc-server)))))))
+ "Return a nicely-formatted response string, incorporating TEXT
+\(and perhaps other arguments). The specific formatting used
+is found by looking up RESPONSE in `rcirc-response-formats'."
+ (let ((chunks
+ (split-string (or (cdr (assoc response rcirc-response-formats))
+ (cdr (assq t rcirc-response-formats)))
+ "%"))
+ (sender (or sender ""))
+ (result "")
+ (face nil)
+ key face-key repl)
+ (when (equal (car chunks) "")
+ (pop chunks))
+ (dolist (chunk chunks)
+ (if (equal chunk "")
+ (setq key ?%)
+ (setq key (aref chunk 0))
+ (setq chunk (substring chunk 1)))
+ (setq repl
+ (cond ((eq key ?%)
+ ;; %% -- literal % character
+ "%")
+ ((or (eq key ?n) (eq key ?N))
+ ;; %n/%N -- nick
+ (let ((nick (concat (if (string= (with-rcirc-process-buffer process
+ rcirc-server)
+ sender)
+ ""
+ sender)
+ (and target (concat "," target)))))
+ (rcirc-facify nick
+ (if (eq key ?n)
+ face
+ (cond ((string= sender (rcirc-nick process))
+ 'rcirc-my-nick)
+ ((and rcirc-bright-nick-regexp
+ (string-match rcirc-bright-nick-regexp sender))
+ 'rcirc-bright-nick)
+ ((and rcirc-dim-nick-regexp
+ (string-match rcirc-dim-nick-regexp sender))
+ 'rcirc-dim-nick)
+ (t
+ 'rcirc-other-nick))))))
+ ((eq key ?T)
+ ;; %T -- timestamp
+ (rcirc-facify
+ (format-time-string rcirc-time-format (current-time))
+ 'rcirc-timestamp))
+ ((eq key ?m)
+ ;; %m -- message text
+ ;; We add the text property `rcirc-text' to identify this
+ ;; as the body text.
+ (propertize
+ (rcirc-mangle-text process (rcirc-facify text face))
+ 'rcirc-text text))
+ ((eq key ?t)
+ ;; %t -- target
+ (rcirc-facify (or rcirc-target "") face))
+ ((eq key ?r)
+ ;; %r -- response
+ (rcirc-facify response face))
+ ((eq key ?f)
+ ;; %f -- change face
+ (setq face-key (aref chunk 0))
+ (setq chunk (substring chunk 1))
+ (cond ((eq face-key ?w)
+ ;; %fw -- warning face
+ (setq face 'font-lock-warning-face))
+ ((eq face-key ?p)
+ ;; %fp -- server-prefix face
+ (setq face 'rcirc-server-prefix))
+ ((eq face-key ?s)
+ ;; %fs -- warning face
+ (setq face 'rcirc-server))
+ ((eq face-key ?-)
+ ;; %fs -- warning face
+ (setq face nil))
+ ((and (eq face-key ?\[)
+ (string-match "^\\([^]]*\\)[]]" chunk)
+ (facep (match-string 1 chunk)))
+ ;; %f[...] -- named face
+ (setq face (intern (match-string 1 chunk)))
+ (setq chunk (substring chunk (match-end 0)))))
+ "")))
+ (setq result (concat result repl (rcirc-facify chunk face))))
+ result))
+
+(defun rcirc-target-buffer (process sender response target text)
+ "Return a buffer to print the server response."
+ (assert (not (bufferp target)))
+ (with-rcirc-process-buffer process
+ (cond ((not target)
+ (rcirc-any-buffer process))
+ ((not (rcirc-channel-p target))
+ ;; message from another user
+ (if (string= response "PRIVMSG")
+ (rcirc-get-buffer-create process (if (string= sender rcirc-nick)
+ target
+ sender))
+ (rcirc-get-buffer process target t)))
+ ((or (rcirc-get-buffer process target)
+ (rcirc-any-buffer process))))))