annotate lisp/utils/thing.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents bcdc7deadc19
children c7528f8e288d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; thing.el --- find language-specific contiguous pieces of text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Keywords: extensions, languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; Authors: David Hughes <djh@cis.prime.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; adapted from Martin Boyer's thing.el for imouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Martin Boyer, IREQ <mboyer@ireq-robot.hydro.qc.ca>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; adapted from Heinz Schmidt's thing.el for sky-mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Heinz Schmidt, ICSI (hws@ICSI.Berkeley.EDU)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; adapted from Dan L. Pierson's epoch-thing.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; Dan L. Pierson <pierson@encore.com>, 2/5/90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; adapted from Joshua Guttman's Thing.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Joshua Guttman, MITRE (guttman@mitre.org)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; adapted from sun-fns.el by Joshua Guttman, MITRE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; Copyright (C) International Computer Science Institute, 1991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; XEmacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; XEmacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; You should have received a copy of the GNU General Public License
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
32 ;; along with XEmacs; see the file COPYING. If not, write to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
33 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; #### FSF has thingatpt.el, which does the same thing. Should merge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; or toss this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;;* FUNCTION: Things are language objects contiguous pieces of text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;* whose boundaries can be defined by syntax or context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;;*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;* RELATED PACKAGES: various packages built on this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;* HISTORY:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;* Last edited: David Hughes 21st December 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;;* jul 21 21:00 1993 (tlp00): added a kludgy thing-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;* Feb 22 21:00 1993 (tlp00): better merge with lucid and imouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;;* Dec 21 11:11 1992 (djh): added thing-report-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;;* Nov 23 18:00 1992 (djh): merged in Guido Bosch's ideas
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;;* Sep 10 15:35 1992 (djh): adapted for Lucid emacs19-mouse.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;;* Nov 28 17:40 1991 (mb): Cleaned up, and added thing-bigger-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;;* May 24 00:33 1991 (hws): overworked and added syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;* Created: 2/5/90 Dan L. Pierson
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (provide 'thing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;;;;;;;;;;; Customization and Entry Point ;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvar thing-boundary-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 '((?w thing-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (?_ thing-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (?\( thing-sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (?\$ thing-sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (?' thing-sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (?\" thing-sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (?\) thing-sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (? thing-whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (?< thing-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (?. thing-next-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "*List of pairs of the form (SYNTAX-CHAR FUNCTION) used by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 the function `thing-boundaries'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar thing-report-char-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "*Non nil means return single char boundaries if all else fails")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar thing-report-whitespace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "*Non nil means that whitespaces are considered as things, otherwise not.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defvar *last-thing*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "The last thing found by thing-boundaries. Used for chaining commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; The variable and function `thing-region' are to avoid the continual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; construction of cons cells as result af the thing scanner functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; This avoids unnecessary garbage collection. Guido Bosch <bosch@loria.fr>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defvar thing-region (cons 'nil 'nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "Cons cell that contains a region (<beginning> . <end>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 The function `thing-region' updates and returns it.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun thing-region (beginning end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Make BEGINNING the car and END the cdr of the cons cell in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 variable `thing-region'. Return the updated cons cell"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (cond ((/= beginning end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setcar thing-region beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setcdr thing-region end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 thing-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defvar thing-bigger-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 '((word-symbol thing-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (symbol thing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (word-sexp thing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (sexp thing-up-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (sexp-up thing-up-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (line thing-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (paragraph thing-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (char thing-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (word-sentence thing-sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (sentence thing-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 "List of pairs to go from one thing to a bigger thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 See mouse-select-bigger-thing and mouse-delete-bigger-thing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defvar thing-word-next nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 "*The next bigger thing after a word. A symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Supported values are: word-symbol, word-sexp, and word-sentence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 Default value is word-sentence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Automatically becomes local when set in any fashion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (make-variable-buffer-local 'thing-word-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun thing-boundaries (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Return start and end of text object at HERE using syntax table and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 thing-boundary-alist. Thing-boundary-alist is a list of pairs of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 form (SYNTAX-CHAR FUNCTION) where FUNCTION takes a single position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 argument and returns a cons of places (start end) representing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 boundaries of the thing at that position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 Typically:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 Left or right Paren syntax indicates an s-expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 The end of a line marks the line including a trailing newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 Word syntax indicates current word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Symbol syntax indicates symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 If it doesn't recognize one of these it selects just the character HERE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 If an error occurs during syntax scanning, the function just prints a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 message and returns `nil'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (interactive "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq *last-thing* nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (if (save-excursion (goto-char here) (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (thing-get-line here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let* ((syntax (char-syntax (char-after here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (pair (assq syntax thing-boundary-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (cond ((and pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (or thing-report-whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (not (eq (car (cdr pair)) 'thing-whitespace))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (funcall (car (cdr pair)) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (thing-report-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq *last-thing* 'char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (thing-region here (1+ here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;;;;;;;;;;;;;;;; Code Delimiters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defun thing-symbol (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "Return start and end of symbol at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (cond ((memq (char-syntax (char-after here)) '(?_ ?w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq *last-thing* 'symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((end (scan-sexps here 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (thing-region (min here (scan-sexps end -1)) end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defun thing-filename (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "Return start and end of filename at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (cond ((memq (char-syntax (char-after here)) '(?w ?_ ?.))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (and (re-search-forward "\\s \\|:\\s\"\\|$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (goto-char (setq end (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (re-search-backward "[^_a-zA-Z0-9---#$.~/@]+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (setq start (+ (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq start (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (thing-region (min start here) (max here end))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;~/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defun thing-sexp-start (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "Return start and end of sexp starting HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq *last-thing* 'sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (thing-region here (scan-sexps here 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defun thing-sexp-end (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 "Return start and end of sexp ending HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (setq *last-thing* 'sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (thing-region (scan-sexps (1+ here) -1) (1+ here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (defun thing-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 "Return start and end of the sexp at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (setq *last-thing* 'sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (thing-region (progn (backward-up-list 1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (progn (forward-list 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun thing-up-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Return start and end of the sexp enclosing the selected area."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq *last-thing* 'sexp-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; Keep going up and backward in sexps. This means that thing-up-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; can only be called after thing-sexp or after itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (thing-region (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (backward-up-list 1) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (forward-list 1) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; Allow punctuation marks not followed by white-space to include
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;; the subsequent sexp. Useful in foo.bar(x).baz and such.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun thing-next-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Return from HERE to the end of the sexp at HERE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 if the character at HERE is part of a sexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq *last-thing* 'sexp-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if (= (char-syntax (char-after (1+ here))) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (thing-region here (1+ here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (thing-region here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (save-excursion (goto-char here) (forward-sexp) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;;; Allow click to comment-char to extend to end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defun thing-comment (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "Return rest of line from HERE to newline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq *last-thing* 'comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (save-excursion (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (while (= (char-syntax (preceding-char)) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (thing-region (point) (progn (end-of-line) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;;;;;;;;;;;;;;;;; Text Delimiters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun thing-word (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Return start and end of word at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq *last-thing*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setq thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ((memq major-mode '(emacs-lisp-mode c-mode c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 fortran-mode latex-mode lisp-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 perl-mode tex-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 'word-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (t 'word-sentence)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (thing-region (point) end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defun thing-sentence (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 "Return start and end of the sentence at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq *last-thing* 'sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (thing-region (progn (backward-sentence) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (progn (forward-sentence) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defun thing-whitespace (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Return start to end of all of whitespace HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq *last-thing* 'whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (let ((start (progn (skip-chars-backward " \t") (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (end (progn (skip-chars-forward " \t") (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (if (= start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (thing-region (1- start) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (thing-region start end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;;;;;;;;;;;;;;; Physical Delimiters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (defun thing-get-line (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 "Return whole of line HERE is in, with newline unless at eob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (setq *last-thing* 'line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (let* ((start (progn (beginning-of-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (thing-region start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defun thing-paragraph (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "Return start and end of the paragraph at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (setq *last-thing* 'paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (thing-region (progn (backward-paragraph) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (progn (forward-paragraph) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun thing-page (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Return start and end of the page at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq *last-thing* 'page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (thing-region (progn (backward-page) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (progn (forward-page) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;;;;;;;;;;;;;;;; Support functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (defun kill-thing-at-point (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 "Kill text object using syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 See thing-boundaries for definition of text objects"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (interactive "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (let ((bounds (thing-boundaries here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (kill-region (car bounds) (cdr bounds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defun copy-thing-at-point (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "Copy text object using syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 See thing-boundaries for definition of text objects"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (interactive "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (let ((bounds (thing-boundaries here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (copy-region-as-kill (car bounds) (cdr bounds))))