annotate lisp/thingatpt.el @ 5882:319a7fcb7609

(difftm): Simplify expression.
author Karl Heuer <kwzh@gnu.org>
date Thu, 10 Feb 1994 20:27:34 +0000
parents 59280129eaac
children c0cc87942423
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; thingatpt.el --- Get the `thing' at point
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1991,1992,1993 Free Software Foundation, Inc.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Mike Williams <mikew@gopher.dosli.govt.nz>
5140
9cde7d7fea1f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4934
diff changeset
6 ;; Keywords: extensions, matching, mouse
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: Thu Mar 28 13:48:23 1991
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
5751
59280129eaac (thing@pt-version): Removed variable.
Richard M. Stallman <rms@gnu.org>
parents: 5140
diff changeset
21 ;;; Commentary: ===========================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; This file provides routines for getting the `thing' at the location of
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; point, whatever that `thing' happens to be. The `thing' is defined by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; it's beginning and end positions in the buffer.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; The function bounds-of-thing-at-point finds the beginning and end
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; positions by moving first forward to the end of the `thing', and then
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; backwards to the beginning. By default, it uses the corresponding
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; forward-`thing' operator (eg. forward-word, forward-line).
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Special cases are allowed for using properties associated with the named
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; `thing':
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; forward-op Function to call to skip forward over a `thing' (or
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; with a negative argument, backward).
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; beginning-op Function to call to skip to the beginning of a `thing'.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; end-op Function to call to skip to the end of a `thing'.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Reliance on existing operators means that many `things' can be accessed
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; without further code: eg.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; (thing-at-point 'line)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; (thing-at-point 'page)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
5751
59280129eaac (thing@pt-version): Removed variable.
Richard M. Stallman <rms@gnu.org>
parents: 5140
diff changeset
46 ;;; Code: =================================================================
4934
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (provide 'thingatpt)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;=== Basic movement ======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defun forward-thing (THING &optional N)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 "Move forward to the end of the next THING."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (let ((forward-op (or (get THING 'forward-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (intern-soft (format "forward-%s" THING)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (if (fboundp forward-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (funcall forward-op (or N 1))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (error "Can't determine how to move over %ss" THING))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;=== General routines ====================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defun bounds-of-thing-at-point (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 "Determine the start and end buffer locations for the THING at point,
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 where THING is an entity for which there is a either a corresponding
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 forward-THING operation, or corresponding beginning-of-THING and
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 end-of-THING operations, eg. 'word, 'sentence, 'defun.
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 Return a cons cell '(start . end) giving the start and end positions."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (let ((orig (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (save-excursion
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (let ((end (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (funcall
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (or (get THING 'end-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (function (lambda () (forward-thing THING 1)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (beg (progn
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (funcall
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (or (get THING 'beginning-op)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (function (lambda () (forward-thing THING -1)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (point))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (if (and beg end (<= beg orig) (< orig end))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (cons beg end))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (error nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;;###autoload
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (defun thing-at-point (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 "Return the THING at point, where THING is an entity defined by
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 bounds-of-thing-at-point."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (if bounds
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (buffer-substring (car bounds) (cdr bounds)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;=== Go to beginning/end =================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defun beginning-of-thing (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (or bounds (error "No %s here" THING))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (goto-char (car bounds))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defun end-of-thing (THING)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (let ((bounds (bounds-of-thing-at-point THING)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (or bounds (error "No %s here" THING))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (goto-char (cdr bounds))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;=== Special cases =======================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;--- Sexps ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun in-string-p ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (let ((orig (point)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (save-excursion
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (beginning-of-defun)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (nth 3 (parse-partial-sexp (point) orig)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (defun end-of-sexp ()
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (let ((char-syntax (char-syntax (char-after (point)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (if (or (eq char-syntax ?\))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (and (eq char-syntax ?\") (in-string-p)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (forward-char 1)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (forward-sexp 1))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (put 'sexp 'end-op 'end-of-sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;;--- Lists ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (put 'list 'end-op (function (lambda () (up-list 1))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (put 'list 'beginning-op 'backward-sexp)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;;--- Filenames ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defvar file-name-chars "~/A-Za-z0-9---_.${}#%,"
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 "Characters allowable in filenames.")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (put 'filename 'end-op
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (function (lambda () (skip-chars-forward file-name-chars))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (put 'filename 'beginning-op
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (function (lambda () (skip-chars-backward file-name-chars (point-min)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;--- Whitespace ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defun forward-whitespace (ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (interactive "p")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (if (natnump ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (re-search-forward "[ \t]+\\|\n" nil nil ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (while (< ARG 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (if (re-search-backward "[ \t]+\\|\n" nil nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (or (eq (char-after (match-beginning 0)) 10)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (skip-chars-backward " \t")))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (setq ARG (1+ ARG)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;;--- Buffer ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (put 'buffer 'end-op 'end-of-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (put 'buffer 'beginning-op 'beginning-of-buffer)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;;--- Symbols ---
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defun forward-symbol (ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (interactive "p")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (if (natnump ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (re-search-forward "\\(\\sw\\|\\s_\\)+" nil nil ARG)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (while (< ARG 0)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (if (re-search-backward "\\(\\sw\\|\\s_\\)+" nil nil)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (skip-syntax-backward "w_"))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (setq ARG (1+ ARG)))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;;=== Aliases =============================================================
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun word-at-point () (thing-at-point 'word))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defun sentence-at-point () (thing-at-point 'sentence))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (defun read-from-whole-string (STR)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 "Read a lisp expression from STR, signalling an error if the entire string
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 was not used."
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (let* ((read-data (read-from-string STR))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (more-left
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (progn (read-from-string (substring STR (cdr read-data)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 t)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (end-of-file nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (if more-left
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (error "Can't read whole string")
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (car read-data))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (defun form-at-point (&optional THING PRED)
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (let ((sexp (condition-case nil
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (read-from-whole-string (thing-at-point (or THING 'sexp)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (error nil))))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if (or (not PRED) (funcall PRED sexp)) sexp)))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (defun sexp-at-point () (form-at-point 'sexp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun symbol-at-point () (form-at-point 'sexp 'symbolp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defun number-at-point () (form-at-point 'sexp 'numberp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (defun list-at-point () (form-at-point 'list 'listp))
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
a8b355b89859 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;; thingatpt.el ends here.