diff options
| author | Stefan Monnier | 2006-07-04 20:27:49 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-07-04 20:27:49 +0000 |
| commit | 2a59b30d1674b21e3fdfd62e9d25799fdd110f24 (patch) | |
| tree | f40100e260401f0a61d9f27d472288a0a29925be | |
| parent | ce0d49986dcc46918109524b2b609c171504e54c (diff) | |
| download | emacs-2a59b30d1674b21e3fdfd62e9d25799fdd110f24.tar.gz emacs-2a59b30d1674b21e3fdfd62e9d25799fdd110f24.zip | |
(symbol-at-point): Don't use `form-at-point' which
fails if the symbol contains chars like ( or '.
(bounds-of-thing-at-point): Remove unused vars `end' and `beg'.
(thing-at-point-bounds-of-url-at-point): Remove unused vars `url' and `short'.
| -rw-r--r-- | lisp/thingatpt.el | 95 |
1 files changed, 46 insertions, 49 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 27fecacdd36..c0aa80ef1ae 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el | |||
| @@ -53,7 +53,7 @@ | |||
| 53 | 53 | ||
| 54 | ;;;###autoload | 54 | ;;;###autoload |
| 55 | (defun forward-thing (thing &optional n) | 55 | (defun forward-thing (thing &optional n) |
| 56 | "Move forward to the end of the next THING." | 56 | "Move forward to the end of the Nth next THING." |
| 57 | (let ((forward-op (or (get thing 'forward-op) | 57 | (let ((forward-op (or (get thing 'forward-op) |
| 58 | (intern-soft (format "forward-%s" thing))))) | 58 | (intern-soft (format "forward-%s" thing))))) |
| 59 | (if (functionp forward-op) | 59 | (if (functionp forward-op) |
| @@ -80,16 +80,13 @@ of the textual entity that was found." | |||
| 80 | (condition-case nil | 80 | (condition-case nil |
| 81 | (save-excursion | 81 | (save-excursion |
| 82 | ;; Try moving forward, then back. | 82 | ;; Try moving forward, then back. |
| 83 | (let ((end (progn | 83 | (funcall ;; First move to end. |
| 84 | (funcall | 84 | (or (get thing 'end-op) |
| 85 | (or (get thing 'end-op) | 85 | (lambda () (forward-thing thing 1)))) |
| 86 | (function (lambda () (forward-thing thing 1))))) | 86 | (funcall ;; Then move to beg. |
| 87 | (point))) | 87 | (or (get thing 'beginning-op) |
| 88 | (beg (progn | 88 | (lambda () (forward-thing thing -1)))) |
| 89 | (funcall | 89 | (let ((beg (point))) |
| 90 | (or (get thing 'beginning-op) | ||
| 91 | (function (lambda () (forward-thing thing -1))))) | ||
| 92 | (point)))) | ||
| 93 | (if (not (and beg (> beg orig))) | 90 | (if (not (and beg (> beg orig))) |
| 94 | ;; If that brings us all the way back to ORIG, | 91 | ;; If that brings us all the way back to ORIG, |
| 95 | ;; it worked. But END may not be the real end. | 92 | ;; it worked. But END may not be the real end. |
| @@ -98,28 +95,25 @@ of the textual entity that was found." | |||
| 98 | (progn | 95 | (progn |
| 99 | (funcall | 96 | (funcall |
| 100 | (or (get thing 'end-op) | 97 | (or (get thing 'end-op) |
| 101 | (function (lambda () (forward-thing thing 1))))) | 98 | (lambda () (forward-thing thing 1)))) |
| 102 | (point)))) | 99 | (point)))) |
| 103 | (if (and beg real-end (<= beg orig) (<= orig real-end)) | 100 | (if (and beg real-end (<= beg orig) (<= orig real-end)) |
| 104 | (cons beg real-end))) | 101 | (cons beg real-end))) |
| 105 | (goto-char orig) | 102 | (goto-char orig) |
| 106 | ;; Try a second time, moving backward first and then forward, | 103 | ;; Try a second time, moving backward first and then forward, |
| 107 | ;; so that we can find a thing that ends at ORIG. | 104 | ;; so that we can find a thing that ends at ORIG. |
| 108 | (let ((beg (progn | 105 | (funcall ;; First, move to beg. |
| 109 | (funcall | 106 | (or (get thing 'beginning-op) |
| 110 | (or (get thing 'beginning-op) | 107 | (lambda () (forward-thing thing -1)))) |
| 111 | (function (lambda () (forward-thing thing -1))))) | 108 | (funcall ;; Then move to end. |
| 112 | (point))) | 109 | (or (get thing 'end-op) |
| 113 | (end (progn | 110 | (lambda () (forward-thing thing 1)))) |
| 114 | (funcall | 111 | (let ((end (point)) |
| 115 | (or (get thing 'end-op) | 112 | (real-beg |
| 116 | (function (lambda () (forward-thing thing 1))))) | ||
| 117 | (point))) | ||
| 118 | (real-beg | ||
| 119 | (progn | 113 | (progn |
| 120 | (funcall | 114 | (funcall |
| 121 | (or (get thing 'beginning-op) | 115 | (or (get thing 'beginning-op) |
| 122 | (function (lambda () (forward-thing thing -1))))) | 116 | (lambda () (forward-thing thing -1)))) |
| 123 | (point)))) | 117 | (point)))) |
| 124 | (if (and real-beg end (<= real-beg orig) (<= orig end)) | 118 | (if (and real-beg end (<= real-beg orig) (<= orig end)) |
| 125 | (cons real-beg end)))))) | 119 | (cons real-beg end)))))) |
| @@ -160,7 +154,7 @@ a symbol as a valid THING." | |||
| 160 | ;; and it has no final newline. | 154 | ;; and it has no final newline. |
| 161 | 155 | ||
| 162 | (put 'line 'beginning-op | 156 | (put 'line 'beginning-op |
| 163 | (function (lambda () (if (bolp) (forward-line -1) (beginning-of-line))))) | 157 | (lambda () (if (bolp) (forward-line -1) (beginning-of-line)))) |
| 164 | 158 | ||
| 165 | ;; Sexps | 159 | ;; Sexps |
| 166 | 160 | ||
| @@ -190,7 +184,7 @@ a symbol as a valid THING." | |||
| 190 | 184 | ||
| 191 | ;; Lists | 185 | ;; Lists |
| 192 | 186 | ||
| 193 | (put 'list 'end-op (function (lambda () (up-list 1)))) | 187 | (put 'list 'end-op (lambda () (up-list 1))) |
| 194 | (put 'list 'beginning-op 'backward-sexp) | 188 | (put 'list 'beginning-op 'backward-sexp) |
| 195 | 189 | ||
| 196 | ;; Filenames and URLs www.com/foo%32bar | 190 | ;; Filenames and URLs www.com/foo%32bar |
| @@ -229,7 +223,7 @@ Hostname matching is stricter in this case than for | |||
| 229 | "afs:" "tn3270:" "mailserver:" | 223 | "afs:" "tn3270:" "mailserver:" |
| 230 | ;; Compatibility | 224 | ;; Compatibility |
| 231 | "snews:") | 225 | "snews:") |
| 232 | "Uniform Resource Identifier (URI) Schemes") | 226 | "Uniform Resource Identifier (URI) Schemes.") |
| 233 | 227 | ||
| 234 | (defvar thing-at-point-url-regexp | 228 | (defvar thing-at-point-url-regexp |
| 235 | (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)" | 229 | (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)" |
| @@ -243,18 +237,19 @@ This may contain whitespace (including newlines) .") | |||
| 243 | 237 | ||
| 244 | (put 'url 'bounds-of-thing-at-point 'thing-at-point-bounds-of-url-at-point) | 238 | (put 'url 'bounds-of-thing-at-point 'thing-at-point-bounds-of-url-at-point) |
| 245 | (defun thing-at-point-bounds-of-url-at-point () | 239 | (defun thing-at-point-bounds-of-url-at-point () |
| 246 | (let ((url "") short strip) | 240 | (let ((strip (thing-at-point-looking-at |
| 247 | (if (or (setq strip (thing-at-point-looking-at | 241 | thing-at-point-markedup-url-regexp))) ;; (url "") short |
| 248 | thing-at-point-markedup-url-regexp)) | 242 | (if (or strip |
| 249 | (thing-at-point-looking-at thing-at-point-url-regexp) | 243 | ` (thing-at-point-looking-at thing-at-point-url-regexp) |
| 250 | ;; Access scheme omitted? | 244 | ;; Access scheme omitted? |
| 251 | (setq short (thing-at-point-looking-at | 245 | ;; (setq short (thing-at-point-looking-at |
| 252 | thing-at-point-short-url-regexp))) | 246 | ;; thing-at-point-short-url-regexp)) |
| 247 | ) | ||
| 253 | (let ((beginning (match-beginning 0)) | 248 | (let ((beginning (match-beginning 0)) |
| 254 | (end (match-end 0))) | 249 | (end (match-end 0))) |
| 255 | (cond (strip | 250 | (when strip |
| 256 | (setq beginning (+ beginning 5)) | 251 | (setq beginning (+ beginning 5)) |
| 257 | (setq end (- end 1)))) | 252 | (setq end (- end 1))) |
| 258 | (cons beginning end))))) | 253 | (cons beginning end))))) |
| 259 | 254 | ||
| 260 | (put 'url 'thing-at-point 'thing-at-point-url-at-point) | 255 | (put 'url 'thing-at-point 'thing-at-point-url-at-point) |
| @@ -327,17 +322,17 @@ point." | |||
| 327 | (looking-at regexp))))) | 322 | (looking-at regexp))))) |
| 328 | 323 | ||
| 329 | (put 'url 'end-op | 324 | (put 'url 'end-op |
| 330 | (function (lambda () | 325 | (lambda () |
| 331 | (let ((bounds (thing-at-point-bounds-of-url-at-point))) | 326 | (let ((bounds (thing-at-point-bounds-of-url-at-point))) |
| 332 | (if bounds | 327 | (if bounds |
| 333 | (goto-char (cdr bounds)) | 328 | (goto-char (cdr bounds)) |
| 334 | (error "No URL here")))))) | 329 | (error "No URL here"))))) |
| 335 | (put 'url 'beginning-op | 330 | (put 'url 'beginning-op |
| 336 | (function (lambda () | 331 | (lambda () |
| 337 | (let ((bounds (thing-at-point-bounds-of-url-at-point))) | 332 | (let ((bounds (thing-at-point-bounds-of-url-at-point))) |
| 338 | (if bounds | 333 | (if bounds |
| 339 | (goto-char (car bounds)) | 334 | (goto-char (car bounds)) |
| 340 | (error "No URL here")))))) | 335 | (error "No URL here"))))) |
| 341 | 336 | ||
| 342 | ;; Whitespace | 337 | ;; Whitespace |
| 343 | 338 | ||
| @@ -385,7 +380,7 @@ point." | |||
| 385 | (defun sentence-at-point () (thing-at-point 'sentence)) | 380 | (defun sentence-at-point () (thing-at-point 'sentence)) |
| 386 | 381 | ||
| 387 | (defun read-from-whole-string (str) | 382 | (defun read-from-whole-string (str) |
| 388 | "Read a lisp expression from STR. | 383 | "Read a Lisp expression from STR. |
| 389 | Signal an error if the entire string was not used." | 384 | Signal an error if the entire string was not used." |
| 390 | (let* ((read-data (read-from-string str)) | 385 | (let* ((read-data (read-from-string str)) |
| 391 | (more-left | 386 | (more-left |
| @@ -407,11 +402,13 @@ Signal an error if the entire string was not used." | |||
| 407 | ;;;###autoload | 402 | ;;;###autoload |
| 408 | (defun sexp-at-point () (form-at-point 'sexp)) | 403 | (defun sexp-at-point () (form-at-point 'sexp)) |
| 409 | ;;;###autoload | 404 | ;;;###autoload |
| 410 | (defun symbol-at-point () (form-at-point 'sexp 'symbolp)) | 405 | (defun symbol-at-point () |
| 406 | (let ((thing (thing-at-point 'symbol))) | ||
| 407 | (if thing (intern thing)))) | ||
| 411 | ;;;###autoload | 408 | ;;;###autoload |
| 412 | (defun number-at-point () (form-at-point 'sexp 'numberp)) | 409 | (defun number-at-point () (form-at-point 'sexp 'numberp)) |
| 413 | ;;;###autoload | 410 | ;;;###autoload |
| 414 | (defun list-at-point () (form-at-point 'list 'listp)) | 411 | (defun list-at-point () (form-at-point 'list 'listp)) |
| 415 | 412 | ||
| 416 | ;;; arch-tag: bb65a163-dae2-4055-aedc-fe11f497f698 | 413 | ;; arch-tag: bb65a163-dae2-4055-aedc-fe11f497f698 |
| 417 | ;;; thingatpt.el ends here | 414 | ;;; thingatpt.el ends here |