annotate lisp/utils/atomic-extents.el @ 151:59463afc5666 r20-3b2

Import from CVS: tag r20-3b2
author cvs
date Mon, 13 Aug 2007 09:37:19 +0200
parents 0293115a14e9
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 ;;; atomic-extents.el --- treat regions of text as a single object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Created: 21-Dec-93, Chuck Thompson <cthomp@cs.uiuc.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Changed: 08-Aug-94, Heiko Muenkel <muenkel@tnt.uni-hannover.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Point is not allowed to fall inside of an atomic extent. This has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; the effect of making all text covered by an atomic extent be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; treated as a single object. Normally point will be adjusted to an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; end of an atomic extent in the direction of motion. If point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; appears inside of an atomic extent (via goto-char for example),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; point will be adjusted to the side closest to the entry point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; To make an extent atomic use the command:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; (set-extent-property #<extent obj> 'atomic t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; Known bug: the atomic property is not detected when sweeping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; regions with the mouse until after the mouse button is released.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; The release point will then be treated as if it had been reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; using 'goto-char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; atomic-extent-goto-char-p is defined in editfns.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (provide 'atomic-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defvar atomic-extent-old-point nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "The value of point when pre-command-hook is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Used to determine the direction of motion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defun atomic-extent-pre-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq atomic-extent-old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (setq atomic-extent-goto-char-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun atomic-extent-post-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (let ((extent (extent-at (point) nil 'atomic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (if extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (let ((begin (extent-start-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (end (extent-end-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (region-set (and (point) (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (if (eq this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 'x-set-point-and-insert-selection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (delete-region (region-beginning) (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (if (/= pos begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if atomic-extent-goto-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (> (- pos begin) (- end pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (goto-char begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (if (> pos atomic-extent-old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (goto-char begin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (if (and region-set (/= pos begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (run-hooks 'zmacs-update-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (x-store-cutbuffer (buffer-substring (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (exchange-point-and-mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (let ((extent (extent-at (point) nil 'atomic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (let ((begin (extent-start-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (end (extent-end-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (region-set (and (point) (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (/= pos begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if atomic-extent-goto-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (> (- pos begin) (- end pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (goto-char begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (if (> pos atomic-extent-old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (goto-char begin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (and region-set (/= pos begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (run-hooks 'zmacs-update-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (x-store-cutbuffer (buffer-substring (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (message "%d, %d" (region-beginning) (region-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (exchange-point-and-mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (add-hook 'pre-command-hook 'atomic-extent-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (add-hook 'post-command-hook 'atomic-extent-post-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; atomic-extents.el ends here