;;; 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
;; Created: Thu Mar 28 13:48:23 1991
-;; Version: $Revision: 1.1 $
;; This file is part of GNU Emacs.
;; 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.
(provide 'thingatpt)
-;;=== Version =============================================================
-
-(defconst thing@pt-version (substring "$Revision: 1.1 $" 11 -2)
- "The revision number of thing@pt (as string). The complete RCS id is:
-
- $Id: thingatpt.el,v 1.1 1993/11/08 14:27:42 rms Exp rms $")
-
-;;=== Basic movement ======================================================
+;; Basic movement
;;;###autoload
(defun forward-thing (THING &optional N)
(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)
(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)))
(or bounds (error "No %s here" THING))
(goto-char (cdr bounds))))
-;;=== Special cases =======================================================
+;; Special cases
+
+;; Lines
-;;--- Sexps ---
+;; bolp will be false when you click on the last line in the buffer
+;; and it has no final newline.
+
+(put 'line 'beginning-op
+ (function (lambda () (if (bolp) (forward-line -1) (beginning-of-line)))))
+
+;; Sexps
(defun in-string-p ()
(let ((orig (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.")
(put 'filename 'beginning-op
(function (lambda () (skip-chars-backward file-name-chars (point-min)))))
-;;--- Whitespace ---
+;; Whitespace
(defun forward-whitespace (ARG)
(interactive "p")
(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")
(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