Mercurial > emacs
annotate lisp/thingatpt.el @ 17085:4dafa5431293
Change coding system name koi8 to koi8-r.
Remove prefix "coding-system-" from coding system symbol names.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 26 Feb 1997 12:27:06 +0000 |
parents | bf249c4b4beb |
children | 3ae7560f0959 |
rev | line source |
---|---|
4934 | 1 ;;; thingatpt.el --- Get the `thing' at point |
2 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
3 ;; Copyright (C) 1991,92,93,94,95,1996 Free Software Foundation, Inc. |
4934 | 4 |
5 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz> | |
5140 | 6 ;; Keywords: extensions, matching, mouse |
4934 | 7 ;; Created: Thu Mar 28 13:48:23 1991 |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
7938 | 21 ;;; Commentary: |
14169 | 22 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
23 ;; This file provides routines for getting the "thing" at the location of |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
24 ;; point, whatever that "thing" happens to be. The "thing" is defined by |
16427 | 25 ;; its beginning and end positions in the buffer. |
4934 | 26 ;; |
27 ;; The function bounds-of-thing-at-point finds the beginning and end | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
28 ;; positions by moving first forward to the end of the "thing", and then |
4934 | 29 ;; backwards to the beginning. By default, it uses the corresponding |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
30 ;; forward-"thing" operator (eg. forward-word, forward-line). |
4934 | 31 ;; |
32 ;; Special cases are allowed for using properties associated with the named | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
33 ;; "thing": |
4934 | 34 ;; |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
35 ;; forward-op Function to call to skip forward over a "thing" (or |
4934 | 36 ;; with a negative argument, backward). |
37 ;; | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
38 ;; beginning-op Function to call to skip to the beginning of a "thing". |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
39 ;; end-op Function to call to skip to the end of a "thing". |
4934 | 40 ;; |
41 ;; Reliance on existing operators means that many `things' can be accessed | |
42 ;; without further code: eg. | |
43 ;; (thing-at-point 'line) | |
44 ;; (thing-at-point 'page) | |
45 | |
14169 | 46 ;;; Code: |
4934 | 47 |
48 (provide 'thingatpt) | |
49 | |
14169 | 50 ;; Basic movement |
4934 | 51 |
52 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
53 (defun forward-thing (thing &optional n) |
4934 | 54 "Move forward to the end of the next THING." |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
55 (let ((forward-op (or (get thing 'forward-op) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
56 (intern-soft (format "forward-%s" thing))))) |
4934 | 57 (if (fboundp forward-op) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
58 (funcall forward-op (or n 1)) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
59 (error "Can't determine how to move over a %s" thing)))) |
4934 | 60 |
14169 | 61 ;; General routines |
4934 | 62 |
63 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
64 (defun bounds-of-thing-at-point (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
65 "Determine the start and end buffer locations for the THING at point. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
66 THING is a symbol which specifies the kind of syntactic entity you want. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
67 Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
68 `word', `sentence', `whitespace', `line', `page' and others. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
69 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
70 See the file `thingatpt.el' for documentation on how to define |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
71 a symbol as a valid THING. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
72 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
73 The value is a cons cell (START . END) giving the start and end positions |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
74 of the textual entity that was found." |
4934 | 75 (let ((orig (point))) |
76 (condition-case nil | |
77 (save-excursion | |
78 (let ((end (progn | |
79 (funcall | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
80 (or (get thing 'end-op) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
81 (function (lambda () (forward-thing thing 1))))) |
4934 | 82 (point))) |
83 (beg (progn | |
84 (funcall | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
85 (or (get thing 'beginning-op) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
86 (function (lambda () (forward-thing thing -1))))) |
4934 | 87 (point)))) |
16668
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
88 (if (and beg end (<= beg orig) (<= orig end)) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
89 (cons beg end) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
90 ;; Try a second time, moving backward first and forward after, |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
91 ;; so that we can find a thing that ends at ORIG. |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
92 (let ((beg (progn |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
93 (funcall |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
94 (or (get thing 'beginning-op) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
95 (function (lambda () (forward-thing thing -1))))) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
96 (point))) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
97 (end (progn |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
98 (funcall |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
99 (or (get thing 'end-op) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
100 (function (lambda () (forward-thing thing 1))))) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
101 (point)))) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
102 (if (and beg end (<= beg orig) (<= orig end)) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
103 (cons beg end)))))) |
4934 | 104 (error nil)))) |
105 | |
106 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
107 (defun thing-at-point (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
108 "Return the THING at point. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
109 THING is a symbol which specifies the kind of syntactic entity you want. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
110 Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
111 `word', `sentence', `whitespace', `line', `page' and others. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
112 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
113 See the file `thingatpt.el' for documentation on how to define |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
114 a symbol as a valid THING." |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
115 (let ((bounds (bounds-of-thing-at-point thing))) |
4934 | 116 (if bounds |
117 (buffer-substring (car bounds) (cdr bounds))))) | |
118 | |
14169 | 119 ;; Go to beginning/end |
4934 | 120 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
121 (defun beginning-of-thing (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
122 (let ((bounds (bounds-of-thing-at-point thing))) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
123 (or bounds (error "No %s here" thing)) |
4934 | 124 (goto-char (car bounds)))) |
125 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
126 (defun end-of-thing (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
127 (let ((bounds (bounds-of-thing-at-point thing))) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
128 (or bounds (error "No %s here" thing)) |
4934 | 129 (goto-char (cdr bounds)))) |
130 | |
14169 | 131 ;; Special cases |
4934 | 132 |
14169 | 133 ;; Lines |
9931
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
134 |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
135 ;; 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
|
136 ;; and it has no final newline. |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
137 |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
138 (put 'line 'beginning-op |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
139 (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
|
140 |
14169 | 141 ;; Sexps |
4934 | 142 |
143 (defun in-string-p () | |
144 (let ((orig (point))) | |
145 (save-excursion | |
146 (beginning-of-defun) | |
147 (nth 3 (parse-partial-sexp (point) orig))))) | |
148 | |
149 (defun end-of-sexp () | |
150 (let ((char-syntax (char-syntax (char-after (point))))) | |
151 (if (or (eq char-syntax ?\)) | |
152 (and (eq char-syntax ?\") (in-string-p))) | |
153 (forward-char 1) | |
154 (forward-sexp 1)))) | |
155 | |
156 (put 'sexp 'end-op 'end-of-sexp) | |
157 | |
14169 | 158 ;; Lists |
4934 | 159 |
160 (put 'list 'end-op (function (lambda () (up-list 1)))) | |
161 (put 'list 'beginning-op 'backward-sexp) | |
162 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
163 ;; Filenames and URLs |
4934 | 164 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
165 (defvar thing-at-point-file-name-chars "~/A-Za-z0-9---_.${}#%,:" |
4934 | 166 "Characters allowable in filenames.") |
167 | |
168 (put 'filename 'end-op | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
169 '(lambda () (skip-chars-forward thing-at-point-file-name-chars))) |
4934 | 170 (put 'filename 'beginning-op |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
171 '(lambda () (skip-chars-backward thing-at-point-file-name-chars))) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
172 |
16668
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
173 (defvar thing-at-point-url-chars "~/A-Za-z0-9---_@$%&=.," |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
174 "Characters allowable in a URL.") |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
175 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
176 (put 'url 'end-op |
16668
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
177 '(lambda () (skip-chars-forward (concat ":" thing-at-point-url-chars)) |
bf249c4b4beb
(bounds-of-thing-at-point): Allow the end
Richard M. Stallman <rms@gnu.org>
parents:
16653
diff
changeset
|
178 (skip-chars-backward ".,:"))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
179 (put 'url 'beginning-op |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
180 '(lambda () |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
181 (skip-chars-backward thing-at-point-url-chars) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
182 (or (= (preceding-char) ?:) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
183 (error "No URL here")) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
184 (forward-char -1) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
185 (skip-chars-backward "a-zA-Z"))) |
4934 | 186 |
14169 | 187 ;; Whitespace |
4934 | 188 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
189 (defun forward-whitespace (arg) |
4934 | 190 (interactive "p") |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
191 (if (natnump arg) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
192 (re-search-forward "[ \t]+\\|\n" nil nil arg) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
193 (while (< arg 0) |
4934 | 194 (if (re-search-backward "[ \t]+\\|\n" nil nil) |
195 (or (eq (char-after (match-beginning 0)) 10) | |
196 (skip-chars-backward " \t"))) | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
197 (setq arg (1+ arg))))) |
4934 | 198 |
14169 | 199 ;; Buffer |
4934 | 200 |
201 (put 'buffer 'end-op 'end-of-buffer) | |
202 (put 'buffer 'beginning-op 'beginning-of-buffer) | |
203 | |
14169 | 204 ;; Symbols |
4934 | 205 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
206 (defun forward-symbol (arg) |
4934 | 207 (interactive "p") |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
208 (if (natnump arg) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
209 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil nil arg) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
210 (while (< arg 0) |
4934 | 211 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil nil) |
212 (skip-syntax-backward "w_")) | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
213 (setq arg (1+ arg))))) |
4934 | 214 |
14169 | 215 ;; Syntax blocks |
12593
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
216 |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
217 (defun forward-same-syntax (&optional arg) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
218 (interactive "p") |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
219 (while (< arg 0) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
220 (skip-syntax-backward |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
221 (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
|
222 (setq arg (1+ arg))) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
223 (while (> arg 0) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
224 (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
|
225 (setq arg (1- arg)))) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
226 |
14169 | 227 ;; Aliases |
4934 | 228 |
229 (defun word-at-point () (thing-at-point 'word)) | |
230 (defun sentence-at-point () (thing-at-point 'sentence)) | |
231 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
232 (defun read-from-whole-string (str) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
233 "Read a lisp expression from STR. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
234 Signal an error if the entire string was not used." |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
235 (let* ((read-data (read-from-string str)) |
4934 | 236 (more-left |
237 (condition-case nil | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
238 (progn (read-from-string (substring str (cdr read-data))) |
4934 | 239 t) |
240 (end-of-file nil)))) | |
241 (if more-left | |
242 (error "Can't read whole string") | |
243 (car read-data)))) | |
244 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
245 (defun form-at-point (&optional thing pred) |
4934 | 246 (let ((sexp (condition-case nil |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
247 (read-from-whole-string (thing-at-point (or thing 'sexp))) |
4934 | 248 (error nil)))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
249 (if (or (not pred) (funcall pred sexp)) sexp))) |
4934 | 250 |
251 (defun sexp-at-point () (form-at-point 'sexp)) | |
252 (defun symbol-at-point () (form-at-point 'sexp 'symbolp)) | |
253 (defun number-at-point () (form-at-point 'sexp 'numberp)) | |
254 (defun list-at-point () (form-at-point 'list 'listp)) | |
255 | |
256 ;; thingatpt.el ends here. |