annotate lisp/thingatpt.el @ 15681:b0652f55a85d

[__GNU_LIBRARY__]: Use <string.h>.
author Karl Heuer <kwzh@gnu.org>
date Mon, 15 Jul 1996 21:25:56 +0000
parents 83f275dcd93a
children 3b9f64eb097b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; thingatpt.el --- Get the `thing' at point
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
12593
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
3 ;; Copyright (C) 1991,1992,1993,1994,1995 Free Software Foundation, Inc.
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
5140
9cde7d7fea1f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
6 ;; Keywords: extensions, matching, mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: Thu Mar 28 13:48:23 1991
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
7938
c0cc87942423 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 5751
diff changeset
21 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
22
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; This file provides routines for getting the `thing' at the location of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; point, whatever that `thing' happens to be. The `thing' is defined by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; it's beginning and end positions in the buffer.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; The function bounds-of-thing-at-point finds the beginning and end
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; positions by moving first forward to the end of the `thing', and then
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; backwards to the beginning. By default, it uses the corresponding
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; forward-`thing' operator (eg. forward-word, forward-line).
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Special cases are allowed for using properties associated with the named
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; `thing':
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; forward-op Function to call to skip forward over a `thing' (or
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; with a negative argument, backward).
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; beginning-op Function to call to skip to the beginning of a `thing'.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; end-op Function to call to skip to the end of a `thing'.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Reliance on existing operators means that many `things' can be accessed
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; without further code: eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; (thing-at-point 'line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; (thing-at-point 'page)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
46 ;;; Code:
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (provide 'thingatpt)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
50 ;; Basic movement
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defun forward-thing (THING &optional N)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 "Move forward to the end of the next THING."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (let ((forward-op (or (get THING 'forward-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (intern-soft (format "forward-%s" THING)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (if (fboundp forward-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (funcall forward-op (or N 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (error "Can't determine how to move over %ss" THING))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
61 ;; General routines
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defun bounds-of-thing-at-point (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 "Determine the start and end buffer locations for the THING at point,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 where THING is an entity for which there is a either a corresponding
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 forward-THING operation, or corresponding beginning-of-THING and
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 end-of-THING operations, eg. 'word, 'sentence, 'defun.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 Return a cons cell '(start . end) giving the start and end positions."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (let ((orig (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (save-excursion
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (let ((end (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (funcall
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (or (get THING 'end-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (function (lambda () (forward-thing THING 1)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (beg (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (funcall
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (or (get THING 'beginning-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (function (lambda () (forward-thing THING -1)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (point))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (if (and beg end (<= beg orig) (< orig end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (cons beg end))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (error nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (defun thing-at-point (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 "Return the THING at point, where THING is an entity defined by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 bounds-of-thing-at-point."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (if bounds
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (buffer-substring (car bounds) (cdr bounds)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
95 ;; Go to beginning/end
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defun beginning-of-thing (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (or bounds (error "No %s here" THING))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (goto-char (car bounds))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defun end-of-thing (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (or bounds (error "No %s here" THING))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (goto-char (cdr bounds))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
107 ;; Special cases
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
109 ;; Lines
9931
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
110
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
111 ;; bolp will be false when you click on the last line in the buffer
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
112 ;; and it has no final newline.
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
113
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
114 (put 'line 'beginning-op
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
115 (function (lambda () (if (bolp) (forward-line -1) (beginning-of-line)))))
23e429e3fb18 (line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents: 7938
diff changeset
116
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
117 ;; Sexps
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defun in-string-p ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (let ((orig (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (save-excursion
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (beginning-of-defun)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (nth 3 (parse-partial-sexp (point) orig)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (defun end-of-sexp ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (let ((char-syntax (char-syntax (char-after (point)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (if (or (eq char-syntax ?\))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (and (eq char-syntax ?\") (in-string-p)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (forward-char 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (forward-sexp 1))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (put 'sexp 'end-op 'end-of-sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
134 ;; Lists
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (put 'list 'end-op (function (lambda () (up-list 1))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (put 'list 'beginning-op 'backward-sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
139 ;; Filenames
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defvar file-name-chars "~/A-Za-z0-9---_.${}#%,"
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 "Characters allowable in filenames.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (put 'filename 'end-op
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (function (lambda () (skip-chars-forward file-name-chars))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (put 'filename 'beginning-op
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (function (lambda () (skip-chars-backward file-name-chars (point-min)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
149 ;; Whitespace
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defun forward-whitespace (ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (interactive "p")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (if (natnump ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (re-search-forward "[ \t]+\\|\n" nil nil ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (while (< ARG 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (if (re-search-backward "[ \t]+\\|\n" nil nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (or (eq (char-after (match-beginning 0)) 10)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (skip-chars-backward " \t")))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (setq ARG (1+ ARG)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
161 ;; Buffer
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (put 'buffer 'end-op 'end-of-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (put 'buffer 'beginning-op 'beginning-of-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
166 ;; Symbols
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (defun forward-symbol (ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (interactive "p")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (if (natnump ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil nil ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (while (< ARG 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (skip-syntax-backward "w_"))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (setq ARG (1+ ARG)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
177 ;; Syntax blocks
12593
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
178
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
179 (defun forward-same-syntax (&optional arg)
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
180 (interactive "p")
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
181 (while (< arg 0)
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
182 (skip-syntax-backward
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
183 (char-to-string (char-syntax (char-after (1- (point))))))
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
184 (setq arg (1+ arg)))
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
185 (while (> arg 0)
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
186 (skip-syntax-forward (char-to-string (char-syntax (char-after (point)))))
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
187 (setq arg (1- arg))))
e961f9a213a7 (forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9931
diff changeset
188
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14010
diff changeset
189 ;; Aliases
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defun word-at-point () (thing-at-point 'word))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (defun sentence-at-point () (thing-at-point 'sentence))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun read-from-whole-string (STR)
14010
d6781ed94da3 (read-from-whole-string): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12593
diff changeset
195 "Read a lisp expression from STR, signaling an error if the entire string
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 was not used."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let* ((read-data (read-from-string STR))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (more-left
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (progn (read-from-string (substring STR (cdr read-data)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (end-of-file nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (if more-left
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (error "Can't read whole string")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (car read-data))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (defun form-at-point (&optional THING PRED)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (let ((sexp (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (read-from-whole-string (thing-at-point (or THING 'sexp)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (error nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (if (or (not PRED) (funcall PRED sexp)) sexp)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun sexp-at-point () (form-at-point 'sexp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defun symbol-at-point () (form-at-point 'sexp 'symbolp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (defun number-at-point () (form-at-point 'sexp 'numberp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun list-at-point () (form-at-point 'list 'listp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; thingatpt.el ends here.