home *** CD-ROM | disk | FTP | other *** search
/ ftp.madoka.org / 2014.12.ftp.madoka.org.tar / ftp.madoka.org / pub / irchat-pj / 2.5 / irchat-pj-2.5.6p.tar.gz / irchat-pj-2.5.6p.tar / irchat-pj-2.5.6p / irchat.el < prev    next >
Lisp/Scheme  |  2001-06-05  |  61KB  |  1,557 lines

  1. ;;; see file irchat-copyright.el for change log and copyright info
  2.  
  3. ;; irchat-2.4jp version by kick@wide.ad.jp (1994/03/17 - 1998/12/21)
  4. ;; Copyright (C) 1994,1995,1996,1997,1998 KIKUCHI Takahiro
  5.  
  6. ;; irchat-pj 2.5.x version by simm@irc.fan.gr.jp (1999/01/16-2000/01/19)
  7. ;; Copyright (C) 1998-2000 irchat-PJ Project
  8.  
  9. ;; $Id: irchat.el,v 1.18 2001/06/05 16:53:34 simm Exp $
  10.  
  11. ;; modified by simm@irc.fan.gr.jp, Tue, 25 Jul 2000 00:29:53 +0900
  12. (require 'pure-generic)
  13. (require 'pure-cs)
  14. (require 'pure-vs)
  15. (require 'pure-bl)
  16. (require 'pure-irc-send)
  17. (require 'pure-irc-dcc)
  18.  
  19. (require 'irchat-commands)
  20. (require 'irchat-handle)
  21. (require 'irchat-filter)
  22. (require 'irchat-vars)
  23.  
  24. (require 'irchat-pj-modeline)
  25. (require 'irchat-pj-sound)
  26.  
  27. (defconst irchat-ctcp-error-msg "Unrecognized command: '%s'"
  28.   "*Error message given to anyone asking wrong CTCP command.")
  29.  
  30. (defconst irchat-pj-initial-buffer-local-variables-list
  31.   '([irchat-freeze-local     irchat-default-freeze-local]
  32.     [irchat-beep-local       irchat-default-beep-local]
  33.     [irchat-suppress-local   irchat-default-suppress-local]
  34.     [irchat-previous-pattern nil])
  35.   "List for buffer local variables for irchat-pj.
  36. This variable is used via pure-bl.el, called from `irchat-pj-window-init' function")
  37.  
  38. (defvar irchat-pj-debug-buffer nil)
  39.  
  40. (defvar irchat-ctcp-lastcommand nil
  41.   "*Place to keep last entered command")
  42.  
  43. (defvar irchat-ctcp-lastnick nil
  44.   "*Place to keep last queried nick")
  45.  
  46. (defvar irchat-command-window-on-top (if irchat-want-traditional nil t)
  47.   "*If non-nil, the Command window will be put at the top of the screen.
  48. Else it is put at the bottom.")
  49.   
  50. (defvar irchat-use-full-window t
  51.   "*If non-nil, IRCHAT will use whole emacs window. Annoying for GNUS-
  52. users, therefore added by nam.")
  53.  
  54. (defvar irchat-ignore-changes nil
  55.   "*Ignore changes? Good in topic-wars/link troubles.")
  56.  
  57. (defvar irchat-ignore-noauths nil
  58.   "*If non nil, ignore no-auth notices if receiving them.")
  59.  
  60. (defvar irchat-ignore-fakes nil
  61.   "*If non nil, ignore fake notices if receiving them.")
  62.  
  63. (defvar irchat-ignore-kills nil
  64.   "*If non nil, ignore kill notices if receiving them.")
  65.  
  66. (defvar irchat-display-channel-always nil
  67.   "*If non nil, display channel name still in channel buffer.")
  68.  
  69. (defvar irchat-default-freeze-local t
  70.   "*If non nil, channel buffer local freeze flag is on at starting.")
  71.  
  72. (defsubst irchat-channel-freeze-local (chan value)
  73.   (put (intern chan) 'freeze value))
  74.  
  75. (defvar irchat-default-beep-local nil
  76.   "*If non nil, channel buffer local beep flag is on at starting.")
  77.  
  78. (defsubst irchat-channel-beep-local (chan value)
  79.   (put (intern chan) 'beep value))
  80.  
  81. (defvar irchat-default-suppress-local nil
  82.   "*If non nil, channel buffer local suppress flag is on at starting.")
  83.  
  84. (defsubst irchat-channel-suppress-local (chan value)
  85.   (put (intern chan) 'suppress value))
  86.  
  87. (defvar irchat-message-try-to-connect-server nil
  88.   "*If non nil, notify to mini buffer when trying to connect server.")
  89.  
  90. (defvar irchat-reconnect-automagic nil
  91.   "*Automatic reconnection, default is disabled")
  92.  
  93. (defvar irchat-ask-for-nickname nil
  94.   "*Ask for nickname if irchat was entered with \\[universal-argument].")
  95.  
  96. (defvar irchat-ask-for-password nil
  97.   "*Ask for password when connecting to server.")
  98.  
  99. (defvar irchat-ask-for-channel-password nil
  100.   "*Ask for channel password when joining channel with password.")
  101.  
  102. (defvar irchat-reconnect-with-password nil
  103.   "*auto recconect to server with password after incorrect password.")
  104.  
  105. (defvar irchat-blink-parens t
  106.   "*Should we blink matching parenthesis in irchat command buffer?")
  107.  
  108. (defvar irchat-one-buffer-mode nil
  109.   "*When non-nil, irchat will put up only a dialogue-buffer (on the
  110. screen). Useful for those (perverts) who use 24 line terminals.")
  111.  
  112. (defvar irchat-channel-buffer-mode nil
  113.   "*When non-nil, irchat will display a channel buffer.")
  114.  
  115. (defvar irchat-channel-filter "" 
  116.   "*Enables use of \\[universal-argument] with NAMES and TOPIC.")
  117.  
  118. (defvar irchat-how-to-show-links-reply nil
  119.   "*how to show LINKS reply.")
  120.  
  121. (defvar irchat-links-reply-count 0
  122.   "*the number of LINKS reply.")
  123.  
  124. (defvar irchat-long-reply-count 0
  125.   "*the number of NAMES/LIST/WHO reply.")
  126.  
  127. (defvar irchat-no-configure-windows t
  128.   "*not yet configure windows")
  129.  
  130. (defvar irchat-fatal-error-message nil
  131.   "*ERROR message")
  132.  
  133. (defvar irchat-while-whois-reply nil
  134.   "*true while whois reply.")
  135.  
  136. (defvar irchat-auto-whois-nick ""
  137.   "*nick which automatically whois.")
  138.  
  139. (defvar irchat-nickname-already-in-use nil
  140.   "*Need ask another nickname.")
  141.  
  142. (defvar irchat-nickname-erroneus nil
  143.   "*Need ask another nickname.")
  144.  
  145. (defvar irchat-grow-tail "_"
  146.   "*Add irchat-grow-tail to nick when reconnecting. Otherwise you might get
  147. killed again if automagic reconnect is too fast.")
  148.  
  149. (defvar irchat-shorten-kills t
  150.   "*Shorten KILL messages to about one line.")
  151.  
  152. (defvar irchat-invited-channel)
  153. (setq irchat-invited-channel nil)
  154.  
  155. (defvar irchat-Command-mode-hook nil
  156.   "*A hook for IRCHAT Command mode.")
  157.  
  158. (defvar irchat-Dialogue-mode-hook nil
  159.   "*A hook for IRCHAT Dialogue mode.")
  160.  
  161. (defvar irchat-Others-mode-hook nil
  162.   "*A hook for IRCHAT Others mode.")
  163.  
  164. (defvar irchat-Channel-mode-hook nil
  165.   "*A hook for IRCHAT Current channel mode.")
  166.  
  167. (defvar irchat-Exit-hook nil
  168.   "*A hook executed when signing off IRC.")
  169.  
  170. (defvar irchat-ignore-nickname nil
  171.   "*A list of nicknames, as symbols, to ignore.  Messages from these people
  172. won't be displayed.")
  173.  
  174. (defvar irchat-kill-realname nil
  175.   "*A list of real names of people to ignore. Messages from them
  176. won't be displayed.")
  177.  
  178. (defvar irchat-kill-logon nil
  179.   "*A list of logon names (user@host.dom.ain). Messages from them
  180. won't be displayed.")
  181.  
  182. (defvar irchat-buggy-emacs-pos-visible-in-window-p nil
  183.   "*You should set non-nil if your emacs has buggy pos-visible-in-window-p.")
  184.  
  185. (defvar irchat-pj-away-p nil)
  186.  
  187. (defvar irchat-trying-nickname nil
  188.   "the nickname that I'm trying to be.")
  189.  
  190. ;; add by simm@irc.fan.gr.jp, Mon, 08 Nov 1999 02:57:29 +0900
  191. (defvar irchat-pj-startup-nickname-rest nil
  192.   "rest nickname list when startup")
  193.  
  194. (defvar irchat-old-window-configuration nil
  195.   "the window configuration before starting irchat.")
  196.  
  197. (defvar irchat-after-registration nil
  198.   "after my registration")
  199.  
  200. (defvar irchat-debugging nil
  201.   "for debugging only")
  202.  
  203. ;; Define hooks for each IRC message the server might send us.
  204. ;; The newer IRC servers use numeric reply codes instead of words.
  205.  
  206. (defvar irchat-msg-list
  207.   '(channel error invite linreply msg namreply nick ping pong quit2
  208.     privmsg quit topic wall whoreply kill wallops mode kick part join
  209.     200 203 204 205 206 209 211 212 213 214 215 216 217 218 219
  210.     301 311 312 313 314 315 317 318 321 322 323 331 332 341 
  211.     351 352 353 361 364 365 366 367 368 371 372 381 382 391
  212.     401 402 403 411 412 421 431 432 433 441 451 461 462 463 
  213.     464 465 471 472 473 474 481 482 491)
  214.   "A list of the IRC messages and numeric reply codes irchat can handle.")
  215.  
  216. (mapcar
  217.  '(lambda (item)
  218.     (eval (list 'defvar (intern (format "irchat-%s-hook" (prin1-to-string item))) nil
  219.         (concat "*A hook that is executed when the IRC "
  220.             "message \"" (upcase (prin1-to-string item)) "\" is received.\n"
  221.             "The hook function is called with two arguments, "
  222.             "PREFIX and REST-OF-LINE.\n"
  223.             "It should return non NIL "
  224.             "if no further processing of the message is to be carried out."))))
  225.  irchat-msg-list)
  226.  
  227. (defvar irchat-current-channel nil
  228.   "The channel you currently have joined.")
  229.  
  230. (defvar irchat-current-channels nil
  231.   "The channels you have currently joined.")
  232.  
  233. (defvar irchat-chanbuf-num 0
  234.   "The channel buffer you currently have selected.")
  235.  
  236. (defvar irchat-chanbuf-list nil
  237.   "The channel buffers list you have currently joined.")
  238.  
  239. (defvar irchat-chanbuf-indicator "Private"
  240.   "The current channel buffer, \"pretty-printed.\"")
  241.  
  242. (defvar irchat-chanbufs-indicator "No channel"
  243.   "The channel buffers list, \"pretty-printed.\"")
  244.  
  245. (defvar irchat-polling nil
  246.   "T when we are automatically polling the server.")
  247.  
  248. (defvar irchat-last-poll-minute nil
  249.   "The minute when we last polled the server.")
  250.  
  251. (defvar irchat-last-timestamp 0
  252.   "The minute we inserted the previous timestamp")
  253.  
  254. (defvar irchat-previous-pattern nil )
  255.  
  256. (defvar irchat-freeze nil
  257.   "If non-nil the Dialogue window will not be scrolled automatically to bring
  258. new entries into view.")
  259.  
  260. (defvar irchat-privmsg-partner nil
  261.   "The person who got your last private message.")
  262.  
  263. (defvar irchat-current-chat-partner nil
  264.   "The person you are in a private conversation with.")
  265.  
  266. (defvar irchat-current-chat-partners nil
  267.   "An list containing nics user is chatting with.")
  268.  
  269. (defvar irchat-command-buffer-mode 'channel
  270.   "symbol chat or channel depending on which is current mode at 
  271. command buffer.")
  272.  
  273. (defvar irchat-nick-alist nil
  274.   "An alist containing the nicknames of users known to currently be on IRC.
  275. Each element in the list is a list containing a nickname.")
  276.  
  277. (defvar irchat-channel-alist nil 
  278.   "An alist containing the channels on IRC.  Each element in the list is 
  279. a list containing a channel name.")
  280.  
  281. (defvar irchat-userhost ""
  282.   "The user@host for the current line.")
  283.  
  284. (defvar irchat-pj-chans nil)
  285. (defvar irchat-pj-users nil)
  286.  
  287. (defvar irchat-debug-buffer nil)
  288. (defvar irchat-server-buffer nil)
  289. (defvar irchat-server-name nil)
  290. (defvar irchat-my-userhost nil)
  291. (defvar irchat-my-user nil)
  292. (defvar irchat-my-host nil)
  293. (defvar irchat-my-server nil)
  294.  
  295. ;; begin: modified by simm@irc.fan.gr.jp, Wed, 21 Jul 1999
  296. (defvar irchat-buffer-base " IRC:")
  297. (defvar irchat-Command-buffer "*IRC*")
  298. (defvar irchat-Dialogue-buffer (concat irchat-buffer-base " Dialogue"))
  299. (defvar irchat-Others-buffer (concat irchat-buffer-base " Others"))
  300. (defvar irchat-Private-buffer (concat irchat-buffer-base " Private"))
  301. (defvar irchat-Channel-buffer nil)
  302. (defvar irchat-KILLS-buffer  (concat irchat-buffer-base " KILLS"))
  303. (defvar irchat-IGNORED-buffer (concat irchat-buffer-base " IGNORED"))
  304. (defvar irchat-WALLOPS-buffer (concat irchat-buffer-base " WALLOPS"))
  305. (defvar irchat-pj-CONVERT-buffer (concat irchat-buffer-base " CONVERT"))
  306. (defvar irchat-show-wallops t)
  307. ;; end
  308.  
  309. (defvar irchat-server-process nil)
  310. (defvar irchat-status-message-string nil)
  311.  
  312. (defvar irchat-command-map nil)
  313. (defvar irchat-Command-mode-map nil)
  314. (defvar irchat-Dialogue-mode-map nil)
  315. (defvar irchat-Others-mode-map nil)
  316. (defvar irchat-Channel-mode-map nil)
  317. (defvar irchat-CTCP-command-map nil)
  318. (defvar irchat-DCC-command-map nil)
  319. (defvar irchat-STATS-command-map nil)
  320. (defvar irchat-buffer-switch-map nil)
  321.  
  322. (put 'irchat-Command-mode 'mode-class 'special)
  323. (put 'irchat-Dialogue-mode 'mode-class 'special)
  324. (put 'irchat-Others-mode 'mode-class 'special)
  325. (put 'irchat-Channel-mode 'mode-class 'special)
  326.  
  327. (if irchat-command-map
  328.     nil
  329.   (define-prefix-command 'irchat-command-map)
  330.   (setq irchat-command-map (make-keymap))
  331.   (fset 'irchat-command-prefix irchat-command-map)
  332.   (define-key irchat-command-map "0" 'irchat-Command-jump-channel0)
  333.   (define-key irchat-command-map "1" 'irchat-Command-jump-channel1)
  334.   (define-key irchat-command-map "2" 'irchat-Command-jump-channel2)
  335.   (define-key irchat-command-map "3" 'irchat-Command-jump-channel3)
  336.   (define-key irchat-command-map "4" 'irchat-Command-jump-channel4)
  337.   (define-key irchat-command-map "5" 'irchat-Command-jump-channel5)
  338.   (define-key irchat-command-map "6" 'irchat-Command-jump-channel6)
  339.   (define-key irchat-command-map "7" 'irchat-Command-jump-channel7)
  340.   (define-key irchat-command-map "8" 'irchat-Command-jump-channel8)
  341.   (define-key irchat-command-map "9" 'irchat-Command-jump-channel9)
  342.   (define-key irchat-command-map "\C-a" 'irchat-Command-alternative-channel)
  343.   (define-key irchat-command-map "A" 'irchat-Command-admin)
  344.   (define-key irchat-command-map "a" 'irchat-Command-away)
  345.   (define-key irchat-command-map "\C-b" 'irchat-buffer-switch-prefix)
  346.   (define-key irchat-command-map "B" 'irchat-Command-beep-on-message)
  347.   (define-key irchat-command-map "b" 'irchat-Command-scroll-down)
  348.   (define-key irchat-command-map "\C-c" 'irchat-CTCP-command-prefix)
  349.   (define-key irchat-command-map "c" 'irchat-Command-inline)
  350.   (define-key irchat-command-map "\C-d" 'irchat-DCC-command-prefix)
  351.   (define-key irchat-command-map "D" 'irchat-Command-debug)
  352.   (define-key irchat-command-map "\C-f" 'irchat-Command-scroll-freeze)
  353.   (define-key irchat-command-map "F" 'irchat-Command-finger-direct)
  354.   (define-key irchat-command-map "f" 'irchat-Command-finger)
  355.   (define-key irchat-command-map "\C-i" 'irchat-Command-ignore)
  356.   (define-key irchat-command-map "i" 'irchat-Command-invite)
  357.   (define-key irchat-command-map "\C-j" 'irchat-Command-next-channel)
  358.   (define-key irchat-command-map "j" 'irchat-Command-join)
  359.   (define-key irchat-command-map "\C-k" 'irchat-Command-kick)
  360.   (define-key irchat-command-map "\C-l" 'irchat-Command-redisplay)
  361.   (define-key irchat-command-map "L" 'irchat-Command-load-vars)
  362.   (define-key irchat-command-map "l" 'irchat-Command-list)
  363.   (define-key irchat-command-map "M" 'irchat-pj-Command-broadcast-minibuffer)
  364.   (define-key irchat-command-map "m" 'irchat-Command-send-minibuffer)
  365.   (define-key irchat-command-map "\C-m" 'irchat-Command-modec)
  366.   (define-key irchat-command-map "\C-n" 'irchat-Command-names)
  367.   (define-key irchat-command-map "n" 'irchat-Command-nickname)
  368.   (define-key irchat-command-map "\C-o" 'irchat-Command-toggle-display-mode)
  369.   (define-key irchat-command-map "o" 'irchat-Command-ison)
  370.   (define-key irchat-command-map "\C-p" 'irchat-Command-part)
  371.   (define-key irchat-command-map "P" 'irchat-Channel-ctcp-ping)
  372.   (define-key irchat-command-map "p" 'irchat-Command-send-private)
  373.   (define-key irchat-command-map "q" 'irchat-Command-quit)
  374.   (define-key irchat-command-map "\C-r" 'irchat-Command-caesar-line)
  375.   (define-key irchat-command-map "r" 'irchat-Command-reconfigure-windows)
  376.   (define-key irchat-command-map "\C-s" 'irchat-STATS-command-prefix)
  377.   (define-key irchat-command-map "S" 'irchat-Command-suppress-others)
  378.   (define-key irchat-command-map "s" 'irchat-Command-servers)
  379.   (define-key irchat-command-map "\C-t" 'irchat-Command-trace)
  380.   (define-key irchat-command-map "T" 'irchat-Channel-ctcp-time)
  381.   (define-key irchat-command-map "t" 'irchat-Command-topic)
  382.   (define-key irchat-command-map "\C-u" 'irchat-Command-userhost)
  383.   (define-key irchat-command-map "U" 'irchat-Channel-ctcp-userinfo)
  384.   (define-key irchat-command-map "u" 'irchat-Command-users)
  385.   (define-key irchat-command-map "V" 'irchat-Channel-ctcp-version)
  386.   (define-key irchat-command-map "v" 'irchat-Command-version)
  387.   (define-key irchat-command-map "w" 'irchat-Command-who)
  388.   (define-key irchat-command-map "W" 'irchat-Command-wait)
  389.   (define-key irchat-command-map "\C-y" 'irchat-Command-send-yank)
  390.   (define-key irchat-command-map "Y" 'irchat-Command-debug-user)
  391.   (define-key irchat-command-map "z" 'irchat-pj-Command-broadcast-message)
  392.   (define-key irchat-command-map "\C-?" 'irchat-Command-scroll-down)
  393.   (define-key irchat-command-map " " 'irchat-Command-scroll-up)
  394.   (define-key irchat-command-map "!" 'irchat-Command-send-exec)
  395.   (define-key irchat-command-map "^" 'irchat-Command-bod-buffer)
  396.   (define-key irchat-command-map "$" 'irchat-Command-eod-buffer)
  397.   (define-key irchat-command-map ">" 'irchat-Command-next-channel)
  398.   (define-key irchat-command-map "<" 'irchat-Command-previous-channel)
  399.   (define-key irchat-command-map "/" 'irchat-Command-generic))
  400.  
  401. (if irchat-CTCP-command-map
  402.     nil
  403.   (define-prefix-command 'irchat-CTCP-command-map)
  404.   (setq irchat-CTCP-command-map (make-keymap))
  405.   (fset 'irchat-CTCP-command-prefix irchat-CTCP-command-map)
  406.   (define-key irchat-CTCP-command-map "0" 'irchat-Command-jump-channel10)
  407.   (define-key irchat-CTCP-command-map "1" 'irchat-Command-jump-channel11)
  408.   (define-key irchat-CTCP-command-map "2" 'irchat-Command-jump-channel12)
  409.   (define-key irchat-CTCP-command-map "3" 'irchat-Command-jump-channel13)
  410.   (define-key irchat-CTCP-command-map "4" 'irchat-Command-jump-channel14)
  411.   (define-key irchat-CTCP-command-map "5" 'irchat-Command-jump-channel15)
  412.   (define-key irchat-CTCP-command-map "6" 'irchat-Command-jump-channel16)
  413.   (define-key irchat-CTCP-command-map "7" 'irchat-Command-jump-channel17)
  414.   (define-key irchat-CTCP-command-map "8" 'irchat-Command-jump-channel18) 
  415.   (define-key irchat-CTCP-command-map "9" 'irchat-Command-jump-channel19)
  416.   (define-key irchat-CTCP-command-map "g" 'irchat-Command-ctcp-generic)
  417.   (define-key irchat-CTCP-command-map "v" 'irchat-Command-ctcp-version)
  418.   (define-key irchat-CTCP-command-map "t" 'irchat-Command-ctcp-time)
  419.   (define-key irchat-CTCP-command-map "f" 'irchat-Command-ctcp-finger)
  420.   (define-key irchat-CTCP-command-map "a" 'irchat-Command-ctcp-action)
  421.   (define-key irchat-CTCP-command-map "r" 'irchat-Command-ctcp-caesar)
  422.   (define-key irchat-CTCP-command-map "u" 'irchat-Command-ctcp-userinfo)
  423.   (define-key irchat-CTCP-command-map "p" 'irchat-Command-ctcp-ping)
  424.   (define-key irchat-CTCP-command-map "c" 'irchat-Command-ctcp-clientinfo)
  425.   (define-key irchat-CTCP-command-map "\C-c"
  426.     'irchat-Command-ctcp-clientinfo-generic)
  427.   (define-key irchat-CTCP-command-map "U" 
  428.     'irchat-Command-ctcp-userinfo-from-minibuffer)
  429.   (define-key irchat-CTCP-command-map "\C-u" 
  430.     'irchat-Command-ctcp-userinfo-from-commandbuffer)
  431.   )
  432.  
  433.  
  434. (if irchat-DCC-command-map
  435.     nil
  436.   (define-prefix-command 'irchat-DCC-command-map)
  437.   (setq irchat-DCC-command-map (make-keymap))
  438.   (fset 'irchat-DCC-command-prefix irchat-DCC-command-map)
  439.   (define-key irchat-DCC-command-map "0" 'irchat-Command-jump-channel20)
  440.   (define-key irchat-DCC-command-map "1" 'irchat-Command-jump-channel21)
  441.   (define-key irchat-DCC-command-map "2" 'irchat-Command-jump-channel22)
  442.   (define-key irchat-DCC-command-map "3" 'irchat-Command-jump-channel23)
  443.   (define-key irchat-DCC-command-map "4" 'irchat-Command-jump-channel24)
  444.   (define-key irchat-DCC-command-map "5" 'irchat-Command-jump-channel25)
  445.   (define-key irchat-DCC-command-map "6" 'irchat-Command-jump-channel26)
  446.   (define-key irchat-DCC-command-map "7" 'irchat-Command-jump-channel27)
  447.   (define-key irchat-DCC-command-map "8" 'irchat-Command-jump-channel28) 
  448.   (define-key irchat-DCC-command-map "9" 'irchat-Command-jump-channel29)
  449.   (define-key irchat-DCC-command-map "c" 'irchat-Command-dcc-chat)
  450.   (define-key irchat-DCC-command-map "g" 'irchat-Command-dcc-get)
  451.   (define-key irchat-DCC-command-map "k" 'irchat-Command-dcc-kill)
  452.   (define-key irchat-DCC-command-map "l" 'irchat-Command-dcc-list)
  453.   (define-key irchat-DCC-command-map "q" 'irchat-pj-Command-dcc-quit)
  454.   (define-key irchat-DCC-command-map "r" 'irchat-Command-dcc-rget)
  455.   (define-key irchat-DCC-command-map "s" 'irchat-Command-dcc-send)
  456.   )
  457.  
  458. (if irchat-STATS-command-map
  459.     nil
  460.   (define-prefix-command 'irchat-STATS-command-map)
  461.   (setq irchat-STATS-command-map (make-keymap))
  462.   (fset 'irchat-STATS-command-prefix irchat-STATS-command-map)
  463.   (define-key irchat-STATS-command-map "c" 'irchat-Command-stats-connection)
  464.   )
  465. (defun irchat-Command-stats-connection ()
  466.   (interactive)
  467.   (if current-prefix-arg
  468.       (irchat-send "STATS C %s" "")
  469.     (irchat-send "STATS C")))
  470.  
  471.  
  472. (if irchat-buffer-switch-map
  473.     nil
  474.   (define-prefix-command 'irchat-buffer-switch-map)
  475.   (setq irchat-buffer-switch-map (make-keymap))
  476.   (fset 'irchat-buffer-switch-prefix irchat-buffer-switch-map)
  477.   (define-key irchat-buffer-switch-map "k" 'irchat-buffer-switch-kill)
  478.   )
  479. (defun irchat-buffer-switch-kill ()
  480.   (interactive)
  481.   (switch-to-buffer-other-window irchat-KILLS-buffer)
  482.   nil)
  483.  
  484.  
  485. (if irchat-Others-mode-map
  486.     nil
  487.   (setq irchat-Others-mode-map (make-keymap))
  488.   (suppress-keymap irchat-Others-mode-map t)
  489.   (let ((i 0))
  490.     (while (< i 128)
  491.       (define-key irchat-Others-mode-map (format "%c" i) 'other-window)
  492.       (setq i (1+ i))))
  493.   (define-key irchat-Others-mode-map "\C-[" nil))
  494.  
  495. (if irchat-Channel-mode-map
  496.     nil
  497.   (setq irchat-Channel-mode-map (make-keymap))
  498.   (suppress-keymap irchat-Channel-mode-map)
  499.   (define-key irchat-Channel-mode-map "0" 'irchat-Command-jump-channel0)
  500.   (define-key irchat-Channel-mode-map "1" 'irchat-Command-jump-channel1)
  501.   (define-key irchat-Channel-mode-map "2" 'irchat-Command-jump-channel2)
  502.   (define-key irchat-Channel-mode-map "3" 'irchat-Command-jump-channel3)
  503.   (define-key irchat-Channel-mode-map "4" 'irchat-Command-jump-channel4)
  504.   (define-key irchat-Channel-mode-map "5" 'irchat-Command-jump-channel5)
  505.   (define-key irchat-Channel-mode-map "6" 'irchat-Command-jump-channel6)
  506.   (define-key irchat-Channel-mode-map "7" 'irchat-Command-jump-channel7)
  507.   (define-key irchat-Channel-mode-map "8" 'irchat-Command-jump-channel8)
  508.   (define-key irchat-Channel-mode-map "9" 'irchat-Command-jump-channel9)
  509.   (define-key irchat-Channel-mode-map "a" 'irchat-Command-away)
  510.   (define-key irchat-Channel-mode-map "A" 'irchat-Command-alternative-channel)
  511.   (define-key irchat-Channel-mode-map "B" 'irchat-Command-beep-on-message)
  512.   (define-key irchat-Channel-mode-map "b" 'irchat-Current-scroll-down)
  513.   (define-key irchat-Channel-mode-map "F" 'irchat-Command-finger-direct)
  514.   (define-key irchat-Channel-mode-map "f" 'irchat-Channel-freeze)
  515.   (define-key irchat-Channel-mode-map "i" 'irchat-Command-invite)
  516.   (define-key irchat-Channel-mode-map "J" 'irchat-Command-next-channel)
  517.   (define-key irchat-Channel-mode-map "j" 'irchat-Command-join)
  518.   (define-key irchat-Channel-mode-map "L" 'irchat-Command-load-vars)
  519.   (define-key irchat-Channel-mode-map "l" 'irchat-Command-list)
  520.   (define-key irchat-Channel-mode-map "m" 'irchat-Command-modec)
  521.   (define-key irchat-Channel-mode-map "n" 'irchat-Command-names)
  522.   (define-key irchat-Channel-mode-map "o" 'other-window)
  523.   (define-key irchat-Channel-mode-map "p" 'irchat-Command-part)
  524.   (define-key irchat-Channel-mode-map "r" 'irchat-Command-reconfigure-windows)
  525.   (define-key irchat-Channel-mode-map "S" 'irchat-Command-suppress-others)
  526.   (define-key irchat-Channel-mode-map "t" 'irchat-Command-topic)
  527.   (define-key irchat-Channel-mode-map "u" 'irchat-Command-users)
  528.   (define-key irchat-Channel-mode-map "v" 'irchat-Command-version)
  529.   (define-key irchat-Channel-mode-map "w" 'irchat-Command-who)
  530.   (define-key irchat-Channel-mode-map "!" 'irchat-Command-send-exec)
  531.   (define-key irchat-Channel-mode-map "^" 'beginning-of-buffer)
  532.   (define-key irchat-Channel-mode-map "$" 'end-of-buffer)
  533.   (define-key irchat-Channel-mode-map "/" 'irchat-Command-generic)
  534.   (define-key irchat-Channel-mode-map ">" 'irchat-Command-next-channel)
  535.   (define-key irchat-Channel-mode-map "<" 'irchat-Command-previous-channel)
  536.   (define-key irchat-Channel-mode-map " " 'irchat-Current-scroll-up)
  537.   (define-key irchat-Channel-mode-map "\C-?" 'irchat-Current-scroll-down)
  538.   ;(define-key irchat-Channel-mode-map "\C-n" 'forward-line)
  539.   (define-key irchat-Channel-mode-map "\C-m" 'irchat-Command-enter-message)
  540.   (define-key irchat-Channel-mode-map "\C-c" 'irchat-command-prefix))
  541.  
  542. (if irchat-Dialogue-mode-map
  543.     nil
  544.   (setq irchat-Dialogue-mode-map (make-keymap))
  545.   (suppress-keymap irchat-Dialogue-mode-map)
  546.   (define-key irchat-Dialogue-mode-map "0" 'irchat-Command-jump-channel0)
  547.   (define-key irchat-Dialogue-mode-map "1" 'irchat-Command-jump-channel1)
  548.   (define-key irchat-Dialogue-mode-map "2" 'irchat-Command-jump-channel2)
  549.   (define-key irchat-Dialogue-mode-map "3" 'irchat-Command-jump-channel3)
  550.   (define-key irchat-Dialogue-mode-map "4" 'irchat-Command-jump-channel4)
  551.   (define-key irchat-Dialogue-mode-map "5" 'irchat-Command-jump-channel5)
  552.   (define-key irchat-Dialogue-mode-map "6" 'irchat-Command-jump-channel6)
  553.   (define-key irchat-Dialogue-mode-map "7" 'irchat-Command-jump-channel7)
  554.   (define-key irchat-Dialogue-mode-map "8" 'irchat-Command-jump-channel8)
  555.   (define-key irchat-Dialogue-mode-map "9" 'irchat-Command-jump-channel9)
  556.   (define-key irchat-Dialogue-mode-map "A" 'irchat-Command-alternative-channel)
  557.   (define-key irchat-Dialogue-mode-map "a" 'irchat-Command-away)
  558.   (define-key irchat-Dialogue-mode-map "b" 'irchat-Current-scroll-down)
  559.   (define-key irchat-Dialogue-mode-map "F" 'irchat-Command-finger-direct)
  560.   (define-key irchat-Dialogue-mode-map "f" 'irchat-Dialogue-freeze)
  561.   (define-key irchat-Dialogue-mode-map "i" 'irchat-Command-invite)
  562.   (define-key irchat-Dialogue-mode-map "J" 'irchat-Command-next-channel)
  563.   (define-key irchat-Dialogue-mode-map "j" 'irchat-Command-join)
  564.   (define-key irchat-Dialogue-mode-map "L" 'irchat-Command-load-vars)
  565.   (define-key irchat-Dialogue-mode-map "l" 'irchat-Command-list)
  566.   (define-key irchat-Dialogue-mode-map "m" 'irchat-Command-modec)
  567.   (define-key irchat-Dialogue-mode-map "n" 'irchat-Command-names)
  568.   (define-key irchat-Dialogue-mode-map "o" 'other-window)
  569.   (define-key irchat-Dialogue-mode-map "p" 'irchat-Command-part)
  570.   (define-key irchat-Dialogue-mode-map "r" 'irchat-Command-reconfigure-windows)
  571.   (define-key irchat-Dialogue-mode-map "t" 'irchat-Command-topic)
  572.   (define-key irchat-Dialogue-mode-map "u" 'irchat-Command-users)
  573.   (define-key irchat-Dialogue-mode-map "v" 'irchat-Command-version)
  574.   (define-key irchat-Dialogue-mode-map "w" 'irchat-Command-who)
  575.   (define-key irchat-Dialogue-mode-map "!" 'irchat-Command-send-exec)
  576.   (define-key irchat-Dialogue-mode-map "^" 'beginning-of-buffer)
  577.   (define-key irchat-Dialogue-mode-map "$" 'end-of-buffer)
  578.   (define-key irchat-Dialogue-mode-map "/" 'irchat-Command-generic)
  579.   (define-key irchat-Dialogue-mode-map ">" 'irchat-Command-next-channel)
  580.   (define-key irchat-Dialogue-mode-map "<" 'irchat-Command-previous-channel)
  581.   (define-key irchat-Dialogue-mode-map " " 'irchat-Current-scroll-up)
  582.   (define-key irchat-Dialogue-mode-map "\C-?" 'irchat-Current-scroll-down)
  583.   ;(define-key irchat-Dialogue-mode-map "\C-n" 'forward-line)
  584.   (define-key irchat-Dialogue-mode-map "\C-m" 'irchat-Command-enter-message)
  585.   (define-key irchat-Dialogue-mode-map "\C-c" 'irchat-command-prefix))
  586.  
  587. (if irchat-Command-mode-map
  588.     nil
  589.   (setq irchat-Command-mode-map (make-sparse-keymap))
  590. ;;(define-key irchat-Command-mode-map "/" 'irchat-Command-irc-compatible)
  591.   (define-key irchat-Command-mode-map "\C-[\C-i" 'lisp-complete-symbol)
  592.   (define-key irchat-Command-mode-map "\C-i" 'irchat-Command-complete)
  593.   (define-key irchat-Command-mode-map "\C-m" 'irchat-pj-Command-send-line)
  594.   (define-key irchat-Command-mode-map "\C-c" 'irchat-command-prefix))
  595.  
  596. ;;;
  597. ;;;
  598. ;;;
  599.  
  600. (defun irchat (&optional confirm)
  601.   "Connect to the IRC server and start chatting.
  602. If optional argument CONFIRM is non-nil, ask which IRC server to connect.
  603. If already connected, just pop up the windows."
  604.   (interactive "P")
  605.   (let ((coding-system-for-read  'no-conversion)
  606.     (coding-system-for-write 'no-conversion))
  607.     (setq irchat-pj-debug-buffer (get-buffer-create " *irchat-pj:debug*"))
  608.     (pure-cs-buffer-unibyte irchat-pj-debug-buffer))
  609.   (or (fboundp (intern (format "irchat-Command-jump-channel%d"
  610.                    (1- irchat-pj-jump-channel-function-maximum))))
  611.       (irchat-pj-generator-Command-jump-channels irchat-pj-jump-channel-function-maximum))
  612.   (if (fboundp 'add-hook)
  613.       (add-hook 'kill-emacs-hook 'irchat-quit))
  614.   (if (file-exists-p (expand-file-name irchat-variables-file))
  615.       (load (expand-file-name irchat-variables-file)))
  616.   (if (irchat-server-opened)
  617.       (irchat-configure-windows)
  618.     (unwind-protect
  619.     (progn
  620.       (setq irchat-fatal-error-message nil)
  621.       (irchat-Command-setup-buffer)
  622.       (irchat-start-server confirm))
  623.       (if (not (irchat-server-opened))
  624.       (irchat-Command-quit 'error)
  625.     ;; IRC server is successfully open. 
  626.     (irchat-pj-window-init)
  627.     (setq irchat-pj-initialize-p  t
  628.           irchat-current-channels nil
  629.           irchat-chanbuf-list     nil)
  630.     (pure-irc-dcc-initialize 'irchat-pj-insert-log 'irchat-pj-insert-dcc-chat)
  631.     (run-hooks 'irchat-Startup-hook)
  632.     (irchat-pj-startup-check-nick)
  633.     (irchat-pj-startup-join)
  634.     (irchat-Channel-select 0)
  635.     (irchat-Channel-change)
  636.     (irchat-Command-describe-briefly)))))
  637.  
  638. ;; split by simm@irc.fan.gr.jp, Mon, 24 Jan 2000 19:12:24 +0900
  639. (defun irchat-pj-window-init ()
  640.   "Window initialization for irchat-pj"
  641.   (if (not  irchat-old-window-configuration)
  642.       (setq irchat-old-window-configuration
  643.         (current-window-configuration)))
  644.   (set-buffer irchat-Command-buffer)
  645.   (let ((buffer-read-only nil))
  646.     (erase-buffer)
  647.     (sit-for 0))
  648.   (pure-bl-make-permanent irchat-pj-initial-buffer-local-variables-list t)
  649.   (irchat-Dialogue-setup-buffer)
  650.   (irchat-Others-setup-buffer)
  651.   (irchat-Private-setup-buffer)
  652.   (irchat-KILLS-setup-buffer)
  653.   (irchat-IGNORED-setup-buffer)
  654.   (irchat-WALLOPS-setup-buffer)
  655.   (setq irchat-no-configure-windows t))
  656.  
  657.  
  658. ;; split by simm@irc.fan.gr.jp, Mon, 08 Nov 1999 02:28:38 +0900
  659. (defun irchat-pj-startup-check-nick ()
  660.   "Nick check when startup"
  661.   (let (ok)
  662.     (while (and (not ok) (irchat-server-opened))
  663.       (accept-process-output irchat-server-process)
  664.       (if (or irchat-nickname-already-in-use irchat-nickname-erroneus)
  665.       (progn
  666.         (if irchat-pj-startup-nickname-rest
  667.         (setq irchat-trying-nickname          (car irchat-pj-startup-nickname-rest)
  668.               irchat-pj-startup-nickname-rest (cdr irchat-pj-startup-nickname-rest))
  669.           ;; modified by simm@irc.fan.gr.jp, Mon, 20 Dec 1999 21:44:10 +0900
  670.           (funcall irchat-pj-sound-error-function)
  671.           (setq irchat-trying-nickname
  672.             (read-from-minibuffer
  673.              (format
  674.               (if irchat-nickname-already-in-use
  675.               "IRC: Nickname \"%s\" already in use. Choose another one: "
  676.             "IRC: Erroneus nickname \"%s\". Choose another one: ")
  677.               irchat-trying-nickname))))
  678.         (if (irchat-server-opened)
  679.         (irchat-send "NICK %s" irchat-trying-nickname)
  680.           (setq irchat-nickname irchat-trying-nickname)
  681.           (setq irchat-nickname-already-in-use nil
  682.             irchat-nickname-erroneus nil)
  683.           (irchat 'always))))
  684.       (setq irchat-nickname-already-in-use nil
  685.         irchat-nickname-erroneus nil)
  686.       (if (not irchat-no-configure-windows)
  687.       (setq ok t)))))
  688.  
  689. (defun irchat-pj-startup-join ()
  690.   "Join channels when startup"
  691.   (let ((chans (or irchat-current-channels irchat-startup-channel-list)))
  692.     (if chans
  693.     (while chans
  694.       (and (stringp (car chans))
  695.            (irchat-Command-join (car chans)))
  696.       (setq chans (cdr chans)))
  697.       (and (stringp irchat-startup-channel)
  698.        (irchat-Command-join irchat-startup-channel)))))
  699. ;; end
  700.  
  701. (defun irchat-Command-mode ()
  702.   "Major mode for IRCHAT.  Normal edit function are available.
  703. Typing Return or Linefeed enters the current line in the dialogue.
  704. The following special commands are available:
  705. For a list of the generic commands type \\[irchat-Command-generic] ? RET.
  706. \\{irchat-Command-mode-map}"
  707.   (interactive)
  708.   (kill-all-local-variables)
  709.  
  710.   ;; modified by negi@KU3G.org, 1 Jun 1999
  711.   (define-abbrev-table 'irchat-pj-abbrev-table ())
  712.  
  713.   (setq irchat-nick-alist (list (list irchat-nickname))
  714.     major-mode 'irchat-Command-mode
  715.     mode-name "IRC Command"
  716.     irchat-privmsg-partner nil
  717.     irchat-pj-away-p nil
  718.     ;; modified by negi@KU3G.org, 1 Jun 1999
  719.     local-abbrev-table irchat-pj-abbrev-table)
  720.   (irchat-pj-modeline-set irchat-pj-modeline-global-status
  721.               irchat-pj-modeline-Command-buffer
  722.               'irchat-pj-modeline-Command)
  723.   (use-local-map irchat-Command-mode-map)
  724.   (if irchat-blink-parens
  725.       nil
  726.     (pure-bl-make-permanent '([blink-matching-paren t]) t)
  727.     (setq blink-matching-paren nil))
  728.   (run-hooks 'irchat-Command-mode-hook))
  729.  
  730.  
  731. (defun irchat-Dialogue-mode ()
  732.   "Major mode for displaying the IRC dialogue.
  733. All normal editing commands are turned off.
  734. Instead, these commands are available:
  735. \\{irchat-Dialogue-mode-map}"
  736.   (kill-all-local-variables)
  737.   (setq major-mode 'irchat-Dialogue-mode
  738.     mode-name "IRC Dialogue")
  739.   (irchat-pj-modeline-set irchat-pj-modeline-global-status
  740.               irchat-pj-modeline-Dialogue-buffer
  741.               'irchat-pj-modeline-Dialogue)
  742.   (use-local-map irchat-Dialogue-mode-map)
  743.   (set-buffer irchat-Dialogue-buffer)
  744.   (setq buffer-read-only t)
  745.   (run-hooks 'irchat-Dialogue-mode-hook))
  746.  
  747.  
  748. (defun irchat-Others-mode ()
  749.   "Major mode for displaying the IRC others message except current channel.
  750. All normal editing commands are turned off.
  751. Instead, these commands are available:
  752. \\{irchat-Others-mode-map}"
  753.   (kill-all-local-variables)
  754.   (setq major-mode 'irchat-Others-mode
  755.     mode-name "IRC Others")
  756.   (irchat-pj-modeline-set irchat-pj-modeline-global-status
  757.               irchat-pj-modeline-Others-buffer
  758.               'irchat-pj-modeline-Others)
  759.   (use-local-map irchat-Others-mode-map)
  760.   (set-buffer irchat-Others-buffer)
  761.   (setq buffer-read-only t)
  762.   (run-hooks 'irchat-Others-mode-hook))
  763.  
  764.  
  765. (defun irchat-Channel-mode ()
  766.   "Major mode for displaying the IRC current channel buffer.
  767. All normal editing commands are turned off.
  768. Instead, these commands are available:
  769. \\{irchat-Channel-mode-map}"
  770.   (kill-all-local-variables)
  771.   (setq major-mode 'irchat-Channel-mode
  772.     mode-name "IRC current")
  773.   (irchat-pj-modeline-set irchat-pj-modeline-local-status
  774.               irchat-pj-modeline-Channel-buffer
  775.               'irchat-pj-modeline-Channel)
  776.   (use-local-map irchat-Channel-mode-map)
  777.   (setq buffer-read-only t)
  778.   (run-hooks 'irchat-Channel-mode-hook))
  779.  
  780.  
  781. (defun irchat-configure-windows ()
  782.   "Configure Command mode and Dialogue mode windows.
  783. One is for entering commands and text, the other displays the IRC dialogue."
  784.   (setq irchat-no-configure-windows nil)
  785.   (let ((obuf (current-buffer)))
  786.     (if (or (one-window-p t)
  787.         (null (get-buffer-window irchat-Command-buffer))
  788.         (null (get-buffer-window irchat-Dialogue-buffer))
  789.         (and irchat-channel-buffer-mode
  790.          (or (null (get-buffer-window irchat-Channel-buffer))
  791.              (null (get-buffer-window irchat-Others-buffer))))
  792.         (and (null irchat-channel-buffer-mode)
  793.          (or (get-buffer-window irchat-Channel-buffer)
  794.              (get-buffer-window irchat-Others-buffer))))
  795.     (progn
  796.       (if irchat-command-window-on-top
  797.           (progn
  798.         (if (not irchat-use-full-window)
  799.             (set-window-configuration irchat-old-window-configuration))
  800.         (switch-to-buffer irchat-Command-buffer)
  801.         (if irchat-use-full-window
  802.             (delete-other-windows))
  803.         (if irchat-one-buffer-mode
  804.             (switch-to-buffer irchat-Dialogue-buffer)
  805.           (split-window-vertically
  806.            (max window-min-height irchat-command-window-height))
  807.           (other-window 1)
  808.           (if irchat-channel-buffer-mode
  809.               (progn
  810.             (split-window-vertically
  811.              (max window-min-height 
  812.                   (/ (* (window-height)
  813.                     irchat-channel-window-height-percent)
  814.                  100)))
  815.             (switch-to-buffer irchat-Channel-buffer)
  816.             (other-window 1)
  817.             (switch-to-buffer irchat-Others-buffer)
  818.             (goto-char (point-max))
  819.             (recenter (- (window-height) 1))
  820.             (select-window
  821.              (get-buffer-window irchat-Command-buffer)))
  822.             (switch-to-buffer irchat-Dialogue-buffer)
  823.             (if (not irchat-freeze)
  824.             (progn
  825.               (goto-char (point-max))
  826.               (recenter (- (window-height) 1))))
  827.             (select-window
  828.              (get-buffer-window irchat-Command-buffer)))))
  829.         ;; mta@tut.fi wants it like this
  830.         (switch-to-buffer irchat-Dialogue-buffer)
  831.         (if (not irchat-freeze)
  832.         (progn
  833.           (goto-char (point-max))
  834.           (recenter (- (window-height) 1))))
  835.         (if irchat-use-full-window
  836.         (delete-other-windows))
  837.         (if irchat-one-buffer-mode
  838.         nil
  839.           (split-window-vertically
  840.            (- (window-height) (max window-min-height 
  841.                        irchat-command-window-height)))
  842.           (if irchat-channel-buffer-mode
  843.           (progn
  844.             (split-window-vertically
  845.              (max window-min-height 
  846.               (/ (* (window-height)
  847.                 (- 100 irchat-channel-window-height-percent))
  848.                  100)))
  849.             (switch-to-buffer irchat-Others-buffer)
  850.             (goto-char (point-max))
  851.             (recenter (- (window-height) 1))
  852.             (other-window 1)
  853.             (switch-to-buffer irchat-Channel-buffer)))
  854.           (other-window 1)
  855.           (switch-to-buffer irchat-Command-buffer)
  856.           (if (not irchat-channel-buffer-mode)
  857.           (progn
  858.             (select-window
  859.              (get-buffer-window irchat-Dialogue-buffer))
  860.             (if (not irchat-freeze)
  861.             (progn
  862.               (goto-char (point-max))
  863.               (recenter (- (window-height) 1))))))
  864.           (select-window
  865.            (get-buffer-window irchat-Command-buffer))))))
  866.     (set-buffer obuf)))
  867.  
  868.  
  869. (defun irchat-Command-setup-buffer ()
  870.   "Initialize Command mode buffer."
  871.   (or (get-buffer irchat-Command-buffer)
  872.       (save-excursion
  873.     (set-buffer (get-buffer-create irchat-Command-buffer))
  874.     (irchat-Command-mode))))
  875.  
  876. (defun irchat-Dialogue-setup-buffer ()
  877.   "Initialize Dialogue mode buffer."
  878.   (or (get-buffer irchat-Dialogue-buffer)
  879.       (save-excursion
  880.     (set-buffer (get-buffer-create irchat-Dialogue-buffer))
  881.     (irchat-Dialogue-mode))))
  882.  
  883. (defun irchat-Others-setup-buffer ()
  884.   "Initialize Others mode buffer."
  885.   (or (get-buffer irchat-Others-buffer)
  886.       (save-excursion
  887.     (set-buffer (get-buffer-create irchat-Others-buffer))
  888.     (irchat-Others-mode))))
  889.  
  890. (defun irchat-Private-setup-buffer ()
  891.   "Initialize private conversation buffer."
  892.   (or (get-buffer irchat-Private-buffer)
  893.       (save-excursion
  894.     (set-buffer (get-buffer-create irchat-Private-buffer))
  895.     (insert "This is my private buffer.\n")
  896.     (irchat-Channel-mode)))
  897.   (setq irchat-Private-buffer (get-buffer irchat-Private-buffer))
  898.   (setq irchat-Channel-buffer irchat-Private-buffer))
  899.  
  900. (defun irchat-KILLS-setup-buffer ()
  901.   "Initialize KILLS buffer."
  902.   (or (get-buffer irchat-KILLS-buffer)
  903.       (save-excursion
  904.     (set-buffer (get-buffer-create irchat-KILLS-buffer)))))
  905.  
  906. (defun irchat-IGNORED-setup-buffer ()
  907.   "Initialize IGNORED buffer."
  908.   (or (get-buffer irchat-IGNORED-buffer)
  909.       (save-excursion
  910.     (set-buffer (get-buffer-create irchat-IGNORED-buffer)))))
  911.  
  912. (defun irchat-WALLOPS-setup-buffer ()
  913.   "Initialize WALLOPS buffer."
  914.   (or (get-buffer irchat-WALLOPS-buffer)
  915.       (save-excursion
  916.     (set-buffer (get-buffer-create irchat-WALLOPS-buffer)))))
  917.  
  918. (defun irchat-clear-system ()
  919.   "Clear all IRCHAT variables and buffers."
  920.   (interactive)
  921.   (if (and irchat-Command-buffer (get-buffer irchat-Command-buffer))
  922.       (bury-buffer irchat-Command-buffer))
  923.   (if (and irchat-Dialogue-buffer (get-buffer irchat-Dialogue-buffer))
  924.       (bury-buffer irchat-Dialogue-buffer))
  925.   (if (and irchat-KILLS-buffer (get-buffer irchat-KILLS-buffer))
  926.       (bury-buffer irchat-KILLS-buffer))
  927.   (if (and irchat-IGNORED-buffer (get-buffer irchat-IGNORED-buffer))
  928.       (bury-buffer irchat-IGNORED-buffer))
  929.   (if (and irchat-WALLOPS-buffer (get-buffer irchat-WALLOPS-buffer))
  930.       (bury-buffer irchat-WALLOPS-buffer))
  931.   (if (and irchat-debug-buffer (get-buffer irchat-debug-buffer))
  932.       (bury-buffer irchat-debug-buffer))
  933.   (setq irchat-debug-buffer nil))
  934.  
  935. (defun irchat-start-server (&optional confirm)
  936.   "Open network stream to remote irc server.
  937. If optional argument CONFIRM is non-nil, ask the host that the server
  938. is running on."
  939.   (if (irchat-server-opened)
  940.       ;; Stream is already opened.
  941.       nil
  942.     ;; Open IRC server.
  943.     (if (or
  944.      (and confirm
  945.           (not (eq confirm 'always)))
  946.      (null irchat-server))
  947.     (setq irchat-server
  948.           (irchat-completing-default-read    
  949.            "IRC server: "
  950.            irchat-server-alist
  951.            '(lambda (s) t) nil irchat-server)))
  952.     ;; modified by simm@irc.fan.gr.jp, Mon, 08 Nov 1999 02:59:18 +0900
  953.     (cond ((and confirm
  954.         (not (eq confirm 'always))
  955.         irchat-ask-for-nickname)
  956.        (setq irchat-nickname
  957.          (read-string "Enter your nickname: " irchat-nickname)))
  958.       (irchat-pj-startup-nickname-list
  959.        (setq irchat-nickname (car irchat-pj-startup-nickname-list)
  960.          irchat-pj-startup-nickname-rest (cdr irchat-pj-startup-nickname-list))))
  961.     ;; If no server name is given, local host is assumed.
  962.     (if (string-equal irchat-server "")
  963.     (setq irchat-server (system-name)))
  964.     (or (irchat-open-server irchat-server irchat-service)
  965.     (and (stringp irchat-status-message-string)
  966.          (string= irchat-status-message-string "Searching for program")
  967.          (error "ERROR: Cannot execute \"%s\" -- Cannot connect IRC server \"%s\""
  968.             irchat-pj-dcc-program (irchat-pj-server-name)))
  969.     (and (stringp irchat-status-message-string)
  970.          (< 0 (length irchat-status-message-string))
  971.          (error "ERROR: %s -- Cannot connect IRC server \"%s\""
  972.             irchat-status-message-string (irchat-pj-server-name)))
  973.     (error "ERROR: Cannot connect IRC server \"%s\"" (irchat-pj-server-name)))))
  974.  
  975. (defun irchat-pj-server-name ()
  976.   "`serverhost:port'-formatted server name.
  977. When display message of irchat-server.
  978. If port is omitted, only `serverhost' displays."
  979.   (if (string-match "\\([^:]+\\):\\([^:]+\\):.*" irchat-server)
  980.       (format "%s:%s"
  981.           (substring irchat-server (match-beginning 1) (match-end 1))
  982.           (substring irchat-server (match-beginning 2) (match-end 2)))
  983.     irchat-server))
  984.  
  985. (defun irchat-open-server (host &optional service)
  986.   "Open chat server on HOST.
  987. If HOST is nil, use value of environment variable \"IRCSERVER\".
  988. If optional argument SERVICE is non-nil, open by the service name."
  989.   (let (status
  990.     tmp
  991.     (host (or host (getenv "IRCSERVER"))))
  992.     (setq irchat-status-message-string "")
  993.     (if (and host (assoc host irchat-server-alist)
  994.          (cdr (assoc host irchat-server-alist)))
  995.     (setq host (cdr (assoc host irchat-server-alist))))
  996.     (if (string-match "^\\([^:]+\\):\\([0-9]+\\)\\(.*\\)" host)
  997.     (progn
  998.       (setq tmp (match-string 3 host)
  999.         service (string-to-int (match-string 2 host))
  1000.         host (match-string 1 host))
  1001.       (if (string-match "^:\\(.*\\)" tmp)
  1002.           (if (string= (match-string 1 tmp) "")
  1003.           (setq irchat-ask-for-password t)
  1004.         (setq irchat-ask-for-password nil)
  1005.         (setq irchat-password (match-string 1 tmp))))))
  1006.     (setq irchat-servername host) ;; temporary
  1007.     (message "Connecting to IRC server %s..." host)
  1008.     (if (not host)
  1009.     (setq irchat-status-message-string "IRC server is not specified.")
  1010.       (if (irchat-open-server-internal host service)
  1011.       (let (password)
  1012.         (pure-irc-send-init)
  1013.         (pure-irc-send-create-buffer irchat-server-process host)
  1014.         (setq irchat-after-registration nil)
  1015.         (if irchat-pj-enable-undernet-server
  1016.         (setq status t)
  1017.           (irchat-send "PING :%s" host)
  1018.           (setq status (irchat-wait-for-response "^:[^ ]+ [4P][5O][1N][ G]")))
  1019.         (if (not status)
  1020.         ;; We have to close connection here, since the function
  1021.         ;;  `irchat-server-opened' may return incorrect status.
  1022.         (irchat-close-server-internal)
  1023.           (setq irchat-after-registration t)
  1024.           (set-process-sentinel irchat-server-process 'irchat-sentinel)
  1025.           ;;(set-process-filter   irchat-server-process 'irchat-pj-filter)
  1026.           (pure-pr-filter-set-filter irchat-server-process 'irchat-pj-parser)
  1027.           (setq password
  1028.             (if (or irchat-ask-for-password irchat-reconnect-with-password)
  1029.             (irchat-read-passwd "Server Password: ")
  1030.  
  1031.               irchat-password))
  1032.           (and password
  1033.            (stringp password)
  1034.            (not (string= "" password))
  1035.            (irchat-send "PASS %s" password))
  1036.           (setq irchat-reconnect-with-password nil)
  1037.            (irchat-send "USER %s * * :%s" 
  1038.                 (or (user-real-login-name) "Nobody")
  1039.                 (if (and irchat-name (not (string= irchat-name "")))
  1040.                     irchat-name "Poor user"))
  1041.           (setq irchat-trying-nickname irchat-nickname)
  1042.           (irchat-send "NICK %s" irchat-nickname)
  1043.           (setq irchat-after-registration t)))))
  1044.     status))
  1045.  
  1046.  
  1047. (defun irchat-close-server ()
  1048.   "Close chat server."
  1049.   (unwind-protect
  1050.       (progn
  1051.     ;; Un-set default sentinel function before closing connection.
  1052.     (and irchat-server-process
  1053.          (eq 'irchat-sentinel
  1054.          (process-sentinel irchat-server-process))
  1055.          (set-process-sentinel irchat-server-process nil))
  1056.     ;; We cannot send QUIT command unless the process is running.
  1057.     (if (irchat-server-opened)
  1058.         (irchat-send "QUIT")))
  1059.     (if (boundp 'pure-irc-dcc-process-list)
  1060.     (pure-irc-dcc-process-kill-all irchat-server-process t))
  1061.     (pure-irc-send-delete-buffer irchat-server-process)
  1062.     (irchat-close-server-internal)))
  1063.  
  1064.  
  1065. (defun irchat-server-opened ()
  1066.   "Return server process status, T or NIL.
  1067. If the stream is opened, return T, otherwise return NIL."
  1068.   (and irchat-server-process
  1069.        (memq (process-status irchat-server-process) '(open run))))
  1070.  
  1071.  
  1072. (defun irchat-open-server-internal (host service)
  1073.   "Open connection to chat server on HOST by SERVICE (default is irc)."
  1074.   (pure-cs-set-noconv-service service)
  1075.   (condition-case err 
  1076.       (save-excursion
  1077.     ;; Initialize communication buffer.
  1078.     (setq irchat-server-buffer (get-buffer-create " *IRC*"))
  1079.     (set-buffer irchat-server-buffer)
  1080.     (kill-all-local-variables)
  1081.     (erase-buffer)
  1082.     (pure-cs-buffer-unibyte)
  1083.     (if (string-match "^[^\\[]" host)
  1084.         (setq irchat-server-process
  1085.           (open-network-stream "IRC" (current-buffer) host service))
  1086.       (if (not (string-match
  1087.             "^\\[\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\)\\]$" host))
  1088.           (setq irchat-status-message-string "Use [nnn.nnn.nnn.nnn]"
  1089.             irchat-server-process nil)
  1090.         (setq irchat-server-process
  1091.           (start-process "IRC" (current-buffer)
  1092.                  irchat-pj-dcc-program "tcp" "connect"
  1093.                  (match-string 1 host) 
  1094.                  (format "%s" service)))
  1095.         (set-process-sentinel irchat-server-process
  1096.                   'irchat-sentinel)))
  1097.     (setq irchat-server-name host)
  1098. ;;     (setq irchat-pj-chans (pure-ds-make 'irc-chan)
  1099. ;;           irchat-pj-users (pure-ds-make 'irc-user))
  1100.     (run-hooks 'irchat-server-hook)
  1101.     ;; Return the server process.
  1102.     irchat-server-process)
  1103.     (error (setq irchat-status-message-string (car (cdr err)))
  1104.        nil)))
  1105.  
  1106.  
  1107. (defun irchat-close-server-internal ()
  1108.   "Close connection to chat server."
  1109.   (if irchat-server-process
  1110.       (delete-process irchat-server-process))
  1111.   (if irchat-server-buffer
  1112.       (kill-buffer irchat-server-buffer))
  1113.   (setq irchat-server-buffer nil
  1114.     irchat-server-process nil))
  1115.  
  1116.  
  1117. (defun irchat-wait-for-response (regexp)
  1118.   "Wait for server response which matches REGEXP."
  1119.   (save-excursion
  1120.     (let ((status t)
  1121.       (wait t))
  1122.       (set-buffer irchat-server-buffer)
  1123.       (irchat-accept-response)
  1124.       (while wait
  1125.     (goto-char (point-min))
  1126.     (cond ((looking-at "ERROR")
  1127.            (setq status nil)
  1128.            (setq wait nil))
  1129.           ((looking-at ".")
  1130.            (setq wait nil))
  1131.           (t (irchat-accept-response))))
  1132.       ;; Save status message.
  1133.       (end-of-line)
  1134.       (setq irchat-status-message-string
  1135.         (buffer-substring (point-min) (point)))
  1136.       (if status
  1137.       (progn
  1138.         (setq wait t)
  1139.         (while wait
  1140.           (goto-char (point-max))
  1141.           (forward-line -1)        ;(beginning-of-line)
  1142.           (if (looking-at regexp)
  1143.           (setq wait nil)
  1144.         (message "IRCHAT: Reading...")
  1145.         (irchat-accept-response)
  1146.         (message "")))
  1147.         ;; Successfully received server response.
  1148.         (delete-region (point-min) (point-max))
  1149.         t)))))
  1150.  
  1151.  
  1152. (defun irchat-accept-response ()
  1153.   "Read response of server. Only used at startup time"
  1154.   ;; To deal with server process exiting before accept-process-output is called.
  1155.   (or (memq (process-status irchat-server-process) '(open run))
  1156.       (if (not irchat-reconnect-automagic)
  1157.       (error "IRCHAT: Connection closed.")
  1158.     (if irchat-grow-tail
  1159.         (irchat 'always)
  1160.       (irchat))))
  1161.   (condition-case errorcode
  1162.       (accept-process-output irchat-server-process)
  1163.     (error
  1164.      (cond ((string-equal "select error: Invalid argument" (nth 1 errorcode))
  1165.         ;; Ignore select error.
  1166.         nil)
  1167.        (t (signal (car errorcode) (cdr errorcode)))))))
  1168.  
  1169.  
  1170. (defun irchat-send-poll (now)
  1171.   (setq irchat-last-poll-minute now
  1172.         irchat-nick-alist nil
  1173.         irchat-channel-alist nil)
  1174.   (irchat-send "PING irchat-polling\nNAMES\n"))
  1175.  
  1176. ;;; As the server PINGs us regularly, we can be sure that we will 
  1177. ;;; have the opportunity to poll it with a NAMES as often.
  1178. ;;; We do this so that we can keep the irchat-nick-alist up-to-date.
  1179. ;;; We send a PING after the NAMES so that we notice when the final
  1180. ;;; NAMREPLY has come.
  1181. (defun irchat-maybe-poll ()
  1182.   (let* ((now (substring (current-time-string) 14 16))
  1183.          (nowint (string-to-int now))
  1184.          (stampint (mod (+ irchat-last-timestamp
  1185.                            (or irchat-timestamp-interval 0))
  1186.                         60)))
  1187.     ;; Print timestamp, this should use timer.el or something
  1188.     (if (or (not irchat-timestamp-interval)
  1189.             (> stampint nowint)
  1190.             (> (- nowint stampint) 30))
  1191.         nil
  1192.       (let ((obuf (current-buffer)))
  1193.         (if (get-buffer irchat-Dialogue-buffer)
  1194.             (progn
  1195.               (set-buffer irchat-Dialogue-buffer)
  1196.               (setq irchat-last-timestamp stampint)
  1197.               (insert (format "%s\n" (format irchat-timestamp-format 
  1198.                                              (current-time-string))))
  1199.               (set-buffer obuf)))))
  1200.     ;; Update names lists
  1201.     (if (or (not irchat-global-names) irchat-pj-away-p)
  1202.         ;; not polling or away, forget it
  1203.         nil
  1204.       ;; polling, see if enoung time has  passed since last poll, or this is 
  1205.       ;; the first poll
  1206.       (if (not irchat-last-poll-minute)
  1207.           (irchat-send-poll nowint)
  1208.         (if (and (numberp irchat-global-names) 
  1209.                  (> irchat-global-names 0))
  1210.             (if (>= (mod (+ irchat-last-poll-minute irchat-global-names) 60)
  1211.                     nowint)
  1212.                 (irchat-send-poll nowint))
  1213.           (if (not (= nowint irchat-last-poll-minute))
  1214.               (irchat-send-poll nowint)))))))
  1215.  
  1216. (defun irchat-ischannel (chan)
  1217.   (string-match "^[+&#!]" chan))
  1218.  
  1219. (defun irchat-send (&rest args)
  1220.   (apply 'pure-irc-send-register irchat-server-process irchat-pj-cs-encode args))
  1221.  
  1222. (defun irchat-scroll-if-visible (window)
  1223.   (if window (set-window-point window (point-max))))
  1224.  
  1225.  
  1226. (defun irchat-pj-insert-log (&rest msgs)
  1227.   "Insert log message."
  1228.   (irchat-insert (concat "*** " (apply 'format msgs) "\n") nil t))
  1229.  
  1230. (defun irchat-insert0 (message)
  1231.   (irchat-insert message nil t))
  1232.  
  1233. (defun irchat-insert-special (string &optional pattern)
  1234.   (irchat-insert string irchat-Private-buffer pattern))
  1235.  
  1236. (defun irchat-insert-allchan (string &optional pattern)
  1237.   (irchat-insert string (cons irchat-Private-buffer
  1238.                   (get (intern irchat-nickname) 'chnl)) pattern))
  1239.  
  1240. (defun irchat-insert (body &optional chans pattern flag head)
  1241.   (let (opoint chan buf win visible)
  1242.     (while chans
  1243.       (if (listp chans)
  1244.       (setq chan (car chans) chans (cdr chans))
  1245.     (setq chan chans chans nil))
  1246.       (if (setq buf (if (bufferp chan) chan (irchat-Channel-exist chan)))
  1247.       (save-excursion
  1248.         (set-buffer buf)
  1249.         (setq opoint (point))
  1250.         (goto-char (point-max))
  1251.         (if (setq win (get-buffer-window buf))
  1252.           (if (or irchat-buggy-emacs-pos-visible-in-window-p
  1253.               (pos-visible-in-window-p (point-max) win))
  1254.               (setq visible t)))
  1255.         (let* ((buffer-read-only nil))
  1256.           (if (and (stringp pattern)
  1257.                        (stringp irchat-previous-pattern)
  1258.                (string= pattern irchat-previous-pattern))
  1259.           (progn
  1260.             (previous-line 1)
  1261.             (if flag
  1262.             (if irchat-print-time (forward-char 6))
  1263.               (end-of-line))
  1264.             (insert head)
  1265.             (goto-char (point-max)))
  1266.                 (and (eq pattern 'privmsg)
  1267.                      irchat-beep-local
  1268.                      (funcall irchat-pj-sound-bell-function))
  1269.                 (if irchat-print-time
  1270.                     (insert (substring (current-time-string) 11 16) " "))
  1271.                 (if (and (not irchat-display-channel-always)
  1272.                          (string-match "^\\([<>(]\\)[^ ]+:\\([^ :]+ .*\\)" body))
  1273.                     (insert (match-string 1 body) (match-string 2 body) "\n")
  1274.                   (insert body))
  1275.                 (setq irchat-previous-pattern pattern)))
  1276.         (if irchat-freeze-local
  1277.         (goto-char opoint))
  1278.             ;; modified by simm@irc.fan.gr.jp, Sun, 27 Jun 1999
  1279.         (if (setq win (get-buffer-window buf irchat-pj-scroll-condition))
  1280.         (progn
  1281.           (if (or irchat-buggy-emacs-pos-visible-in-window-p
  1282.               (pos-visible-in-window-p (point-max) win))
  1283.               (setq visible t))
  1284.           (if (not irchat-freeze-local)
  1285.               (set-window-point win (point-max)))))
  1286.         (if irchat-suppress-local
  1287.         (setq visible t)))))
  1288.     (or visible
  1289.     (save-excursion
  1290.       (set-buffer irchat-Others-buffer)
  1291.       (if (> (point-max) irchat-others-high-watermark)
  1292.           (let ((buffer-read-only nil))
  1293.         (delete-region 1 (- (point-max) irchat-others-low-watermark))))
  1294.       (goto-char (point-max))
  1295.       (let ((buffer-read-only nil))
  1296.         (if irchat-print-time
  1297.         (insert (substring (current-time-string) 11 16) " "))
  1298.         (insert body))
  1299.       (setq irchat-previous-pattern nil)
  1300.           ;; begin: modified by simm@irc.fan.gr.jp, Sun, 27 Jun 1999
  1301.           ;;        last-modified by simm@irc.fan.gr.jp, Sat, 3 Jul 1999 
  1302.           (if (setq win (get-buffer-window irchat-Others-buffer irchat-pj-scroll-condition))
  1303.               (let ((cwin nil)
  1304.                     (owin (selected-window)))
  1305.                 (set-window-point win (point-max))
  1306.                 (select-window win)
  1307.                 (recenter (- (window-height) 1))
  1308.                 (and irchat-pj-scroll-condition
  1309.                      (setq cwin (get-buffer-window irchat-Command-buffer
  1310.                                                    irchat-pj-scroll-condition))
  1311.                      (select-window cwin))
  1312.                 (select-window owin)))))
  1313.           ;; end
  1314.     (save-excursion
  1315.       (set-buffer irchat-Dialogue-buffer)
  1316.       (let ((opoint (point)))
  1317.     (goto-char (point-max))
  1318.     (let ((buffer-read-only nil))
  1319.       (if irchat-print-time
  1320.           (insert (substring (current-time-string) 11 16) " "))
  1321.       (insert body))
  1322.     (setq irchat-previous-pattern nil)
  1323.     ;; modified by simm@irc.fan.gr.jp, Sun, 27 Jun 1999
  1324.     (if (setq win (get-buffer-window irchat-Dialogue-buffer irchat-pj-scroll-condition))
  1325.         (if irchat-freeze
  1326.         (goto-char opoint)
  1327.           ;;(set-window-point win (point-max))
  1328.           (if (not (pos-visible-in-window-p (point-max) win))
  1329.           (let ((owin (selected-window)))
  1330.             (select-window win)
  1331.             (goto-char (point-max))
  1332.             (recenter (- (window-height) 1))
  1333.             (select-window owin)))))))))
  1334.  
  1335. (defun irchat-insert-private (to-me partner xmsg)
  1336.   (if (not (irchat-ischannel partner))
  1337.       (if (null to-me)
  1338.       ;; my message to partner
  1339.       (irchat-insert (format ">%s< %s\n" partner xmsg)
  1340.              (or (irchat-Channel-exist partner) irchat-Private-buffer)
  1341.              'my-privmsg)
  1342.     ;; message from partner
  1343.     ;; begin sound extension: modified by kaoru@kaisei.org
  1344.     (if irchat-pj-sound-when-private
  1345.         (or (irchat-Channel-exist partner)
  1346.         (funcall irchat-pj-sound-private-function)))
  1347.     (irchat-insert (format "=%s= %s\n" partner xmsg)
  1348.                (or (irchat-Channel-exist partner) irchat-Private-buffer)
  1349.                'privmsg))
  1350.     ;; my message to channel (partner is channel)
  1351.     (irchat-insert (format ">%s:%s< %s\n"
  1352.                (irchat-chan-virtual partner)
  1353.                irchat-nickname xmsg)
  1354.            partner 'my-privmsg)))
  1355.  
  1356. (defun irchat-pj-insert-dcc-chat (nick msg)
  1357.   "Insert DCC CHAT message."
  1358.   (irchat-insert-private t (concat "=" nick) msg))
  1359.  
  1360. ;;;
  1361. ;;; this function handles default arguments more user friendly
  1362. ;;;
  1363. (defun irchat-pj-cut-nil-from-list (table)
  1364.   (let ((tmp table) (result nil))
  1365.     (while tmp
  1366.       (if (car (car tmp))
  1367.       (setq result (append result (list (car tmp)))))
  1368.       (setq tmp (cdr tmp)))
  1369.     result))
  1370.  
  1371. (defun irchat-pj-completing-read
  1372.   (prompt table &optional predicate require-match initial-input)
  1373.   (completing-read prompt
  1374.            (if (featurep 'xemacs) (irchat-pj-cut-nil-from-list table) table)
  1375.            predicate require-match initial-input))
  1376.  
  1377. (defun irchat-completing-default-read
  1378.   (prompt table predicate require-match initial-input)
  1379.   "completing-read w/ default argument like in 'kill-buffer'"
  1380.   (let ((default-read
  1381.       (irchat-pj-completing-read
  1382.        (if initial-input
  1383.            (format "%s(default %s) "
  1384.                prompt initial-input)
  1385.          (format "%s" prompt))
  1386.        table predicate require-match nil)))
  1387.     (if (and (string= default-read "") initial-input)
  1388.     initial-input
  1389.       default-read)))
  1390.  
  1391. ;;; caesar-region written by phr@prep.ai.mit.edu  Nov 86
  1392. ;;; modified by tower@prep Nov 86
  1393. ;;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
  1394.  
  1395. ;;; irchat-pj-caesar-region by simm@irc.fan.gr.jp for ROT5-13-47-48
  1396. ;;; on Sun, 29 Aug 1999 22:25:51 +0900
  1397. ;;; from mule-caesar-region (in APEL)
  1398. ;;; so, irchat-caesar-region is obsolete.
  1399.  
  1400. (cond ((and (fboundp 'charset-chars) (fboundp 'char-charset))
  1401.        (defsubst irchat-pj-get-rotate-times (chr)
  1402.          (lsh (charset-chars (char-charset chr)) -1)))
  1403.       ((fboundp 'char-leading-char)
  1404.        (defsubst irchat-pj-get-rotate-times (chr)
  1405.          (if (= (logand (nth 2 (character-set (char-leading-char chr))) 1) 1) 48 47)))
  1406.       (t
  1407.        (defsubst irchat-pj-get-rotate-times (chr)
  1408.          47)))
  1409.  
  1410. (if (fboundp 'split-char)
  1411.     (defalias 'irchat-pj-split-char 'split-char)
  1412.   (defun irchat-pj-split-char (chr)
  1413.     "Return list charset and wone or two position-codes-of CHR."
  1414.     (let (dst (p (1- (char-bytes chr))))
  1415.       (while (>= p 1)
  1416.         (setq dst (cons (- (char-component chr p) 128) dst)
  1417.               p (1- p)))
  1418.       (cons (char-leading-char chr) dst))))
  1419.  
  1420. (cond ((and (fboundp 'make-char) (fboundp 'char-charset))
  1421.        (defsubst irchat-pj-rotate-result (chr ret)
  1422.          (make-char (char-charset chr) (car ret) (car (cdr ret)))))
  1423.       ((and (fboundp 'make-character) (fboundp 'char-leading-char))
  1424.        (defsubst irchat-pj-rotate-result (chr ret)
  1425.          (make-character (char-leading-char chr) (car ret) (car (cdr ret)))))
  1426.       (t
  1427.        (defsubst irchat-pj-rotate-result (chr ret)
  1428.          (+ 128 ret))))
  1429.  
  1430. (defun irchat-pj-caesar-region (start end &optional num-rotate ascii-rotate)
  1431.   "Caesar rotation of current region.
  1432. Optional argument NUM-ROTATE is rotation-size for Latin number \(0-9).
  1433. Optional argument ASCII-ROTATE is rotation-size for Latin alphabet
  1434. \(A-Z and a-z).  For non-ASCII text, ROT-N/2 will be performed in any
  1435. case (N=charset-chars; 94 for 94 or 94x94 graphic character set; 96
  1436. for 96 or 96x96 graphic character set).
  1437.  
  1438. Default NUM-ROTATE is 5, and ASCII-ROTATE is 13, so this performes ROT5-13-47-48."
  1439.   (interactive "r\nP")
  1440.   (setq ascii-rotate (if ascii-rotate
  1441.              (mod ascii-rotate 26)
  1442.                13)
  1443.         num-rotate (if num-rotate
  1444.                        (mod num-rotate 10)
  1445.                      5))
  1446.   (save-excursion
  1447.     (save-restriction
  1448.       (narrow-to-region start end)
  1449.       (goto-char start)
  1450.       (while (< (point)(point-max))
  1451.     (let* ((chr (char-after (point))))
  1452.       (cond ((and (<= ?A chr) (<= chr ?Z))
  1453.          (setq chr (+ chr ascii-rotate))
  1454.          (if (> chr ?Z)
  1455.              (setq chr (- chr 26)))
  1456.          (delete-char 1)
  1457.          (insert chr))
  1458.         ((and (<= ?a chr) (<= chr ?z))
  1459.          (setq chr (+ chr ascii-rotate))
  1460.          (if (> chr ?z)
  1461.              (setq chr (- chr 26)))
  1462.          (delete-char 1)
  1463.          (insert chr))
  1464.                 ((and (<= ?0 chr) (<= chr ?9))
  1465.                  (setq chr (+ chr num-rotate))
  1466.                  (if (> chr ?9)
  1467.                      (setq chr (- chr 10))))
  1468.         ((<= chr ?\x9f)
  1469.          (forward-char))
  1470.         (t
  1471.          (let* ((multi-rotate (irchat-pj-get-rotate-times chr))
  1472.             (ret (mapcar (function
  1473.                       (lambda (octet)
  1474.                     (if (< octet 80)
  1475.                         (+ octet multi-rotate)
  1476.                       (- octet multi-rotate))))
  1477.                      (cdr (irchat-pj-split-char chr)))))
  1478.            (delete-char 1)
  1479.                    (insert (irchat-pj-rotate-result chr ret)))))))))
  1480.   (goto-char end))
  1481.  
  1482. (defun irchat-pj-caesar-string (string &optional num-rotate ascii-rotate)
  1483.   (interactive)
  1484.   (let (beg end str)
  1485.     (save-excursion
  1486.       (if (get-buffer irchat-pj-CONVERT-buffer)
  1487.           (set-buffer irchat-pj-CONVERT-buffer)
  1488.         (get-buffer-create irchat-pj-CONVERT-buffer))
  1489.       (setq beg (point))
  1490.       (insert string)
  1491.       (setq end (point))
  1492.       (irchat-pj-caesar-region beg end num-rotate ascii-rotate)
  1493.       (setq str (buffer-substring beg end))
  1494.       (delete-region beg end))
  1495.     str))
  1496.  
  1497. ;;;
  1498. ;;; this function from ange-ftp.el by Andy Norman (ange@hplb.hpl.hp.com)
  1499. ;;;
  1500. (defun irchat-read-passwd (prompt)
  1501.   "Read a password from the user. Echos a . for each character typed.
  1502. End with RET, LFD, or ESC. DEL or C-h rubs out."
  1503.   (let ((pass "")
  1504.     (c 0)
  1505.     (echo-keystrokes 0)
  1506.     (cursor-in-echo-area t))
  1507.     (while (and (/= c ?\r) (/= c ?\n) (/= c ?\e))
  1508.       (message "%s%s"
  1509.            prompt
  1510.            (make-string (length pass) ?.))
  1511.       (setq c (read-char))
  1512.       (if (and (/= c ?\b) (/= c ?\177))
  1513.       (setq pass (concat pass (char-to-string c)))
  1514.     (if (> (length pass) 0)
  1515.         (setq pass (substring pass 0 -1)))))
  1516.     (substring pass 0 -1)))
  1517.  
  1518. ;;;
  1519. ;;; save log by negi@KU3G.org, Tue, 1 Jun 1999
  1520. ;;;   last modify by simm@irc.fan.gr.jp, Sat, 5 Jun 1999
  1521. ;;;
  1522.  
  1523. (defun irchat-pj-save-log ()
  1524.   "Save log according to irchat-pj-save-log-channel-alist.
  1525. See also irchat-pj-save-log-channel-alist."
  1526.   (interactive)
  1527.   (let ((cur nil)
  1528.         (backup (current-buffer)))
  1529.     (or (eq ?/ (elt irchat-pj-save-log-directory
  1530.                     (1- (length irchat-pj-save-log-directory))))
  1531.         (setq irchat-pj-save-log-directory
  1532.               (concat irchat-pj-save-log-directory "/")))
  1533.     (unwind-protect
  1534.         (mapcar
  1535.          '(lambda (buf-list)
  1536.             (setq cur (or (get-buffer (concat " IRC:" (car buf-list)))
  1537.                           (get-buffer (concat " IRC: " (car buf-list)))))
  1538.             (if cur
  1539.                 (progn
  1540.                   (set-buffer cur)
  1541.                   (append-to-file
  1542.                    (point-min) (point-max)
  1543.                    (concat (expand-file-name irchat-pj-save-log-directory)
  1544.                            (cdr buf-list)
  1545.                            "-"
  1546.                            (format-time-string "%m%d" (current-time)))))))
  1547.          irchat-pj-save-log-channel-alist)
  1548.       (set-buffer backup)
  1549.       (message ""))))
  1550.                      
  1551. ;; That's all
  1552. (provide 'irchat)
  1553.  
  1554. ;;;
  1555. ;;; eof
  1556. ;;;
  1557.