annotate lisp/utils/thing.el @ 211:78478c60bfcd r20-4b4

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