aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMiles Bader2006-02-11 21:42:23 +0000
committerMiles Bader2006-02-11 21:42:23 +0000
commit324e4da7fb68dc8b8e12d6b816dd6b6a4a892d36 (patch)
tree318d7b660f4e7d2c587b33e436fbe1ab70f39285 /lisp
parent0ccc88374941651c5358bb91411a1a18b868783f (diff)
downloademacs-324e4da7fb68dc8b8e12d6b816dd6b6a4a892d36.tar.gz
emacs-324e4da7fb68dc8b8e12d6b816dd6b6a4a892d36.zip
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-69
rcirc: Add flexible response formatting; Add nick abbrevs 2006-02-12 Miles Bader <miles@gnu.org> * lisp/net/rcirc.el (rcirc-nick-abbrevs, rcirc-response-formats): New variables. (rcirc-abbrev-nick): New function. (rcirc-format-response-string): Rewrite to use the formats in `rcirc-response-formats' and expand escape sequences therein. A text-property `rcirc-text' is added over the actual response text to make easy to find inside the returned string. (rcirc-print): When filling, just look for the `rcirc-text' text-property to find the appropriate fill prefix, instead of using hardwired patterns.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/net/rcirc.el214
2 files changed, 154 insertions, 73 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4b8d09e7534..ddd50210928 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12006-02-12 Miles Bader <miles@gnu.org>
2
3 * net/rcirc.el (rcirc-nick-abbrevs, rcirc-response-formats):
4 New variables.
5 (rcirc-abbrev-nick): New function.
6 (rcirc-format-response-string): Rewrite to use the formats in
7 `rcirc-response-formats' and expand escape sequences therein.
8 A text-property `rcirc-text' is added over the actual response
9 text to make easy to find inside the returned string.
10 (rcirc-print): When filling, just look for the `rcirc-text'
11 text-property to find the appropriate fill prefix, instead of
12 using hardwired patterns.
13
12006-02-11 Mathias Dahl <brakjoller@hotmail.com> 142006-02-11 Mathias Dahl <brakjoller@hotmail.com>
2 15
3 * tumme.el: Enhanced some docstrings. Added todo item about 16 * tumme.el: Enhanced some docstrings. Added todo item about
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 29beea21a89..c0bf8be3cf8 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -195,6 +195,12 @@ Use /ignore to list them, use /ignore NICK to add or remove a nick."
195 :type '(repeat string) 195 :type '(repeat string)
196 :group 'rcirc) 196 :group 'rcirc)
197 197
198(defcustom rcirc-nick-abbrevs nil
199 "List of short replacements for printing nicks."
200 :type '(alist :key-type (string :tag "Nick")
201 :value-type (string :tag "Abbrev"))
202 :group 'rcirc)
203
198(defvar rcirc-ignore-list-automatic () 204(defvar rcirc-ignore-list-automatic ()
199 "List of ignored nicks added to `rcirc-ignore-list' because of renaming. 205 "List of ignored nicks added to `rcirc-ignore-list' because of renaming.
200When an ignored person renames, their nick is added to both lists. 206When an ignored person renames, their nick is added to both lists.
@@ -480,6 +486,11 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
480 (with-rcirc-process-buffer process 486 (with-rcirc-process-buffer process
481 rcirc-nick)) 487 rcirc-nick))
482 488
489(defun rcirc-abbrev-nick (nick)
490 "If NICK has an entry in `rcirc-nick-abbrevs', return its abbreviation,
491otherwise return NICK."
492 (or (cdr (assoc nick rcirc-nick-abbrevs)) nick))
493
483(defvar rcirc-max-message-length 450 494(defvar rcirc-max-message-length 450
484 "Messages longer than this value will be split.") 495 "Messages longer than this value will be split.")
485 496
@@ -895,48 +906,112 @@ Create the buffer if it doesn't exist."
895 buffer 906 buffer
896 (process-buffer process)))) 907 (process-buffer process))))
897 908
909(defcustom rcirc-response-formats
910 '(("PRIVMSG" . "%T<%n> %m")
911 ("NOTICE" . "%T-%n- %m")
912 ("ACTION" . "%T[%n] %m")
913 ("COMMAND" . "%T%m")
914 ("ERROR" . "%T%fw!!! %m")
915 (t . "%T%fp*** %fs%n %r %m"))
916 "An alist of formats used for printing responses.
917The format is looked up using the response-type as a key;
918if no match is found, the default entry (with a key of `t') is used.
919
920The entry's value part should be a string, which is inserted with
921the of the following escape sequences replaced by the described values:
922
923 %m The message text
924 %n The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick')
925 %r The response-type
926 %T The timestamp (with face `rcirc-timestamp')
927 %t The target
928 %fw Following text uses the face `font-lock-warning-face'
929 %fp Following text uses the face `rcirc-server-prefix'
930 %fs Following text uses the face `rcirc-server'
931 %f[FACE] Following text uses the face FACE
932 %f- Following text uses the default face
933 %% A literal `%' character
934"
935 :type '(alist :key-type (choice (string :tag "Type")
936 (const :tag "Default" t))
937 :value-type string)
938 :group 'rcirc)
939
898(defun rcirc-format-response-string (process sender response target text) 940(defun rcirc-format-response-string (process sender response target text)
899 (concat (rcirc-facify (format-time-string rcirc-time-format (current-time)) 941 "Return a nicely-formatted response string, incorporating TEXT
900 'rcirc-timestamp) 942\(and perhaps other arguments). The specific formatting used
901 (cond ((or (string= response "PRIVMSG") 943is found by looking up RESPONSE in `rcirc-response-formats'."
902 (string= response "NOTICE") 944 (let ((chunks
903 (string= response "ACTION")) 945 (split-string (or (cdr (assoc response rcirc-response-formats))
904 (let (first middle end) 946 (cdr (assq t rcirc-response-formats)))
905 (cond ((string= response "PRIVMSG") 947 "%"))
906 (setq first "<" middle "> ")) 948 (result "")
907 ((string= response "NOTICE") 949 (face nil)
908 (when sender 950 key face-key repl)
909 (setq first "-" middle "- "))) 951 (when (equal (car chunks) "")
910 (t 952 (pop chunks))
911 (setq first "[" middle " " end "]"))) 953 (dolist (chunk chunks)
912 (concat first 954 (if (equal chunk "")
913 (rcirc-facify (concat 955 (setq key ?%)
914 sender 956 (setq key (aref chunk 0))
915 (when target (concat "," target))) 957 (setq chunk (substring chunk 1)))
916 (if (string= sender 958 (setq repl
917 (rcirc-nick process)) 959 (cond ((eq key ?%)
918 'rcirc-my-nick 960 ;; %% -- literal % character ;
919 'rcirc-other-nick)) 961 "%")
920 middle 962 ((eq key ?n)
921 (rcirc-mangle-text process text) 963 ;; %n -- nick ;
922 end))) 964 (rcirc-facify (concat (rcirc-abbrev-nick sender)
923 ((string= response "COMMAND") 965 (and target (concat "," target)))
924 text) 966 (if (string= sender (rcirc-nick process))
925 ((string= response "ERROR") 967 'rcirc-my-nick
926 (propertize (concat "!!! " text) 968 'rcirc-other-nick)))
927 'face 'font-lock-warning-face)) 969 ((eq key ?T)
928 (t 970 ;; %T -- timestamp ;
929 (rcirc-mangle-text 971 (rcirc-facify
930 process 972 (format-time-string rcirc-time-format (current-time))
931 (concat (rcirc-facify "*** " 'rcirc-server-prefix) 973 'rcirc-timestamp))
932 (rcirc-facify 974 ((eq key ?m)
933 (concat 975 ;; %m -- message text ;
934 (when (not (string= sender (rcirc-server process))) 976 ;; We add the text property `rcirc-text' to identify this ;
935 (concat sender " ")) 977 ;; as the body text. ;
936 (when (zerop (string-to-number response)) 978 (propertize
937 (concat response " ")) 979 (rcirc-mangle-text process (rcirc-facify text face))
938 text) 980 'rcirc-text text))
939 'rcirc-server))))))) 981 ((eq key ?t)
982 ;; %t -- target ;
983 (rcirc-facify (or rcirc-target "") face))
984 ((eq key ?r)
985 ;; %r -- response ;
986 (rcirc-facify response face))
987 ((eq key ?f)
988 ;; %f -- change face ;
989 (setq face-key (aref chunk 0))
990 (cond ((eq face-key ?w)
991 ;; %fw -- warning face ;
992 (setq face 'font-lock-warning-face))
993 ((eq face-key ?p)
994 ;; %fp -- server-prefix face ;
995 (setq face 'rcirc-server-prefix))
996 ((eq face-key ?s)
997 ;; %fs -- warning face ;
998 (setq face 'rcirc-server))
999 ((eq face-key ?-)
1000 ;; %fs -- warning face ;
1001 (setq face nil))
1002 ((and (eq face-key ?\[)
1003 (string-match "^[[]\\([^]]*\\)[]]" chunk)
1004 (facep (match-string 1 chunk)))
1005 ;; %f[...] -- named face ;
1006 (setq face (intern (match-string 1 chunk)))
1007 (setq chunk (substring chunk (match-end 1)))))
1008 (setq chunk (substring chunk 1))
1009 "")
1010 (t
1011 ;; just insert the key literally ;
1012 (rcirc-facify (substring chunk 0 1) face))))
1013 (setq result (concat result repl (rcirc-facify chunk face))))
1014 result))
940 1015
941(defun rcirc-target-buffer (process sender response target text) 1016(defun rcirc-target-buffer (process sender response target text)
942 "Return a buffer to print the server response." 1017 "Return a buffer to print the server response."
@@ -988,38 +1063,31 @@ record activity."
988 (goto-char rcirc-prompt-start-marker) 1063 (goto-char rcirc-prompt-start-marker)
989 (set-marker-insertion-type rcirc-prompt-start-marker t) 1064 (set-marker-insertion-type rcirc-prompt-start-marker t)
990 (set-marker-insertion-type rcirc-prompt-end-marker t) 1065 (set-marker-insertion-type rcirc-prompt-end-marker t)
991 (insert 1066
992 (rcirc-format-response-string process sender response nil text) 1067 (let ((fmted-text
993 (propertize "\n" 'hard t)) 1068 (rcirc-format-response-string process sender response nil
994 (set-marker-insertion-type rcirc-prompt-start-marker nil) 1069 text)))
995 (set-marker-insertion-type rcirc-prompt-end-marker nil) 1070
996 1071 (insert fmted-text (propertize "\n" 'hard t))
997 ;; fill the text we just inserted, maybe 1072 (set-marker-insertion-type rcirc-prompt-start-marker nil)
998 (when (and rcirc-fill-flag 1073 (set-marker-insertion-type rcirc-prompt-end-marker nil)
999 (not (string= response "372"))) ;/motd 1074
1000 (let ((fill-prefix 1075 ;; fill the text we just inserted, maybe
1001 (or rcirc-fill-prefix 1076 (when (and rcirc-fill-flag
1002 (make-string 1077 (not (string= response "372"))) ;/motd
1003 (+ (if rcirc-time-format 1078 (let ((fill-prefix
1004 (length (format-time-string 1079 (or rcirc-fill-prefix
1005 rcirc-time-format)) 1080 (make-string
1006 0) 1081 (or (next-single-property-change 0 'rcirc-text
1007 (cond ((or (string= response "PRIVMSG") 1082 fmted-text)
1008 (string= response "NOTICE")) 1083 8)
1009 (+ (length sender) 1084 ?\s)))
1010 2)) ; <> 1085 (fill-column (cond ((eq rcirc-fill-column 'frame-width)
1011 ((string= response "ACTION") 1086 (1- (frame-width)))
1012 (+ (length sender) 1087 (rcirc-fill-column
1013 1)) ; [ 1088 rcirc-fill-column)
1014 (t 3)) ; *** 1089 (t fill-column))))
1015 1) 1090 (fill-region fill-start rcirc-prompt-start-marker 'left t))))
1016 ?\s)))
1017 (fill-column (cond ((eq rcirc-fill-column 'frame-width)
1018 (1- (frame-width)))
1019 (rcirc-fill-column
1020 rcirc-fill-column)
1021 (t fill-column))))
1022 (fill-region fill-start rcirc-prompt-start-marker 'left t)))
1023 1091
1024 ;; set inserted text to be read-only 1092 ;; set inserted text to be read-only
1025 (when rcirc-read-only-flag 1093 (when rcirc-read-only-flag