Mercurial > emacs
view lisp/erc/erc-services.el @ 80455:4b3759b14cc7
(mac_end_cg_clip): Add argument F. All uses changed.
(mac_begin_cg_clip, mac_end_cg_clip): Allow null GC.
(mac_invert_rectangle, mac_compute_glyph_string_overhangs)
(mac_load_query_font): Use them instead of SetPortWindowPort.
(mac_clear_window) [!USE_CG_DRAWING]: Likewise.
(mac_draw_image_string_cg): Call CGContextSetTextMatrix.
(x_update_begin, x_update_end): Call mac_update_begin and
mac_update_end.
(XTframe_up_to_date): Call mac_frame_up_to_date.
(XTring_bell): Use mac_alert_sound_play.
(note_mouse_movement): Use mac_get_frame_bounds.
(XTmouse_position): Use mac_get_frame_mouse.
(x_scroll_bar_create): Use mac_create_scroll_bar.
(x_scroll_bar_remove): Use mac_dispose_scroll_bar.
(XTset_vertical_scroll_bar): Use mac_set_scroll_bar_bounds and
mac_redraw_scroll_bar.
(mac_move_window_with_gravity) [USE_MAC_TOOLBAR]: Use mac_move_window
instead of MoveWindow.
(mac_handle_size_change) [TARGET_API_MAC_CARBON]:
Use mac_reposition_hourglass.
(x_set_offset): Use mac_move_window_structure instead of
MoveWindowStructure.
(x_set_window_size): Use mac_size_window instead of SizeWindow.
(x_set_mouse_pixel_position) [MAC_OSX]:
Use mac_convert_frame_point_to_global.
(x_raise_frame): Use mac_bring_window_to_front instead of BringToFront.
(x_lower_frame): Use mac_send_window_behind instead of SendBehind.
(mac_handle_visibility_change): Use Window instead of WindowRef.
Use mac_is_window_visible/mac_is_window_collapsed instead of
IsWindowVisible/IsWindowCollapsed, respectively.
Use mac_collapse_window/mac_show_window instead of
CollapseWindow/ShowWindow, respectively.
(x_make_frame_invisible): Use mac_hide_window instead of HideWindow.
(x_iconify_frame): Use mac_show_window instead of ShowWindow.
Use mac_collapse_window instead of CollapseWindow.
(x_free_frame_resources): Use Window instead of WindowRef.
Use mac_dispose_frame_window. Clean up focus-related variables before
calling mac_dispose_frame_window.
(do_zoom_window) [MAC_OS8]: Use mac_clear_area instead of
mac_clear_window.
(mac_initialize): Use mac_toolbox_initialize instead of
initializing any_help_event_p and calling init_apple_event_handler,
init_tsm, and init_menu_bar.
(any_help_event_p, last_window, save_port_clip_region)
(read_socket_inev, saved_menu_event_location): Move variables to
mactoolbox.c.
(last_scroll_bar_part, scroll_bar_timer)
(scroll_bar_timer_event_posted_p) [USE_TOOLKIT_SCROLL_BARS]: Likewise.
(font_panel_shown_p) [USE_MAC_FONT_PANEL]: Likewise.
(tsm_document_id) [USE_MAC_TSM]: Likewise.
(mouse_region) [!TARGET_API_MAC_CARBON]: Likewise.
(mac_window_to_frame, DEFAULT_NUM_COLS, MIN_DOC_SIZE, MAX_DOC_SIZE):
Move defines to mactoolbox.c.
(FRAME_CG_CONTEXT) [USE_CG_DRAWING]: Likewise.
(SCROLL_BAR_FIRST_DELAY, SCROLL_BAR_CONTINUOUS_DELAY)
[USE_TOOLKIT_SCROLL_BARS]: Likewise.
(TOOLBAR_IDENTIFIER, TOOLBAR_ICON_ITEM_IDENTIFIER)
(TOOLBAR_ITEM_COMMAND_ID_OFFSET, TOOLBAR_ITEM_COMMAND_ID_P)
(TOOLBAR_ITEM_COMMAND_ID_VALUE, TOOLBAR_ITEM_MAKE_COMMAND_ID)
[USE_MAC_TOOLBAR]: Likewise.
(M_APPLE, I_ABOUT, EXTRA_STACK_ALLOC, ARGV_STRING_LIST_ID)
(RAM_TOO_LARGE_ALERT_ID, ABOUT_ALERT_ID): Move defines to macgui.h
(x_flush, is_emacs_window, mac_begin_clip, mac_end_clip)
(x_scroll_bar_handle_click, x_scroll_bar_report_motion)
(mac_get_window_bounds, do_window_update, is_emacs_window)
(do_grow_window, do_zoom_window, install_window_handler)
(remove_window_handler, XTread_socket, init_menu_bar): Move functions
to mactoolbox.c.
(mac_flush_display_optional, mac_begin_cg_clip, mac_end_cg_clip)
(mac_prepare_for_quickdraw) [USE_CG_DRAWING]: Likewise.
(mac_scroll_area, mac_event_to_emacs_modifiers, mac_get_mouse_btn)
(mac_convert_event_ref, mac_get_ideal_size, mac_store_drag_event)
(mac_handle_window_event, mac_handle_keyboard_event)
(mac_handle_command_event, mac_handle_mouse_event)
(install_application_handler, mac_post_mouse_moved_event)
[TARGET_API_MAC_CARBON]: Likewise.
(scroll_bar_timer_callback, install_scroll_bar_timer)
(set_scroll_bar_timer, control_part_code_to_scroll_bar_part)
(construct_scroll_bar_click, get_control_part_bounds)
(x_scroll_bar_handle_press, x_scroll_bar_handle_release)
(x_scroll_bar_handle_drag, x_set_toolkit_scroll_bar_thumb)
[USE_TOOLKIT_SCROLL_BARS]: Likewise.
(x_scroll_bar_set_handle, x_scroll_bar_note_movement)
[!USE_TOOLKIT_SCROLL_BARS]: Likewise.
(mac_handle_toolbar_event, mac_create_frame_tool_bar)
(update_frame_tool_bar, free_frame_tool_bar)
(mac_tool_bar_note_mouse_movement, mac_handle_toolbar_command_event)
[USE_MAC_TOOLBAR]: Likewise.
(mac_font_panel_visible_p, mac_handle_font_event)
(mac_show_hide_font_panel, mac_set_font_info_for_selection)
[USE_MAC_FONT_PANEL]: Likewise.
(mac_handle_text_input_event, init_tsm) [USE_MAC_TSM]: Likewise.
(do_apple_menu, mac_wait_next_event) [!TARGET_API_MAC_CARBON]: Likewise.
(mac_store_service_event) [MAC_OSX]: Likewise.
(last_mouse_glyph, last_mouse_glyph_frame, last_mouse_scroll_bar)
(last_mouse_movement_time, input_signal_count)
(mac_screen_config_changed, Qhi_command, Qtoolbar_switch_mode)
(Qservice, Qpaste, Qperform, keycode_to_xkeysym_table): Make variables
non-static.
(Qpanel_closed, Qselection) [USE_MAC_FONT_PANEL]: Likewise.
(Qtext_input, Vmac_ts_active_input_overlay, Qupdate_active_input_area)
(Qunicode_for_key_event, Vmac_ts_script_language_on_focus)
(saved_ts_script_language_on_focus) [USE_MAC_TSM]: Likewise.
(mac_focus_changed, note_mouse_movement, mac_focus_frame)
(mac_handle_origin_change, mac_handle_size_change)
(mac_handle_visibility_change, mac_to_emacs_modifiers)
(mac_mapped_modifiers, mac_get_emulated_btn, do_keystroke)
(mac_get_screen_info): Make functions non-static.
(mac_move_window_with_gravity, mac_get_window_origin_with_gravity)
(mac_image_spec_to_cg_image) [USE_MAC_TOOLBAR]: Likewise.
(mac_store_event_ref_as_apple_event) [TARGET_API_MAC_CARBON]: Likewise.
(Qwindow, mac_ready_for_apple_events): Move externs to mactoolbox.c.
(Qbefore_string) [USE_MAC_TSM]: Likewise.
(mac_toolbox_initialize, x_scroll_bar_report_motion, XTread_socket):
Add externs.
(mac_flush_display_optional) [USE_CG_DRAWING]: Likewise.
(install_drag_handler, remove_drag_handler, install_service_handler)
(install_menu_target_item_handler): Remove externs.
(XSetWindowBackground): Rename to mac_set_frame_window_background.
Take frame as argument instead of display and window.
Move to mactoolbox.c.
(mac_restore_keyboard_input_source, mac_save_keyboard_input_source)
[USE_MAC_TSM]: New functions created from mac_tsm_resume and
mac_tsm_suspend, respectively.
(mac_tsm_resume, mac_tsm_suspend) [USE_MAC_TSM]: Use them.
Move to mactoolbox.c.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Sun, 06 Apr 2008 01:58:59 +0000 |
parents | 5f92874bde07 |
children | 107ccd98fa12 |
line wrap: on
line source
;;; erc-services.el --- Identify to NickServ ;; Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; There are two ways to go about identifying yourself automatically to ;; NickServ with this module. The more secure way is to listen for identify ;; requests from the user NickServ. Another way is to identify yourself to ;; NickServ directly after a successful connection and every time you change ;; your nickname. This method is rather insecure, though, because no checks ;; are made to test if NickServ is the real NickServ for a given network or ;; server. ;; As a default, ERC has the data for the official nickname services on the ;; networks Austnet, BrasNET, Dalnet, freenode, GalaxyNet, and Slashnet. ;; You can add more by using M-x customize-variable RET erc-nickserv-alist. ;; Usage: ;; ;; Put into your .emacs: ;; ;; (require 'erc-services) ;; (erc-services-mode 1) ;; ;; Add your nickname and NickServ password to `erc-nickserv-passwords'. ;; Using the freenode network as an example: ;; ;; (setq erc-nickserv-passwords '((freenode (("nickname" "password"))))) ;; ;; The default automatic identification mode is autodetection of NickServ ;; identify requests. Set the variable `erc-nickserv-identify-mode' if ;; you'd like to change this behavior. You can also change the way ;; automatic identification is handled by using: ;; ;; M-x erc-nickserv-identify-mode ;; ;; If you'd rather not identify yourself automatically but would like access ;; to the functions contained in this file, just load this file without ;; enabling `erc-services-mode'. ;; ;;; Code: (require 'erc) (require 'erc-networks) (eval-when-compile (require 'cl)) ;; Customization: (defgroup erc-services nil "Configuration for IRC services. On some networks, there exists a special type of automated irc bot, called Services. Those usually allow you to register your nickname, post/read memos to other registered users who are currently offline, and do various other things. This group allows you to set variables to somewhat automate communication with those Services." :group 'erc) (defcustom erc-nickserv-identify-mode 'both "The mode which is used when identifying to Nickserv. Possible settings are:. 'autodetect - Identify when the real Nickserv sends an identify request. 'nick-change - Identify when you log in or change your nickname. 'both - Do the former if the network supports it, otherwise do the latter. nil - Disables automatic Nickserv identification. You can also use M-x erc-nickserv-identify-mode to change modes." :group 'erc-services :type '(choice (const autodetect) (const nick-change) (const both) (const nil)) :set (lambda (sym val) (set sym val) ;; avoid recursive load at startup (when (featurep 'erc-services) (erc-nickserv-identify-mode val)))) ;;;###autoload (autoload 'erc-services-mode "erc-services" nil t) (define-erc-module services nickserv "This mode automates communication with services." ((erc-nickserv-identify-mode erc-nickserv-identify-mode)) ((remove-hook 'erc-server-NOTICE-functions 'erc-nickserv-identify-autodetect) (remove-hook 'erc-after-connect 'erc-nickserv-identify-on-connect) (remove-hook 'erc-nick-changed-functions 'erc-nickserv-identify-on-nick-change))) ;;;###autoload (defun erc-nickserv-identify-mode (mode) "Set up hooks according to which MODE the user has chosen." (interactive (list (intern (completing-read "Choose Nickserv identify mode (RET to disable): " '(("autodetect") ("nick-change") ("both")) nil t)))) (cond ((eq mode 'autodetect) (setq erc-nickserv-identify-mode 'autodetect) (add-hook 'erc-server-NOTICE-functions 'erc-nickserv-identify-autodetect) (remove-hook 'erc-nick-changed-functions 'erc-nickserv-identify-on-nick-change) (remove-hook 'erc-after-connect 'erc-nickserv-identify-on-connect)) ((eq mode 'nick-change) (setq erc-nickserv-identify-mode 'nick-change) (add-hook 'erc-after-connect 'erc-nickserv-identify-on-connect) (add-hook 'erc-nick-changed-functions 'erc-nickserv-identify-on-nick-change) (remove-hook 'erc-server-NOTICE-functions 'erc-nickserv-identify-autodetect)) ((eq mode 'both) (setq erc-nickserv-identify-mode 'both) (add-hook 'erc-server-NOTICE-functions 'erc-nickserv-identify-autodetect) (add-hook 'erc-after-connect 'erc-nickserv-identify-on-connect) (add-hook 'erc-nick-changed-functions 'erc-nickserv-identify-on-nick-change)) (t (setq erc-nickserv-identify-mode nil) (remove-hook 'erc-server-NOTICE-functions 'erc-nickserv-identify-autodetect) (remove-hook 'erc-after-connect 'erc-nickserv-identify-on-connect) (remove-hook 'erc-nick-changed-functions 'erc-nickserv-identify-on-nick-change)))) (defcustom erc-prompt-for-nickserv-password t "Ask for the password when identifying to NickServ." :group 'erc-services :type 'boolean) (defcustom erc-nickserv-passwords nil "Passwords used when identifying to NickServ automatically. Example of use: (setq erc-nickserv-passwords '((freenode ((\"nick-one\" . \"password\") (\"nick-two\" . \"password\"))) (DALnet ((\"nick\" . \"password\")))))" :group 'erc-services :type '(repeat (list :tag "Network" (choice :tag "Network name" (const Ars) (const Austnet) (const Azzurra) (const BitlBee) (const BRASnet) (const DALnet) (const freenode) (const GalaxyNet) (const iip) (const OFTC) (const QuakeNet) (const SlashNET) (symbol :tag "Network name")) (repeat :tag "Nickname and password" (cons :tag "Identity" (string :tag "Nick") (string :tag "Password")))))) ;; Variables: (defcustom erc-nickserv-alist '((Ars nil nil "Census" "IDENTIFY" nil nil) (Austnet "NickOP!service@austnet.org" "/msg\\s-NickOP@austnet.org\\s-identify\\s-<password>" "nickop@austnet.org" "identify" nil nil) (Azzurra "NickServ!service@azzurra.org" "/ns\\s-IDENTIFY\\s-password" "NickServ" "IDENTIFY" nil nil) (BitlBee nil nil "&bitlbee" "identify" nil nil) (BRASnet "NickServ!services@brasnet.org" "/NickServ\\s-IDENTIFY\\s-senha" "NickServ" "IDENTIFY" nil "") (DALnet "NickServ!service@dal.net" "/msg\\s-NickServ@services.dal.net\\s-IDENTIFY\\s-<password>" "NickServ@services.dal.net" "IDENTIFY" nil nil) (freenode "NickServ!NickServ@services." "/msg\\s-NickServ\\s-IDENTIFY\\s-<password>" "NickServ" "IDENTIFY" nil nil) (GalaxyNet "NS!nickserv@galaxynet.org" "Please\\s-change\\s-nicks\\s-or\\s-authenticate." "NS@services.galaxynet.org" "AUTH" t nil) (iip "Trent@anon.iip" "type\\s-/squery\\s-Trent\\s-identify\\s-<password>" "Trent@anon.iip" "IDENTIFY" nil "SQUERY") (OFTC "NickServ!services@services.oftc.net" "type\\s-/msg\\s-NickServ\\s-IDENTIFY\\s-password." "NickServ" "IDENTIFY" nil nil) (QuakeNet nil nil "Q@CServe.quakenet.org" "auth" t nil) (SlashNET "NickServ!services@services.slashnet.org" "/msg\\s-NickServ\\s-IDENTIFY\\s-password" "NickServ@services.slashnet.org" "IDENTIFY" nil nil)) "Alist of NickServer details, sorted by network. Every element in the list has the form \(SYMBOL NICKSERV REGEXP NICK KEYWORD USE-CURRENT ANSWER) SYMBOL is a network identifier, a symbol, as used in `erc-networks-alist'. NICKSERV is the description of the nickserv in the form nick!user@host. REGEXP is a regular expression matching the message from nickserv. NICK is nickserv's nickname. Use nick@server where necessary/possible. KEYWORD is the keyword to use in the reply message to identify yourself. USE-CURRENT indicates whether the current nickname must be used when identifying. ANSWER is the command to use for the answer. The default is 'privmsg. This last element is optional." :group 'erc-services :type '(repeat (list :tag "Nickserv data" (symbol :tag "Network name") (choice (string :tag "Nickserv's nick!user@host") (const :tag "No message sent by Nickserv" nil)) (choice (regexp :tag "Identify request sent by Nickserv") (const :tag "No message sent by Nickserv" nil)) (string :tag "Identify to") (string :tag "Identify keyword") (boolean :tag "Use current nick in identify message?") (choice :tag "Command to use (optional)" (string :tag "Command") (const :tag "No special command necessary" nil))))) (defsubst erc-nickserv-alist-sender (network &optional entry) (nth 1 (or entry (assoc network erc-nickserv-alist)))) (defsubst erc-nickserv-alist-regexp (network &optional entry) (nth 2 (or entry (assoc network erc-nickserv-alist)))) (defsubst erc-nickserv-alist-nickserv (network &optional entry) (nth 3 (or entry (assoc network erc-nickserv-alist)))) (defsubst erc-nickserv-alist-ident-keyword (network &optional entry) (nth 4 (or entry (assoc network erc-nickserv-alist)))) (defsubst erc-nickserv-alist-use-nick-p (network &optional entry) (nth 5 (or entry (assoc network erc-nickserv-alist)))) (defsubst erc-nickserv-alist-ident-command (network &optional entry) (nth 6 (or entry (assoc network erc-nickserv-alist)))) ;; Functions: (defun erc-nickserv-identify-autodetect (proc parsed) "Check for a NickServ identify request everytime a notice is received. Make sure it is the real NickServ for this network and that it has specifically asked the user to IDENTIFY. If `erc-prompt-for-nickserv-password' is non-nil, prompt the user for the password for this nickname, otherwise try to send it automatically." (unless (and (null erc-nickserv-passwords) (null erc-prompt-for-nickserv-password)) (let* ((network (erc-network)) (sender (erc-nickserv-alist-sender network)) (identify-regex (erc-nickserv-alist-regexp network)) (sspec (erc-response.sender parsed)) (nick (car (erc-response.command-args parsed))) (msg (erc-response.contents parsed))) ;; continue only if we're sure it's the real nickserv for this network ;; and it's asked us to identify (when (and sender (equal sspec sender) (string-match identify-regex msg)) (erc-log "NickServ IDENTIFY request detected") (erc-nickserv-call-identify-function nick) nil)))) (defun erc-nickserv-identify-on-connect (server nick) "Identify to Nickserv after the connection to the server is established." (unless (or (and (null erc-nickserv-passwords) (null erc-prompt-for-nickserv-password)) (and (eq erc-nickserv-identify-mode 'both) (erc-nickserv-alist-regexp (erc-network)))) (erc-nickserv-call-identify-function nick))) (defun erc-nickserv-identify-on-nick-change (nick old-nick) "Identify to Nickserv whenever your nick changes." (unless (or (and (null erc-nickserv-passwords) (null erc-prompt-for-nickserv-password)) (and (eq erc-nickserv-identify-mode 'both) (erc-nickserv-alist-regexp (erc-network)))) (erc-nickserv-call-identify-function nick))) (defun erc-nickserv-call-identify-function (nickname) "Call `erc-nickserv-identify' interactively or run it with NICKNAME's password. The action is determined by the value of `erc-prompt-for-nickserv-password'." (if erc-prompt-for-nickserv-password (call-interactively 'erc-nickserv-identify) (when erc-nickserv-passwords (erc-nickserv-identify (cdr (assoc nickname (nth 1 (assoc (erc-network) erc-nickserv-passwords)))))))) ;;;###autoload (defun erc-nickserv-identify (password) "Send an \"identify <PASSWORD>\" message to NickServ. When called interactively, read the password using `read-passwd'." (interactive (list (read-passwd (format "NickServ password for %s on %s (RET to cancel): " (erc-current-nick) (or (and (erc-network) (symbol-name (erc-network))) "Unknown network"))))) (when (and password (not (string= "" password))) (let* ((erc-auto-discard-away nil) (network (erc-network)) (nickserv-info (assoc network erc-nickserv-alist)) (nickserv (or (erc-nickserv-alist-nickserv nil nickserv-info) "NickServ")) (identify-word (or (erc-nickserv-alist-ident-keyword nil nickserv-info) "IDENTIFY")) (nick (if (erc-nickserv-alist-use-nick-p nil nickserv-info) (concat (erc-current-nick) " ") "")) (msgtype (or (erc-nickserv-alist-ident-command nil nickserv-info) "PRIVMSG"))) (erc-message msgtype (concat nickserv " " identify-word " " nick password))))) (provide 'erc-services) ;;; erc-services.el ends here ;; ;; Local Variables: ;; indent-tabs-mode: t ;; tab-width: 8 ;; End: ;; arch-tag: d401c8aa-d938-4255-96a9-3efb64c47e58