annotate lisp/utils/atomic-extents.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents 376386a54a3c
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Point is not allowed to fall inside of an atomic extent. This has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; the effect of making all text covered by an atomic extent be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; treated as a single object. Normally point will be adjusted to an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; end of an atomic extent in the direction of motion. If point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; appears inside of an atomic extent (via goto-char for example),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; point will be adjusted to the side closest to the entry point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; To make an extent atomic use the command:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; (set-extent-property #<extent obj> 'atomic t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Known bug: the atomic property is not detected when sweeping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; regions with the mouse until after the mouse button is released.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; The release point will then be treated as if it had been reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; using 'goto-char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; atomic-extent-goto-char-p is defined in editfns.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (provide 'atomic-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar atomic-extent-old-point nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "The value of point when pre-command-hook is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Used to determine the direction of motion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun atomic-extent-pre-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq atomic-extent-old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq atomic-extent-goto-char-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defun atomic-extent-post-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (let ((extent (extent-at (point) nil 'atomic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (let ((begin (extent-start-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (end (extent-end-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (region-set (and (point) (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if (eq this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 'x-set-point-and-insert-selection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (delete-region (region-beginning) (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (/= pos begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (if atomic-extent-goto-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (> (- pos begin) (- end pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (goto-char begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (> pos atomic-extent-old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (goto-char begin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (and region-set (/= pos begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (run-hooks 'zmacs-update-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (x-store-cutbuffer (buffer-substring (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (if (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (exchange-point-and-mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (let ((extent (extent-at (point) nil 'atomic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (let ((begin (extent-start-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (end (extent-end-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (region-set (and (point) (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (if (/= pos begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if atomic-extent-goto-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (> (- pos begin) (- end pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (goto-char begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (> pos atomic-extent-old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (goto-char begin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if (and region-set (/= pos begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (run-hooks 'zmacs-update-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (x-store-cutbuffer (buffer-substring (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (message "%d, %d" (region-beginning) (region-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (exchange-point-and-mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (add-hook 'pre-command-hook 'atomic-extent-pre-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (add-hook 'post-command-hook 'atomic-extent-post-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; atomic-extents.el ends here