]> code.delx.au - gnu-emacs/blobdiff - lisp/thingatpt.el
(mh-version): Use mh-e-RCS-id rather than mh-e-version
[gnu-emacs] / lisp / thingatpt.el
index 76caac9e3dbe5750f850d4b83bd429781caee07c..0596f8b5bffb65246213a8d49b02b56e9dae13bc 100644 (file)
@@ -1,6 +1,6 @@
 ;;; thingatpt.el --- Get the `thing' at point
 
-;; Copyright (C) 1991,1992,1993 Free Software Foundation, Inc.
+;; Copyright (C) 1991,1992,1993,1994,1995 Free Software Foundation, Inc.
 
 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
 ;; Keywords: extensions, matching, mouse
@@ -19,7 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;;; Commentary:
-;;
+
 ;; This file provides routines for getting the `thing' at the location of
 ;; point, whatever that `thing' happens to be.  The `thing' is defined by
 ;; it's beginning and end positions in the buffer.
 ;;     (thing-at-point 'line)
 ;;     (thing-at-point 'page)
 
-;;; Code: =================================================================
+;;; Code:
 
 (provide 'thingatpt)
 
-;;=== Basic movement ======================================================
+;; Basic movement
 
 ;;;###autoload
 (defun forward-thing (THING &optional N)
@@ -58,7 +58,7 @@
        (funcall forward-op (or N 1))
       (error "Can't determine how to move over %ss" THING))))
 
-;;=== General routines ====================================================
+;; General routines
 
 ;;;###autoload
 (defun bounds-of-thing-at-point (THING)
@@ -92,7 +92,7 @@ bounds-of-thing-at-point."
     (if bounds 
        (buffer-substring (car bounds) (cdr bounds)))))
 
-;;=== Go to beginning/end =================================================
+;; Go to beginning/end
 
 (defun beginning-of-thing (THING)
   (let ((bounds (bounds-of-thing-at-point THING)))
@@ -104,9 +104,17 @@ bounds-of-thing-at-point."
     (or bounds (error "No %s here" THING))
     (goto-char (cdr bounds))))
 
-;;=== Special cases =======================================================
+;;  Special cases 
+
+;;  Lines 
+
+;; bolp will be false when you click on the last line in the buffer
+;; and it has no final newline.
 
-;;--- Sexps ---
+(put 'line 'beginning-op
+     (function (lambda () (if (bolp) (forward-line -1) (beginning-of-line)))))
+
+;;  Sexps 
 
 (defun in-string-p ()
   (let ((orig (point)))
@@ -123,12 +131,12 @@ bounds-of-thing-at-point."
 
 (put 'sexp 'end-op 'end-of-sexp)
 
-;;--- Lists ---
+;;  Lists 
 
 (put 'list 'end-op (function (lambda () (up-list 1))))
 (put 'list 'beginning-op 'backward-sexp)
 
-;;--- Filenames ---
+;;  Filenames 
 
 (defvar file-name-chars "~/A-Za-z0-9---_.${}#%,"
   "Characters allowable in filenames.")
@@ -138,7 +146,7 @@ bounds-of-thing-at-point."
 (put 'filename 'beginning-op
      (function (lambda () (skip-chars-backward file-name-chars (point-min)))))
 
-;;--- Whitespace ---
+;;  Whitespace 
 
 (defun forward-whitespace (ARG)
   (interactive "p")
@@ -150,12 +158,12 @@ bounds-of-thing-at-point."
              (skip-chars-backward " \t")))
       (setq ARG (1+ ARG)))))
 
-;;--- Buffer ---
+;;  Buffer 
 
 (put 'buffer 'end-op 'end-of-buffer)
 (put 'buffer 'beginning-op 'beginning-of-buffer)
 
-;;--- Symbols ---
+;;  Symbols 
 
 (defun forward-symbol (ARG)
   (interactive "p")
@@ -166,13 +174,25 @@ bounds-of-thing-at-point."
          (skip-syntax-backward "w_"))
       (setq ARG (1+ ARG)))))
 
-;;=== Aliases =============================================================
+;;  Syntax blocks 
+
+(defun forward-same-syntax (&optional arg)
+  (interactive "p")
+  (while (< arg 0)
+    (skip-syntax-backward 
+     (char-to-string (char-syntax (char-after (1- (point))))))
+    (setq arg (1+ arg)))
+  (while (> arg 0)
+    (skip-syntax-forward (char-to-string (char-syntax (char-after (point)))))
+    (setq arg (1- arg))))
+
+;;  Aliases 
 
 (defun word-at-point () (thing-at-point 'word))
 (defun sentence-at-point () (thing-at-point 'sentence))
 
 (defun read-from-whole-string (STR)
-  "Read a lisp expression from STR, signalling an error if the entire string
+  "Read a lisp expression from STR, signaling an error if the entire string
 was not used."
   (let* ((read-data (read-from-string STR))
         (more-left