aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/thingatpt.el62
2 files changed, 58 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5d19a486aa1..d484c06207b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12011-07-07 Chong Yidong <cyd@stupidchicken.com>
2
3 * thingatpt.el (forward-thing, bounds-of-thing-at-point)
4 (thing-at-point, beginning-of-thing, end-of-thing, in-string-p)
5 (end-of-sexp, beginning-of-sexp)
6 (thing-at-point-bounds-of-list-at-point, forward-whitespace)
7 (forward-symbol, forward-same-syntax, word-at-point)
8 (sentence-at-point): Doc fix (Bug#1144).
9
12011-07-07 Lars Magne Ingebrigtsen <larsi@gnus.org> 102011-07-07 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 11
3 * info.el (Info-mode-map): Remove S-TAB binding, since [backtab] 12 * info.el (Info-mode-map): Remove S-TAB binding, since [backtab]
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index a7ff23949fe..ff63ca34035 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -55,7 +55,11 @@
55 55
56;;;###autoload 56;;;###autoload
57(defun forward-thing (thing &optional n) 57(defun forward-thing (thing &optional n)
58 "Move forward to the end of the Nth next THING." 58 "Move forward to the end of the Nth next THING.
59THING should be a symbol specifying a type of syntactic entity.
60Possibilities include `symbol', `list', `sexp', `defun',
61`filename', `url', `email', `word', `sentence', `whitespace',
62`line', and `page'."
59 (let ((forward-op (or (get thing 'forward-op) 63 (let ((forward-op (or (get thing 'forward-op)
60 (intern-soft (format "forward-%s" thing))))) 64 (intern-soft (format "forward-%s" thing)))))
61 (if (functionp forward-op) 65 (if (functionp forward-op)
@@ -67,15 +71,16 @@
67;;;###autoload 71;;;###autoload
68(defun bounds-of-thing-at-point (thing) 72(defun bounds-of-thing-at-point (thing)
69 "Determine the start and end buffer locations for the THING at point. 73 "Determine the start and end buffer locations for the THING at point.
70THING is a symbol which specifies the kind of syntactic entity you want. 74THING should be a symbol specifying a type of syntactic entity.
71Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', 75Possibilities include `symbol', `list', `sexp', `defun',
72`email', `word', `sentence', `whitespace', `line', `page' and others. 76`filename', `url', `email', `word', `sentence', `whitespace',
77`line', and `page'.
73 78
74See the file `thingatpt.el' for documentation on how to define 79See the file `thingatpt.el' for documentation on how to define a
75a symbol as a valid THING. 80valid THING.
76 81
77The value is a cons cell (START . END) giving the start and end positions 82Return a cons cell (START . END) giving the start and end
78of the textual entity that was found." 83positions of the thing found."
79 (if (get thing 'bounds-of-thing-at-point) 84 (if (get thing 'bounds-of-thing-at-point)
80 (funcall (get thing 'bounds-of-thing-at-point)) 85 (funcall (get thing 'bounds-of-thing-at-point))
81 (let ((orig (point))) 86 (let ((orig (point)))
@@ -125,9 +130,10 @@ of the textual entity that was found."
125;;;###autoload 130;;;###autoload
126(defun thing-at-point (thing) 131(defun thing-at-point (thing)
127 "Return the THING at point. 132 "Return the THING at point.
128THING is a symbol which specifies the kind of syntactic entity you want. 133THING should be a symbol specifying a type of syntactic entity.
129Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', 134Possibilities include `symbol', `list', `sexp', `defun',
130`email', `word', `sentence', `whitespace', `line', `page' and others. 135`filename', `url', `email', `word', `sentence', `whitespace',
136`line', and `page'.
131 137
132See the file `thingatpt.el' for documentation on how to define 138See the file `thingatpt.el' for documentation on how to define
133a symbol as a valid THING." 139a symbol as a valid THING."
@@ -140,11 +146,15 @@ a symbol as a valid THING."
140;; Go to beginning/end 146;; Go to beginning/end
141 147
142(defun beginning-of-thing (thing) 148(defun beginning-of-thing (thing)
149 "Move point to the beginning of THING.
150The bounds of THING are determined by `bounds-of-thing-at-point'."
143 (let ((bounds (bounds-of-thing-at-point thing))) 151 (let ((bounds (bounds-of-thing-at-point thing)))
144 (or bounds (error "No %s here" thing)) 152 (or bounds (error "No %s here" thing))
145 (goto-char (car bounds)))) 153 (goto-char (car bounds))))
146 154
147(defun end-of-thing (thing) 155(defun end-of-thing (thing)
156 "Move point to the end of THING.
157The bounds of THING are determined by `bounds-of-thing-at-point'."
148 (let ((bounds (bounds-of-thing-at-point thing))) 158 (let ((bounds (bounds-of-thing-at-point thing)))
149 (or bounds (error "No %s here" thing)) 159 (or bounds (error "No %s here" thing))
150 (goto-char (cdr bounds)))) 160 (goto-char (cdr bounds))))
@@ -162,12 +172,16 @@ a symbol as a valid THING."
162;; Sexps 172;; Sexps
163 173
164(defun in-string-p () 174(defun in-string-p ()
175 "Return non-nil if point is in a string.
176\[This is an internal function.]"
165 (let ((orig (point))) 177 (let ((orig (point)))
166 (save-excursion 178 (save-excursion
167 (beginning-of-defun) 179 (beginning-of-defun)
168 (nth 3 (parse-partial-sexp (point) orig))))) 180 (nth 3 (parse-partial-sexp (point) orig)))))
169 181
170(defun end-of-sexp () 182(defun end-of-sexp ()
183 "Move point to the end of the current sexp.
184\[This is an internal function.]"
171 (let ((char-syntax (char-syntax (char-after)))) 185 (let ((char-syntax (char-syntax (char-after))))
172 (if (or (eq char-syntax ?\)) 186 (if (or (eq char-syntax ?\))
173 (and (eq char-syntax ?\") (in-string-p))) 187 (and (eq char-syntax ?\") (in-string-p)))
@@ -177,6 +191,8 @@ a symbol as a valid THING."
177(put 'sexp 'end-op 'end-of-sexp) 191(put 'sexp 'end-op 'end-of-sexp)
178 192
179(defun beginning-of-sexp () 193(defun beginning-of-sexp ()
194 "Move point to the beginning of the current sexp.
195\[This is an internal function.]"
180 (let ((char-syntax (char-syntax (char-before)))) 196 (let ((char-syntax (char-syntax (char-before))))
181 (if (or (eq char-syntax ?\() 197 (if (or (eq char-syntax ?\()
182 (and (eq char-syntax ?\") (in-string-p))) 198 (and (eq char-syntax ?\") (in-string-p)))
@@ -190,6 +206,8 @@ a symbol as a valid THING."
190(put 'list 'bounds-of-thing-at-point 'thing-at-point-bounds-of-list-at-point) 206(put 'list 'bounds-of-thing-at-point 'thing-at-point-bounds-of-list-at-point)
191 207
192(defun thing-at-point-bounds-of-list-at-point () 208(defun thing-at-point-bounds-of-list-at-point ()
209 "Return the bounds of the list at point.
210\[Internal function used by `bounds-of-thing-at-point'.]"
193 (save-excursion 211 (save-excursion
194 (let ((opoint (point)) 212 (let ((opoint (point))
195 (beg (condition-case nil 213 (beg (condition-case nil
@@ -397,6 +415,11 @@ with angle brackets.")
397;; Whitespace 415;; Whitespace
398 416
399(defun forward-whitespace (arg) 417(defun forward-whitespace (arg)
418 "Move point to the end of the next sequence of whitespace chars.
419Each such sequence may be a single newline, or a sequence of
420consecutive space and/or tab characters.
421With prefix argument ARG, do it ARG times if positive, or move
422backwards ARG times if negative."
400 (interactive "p") 423 (interactive "p")
401 (if (natnump arg) 424 (if (natnump arg)
402 (re-search-forward "[ \t]+\\|\n" nil 'move arg) 425 (re-search-forward "[ \t]+\\|\n" nil 'move arg)
@@ -414,6 +437,11 @@ with angle brackets.")
414;; Symbols 437;; Symbols
415 438
416(defun forward-symbol (arg) 439(defun forward-symbol (arg)
440 "Move point to the next position that is the end of a symbol.
441A symbol is any sequence of characters that are in either the
442word constituent or symbol constituent syntax class.
443With prefix argument ARG, do it ARG times if positive, or move
444backwards ARG times if negative."
417 (interactive "p") 445 (interactive "p")
418 (if (natnump arg) 446 (if (natnump arg)
419 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg) 447 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg)
@@ -425,6 +453,9 @@ with angle brackets.")
425;; Syntax blocks 453;; Syntax blocks
426 454
427(defun forward-same-syntax (&optional arg) 455(defun forward-same-syntax (&optional arg)
456 "Move point past all characters with the same syntax class.
457With prefix argument ARG, do it ARG times if positive, or move
458backwards ARG times if negative."
428 (interactive "p") 459 (interactive "p")
429 (while (< arg 0) 460 (while (< arg 0)
430 (skip-syntax-backward 461 (skip-syntax-backward
@@ -436,8 +467,13 @@ with angle brackets.")
436 467
437;; Aliases 468;; Aliases
438 469
439(defun word-at-point () (thing-at-point 'word)) 470(defun word-at-point ()
440(defun sentence-at-point () (thing-at-point 'sentence)) 471 "Return the word at point. See `thing-at-point'."
472 (thing-at-point 'word))
473
474(defun sentence-at-point ()
475 "Return the sentence at point. See `thing-at-point'."
476 (thing-at-point 'sentence))
441 477
442(defun read-from-whole-string (str) 478(defun read-from-whole-string (str)
443 "Read a Lisp expression from STR. 479 "Read a Lisp expression from STR.