]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-button.el
*** empty log message ***
[gnu-emacs] / lisp / erc / erc-button.el
index 6c6998a3afc388d1f037b7b620def27293dbc706..4fb4c1d11492747a5779d1a297b5c9b6413b6fb9 100644 (file)
@@ -1,7 +1,7 @@
 ;; erc-button.el --- A way of buttonizing certain things in ERC buffers
 
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2006 Free Software Foundation, Inc.
+;;   2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Mario Lang <mlang@delysid.org>
 ;; Keywords: irc, button, url, regexp
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, 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
@@ -20,9 +20,7 @@
 ;; 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.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
   "This mode buttonizes all messages according to `erc-button-alist'."
   ((add-hook 'erc-insert-modify-hook 'erc-button-add-buttons 'append)
    (add-hook 'erc-send-modify-hook 'erc-button-add-buttons 'append)
-   (add-hook 'erc-complete-functions 'erc-button-next))
+   (add-hook 'erc-complete-functions 'erc-button-next)
+   (add-hook 'erc-mode-hook 'erc-button-setup))
   ((remove-hook 'erc-insert-modify-hook 'erc-button-add-buttons)
    (remove-hook 'erc-send-modify-hook 'erc-button-add-buttons)
-   (remove-hook 'erc-complete-functions 'erc-button-next)))
-
-;; Make XEmacs use `erc-button-face'.
-(when (featurep 'xemacs)
-  (add-hook 'erc-mode-hook
-            (lambda () (set (make-local-variable 'widget-button-face) nil))))
+   (remove-hook 'erc-complete-functions 'erc-button-next)
+   (remove-hook 'erc-mode-hook 'erc-button-setup)
+   (when (featurep 'xemacs)
+     (dolist (buffer (erc-buffer-list))
+       (with-current-buffer buffer
+         (kill-local-variable 'widget-button-face))))))
 
 ;;; Variables
 
@@ -97,7 +96,7 @@ above them."
   (concat "\\(www\\.\\|\\(s?https?\\|"
           "ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)"
           "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
-          "[-a-zA-Z0-9_=!?#$@~`%&*+\\/:;.,]+[-a-zA-Z0-9_=#$@~`%&*+\\/]")
+          "[-a-zA-Z0-9_=!?#$@~`%&*+\\/:;.,()]+[-a-zA-Z0-9_=#$@~`%&*+\\/()]")
   "Regular expression that matches URLs."
   :group 'erc-button
   :type 'regexp)
@@ -216,6 +215,7 @@ PAR is a number of a regexp grouping whose text will be passed to
         (define-key map (kbd "<button2>") 'erc-button-click-button)
       (define-key map (kbd "<mouse-2>") 'erc-button-click-button))
     (define-key map (kbd "TAB") 'erc-button-next)
+    (define-key map (kbd "<backtab>") 'erc-button-previous)
     (set-keymap-parent map erc-mode-map)
     map)
   "Local keymap for ERC buttons.")
@@ -237,9 +237,23 @@ PAR is a number of a regexp grouping whose text will be passed to
     (modify-syntax-entry ?\\ "w" table)
     table)
   "Syntax table used when buttonizing messages.
-This syntax table should make all the legal nick characters word
+This syntax table should make all the valid nick characters word
 constituents.")
 
+(defvar erc-button-keys-added nil
+  "Internal variable used to keep track of whether we've added the
+global-level ERC button keys yet.")
+
+(defun erc-button-setup ()
+  "Add ERC mode-level button movement keys.  This is only done once."
+  ;; Make XEmacs use `erc-button-face'.
+  (when (featurep 'xemacs)
+    (set (make-local-variable 'widget-button-face) nil))
+  ;; Add keys.
+  (unless erc-button-keys-added
+    (define-key erc-mode-map (kbd "<backtab>") 'erc-button-previous)
+    (setq erc-button-keys-added t)))
+
 (defun erc-button-add-buttons ()
   "Find external references in the current buffer and make buttons of them.
 \"External references\" are things like URLs, as
@@ -286,9 +300,10 @@ specified by `erc-button-alist'."
         (setq bounds (bounds-of-thing-at-point 'word))
         (setq word (buffer-substring-no-properties
                     (car bounds) (cdr bounds)))
-        (if (erc-get-server-user word)
-            (erc-button-add-button (car bounds) (cdr bounds)
-                                   fun t (list word)))))))
+        (when (or (and (erc-server-buffer-p) (erc-get-server-user word))
+                  (and erc-channel-users (erc-get-channel-user word)))
+          (erc-button-add-button (car bounds) (cdr bounds)
+                                 fun t (list word)))))))
 
 (defun erc-button-add-buttons-1 (regexp entry)
   "Search through the buffer for matches to ENTRY and add buttons."
@@ -427,6 +442,22 @@ call it with the value of the `erc-data' text property."
         (error "No next button"))
       t)))
 
+(defun erc-button-previous ()
+  "Go to the previous button in this buffer."
+  (interactive)
+  (let ((here (point)))
+    (when (< here (erc-beg-of-input-line))
+      (while (and (get-text-property here 'erc-callback)
+                  (not (= here (point-min))))
+        (setq here (1- here)))
+      (while (and (not (get-text-property here 'erc-callback))
+                  (not (= here (point-min))))
+        (setq here (1- here)))
+      (if (> here (point-min))
+          (goto-char here)
+        (error "No previous button"))
+      t)))
+
 (defun erc-browse-emacswiki (thing)
   "Browse to thing in the emacs-wiki."
   (browse-url (concat erc-emacswiki-url thing)))