comparison lisp/net/rcirc.el @ 68960:6e3160901812

(rcirc-connect): Make all arguments optional, and default to global variable values for unsupplied args. (rcirc-get-buffer-create): Fix bug with setting the target. (rcirc-any-buffer): Rename from rcirc-get-any-buffer, and include test for rcirc-always-use-server-buffer-flag here. (rcirc-response-formats): Add %N, which is a facified nick. %n uses the default face. Change the ACTION format string. If the "nick" is the server, don't print anything for that field. Comment fixes. (rcirc-target-buffer): Don't test rcirc-always-use-server-buffer-flag here. (rcirc-print): Squeeze extra spaces out of the text before message. (rcirc-put-nick-channel): Strip potential "@" char from nick before adding them to nick table. (rcirc-url-regexp): Improve to match address like "foo.com".
author Eli Zaretskii <eliz@gnu.org>
date Fri, 17 Feb 2006 11:19:00 +0000
parents 6a3bf61d8473
children 45e1ec6f858b d08a7ef0cb8a d1c5430c5bff
comparison
equal deleted inserted replaced
68959:ba7509deaeff 68960:6e3160901812
47 (eval-when-compile (require 'cl)) 47 (eval-when-compile (require 'cl))
48 48
49 (defgroup rcirc nil 49 (defgroup rcirc nil
50 "Simple IRC client." 50 "Simple IRC client."
51 :version "22.1" 51 :version "22.1"
52 :prefix "rcirc" 52 :prefix "rcirc-"
53 :group 'applications) 53 :group 'applications)
54 54
55 (defcustom rcirc-server "irc.freenode.net" 55 (defcustom rcirc-server "irc.freenode.net"
56 "The default server to connect to." 56 "The default server to connect to."
57 :type 'string 57 :type 'string
293 293
294 (defvar rcirc-process-output nil) 294 (defvar rcirc-process-output nil)
295 (defvar rcirc-topic nil) 295 (defvar rcirc-topic nil)
296 (defvar rcirc-keepalive-timer nil) 296 (defvar rcirc-keepalive-timer nil)
297 (defvar rcirc-last-server-message-time nil) 297 (defvar rcirc-last-server-message-time nil)
298 (defun rcirc-connect (server port nick user-name full-name startup-channels) 298 (defun rcirc-connect (&optional server port nick user-name full-name startup-channels)
299 (add-hook 'window-configuration-change-hook 299 (add-hook 'window-configuration-change-hook
300 'rcirc-window-configuration-change) 300 'rcirc-window-configuration-change)
301 301
302 (save-excursion 302 (save-excursion
303 (message "Connecting to %s..." server) 303 (message "Connecting to %s..." server)
304 (let* ((inhibit-eol-conversion) 304 (let* ((inhibit-eol-conversion)
305 (port-number (if (stringp port) 305 (port-number (if port
306 (string-to-number port) 306 (if (stringp port)
307 port)) 307 (string-to-number port)
308 port)
309 rcirc-port))
310 (server (or server rcirc-server))
311 (nick (or nick rcirc-nick))
312 (user-name (or user-name rcirc-user-name))
313 (full-name (or full-name rcirc-user-full-name))
314 (startup-channels (or startup-channels (rcirc-startup-channels server)))
308 (process (open-network-stream server nil server port-number))) 315 (process (open-network-stream server nil server port-number)))
309 ;; set up process 316 ;; set up process
310 (set-process-coding-system process 'raw-text 'raw-text) 317 (set-process-coding-system process 'raw-text 'raw-text)
311 (set-process-filter process 'rcirc-filter) 318 (set-process-filter process 'rcirc-filter)
312 (switch-to-buffer (rcirc-generate-new-buffer-name process nil)) 319 (switch-to-buffer (rcirc-generate-new-buffer-name process nil))
756 (defun rcirc-get-buffer-create (process target) 763 (defun rcirc-get-buffer-create (process target)
757 "Return the buffer associated with the PROCESS and TARGET. 764 "Return the buffer associated with the PROCESS and TARGET.
758 Create the buffer if it doesn't exist." 765 Create the buffer if it doesn't exist."
759 (let ((buffer (rcirc-get-buffer process target))) 766 (let ((buffer (rcirc-get-buffer process target)))
760 (if buffer 767 (if buffer
761 (progn 768 (with-current-buffer buffer
762 (when (not rcirc-target) 769 (when (not rcirc-target)
763 (setq rcirc-target target)) 770 (setq rcirc-target target))
764 buffer) 771 buffer)
765 ;; create the buffer 772 ;; create the buffer
766 (with-rcirc-process-buffer process 773 (with-rcirc-process-buffer process
767 (let ((new-buffer (get-buffer-create 774 (let ((new-buffer (get-buffer-create
768 (rcirc-generate-new-buffer-name process target)))) 775 (rcirc-generate-new-buffer-name process target))))
894 (interactive) 901 (interactive)
895 (assert (and (eq major-mode 'rcirc-multiline-edit-mode))) 902 (assert (and (eq major-mode 'rcirc-multiline-edit-mode)))
896 (kill-buffer (current-buffer)) 903 (kill-buffer (current-buffer))
897 (set-window-configuration rcirc-window-configuration)) 904 (set-window-configuration rcirc-window-configuration))
898 905
899 (defun rcirc-get-any-buffer (process) 906 (defun rcirc-any-buffer (process)
900 "Return a buffer for PROCESS, either the one selected or the process buffer." 907 "Return a buffer for PROCESS, either the one selected or the process buffer."
901 (let ((buffer (window-buffer (selected-window)))) 908 (if rcirc-always-use-server-buffer-flag
902 (if (and buffer 909 (process-buffer process)
903 (with-current-buffer buffer 910 (let ((buffer (window-buffer (selected-window))))
904 (and (eq major-mode 'rcirc-mode) 911 (if (and buffer
905 (eq rcirc-process process)))) 912 (with-current-buffer buffer
906 buffer 913 (and (eq major-mode 'rcirc-mode)
907 (process-buffer process)))) 914 (eq rcirc-process process))))
915 buffer
916 (process-buffer process)))))
908 917
909 (defcustom rcirc-response-formats 918 (defcustom rcirc-response-formats
910 '(("PRIVMSG" . "%T<%n> %m") 919 '(("PRIVMSG" . "%T<%N> %m")
911 ("NOTICE" . "%T-%n- %m") 920 ("NOTICE" . "%T-%N- %m")
912 ("ACTION" . "%T[%n] %m") 921 ("ACTION" . "%T[%N %m]")
913 ("COMMAND" . "%T%m") 922 ("COMMAND" . "%T%m")
914 ("ERROR" . "%T%fw!!! %m") 923 ("ERROR" . "%T%fw!!! %m")
915 (t . "%T%fp*** %fs%n %r %m")) 924 (t . "%T%fp*** %fs%n %r %m"))
916 "An alist of formats used for printing responses. 925 "An alist of formats used for printing responses.
917 The format is looked up using the response-type as a key; 926 The format is looked up using the response-type as a key;
919 928
920 The entry's value part should be a string, which is inserted with 929 The entry's value part should be a string, which is inserted with
921 the of the following escape sequences replaced by the described values: 930 the of the following escape sequences replaced by the described values:
922 931
923 %m The message text 932 %m The message text
924 %n The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick') 933 %n The sender's nick
934 %N The sender's nick (with face `rcirc-my-nick' or `rcirc-other-nick')
925 %r The response-type 935 %r The response-type
926 %T The timestamp (with face `rcirc-timestamp') 936 %T The timestamp (with face `rcirc-timestamp')
927 %t The target 937 %t The target
928 %fw Following text uses the face `font-lock-warning-face' 938 %fw Following text uses the face `font-lock-warning-face'
929 %fp Following text uses the face `rcirc-server-prefix' 939 %fp Following text uses the face `rcirc-server-prefix'
957 (setq chunk (substring chunk 1))) 967 (setq chunk (substring chunk 1)))
958 (setq repl 968 (setq repl
959 (cond ((eq key ?%) 969 (cond ((eq key ?%)
960 ;; %% -- literal % character 970 ;; %% -- literal % character
961 "%") 971 "%")
962 ((eq key ?n) 972 ((or (eq key ?n) (eq key ?N))
963 ;; %n -- nick 973 ;; %n/%N -- nick
964 (rcirc-facify (concat (rcirc-abbrev-nick sender) 974 (let ((nick (concat (if (string= (with-rcirc-process-buffer
965 (and target (concat "," target))) 975 process rcirc-server)
966 (if (string= sender (rcirc-nick process)) 976 sender)
967 'rcirc-my-nick 977 ""
968 'rcirc-other-nick))) 978 (rcirc-abbrev-nick sender))
979 (and target (concat "," target)))))
980 (rcirc-facify nick
981 (if (eq key ?n)
982 face
983 (if (string= sender (rcirc-nick process))
984 'rcirc-my-nick
985 'rcirc-other-nick)))))
969 ((eq key ?T) 986 ((eq key ?T)
970 ;; %T -- timestamp 987 ;; %T -- timestamp
971 (rcirc-facify 988 (rcirc-facify
972 (format-time-string rcirc-time-format (current-time)) 989 (format-time-string rcirc-time-format (current-time))
973 'rcirc-timestamp)) 990 'rcirc-timestamp))
1013 (defun rcirc-target-buffer (process sender response target text) 1030 (defun rcirc-target-buffer (process sender response target text)
1014 "Return a buffer to print the server response." 1031 "Return a buffer to print the server response."
1015 (assert (not (bufferp target))) 1032 (assert (not (bufferp target)))
1016 (with-rcirc-process-buffer process 1033 (with-rcirc-process-buffer process
1017 (cond ((not target) 1034 (cond ((not target)
1018 (if rcirc-always-use-server-buffer-flag 1035 (rcirc-any-buffer process))
1019 (process-buffer process)
1020 (rcirc-get-any-buffer process)))
1021 ((not (rcirc-channel-p target)) 1036 ((not (rcirc-channel-p target))
1022 ;; message from another user 1037 ;; message from another user
1023 (if (string= response "PRIVMSG") 1038 (if (string= response "PRIVMSG")
1024 (rcirc-get-buffer-create process (if (string= sender rcirc-nick) 1039 (rcirc-get-buffer-create process (if (string= sender rcirc-nick)
1025 target 1040 target
1026 sender)) 1041 sender))
1027 (rcirc-get-buffer process target t))) 1042 (rcirc-get-buffer process target t)))
1028 ((or (rcirc-get-buffer process target) 1043 ((or (rcirc-get-buffer process target)
1029 (rcirc-get-any-buffer process)))))) 1044 (rcirc-any-buffer process))))))
1030 1045
1031 (defvar rcirc-activity-type nil) 1046 (defvar rcirc-activity-type nil)
1032 (make-variable-buffer-local 'rcirc-activity-type) 1047 (make-variable-buffer-local 'rcirc-activity-type)
1033 (defun rcirc-print (process sender response target text &optional activity) 1048 (defun rcirc-print (process sender response target text &optional activity)
1034 "Print TEXT in the buffer associated with TARGET. 1049 "Print TEXT in the buffer associated with TARGET.
1067 1082
1068 (insert fmted-text (propertize "\n" 'hard t)) 1083 (insert fmted-text (propertize "\n" 'hard t))
1069 (set-marker-insertion-type rcirc-prompt-start-marker nil) 1084 (set-marker-insertion-type rcirc-prompt-start-marker nil)
1070 (set-marker-insertion-type rcirc-prompt-end-marker nil) 1085 (set-marker-insertion-type rcirc-prompt-end-marker nil)
1071 1086
1072 ;; fill the text we just inserted, maybe 1087 (let ((text-start (make-marker)))
1073 (when (and rcirc-fill-flag 1088 (set-marker text-start
1074 (not (string= response "372"))) ;/motd 1089 (or (next-single-property-change fill-start
1075 (let ((fill-prefix 1090 'rcirc-text)
1076 (or rcirc-fill-prefix 1091 (point-max)))
1077 (make-string 1092 ;; squeeze spaces out of text before rcirc-text
1078 (or (next-single-property-change 0 'rcirc-text 1093 (fill-region fill-start (1- text-start))
1079 fmted-text) 1094
1080 8) 1095 ;; fill the text we just inserted, maybe
1081 ?\s))) 1096 (when (and rcirc-fill-flag
1082 (fill-column (cond ((eq rcirc-fill-column 'frame-width) 1097 (not (string= response "372"))) ;/motd
1083 (1- (frame-width))) 1098 (let ((fill-prefix
1084 (rcirc-fill-column 1099 (or rcirc-fill-prefix
1085 rcirc-fill-column) 1100 (make-string (- text-start fill-start) ?\s)))
1086 (t fill-column)))) 1101 (fill-column (cond ((eq rcirc-fill-column 'frame-width)
1087 (fill-region fill-start rcirc-prompt-start-marker 'left t)))) 1102 (1- (frame-width)))
1103 (rcirc-fill-column
1104 rcirc-fill-column)
1105 (t fill-column))))
1106 (fill-region fill-start rcirc-prompt-start-marker 'left t)))))
1088 1107
1089 ;; set inserted text to be read-only 1108 ;; set inserted text to be read-only
1090 (when rcirc-read-only-flag 1109 (when rcirc-read-only-flag
1091 (put-text-property rcirc-prompt-start-marker fill-start 'read-only t) 1110 (put-text-property rcirc-prompt-start-marker fill-start 'read-only t)
1092 (let ((inhibit-read-only t)) 1111 (let ((inhibit-read-only t))
1173 (mapcar (lambda (x) (car x)) 1192 (mapcar (lambda (x) (car x))
1174 (gethash nick rcirc-nick-table)))) 1193 (gethash nick rcirc-nick-table))))
1175 1194
1176 (defun rcirc-put-nick-channel (process nick channel) 1195 (defun rcirc-put-nick-channel (process nick channel)
1177 "Add CHANNEL to list associated with NICK." 1196 "Add CHANNEL to list associated with NICK."
1178 (with-rcirc-process-buffer process 1197 (let ((nick (rcirc-user-nick nick)))
1179 (let* ((chans (gethash nick rcirc-nick-table)) 1198 (with-rcirc-process-buffer process
1180 (record (assoc-string channel chans t))) 1199 (let* ((chans (gethash nick rcirc-nick-table))
1181 (if record 1200 (record (assoc-string channel chans t)))
1182 (setcdr record (current-time)) 1201 (if record
1183 (puthash nick (cons (cons channel (current-time)) 1202 (setcdr record (current-time))
1184 chans) 1203 (puthash nick (cons (cons channel (current-time))
1185 rcirc-nick-table))))) 1204 chans)
1205 rcirc-nick-table))))))
1186 1206
1187 (defun rcirc-nick-remove (process nick) 1207 (defun rcirc-nick-remove (process nick)
1188 "Remove NICK from table." 1208 "Remove NICK from table."
1189 (with-rcirc-process-buffer process 1209 (with-rcirc-process-buffer process
1190 (remhash nick rcirc-nick-table))) 1210 (remhash nick rcirc-nick-table)))
1611 (defun rcirc-facify (string face) 1631 (defun rcirc-facify (string face)
1612 "Return a copy of STRING with FACE property added." 1632 "Return a copy of STRING with FACE property added."
1613 (propertize (or string "") 'face face 'rear-nonsticky t)) 1633 (propertize (or string "") 'face face 'rear-nonsticky t))
1614 1634
1615 (defvar rcirc-url-regexp 1635 (defvar rcirc-url-regexp
1616 (rx word-boundary 1636 (rx-to-string
1617 (or "www." 1637 `(and word-boundary
1618 (and (or "http" "https" "ftp" "file" "gopher" "news" "telnet" "wais" 1638 (or "www."
1619 "mailto") 1639 (and (or "http" "https" "ftp" "file" "gopher" "news" "telnet"
1620 "://" 1640 "wais" "mailto")
1621 (1+ (char "a-zA-Z0-9_.")) 1641 "://"
1622 (optional ":" (1+ (char "0-9"))))) 1642 (1+ (char "-a-zA-Z0-9_."))
1623 (1+ (char "-a-zA-Z0-9_=!?#$\@~`%&*+|\\/:;.,{}[]")) 1643 (optional ":" (1+ (char "0-9"))))
1624 (char "-a-zA-Z0-9_=#$\@~`%&*+|\\/:;{}[]")) 1644 (and (1+ (char "-a-zA-Z0-9_."))
1645 (or ".com" ".net" ".org")
1646 word-boundary))
1647 (optional
1648 (and "/"
1649 (1+ (char "-a-zA-Z0-9_=!?#$\@~`%&*+|\\/:;.,{}[]"))
1650 (char "-a-zA-Z0-9_=#$\@~`%&*+|\\/:;{}[]")))))
1625 "Regexp matching URLs. Set to nil to disable URL features in rcirc.") 1651 "Regexp matching URLs. Set to nil to disable URL features in rcirc.")
1626 1652
1627 (defun rcirc-browse-url (&optional arg) 1653 (defun rcirc-browse-url (&optional arg)
1628 "Prompt for URL to browse based on URLs in buffer." 1654 "Prompt for URL to browse based on URLs in buffer."
1629 (interactive) 1655 (interactive)