Mercurial > emacs
annotate lisp/thingatpt.el @ 97075:864ac210d576
* xmenu.c (Fx_menu_bar_open_internal): Use activate_item signal to
open menu.
* gtkutil.c (menu_nav_ended): Remove.
(create_menus): Remove signal connect for menu_nav_ended.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Tue, 29 Jul 2008 09:25:04 +0000 |
parents | ee5932bf781d |
children | 536c0f16eb08 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
30818
diff
changeset
|
1 ;;; thingatpt.el --- get the `thing' at point |
4934 | 2 |
74442 | 3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
5 ;; Free Software Foundation, Inc. |
4934 | 6 |
7 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz> | |
29516
4e7f28c8e364
(forward-thing): Use functionp instead of fboundp.
Gerd Moellmann <gerd@gnu.org>
parents:
27581
diff
changeset
|
8 ;; Maintainer: FSF |
5140 | 9 ;; Keywords: extensions, matching, mouse |
4934 | 10 ;; Created: Thu Mar 28 13:48:23 1991 |
11 | |
12 ;; This file is part of GNU Emacs. | |
13 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
4934 | 15 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
17 ;; (at your option) any later version. |
4934 | 18 |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
26 |
7938 | 27 ;;; Commentary: |
14169 | 28 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
29 ;; 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
|
30 ;; point, whatever that "thing" happens to be. The "thing" is defined by |
16427 | 31 ;; its beginning and end positions in the buffer. |
4934 | 32 ;; |
33 ;; 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
|
34 ;; positions by moving first forward to the end of the "thing", and then |
4934 | 35 ;; 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
|
36 ;; forward-"thing" operator (eg. forward-word, forward-line). |
4934 | 37 ;; |
38 ;; Special cases are allowed for using properties associated with the named | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
39 ;; "thing": |
4934 | 40 ;; |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
41 ;; forward-op Function to call to skip forward over a "thing" (or |
4934 | 42 ;; with a negative argument, backward). |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
43 ;; |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
44 ;; 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
|
45 ;; end-op Function to call to skip to the end of a "thing". |
4934 | 46 ;; |
47 ;; Reliance on existing operators means that many `things' can be accessed | |
48 ;; without further code: eg. | |
49 ;; (thing-at-point 'line) | |
50 ;; (thing-at-point 'page) | |
51 | |
14169 | 52 ;;; Code: |
4934 | 53 |
54 (provide 'thingatpt) | |
55 | |
14169 | 56 ;; Basic movement |
4934 | 57 |
58 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
59 (defun forward-thing (thing &optional n) |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
60 "Move forward to the end of the Nth next THING." |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
61 (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
|
62 (intern-soft (format "forward-%s" thing))))) |
29516
4e7f28c8e364
(forward-thing): Use functionp instead of fboundp.
Gerd Moellmann <gerd@gnu.org>
parents:
27581
diff
changeset
|
63 (if (functionp forward-op) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
64 (funcall forward-op (or n 1)) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
65 (error "Can't determine how to move over a %s" thing)))) |
4934 | 66 |
14169 | 67 ;; General routines |
4934 | 68 |
69 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
70 (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
|
71 "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
|
72 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
|
73 Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
81447
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
74 `email', `word', `sentence', `whitespace', `line', `page' and others. |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
75 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
76 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
|
77 a symbol as a valid THING. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
78 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
79 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
|
80 of the textual entity that was found." |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
81 (if (get thing 'bounds-of-thing-at-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
82 (funcall (get thing 'bounds-of-thing-at-point)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
83 (let ((orig (point))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
84 (condition-case nil |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
85 (save-excursion |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
86 ;; Try moving forward, then back. |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
87 (funcall ;; First move to end. |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
88 (or (get thing 'end-op) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
89 (lambda () (forward-thing thing 1)))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
90 (funcall ;; Then move to beg. |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
91 (or (get thing 'beginning-op) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
92 (lambda () (forward-thing thing -1)))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
93 (let ((beg (point))) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
94 (if (not (and beg (> beg orig))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
95 ;; If that brings us all the way back to ORIG, |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
96 ;; it worked. But END may not be the real end. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
97 ;; So find the real end that corresponds to BEG. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
98 (let ((real-end |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
99 (progn |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
100 (funcall |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
101 (or (get thing 'end-op) |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
102 (lambda () (forward-thing thing 1)))) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
103 (point)))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
104 (if (and beg real-end (<= beg orig) (<= orig real-end)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
105 (cons beg real-end))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
106 (goto-char orig) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
107 ;; Try a second time, moving backward first and then forward, |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
108 ;; so that we can find a thing that ends at ORIG. |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
109 (funcall ;; First, move to beg. |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
110 (or (get thing 'beginning-op) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
111 (lambda () (forward-thing thing -1)))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
112 (funcall ;; Then move to end. |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
113 (or (get thing 'end-op) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
114 (lambda () (forward-thing thing 1)))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
115 (let ((end (point)) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
116 (real-beg |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
117 (progn |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
118 (funcall |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
119 (or (get thing 'beginning-op) |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
120 (lambda () (forward-thing thing -1)))) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
121 (point)))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
122 (if (and real-beg end (<= real-beg orig) (<= orig end)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
123 (cons real-beg end)))))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
124 (error nil))))) |
4934 | 125 |
126 ;;;###autoload | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
127 (defun thing-at-point (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
128 "Return the THING at point. |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
129 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
|
130 Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', |
81447
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
131 `email', `word', `sentence', `whitespace', `line', `page' and others. |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
132 |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
133 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
|
134 a symbol as a valid THING." |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
135 (if (get thing 'thing-at-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
136 (funcall (get thing 'thing-at-point)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
137 (let ((bounds (bounds-of-thing-at-point thing))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
138 (if bounds |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
139 (buffer-substring (car bounds) (cdr bounds)))))) |
4934 | 140 |
14169 | 141 ;; Go to beginning/end |
4934 | 142 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
143 (defun beginning-of-thing (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
144 (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
|
145 (or bounds (error "No %s here" thing)) |
4934 | 146 (goto-char (car bounds)))) |
147 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
148 (defun end-of-thing (thing) |
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
149 (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
|
150 (or bounds (error "No %s here" thing)) |
4934 | 151 (goto-char (cdr bounds)))) |
152 | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
153 ;; Special cases |
4934 | 154 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
155 ;; Lines |
9931
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
156 |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
157 ;; 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
|
158 ;; and it has no final newline. |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
159 |
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
160 (put 'line 'beginning-op |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
161 (lambda () (if (bolp) (forward-line -1) (beginning-of-line)))) |
9931
23e429e3fb18
(line): Add a beginning-op function.
Richard M. Stallman <rms@gnu.org>
parents:
7938
diff
changeset
|
162 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
163 ;; Sexps |
4934 | 164 |
165 (defun in-string-p () | |
166 (let ((orig (point))) | |
167 (save-excursion | |
168 (beginning-of-defun) | |
169 (nth 3 (parse-partial-sexp (point) orig))))) | |
170 | |
171 (defun end-of-sexp () | |
172 (let ((char-syntax (char-syntax (char-after (point))))) | |
173 (if (or (eq char-syntax ?\)) | |
174 (and (eq char-syntax ?\") (in-string-p))) | |
175 (forward-char 1) | |
176 (forward-sexp 1)))) | |
177 | |
178 (put 'sexp 'end-op 'end-of-sexp) | |
179 | |
18432
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
180 (defun beginning-of-sexp () |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
181 (let ((char-syntax (char-syntax (char-before (point))))) |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
182 (if (or (eq char-syntax ?\() |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
183 (and (eq char-syntax ?\") (in-string-p))) |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
184 (forward-char -1) |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
185 (forward-sexp -1)))) |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
186 |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
187 (put 'sexp 'beginning-op 'beginning-of-sexp) |
b2bc7438b6b0
(beginning-of-sexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17790
diff
changeset
|
188 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
189 ;; Lists |
4934 | 190 |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
191 (put 'list 'end-op (lambda () (up-list 1))) |
4934 | 192 (put 'list 'beginning-op 'backward-sexp) |
193 | |
49270
c84445fe778c
(thing-at-point-file-name-chars): Include non-ASCII
Dave Love <fx@gnu.org>
parents:
47862
diff
changeset
|
194 ;; Filenames and URLs www.com/foo%32bar |
4934 | 195 |
49486
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
196 (defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:" |
4934 | 197 "Characters allowable in filenames.") |
198 | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
199 (put 'filename 'end-op |
49486
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
200 (lambda () |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
201 (re-search-forward (concat "\\=[" thing-at-point-file-name-chars "]*") |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
202 nil t))) |
4934 | 203 (put 'filename 'beginning-op |
49486
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
204 (lambda () |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
205 (if (re-search-backward (concat "[^" thing-at-point-file-name-chars "]") |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
206 nil t) |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
207 (forward-char) |
b8c5db4dbb2b
(thing-at-point-file-name-chars): Include
Dave Love <fx@gnu.org>
parents:
49461
diff
changeset
|
208 (goto-char (point-min))))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
209 |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
210 (defvar thing-at-point-url-path-regexp |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
211 "[^]\t\n \"'()<>[^`{}]*[^]\t\n \"'()<>[^`{}.,;]+" |
47786
a9de3e936eef
(thing-at-point-url-path-regexp): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47769
diff
changeset
|
212 "A regular expression probably matching the host and filename or e-mail part of a URL.") |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
213 |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
214 (defvar thing-at-point-short-url-regexp |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
215 (concat "[-A-Za-z0-9.]+" thing-at-point-url-path-regexp) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
216 "A regular expression probably matching a URL without an access scheme. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
217 Hostname matching is stricter in this case than for |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
218 ``thing-at-point-url-regexp''.") |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
219 |
47769
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
220 (defvar thing-at-point-uri-schemes |
74109
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
221 ;; Officials from http://www.iana.org/assignments/uri-schemes.html |
47769
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
222 '("ftp://" "http://" "gopher://" "mailto:" "news:" "nntp:" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
223 "telnet://" "wais://" "file:/" "prospero:" "z39.50s:" "z39.50r:" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
224 "cid:" "mid:" "vemmi:" "service:" "imap:" "nfs:" "acap:" "rtsp:" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
225 "tip:" "pop:" "data:" "dav:" "opaquelocktoken:" "sip:" "tel:" "fax:" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
226 "modem:" "ldap:" "https://" "soap.beep:" "soap.beeps:" "urn:" "go:" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
227 "afs:" "tn3270:" "mailserver:" |
74109
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
228 "crid:" "dict:" "dns:" "dtn:" "h323:" "im:" "info:" "ipp:" |
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
229 "iris.beep:" "mtqp:" "mupdate:" "pres:" "sips:" "snmp:" "tag:" |
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
230 "tftp:" "xmlrpc.beep:" "xmlrpc.beeps:" "xmpp:" |
47769
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
231 ;; Compatibility |
74109
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
232 "snews:" "irc:" "mms://" "mmsh://") |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
233 "Uniform Resource Identifier (URI) Schemes.") |
47769
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
234 |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
235 (defvar thing-at-point-url-regexp |
47769
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
236 (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)" |
2a1b3fb46c95
(thing-at-point-uri-schemes): New variable.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
38412
diff
changeset
|
237 thing-at-point-url-path-regexp) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
238 "A regular expression probably matching a complete URL.") |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
239 |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
240 (defvar thing-at-point-markedup-url-regexp |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
241 "<URL:[^>]+>" |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
242 "A regular expression matching a URL marked up per RFC1738. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
243 This may contain whitespace (including newlines) .") |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
244 |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
245 (put 'url 'bounds-of-thing-at-point 'thing-at-point-bounds-of-url-at-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
246 (defun thing-at-point-bounds-of-url-at-point () |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
247 (let ((strip (thing-at-point-looking-at |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
248 thing-at-point-markedup-url-regexp))) ;; (url "") short |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
249 (if (or strip |
72849
1302db63b66b
(thing-at-point-bounds-of-url-at-point): Delete spurious backquote.
Richard M. Stallman <rms@gnu.org>
parents:
71614
diff
changeset
|
250 (thing-at-point-looking-at thing-at-point-url-regexp) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
251 ;; Access scheme omitted? |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
252 ;; (setq short (thing-at-point-looking-at |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
253 ;; thing-at-point-short-url-regexp)) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
254 ) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
255 (let ((beginning (match-beginning 0)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
256 (end (match-end 0))) |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
257 (when strip |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
258 (setq beginning (+ beginning 5)) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
259 (setq end (- end 1))) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
260 (cons beginning end))))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
261 |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
262 (put 'url 'thing-at-point 'thing-at-point-url-at-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
263 (defun thing-at-point-url-at-point () |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
264 "Return the URL around or before point. |
20982
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
265 |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
266 Search backwards for the start of a URL ending at or after point. If |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
267 no URL found, return nil. The access scheme will be prepended if |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
268 absent: \"mailto:\" if the string contains \"@\", \"ftp://\" if it |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
269 starts with \"ftp\" and not \"ftp:/\", or \"http://\" by default." |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
270 |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
271 (let ((url "") short strip) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
272 (if (or (setq strip (thing-at-point-looking-at |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
273 thing-at-point-markedup-url-regexp)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
274 (thing-at-point-looking-at thing-at-point-url-regexp) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
275 ;; Access scheme omitted? |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
276 (setq short (thing-at-point-looking-at |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
277 thing-at-point-short-url-regexp))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
278 (progn |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
279 (setq url (buffer-substring-no-properties (match-beginning 0) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
280 (match-end 0))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
281 (and strip (setq url (substring url 5 -1))) ; Drop "<URL:" & ">" |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
282 ;; strip whitespace |
23764
615a6a17e7d6
(thing-at-point-url-at-point): Don't use current
Richard M. Stallman <rms@gnu.org>
parents:
20982
diff
changeset
|
283 (while (string-match "[ \t\n\r]+" url) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
284 (setq url (replace-match "" t t url))) |
74109
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
285 (and short (setq url (concat (cond ((string-match "^[a-zA-Z]+:" url) |
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
286 ;; already has a URL scheme. |
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
287 "") |
b67c1da1e80e
(thing-at-point-url-at-point): Don't add a redundant scheme.
Richard M. Stallman <rms@gnu.org>
parents:
72849
diff
changeset
|
288 ((string-match "@" url) |
20982
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
289 "mailto:") |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
290 ;; e.g. ftp.swiss... or ftp-swiss... |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
291 ((string-match "^ftp" url) |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
292 "ftp://") |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
293 (t "http://")) |
3a01b0f0338f
(thing-at-point-url-at-point): Intuit ftp:// on `short' URLs.
Dave Love <fx@gnu.org>
parents:
18682
diff
changeset
|
294 url))) |
18610
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
295 (if (string-equal "" url) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
296 nil |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
297 url))))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
298 |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
299 ;; The normal thingatpt mechanism doesn't work for complex regexps. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
300 ;; This should work for almost any regexp wherever we are in the |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
301 ;; match. To do a perfect job for any arbitrary regexp would mean |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
302 ;; testing every position before point. Regexp searches won't find |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
303 ;; matches that straddle the start position so we search forwards once |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
304 ;; and then back repeatedly and then back up a char at a time. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
305 |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
306 (defun thing-at-point-looking-at (regexp) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
307 "Return non-nil if point is in or just after a match for REGEXP. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
308 Set the match data from the earliest such match ending at or after |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
309 point." |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
310 (save-excursion |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
311 (let ((old-point (point)) match) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
312 (and (looking-at regexp) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
313 (>= (match-end 0) old-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
314 (setq match (point))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
315 ;; Search back repeatedly from end of next match. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
316 ;; This may fail if next match ends before this match does. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
317 (re-search-forward regexp nil 'limit) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
318 (while (and (re-search-backward regexp nil t) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
319 (or (> (match-beginning 0) old-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
320 (and (looking-at regexp) ; Extend match-end past search start |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
321 (>= (match-end 0) old-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
322 (setq match (point)))))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
323 (if (not match) nil |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
324 (goto-char match) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
325 ;; Back up a char at a time in case search skipped |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
326 ;; intermediate match straddling search start pos. |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
327 (while (and (not (bobp)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
328 (progn (backward-char 1) (looking-at regexp)) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
329 (>= (match-end 0) old-point) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
330 (setq match (point)))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
331 (goto-char match) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
332 (looking-at regexp))))) |
4726c7bb05a9
(thing-at-point): Use `thing-at-point' property, if any.
Richard M. Stallman <rms@gnu.org>
parents:
18439
diff
changeset
|
333 |
18682
28f77aef27b2
(url): Define end-op property again. Wrap end-op
Richard M. Stallman <rms@gnu.org>
parents:
18610
diff
changeset
|
334 (put 'url 'end-op |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
335 (lambda () |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
336 (let ((bounds (thing-at-point-bounds-of-url-at-point))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
337 (if bounds |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
338 (goto-char (cdr bounds)) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
339 (error "No URL here"))))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
340 (put 'url 'beginning-op |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
341 (lambda () |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
342 (let ((bounds (thing-at-point-bounds-of-url-at-point))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
343 (if bounds |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
344 (goto-char (car bounds)) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
345 (error "No URL here"))))) |
4934 | 346 |
81447
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
347 ;; Email addresses |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
348 (defvar thing-at-point-email-regexp |
81448
3513d3f93273
* thingatpt.el (thing-at-point-email-regexp): Don't require two chars
Karl Fogel <kfogel@red-bean.com>
parents:
81447
diff
changeset
|
349 "<?[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]*@[-.a-zA-Z0-9]+>?" |
81447
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
350 "A regular expression probably matching an email address. |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
351 This does not match the real name portion, only the address, optionally |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
352 with angle brackets.") |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
353 |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
354 ;; Haven't set 'forward-op on 'email nor defined 'forward-email' because |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
355 ;; not sure they're actually needed, and URL seems to skip them too. |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
356 ;; Note that (end-of-thing 'email) and (beginning-of-thing 'email) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
357 ;; work automagically, though. |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
358 |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
359 (put 'email 'bounds-of-thing-at-point |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
360 (lambda () |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
361 (let ((thing (thing-at-point-looking-at thing-at-point-email-regexp))) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
362 (if thing |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
363 (let ((beginning (match-beginning 0)) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
364 (end (match-end 0))) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
365 (cons beginning end)))))) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
366 |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
367 (put 'email 'thing-at-point |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
368 (lambda () |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
369 (let ((boundary-pair (bounds-of-thing-at-point 'email))) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
370 (if boundary-pair |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
371 (buffer-substring-no-properties |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
372 (car boundary-pair) (cdr boundary-pair)))))) |
697178a8197c
* thingatpt.el: Add support for email addresses (`email').
Karl Fogel <kfogel@red-bean.com>
parents:
75347
diff
changeset
|
373 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
374 ;; Whitespace |
4934 | 375 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
376 (defun forward-whitespace (arg) |
4934 | 377 (interactive "p") |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
378 (if (natnump arg) |
17790
3ae7560f0959
(forward-whitespace, forward-symbol):
Richard M. Stallman <rms@gnu.org>
parents:
16668
diff
changeset
|
379 (re-search-forward "[ \t]+\\|\n" nil 'move arg) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
380 (while (< arg 0) |
17790
3ae7560f0959
(forward-whitespace, forward-symbol):
Richard M. Stallman <rms@gnu.org>
parents:
16668
diff
changeset
|
381 (if (re-search-backward "[ \t]+\\|\n" nil 'move) |
4934 | 382 (or (eq (char-after (match-beginning 0)) 10) |
383 (skip-chars-backward " \t"))) | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
384 (setq arg (1+ arg))))) |
4934 | 385 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
386 ;; Buffer |
4934 | 387 |
29592
9d10c14d8199
(toplevel symbol-properties): Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29516
diff
changeset
|
388 (put 'buffer 'end-op (lambda () (goto-char (point-max)))) |
9d10c14d8199
(toplevel symbol-properties): Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29516
diff
changeset
|
389 (put 'buffer 'beginning-op (lambda () (goto-char (point-min)))) |
4934 | 390 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
391 ;; Symbols |
4934 | 392 |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
393 (defun forward-symbol (arg) |
4934 | 394 (interactive "p") |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
395 (if (natnump arg) |
17790
3ae7560f0959
(forward-whitespace, forward-symbol):
Richard M. Stallman <rms@gnu.org>
parents:
16668
diff
changeset
|
396 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil 'move arg) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
397 (while (< arg 0) |
17790
3ae7560f0959
(forward-whitespace, forward-symbol):
Richard M. Stallman <rms@gnu.org>
parents:
16668
diff
changeset
|
398 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil 'move) |
4934 | 399 (skip-syntax-backward "w_")) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
400 (setq arg (1+ arg))))) |
4934 | 401 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
402 ;; Syntax blocks |
12593
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
403 |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
404 (defun forward-same-syntax (&optional arg) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
405 (interactive "p") |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
406 (while (< arg 0) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
407 (skip-syntax-backward |
12593
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
408 (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
|
409 (setq arg (1+ arg))) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
410 (while (> arg 0) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
411 (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
|
412 (setq arg (1- arg)))) |
e961f9a213a7
(forward-same-syntax): New function.
Richard M. Stallman <rms@gnu.org>
parents:
9931
diff
changeset
|
413 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
414 ;; Aliases |
4934 | 415 |
416 (defun word-at-point () (thing-at-point 'word)) | |
417 (defun sentence-at-point () (thing-at-point 'sentence)) | |
418 | |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
419 (defun read-from-whole-string (str) |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
420 "Read a Lisp expression from STR. |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
421 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
|
422 (let* ((read-data (read-from-string str)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
423 (more-left |
4934 | 424 (condition-case nil |
47862 | 425 ;; The call to `ignore' suppresses a compiler warning. |
47861
1a9d2889f455
(read-from-whole-string): Add call to `ignore'.
Richard M. Stallman <rms@gnu.org>
parents:
47786
diff
changeset
|
426 (progn (ignore (read-from-string (substring str (cdr read-data)))) |
4934 | 427 t) |
428 (end-of-file nil)))) | |
429 (if more-left | |
430 (error "Can't read whole string") | |
431 (car read-data)))) | |
432 | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
433 (defun form-at-point (&optional thing pred) |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49486
diff
changeset
|
434 (let ((sexp (condition-case nil |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
435 (read-from-whole-string (thing-at-point (or thing 'sexp))) |
4934 | 436 (error nil)))) |
16629
a3345c8d1779
(thing-at-point-url-chars): Allow period.
Richard M. Stallman <rms@gnu.org>
parents:
16427
diff
changeset
|
437 (if (or (not pred) (funcall pred sexp)) sexp))) |
4934 | 438 |
27581 | 439 ;;;###autoload |
4934 | 440 (defun sexp-at-point () (form-at-point 'sexp)) |
27581 | 441 ;;;###autoload |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
442 (defun symbol-at-point () |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
443 (let ((thing (thing-at-point 'symbol))) |
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
444 (if thing (intern thing)))) |
27581 | 445 ;;;###autoload |
4934 | 446 (defun number-at-point () (form-at-point 'sexp 'numberp)) |
27581 | 447 ;;;###autoload |
4934 | 448 (defun list-at-point () (form-at-point 'list 'listp)) |
449 | |
71614
07e63b17c925
(symbol-at-point): Don't use `form-at-point' which
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68651
diff
changeset
|
450 ;; arch-tag: bb65a163-dae2-4055-aedc-fe11f497f698 |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
30818
diff
changeset
|
451 ;;; thingatpt.el ends here |