diff options
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/thingatpt.el | 62 |
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 @@ | |||
| 1 | 2011-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 | |||
| 1 | 2011-07-07 Lars Magne Ingebrigtsen <larsi@gnus.org> | 10 | 2011-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. |
| 59 | THING should be a symbol specifying a type of syntactic entity. | ||
| 60 | Possibilities 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. |
| 70 | THING is a symbol which specifies the kind of syntactic entity you want. | 74 | THING should be a symbol specifying a type of syntactic entity. |
| 71 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', | 75 | Possibilities 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 | ||
| 74 | See the file `thingatpt.el' for documentation on how to define | 79 | See the file `thingatpt.el' for documentation on how to define a |
| 75 | a symbol as a valid THING. | 80 | valid THING. |
| 76 | 81 | ||
| 77 | The value is a cons cell (START . END) giving the start and end positions | 82 | Return a cons cell (START . END) giving the start and end |
| 78 | of the textual entity that was found." | 83 | positions 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. |
| 128 | THING is a symbol which specifies the kind of syntactic entity you want. | 133 | THING should be a symbol specifying a type of syntactic entity. |
| 129 | Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', | 134 | Possibilities 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 | ||
| 132 | See the file `thingatpt.el' for documentation on how to define | 138 | See the file `thingatpt.el' for documentation on how to define |
| 133 | a symbol as a valid THING." | 139 | a 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. | ||
| 150 | The 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. | ||
| 157 | The 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. | ||
| 419 | Each such sequence may be a single newline, or a sequence of | ||
| 420 | consecutive space and/or tab characters. | ||
| 421 | With prefix argument ARG, do it ARG times if positive, or move | ||
| 422 | backwards 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. | ||
| 441 | A symbol is any sequence of characters that are in either the | ||
| 442 | word constituent or symbol constituent syntax class. | ||
| 443 | With prefix argument ARG, do it ARG times if positive, or move | ||
| 444 | backwards 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. | ||
| 457 | With prefix argument ARG, do it ARG times if positive, or move | ||
| 458 | backwards 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. |