annotate lisp/utils/thing.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents 376386a54a3c
children 131b0175ea99
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
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
32 ;; along with XEmacs; see the file COPYING. If not, write to the Free
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
33 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
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)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (thing-region (min here (scan-sexps end -1)) end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun thing-filename (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Return start and end of filename at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (cond ((memq (char-syntax (char-after here)) '(?w ?_ ?.))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (and (re-search-forward "\\s \\|:\\s\"\\|$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (goto-char (setq end (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (re-search-backward "[^_a-zA-Z0-9---#$.~/@]+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq start (+ (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (setq start (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (thing-region (min start here) (max here end))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;~/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defun thing-sexp-start (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "Return start and end of sexp starting HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq *last-thing* 'sexp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (thing-region here (scan-sexps here 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun thing-sexp-end (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Return start and end of sexp ending HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq *last-thing* 'sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (thing-region (scan-sexps (1+ here) -1) (1+ here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defun thing-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 "Return start and end of the sexp at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setq *last-thing* 'sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (thing-region (progn (backward-up-list 1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (progn (forward-list 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (defun thing-up-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 "Return start and end of the sexp enclosing the selected area."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq *last-thing* 'sexp-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Keep going up and backward in sexps. This means that thing-up-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; can only be called after thing-sexp or after itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (thing-region (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (backward-up-list 1) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (forward-list 1) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;; Allow punctuation marks not followed by white-space to include
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; the subsequent sexp. Useful in foo.bar(x).baz and such.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defun thing-next-sexp (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "Return from HERE to the end of the sexp at HERE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 if the character at HERE is part of a sexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq *last-thing* 'sexp-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (= (char-syntax (char-after (1+ here))) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (thing-region here (1+ here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (thing-region here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (save-excursion (goto-char here) (forward-sexp) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;;; Allow click to comment-char to extend to end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun thing-comment (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Return rest of line from HERE to newline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq *last-thing* 'comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (save-excursion (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (while (= (char-syntax (preceding-char)) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (thing-region (point) (progn (end-of-line) (point)))))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;;;;;;;;;;;;;;;; Text Delimiters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun thing-word (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Return start and end of word at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq *last-thing*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq thing-word-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ((memq major-mode '(emacs-lisp-mode c-mode c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 fortran-mode latex-mode lisp-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 perl-mode tex-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 'word-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (t 'word-sentence)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (let ((end (point)))
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 (thing-region (point) end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun thing-sentence (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Return start and end of the sentence at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (setq *last-thing* 'sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (thing-region (progn (backward-sentence) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (progn (forward-sentence) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (defun thing-whitespace (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 "Return start to end of all of whitespace HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq *last-thing* 'whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((start (progn (skip-chars-backward " \t") (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (end (progn (skip-chars-forward " \t") (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if (= start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (thing-region (1- start) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (thing-region start end)))))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;;;;;;;;;;;;;; Physical Delimiters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun thing-get-line (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "Return whole of line HERE is in, with newline unless at eob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq *last-thing* 'line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (let* ((start (progn (beginning-of-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (thing-region start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defun thing-paragraph (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "Return start and end of the paragraph at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq *last-thing* 'paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (thing-region (progn (backward-paragraph) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (progn (forward-paragraph) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defun thing-page (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "Return start and end of the page at HERE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq *last-thing* 'page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (thing-region (progn (backward-page) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (progn (forward-page) (point)))))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;;;;;;;;;;;;;;;; Support functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (defun kill-thing-at-point (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "Kill text object using syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 See thing-boundaries for definition of text objects"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (interactive "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let ((bounds (thing-boundaries here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (kill-region (car bounds) (cdr bounds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defun copy-thing-at-point (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 "Copy text object using syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 See thing-boundaries for definition of text objects"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (interactive "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (let ((bounds (thing-boundaries here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (copy-region-as-kill (car bounds) (cdr bounds))))