(gdb-starting): Set gdb-running to t.
[bpt/emacs.git] / lisp / thingatpt.el
index 4ea50c5..47caf02 100644 (file)
@@ -1,8 +1,10 @@
-;;; thingatpt.el --- Get the `thing' at point
+;;; thingatpt.el --- get the `thing' at point
 
-;; Copyright (C) 1991,92,93,94,95,96,1997 Free Software Foundation, Inc.
+;; Copyright (C) 1991,92,93,94,95,96,97,1998,2000
+;;  Free Software Foundation, Inc.
 
 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
+;; Maintainer: FSF
 ;; Keywords: extensions, matching, mouse
 ;; Created: Thu Mar 28 13:48:23 1991
 
@@ -54,7 +56,7 @@
   "Move forward to the end of the next THING."
   (let ((forward-op (or (get thing 'forward-op)
                        (intern-soft (format "forward-%s" thing)))))
-    (if (fboundp forward-op)
+    (if (functionp forward-op)
        (funcall forward-op (or n 1))
       (error "Can't determine how to move over a %s" thing))))
 
@@ -197,13 +199,13 @@ a symbol as a valid THING."
   "Characters allowable in filenames.")
 
 (put 'filename 'end-op    
-     '(lambda () (skip-chars-forward thing-at-point-file-name-chars)))
+     (lambda () (skip-chars-forward thing-at-point-file-name-chars)))
 (put 'filename 'beginning-op
-     '(lambda () (skip-chars-backward thing-at-point-file-name-chars)))
+     (lambda () (skip-chars-backward thing-at-point-file-name-chars)))
 
 (defvar thing-at-point-url-path-regexp
   "[^]\t\n \"'()<>[^`{}]*[^]\t\n \"'()<>[^`{}.,;]+"
-  "A regular expression probably matching the host, path or e-mail part of a URL.")
+  "A regular expression probably matching the host and filename or e-mail part of a URL.")
 
 (defvar thing-at-point-short-url-regexp
   (concat "[-A-Za-z0-9.]+" thing-at-point-url-path-regexp)
@@ -211,10 +213,21 @@ a symbol as a valid THING."
 Hostname matching is stricter in this case than for
 ``thing-at-point-url-regexp''.")
 
+(defvar thing-at-point-uri-schemes
+  ;; Officials from http://www.iana.org/assignments/uri-schemes
+  '("ftp://" "http://" "gopher://" "mailto:" "news:" "nntp:"
+    "telnet://" "wais://" "file:/" "prospero:" "z39.50s:" "z39.50r:"
+    "cid:" "mid:" "vemmi:" "service:" "imap:" "nfs:" "acap:" "rtsp:"
+    "tip:" "pop:" "data:" "dav:" "opaquelocktoken:" "sip:" "tel:" "fax:"
+    "modem:" "ldap:" "https://" "soap.beep:" "soap.beeps:" "urn:" "go:"
+    "afs:" "tn3270:" "mailserver:"
+  ;; Compatibility
+    "snews:")
+  "Uniform Resource Identifier (URI) Schemes")
+
 (defvar thing-at-point-url-regexp
-  (concat
-   "\\(https?://\\|ftp://\\|gopher://\\|telnet://\\|wais://\\|file:/\\|s?news:\\|mailto:\\)"
-   thing-at-point-url-path-regexp)
+  (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)"
+          thing-at-point-url-path-regexp)
   "A regular expression probably matching a complete URL.")
 
 (defvar thing-at-point-markedup-url-regexp
@@ -241,9 +254,12 @@ This may contain whitespace (including newlines) .")
 (put 'url 'thing-at-point 'thing-at-point-url-at-point)
 (defun thing-at-point-url-at-point ()
   "Return the URL around or before point.
-Search backwards for the start of a URL ending at or after 
-point.  If no URL found, return nil.  The access scheme, `http://'
-will be prepended if absent."
+
+Search backwards for the start of a URL ending at or after point.  If
+no URL found, return nil.  The access scheme will be prepended if
+absent: \"mailto:\" if the string contains \"@\", \"ftp://\" if it
+starts with \"ftp\" and not \"ftp:/\", or \"http://\" by default."
+
   (let ((url "") short strip)
     (if (or (setq strip (thing-at-point-looking-at
                         thing-at-point-markedup-url-regexp))
@@ -256,10 +272,15 @@ will be prepended if absent."
                                                    (match-end 0)))
          (and strip (setq url (substring url 5 -1))) ; Drop "<URL:" & ">"
          ;; strip whitespace
-         (while (string-match "\\s +\\|\n+" url)
+         (while (string-match "[ \t\n\r]+" url)
            (setq url (replace-match "" t t url)))
-         (and short (setq url (concat (if (string-match "@" url)
-                                          "mailto:" "http://") url)))
+         (and short (setq url (concat (cond ((string-match "@" url)
+                                              "mailto:")
+                                            ;; e.g. ftp.swiss... or ftp-swiss...
+                                             ((string-match "^ftp" url)
+                                              "ftp://")
+                                             (t "http://"))
+                                       url)))
          (if (string-equal "" url)
              nil
            url)))))
@@ -299,16 +320,18 @@ point."
        (goto-char match)
        (looking-at regexp)))))
 
-;; Can't do it sensibly?
-;(put 'url 'end-op    
-;     '(lambda () (skip-chars-forward (concat ":" thing-at-point-url-chars))
-;      (skip-chars-backward ".,:")))
+(put 'url 'end-op
+     (function (lambda ()
+                (let ((bounds (thing-at-point-bounds-of-url-at-point)))
+                  (if bounds
+                      (goto-char (cdr bounds))
+                    (error "No URL here"))))))
 (put 'url 'beginning-op
-     '(lambda ()
-       (let ((bounds (thing-at-point-bounds-of-url-at-point)))
-         (if bounds
-             (goto-char (car bounds))
-           (error "No URL here")))))
+     (function (lambda ()
+                (let ((bounds (thing-at-point-bounds-of-url-at-point)))
+                  (if bounds
+                      (goto-char (car bounds))
+                    (error "No URL here"))))))
 
 ;;  Whitespace 
 
@@ -324,8 +347,8 @@ point."
 
 ;;  Buffer 
 
-(put 'buffer 'end-op '(lambda () (goto-char (point-max))))
-(put 'buffer 'beginning-op '(lambda () (goto-char (point-min))))
+(put 'buffer 'end-op (lambda () (goto-char (point-max))))
+(put 'buffer 'beginning-op (lambda () (goto-char (point-min))))
 
 ;;  Symbols 
 
@@ -361,7 +384,8 @@ Signal an error if the entire string was not used."
   (let* ((read-data (read-from-string str))
         (more-left 
          (condition-case nil
-             (progn (read-from-string (substring str (cdr read-data)))
+             ;; The call to `ignore' suppresses a compiler warning.
+             (progn (ignore (read-from-string (substring str (cdr read-data))))
                     t)
            (end-of-file nil))))
     (if more-left
@@ -374,9 +398,13 @@ Signal an error if the entire string was not used."
                (error nil))))
     (if (or (not pred) (funcall pred sexp)) sexp)))
 
+;;;###autoload
 (defun sexp-at-point ()   (form-at-point 'sexp))
+;;;###autoload
 (defun symbol-at-point () (form-at-point 'sexp 'symbolp))
+;;;###autoload
 (defun number-at-point () (form-at-point 'sexp 'numberp))
+;;;###autoload
 (defun list-at-point ()   (form-at-point 'list 'listp))
 
-;; thingatpt.el ends here.
+;;; thingatpt.el ends here