annotate lisp/emulation/cua-gmrk.el @ 79288:60939d2c4cf8

*** empty log message ***
author Juanma Barranquero <lekktu@gmail.com>
date Wed, 31 Oct 2007 12:19:55 +0000
parents ac0efac52065
children d6d821e3ae21 e460f7bcfb6d f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1 ;;; cua-gmrk.el --- CUA unified global mark support
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
2
64701
34bd8e434dd7 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
75346
7a3f13e2dd57 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 69902
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
5
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
6 ;; Author: Kim F. Storm <storm@cua.dk>
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
7 ;; Keywords: keyboard emulations convenience cua mark
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
8
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
10
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78218
ac0efac52065 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
14 ;; any later version.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
15
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
19 ;; GNU General Public License for more details.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
20
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63870
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63870
diff changeset
24 ;; Boston, MA 02110-1301, USA.
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
25
45078
829beb9a6a4b Follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 44938
diff changeset
26 ;;; Commentary:
829beb9a6a4b Follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 44938
diff changeset
27
829beb9a6a4b Follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 44938
diff changeset
28 ;;; Code:
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
29
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
30 (provide 'cua-gmrk)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
31
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
32 (eval-when-compile
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
33 (require 'cua-base)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
34 (require 'cua-rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
35 )
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
36
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45503
diff changeset
37 ;;; Global Marker
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
38
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
39 ;; Non-nil when global marker is active.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
40 (defvar cua--global-mark-active nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
41
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
42 ;; Global mark position marker.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
43 (defvar cua--global-mark-marker nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
44
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
45 ;; Overlay for global mark position.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
46 (defvar cua--global-mark-overlay nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
47
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
48 ;; Initialize global mark things once...
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
49 (defvar cua--global-mark-initialized nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
50
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
51 ;; Saved configured blink-cursor-interval
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
52 (defvar cua--orig-blink-cursor-interval nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
53
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
54 (defun cua--deactivate-global-mark (&optional msg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
55 (when cua--global-mark-overlay
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
56 (delete-overlay cua--global-mark-overlay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
57 (setq cua--global-mark-overlay nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
58 (if (markerp cua--global-mark-marker)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
59 (move-marker cua--global-mark-marker nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
60 (if cua--orig-blink-cursor-interval
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
61 (setq blink-cursor-interval cua--orig-blink-cursor-interval
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
62 cua--orig-blink-cursor-interval nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
63 (setq cua--global-mark-active nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
64 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
65 (message "Global Mark Cleared")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
66
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
67 (defun cua--activate-global-mark (&optional msg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
68 (if (not (markerp cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
69 (setq cua--global-mark-marker (make-marker)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
70 (when (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
71 (insert " ")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
72 (backward-char 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
73 (move-marker cua--global-mark-marker (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
74 (if (overlayp cua--global-mark-overlay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
75 (move-overlay cua--global-mark-overlay (point) (1+ (point)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45503
diff changeset
76 (setq cua--global-mark-overlay
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
77 (make-overlay (point) (1+ (point))))
63073
f1bf3660220e * emulation/cua-base.el (cua-rectangle, cua-rectangle-noselect)
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
78 (overlay-put cua--global-mark-overlay 'face 'cua-global-mark))
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
79 (if (and cua-global-mark-blink-cursor-interval
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
80 (not cua--orig-blink-cursor-interval))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45503
diff changeset
81 (setq cua--orig-blink-cursor-interval blink-cursor-interval
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
82 blink-cursor-interval cua-global-mark-blink-cursor-interval))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
83 (setq cua--global-mark-active t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
84 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
85 (message "Global Mark Set")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
86
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
87 (defun cua--global-mark-active ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
88 (if cua--global-mark-active
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
89 (or (and (markerp cua--global-mark-marker)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
90 (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
91 (and (cua--deactivate-global-mark nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
92 nil))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
93
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
94 (defun cua-toggle-global-mark (stay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
95 "Set or cancel the global marker.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96 When the global marker is set, CUA cut and copy commands will automatically
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
97 insert the deleted or copied text before the global marker, even when the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
98 global marker is in another buffer.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
99 If the global marker isn't set, set the global marker at point in the current
63870
66f83ad1a264 (cua-toggle-global-mark, cua-cut-region-to-global-mark,
Juanma Barranquero <lekktu@gmail.com>
parents: 63073
diff changeset
100 buffer. Otherwise jump to the global marker position and cancel it.
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
101 With prefix argument, don't jump to global mark when cancelling it."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
102 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
103 (unless cua--global-mark-initialized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
104 (cua--init-global-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
105 (if (not (cua--global-mark-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
106 (if (not buffer-read-only)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
107 (cua--activate-global-mark t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
108 (ding)
63870
66f83ad1a264 (cua-toggle-global-mark, cua-cut-region-to-global-mark,
Juanma Barranquero <lekktu@gmail.com>
parents: 63073
diff changeset
109 (message "Cannot set global mark in read-only buffer"))
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
110 (when (not stay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
111 (pop-to-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
112 (goto-char cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
113 (cua--deactivate-global-mark t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
114
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
115 (defun cua--insert-at-global-mark (str &optional msg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
116 ;; Insert string at global marker and move marker
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
117 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
118 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
119 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
120 (insert-for-yank str)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
121 (cua--activate-global-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
122 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
123 (message "%s %d to global mark in %s:%d" msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 (length str)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
125 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
126 (marker-position cua--global-mark-marker))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
127
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
128 (defun cua--delete-at-global-mark (arg &optional msg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
129 ;; Delete chars at global marker
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
130 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
132 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
133 (delete-char arg))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
134 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
135 (message "%s %d chars at global mark in %s:%d" msg arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
136 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
137 (marker-position cua--global-mark-marker))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
138
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
139 (defun cua-copy-region-to-global-mark (start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
140 "Copy region to global mark buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
141 (interactive "r")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
142 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
143 (let ((src-buf (current-buffer)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
144 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
145 (if (equal (marker-buffer cua--global-mark-marker) src-buf)
69902
eea8aee5048b (cua-copy-region-to-global-mark)
Kim F. Storm <storm@cua.dk>
parents: 68648
diff changeset
146 (let ((text (filter-buffer-substring start end nil t)))
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
147 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
148 (insert text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
150 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
151 (insert-buffer-substring-as-yank src-buf start end))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
152 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
153 (message "Copied %d to global mark in %s:%d"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154 (abs (- end start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
156 (marker-position cua--global-mark-marker))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
157 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
158 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
159
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
160 (defun cua-cut-region-to-global-mark (start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
161 "Move region to global buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
162 (interactive "r")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
163 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
164 (let ((src-buf (current-buffer)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
165 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
166 (if (equal (marker-buffer cua--global-mark-marker) src-buf)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
167 (if (and (< start (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
168 (< (marker-position cua--global-mark-marker) end))
63870
66f83ad1a264 (cua-toggle-global-mark, cua-cut-region-to-global-mark,
Juanma Barranquero <lekktu@gmail.com>
parents: 63073
diff changeset
169 (message "Can't move region into itself")
69902
eea8aee5048b (cua-copy-region-to-global-mark)
Kim F. Storm <storm@cua.dk>
parents: 68648
diff changeset
170 (let ((text (filter-buffer-substring start end nil t))
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
171 (p1 (copy-marker start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
172 (p2 (copy-marker end)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
173 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174 (insert text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
175 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
176 (delete-region (marker-position p1) (marker-position p2))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
177 (move-marker p1 nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
178 (move-marker p2 nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
179 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
180 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
181 (insert-buffer-substring src-buf start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
182 (message "Moved %d to global mark in %s:%d"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
183 (abs (- end start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
184 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
185 (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
186 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
187 (set-buffer src-buf)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
188 (delete-region start end))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
189 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
190 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
191
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
192 (defun cua--copy-rectangle-to-global-mark (as-text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 ;; Copy rectangle to global mark buffer/position.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
194 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
195 (let ((src-buf (current-buffer))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
196 (text (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
199 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
200 (if as-text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
201 (while text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
202 (insert-for-yank (car text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
203 (if (setq text (cdr text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
204 (insert "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
205 (cua--insert-rectangle text 'auto))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
206 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
207 (message "Copied rectangle to global mark in %s:%d"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
208 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
209 (marker-position cua--global-mark-marker))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
210 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
211 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
212
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
213 (defun cua--cut-rectangle-to-global-mark (as-text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
214 ;; Move rectangle to global buffer/position.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
215 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
216 (let ((src-buf (current-buffer)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
217 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
218 (if (equal (marker-buffer cua--global-mark-marker) src-buf)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219 (let ((olist (overlays-at (marker-position cua--global-mark-marker)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
220 in-rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
221 (while olist
63073
f1bf3660220e * emulation/cua-base.el (cua-rectangle, cua-rectangle-noselect)
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
222 (if (eq (overlay-get (car olist) 'face) 'cua-rectangle)
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
223 (setq in-rect t olist nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
224 (setq olist (cdr olist))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
225 (if in-rect
63870
66f83ad1a264 (cua-toggle-global-mark, cua-cut-region-to-global-mark,
Juanma Barranquero <lekktu@gmail.com>
parents: 63073
diff changeset
226 (message "Can't move rectangle into itself")
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
227 (let ((text (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
228 (cua--delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
229 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
230 (if as-text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
231 (while text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
232 (insert-for-yank (car text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
233 (if (setq text (cdr text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
234 (insert "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
235 (cua--insert-rectangle text 'auto))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
236 (cua--activate-global-mark))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
237 (let ((text (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
238 (cua--delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
239 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
240 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
241 (cua--insert-rectangle text 'auto))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
242 (message "Moved rectangle to global mark in %s:%d"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
243 (buffer-name (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
244 (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
245 (cua--activate-global-mark))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
246 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
247 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
248
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
249 (defun cua-copy-to-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
250 "Copy active region/rectangle to global mark buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
251 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
252 (setq cua--last-killed-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
253 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
254 (cua--copy-rectangle-to-global-mark nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
255 (let ((start (mark)) (end (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
256 (or (<= start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
257 (setq start (prog1 end (setq end start))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
258 (cua-copy-region-to-global-mark start end))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
259
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
260 (defun cua-copy-next-to-global-mark (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
261 "Copy the following N characters in buffer to global mark buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
262 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
263 (setq cua--last-killed-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
264 (or (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 (let ((p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
266 (goto-char (+ p n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
267 (cua-copy-region-to-global-mark p (point)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
268
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
269 (defun cua-cut-to-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
270 "Move active region/rectangle to global mark buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
271 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
272 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
273 (cua-copy-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
274 (setq cua--last-killed-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
275 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
276 (cua--cut-rectangle-to-global-mark nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
277 (let ((start (mark)) (end (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
278 (or (<= start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
279 (setq start (prog1 end (setq end start))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
280 (cua-cut-region-to-global-mark start end)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
281
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
282 (defun cua-cut-next-to-global-mark (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
283 "Move the following N characters in buffer to global mark buffer/position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
284 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
285 (setq cua--last-killed-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
286 (or (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
287 (let ((p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
288 (goto-char (+ p n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
289 (cua-cut-region-to-global-mark p (point)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
290
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
291 (defun cua-delete-char-at-global-mark (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
292 "Delete character following the global mark position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
293 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
294 (cua--delete-at-global-mark arg "Deleted"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
295
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
296 (defun cua-delete-backward-char-at-global-mark (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
297 "Delete character before the global mark position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
298 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
299 (cua--delete-at-global-mark (- arg) "Deleted backward"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
300
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
301 (defun cua-insert-char-at-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
302 "Insert the character you type at the global mark position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
303 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
304 (cua--insert-at-global-mark (char-to-string (aref (this-single-command-keys) 0)) "Inserted"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
305
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
306 (defun cua-insert-newline-at-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
307 "Insert a newline at the global mark position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
308 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
309 (cua--insert-at-global-mark "\n"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
310
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
311 (defun cua-indent-to-global-mark-column ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 "Indent current line or rectangle to global mark column."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 (interactive "*")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
314 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
315 (let (col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 (set-buffer (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
319 (setq col (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
320 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
321 (cua--indent-rectangle nil col t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
322 (indent-to col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
323 (if (eq (current-buffer) (marker-buffer cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
324 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
325 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
326 (move-to-column col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
327 (move-marker cua--global-mark-marker (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
328 (move-overlay cua--global-mark-overlay (point) (1+ (point))))))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45503
diff changeset
329
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
330
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
331 (defun cua-cancel-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 "Cancel the global mark."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
333 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
334 (if mark-active
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
335 (cua-cancel)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
336 (if (cua--global-mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
337 (cua--deactivate-global-mark t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
338 (cua--fallback))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
339
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
340 ;;; Post-command hook for global mark.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
341
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
342 (defun cua--global-mark-post-command ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
343 (when (and (cua--global-mark-active) ;; Updates cua--global-mark-active variable
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
344 cua-global-mark-keep-visible)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
345 ;; keep global mark position visible
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
346 (sit-for 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
347 (if (or (not (eq (current-buffer) (marker-buffer cua--global-mark-marker)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
348 (not (pos-visible-in-window-p (marker-position cua--global-mark-marker))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
349 (let ((w (selected-window)) (p (point)) h)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 45503
diff changeset
350 ;; The following code is an attempt to keep the global mark visible in
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
351 ;; other window -- but it doesn't work.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
352 (switch-to-buffer-other-window (marker-buffer cua--global-mark-marker) t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
353 (goto-char (marker-position cua--global-mark-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354 (if (not (pos-visible-in-window-p (marker-position cua--global-mark-marker)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
355 (recenter (if (> (setq h (- (window-height) 4)) 1) h '(4))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356 (select-window w)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
357 (goto-char p)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
358
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
359 ;;; Initialization
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
360
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
361 (defun cua--init-global-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
362 (define-key cua--global-mark-keymap [remap copy-region-as-kill] 'cua-copy-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
363 (define-key cua--global-mark-keymap [remap kill-ring-save] 'cua-copy-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
364 (define-key cua--global-mark-keymap [remap kill-region] 'cua-cut-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
365 (define-key cua--global-mark-keymap [remap yank] 'cua-copy-next-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
366
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
367 (define-key cua--global-mark-keymap [remap keyboard-escape-quit] 'cua-cancel-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
368 (define-key cua--global-mark-keymap [remap keyboard-quit] 'cua-cancel-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
369
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
370 (define-key cua--global-mark-keymap [(control ?d)] 'cua-cut-next-to-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
371 (define-key cua--global-mark-keymap [remap delete-backward-char] 'cua-delete-backward-char-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
372 (define-key cua--global-mark-keymap [remap backward-delete-char] 'cua-delete-backward-char-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
373 (define-key cua--global-mark-keymap [remap backward-delete-char-untabify] 'cua-delete-backward-char-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
374 (define-key cua--global-mark-keymap [remap self-insert-command] 'cua-insert-char-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
375 (define-key cua--global-mark-keymap [remap self-insert-iso] 'cua-insert-char-at-global-mark)
45503
b5885da440b5 (cua--init-global-mark): Install default
Kim F. Storm <storm@cua.dk>
parents: 45078
diff changeset
376
b5885da440b5 (cua--init-global-mark): Install default
Kim F. Storm <storm@cua.dk>
parents: 45078
diff changeset
377 ;; Catch self-inserting characters which are "stolen" by other modes
b5885da440b5 (cua--init-global-mark): Install default
Kim F. Storm <storm@cua.dk>
parents: 45078
diff changeset
378 (define-key cua--global-mark-keymap [t]
b5885da440b5 (cua--init-global-mark): Install default
Kim F. Storm <storm@cua.dk>
parents: 45078
diff changeset
379 '(menu-item "sic" cua-insert-char-at-global-mark :filter cua--self-insert-char-p))
b5885da440b5 (cua--init-global-mark): Install default
Kim F. Storm <storm@cua.dk>
parents: 45078
diff changeset
380
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
381 (define-key cua--global-mark-keymap [remap newline] 'cua-insert-newline-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
382 (define-key cua--global-mark-keymap [remap newline-and-indent] 'cua-insert-newline-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 (define-key cua--global-mark-keymap "\r" 'cua-insert-newline-at-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
384
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
385 (define-key cua--global-mark-keymap "\t" 'cua-indent-to-global-mark-column)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
386
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
387 (setq cua--global-mark-initialized t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
389 ;;; arch-tag: 553d8076-a91d-48ae-825d-6cb962a5f67f
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
390 ;;; cua-gmrk.el ends here