annotate lisp/emulation/cua-gmrk.el @ 44938:358d42530d42

Added cua-mode based files [split from original cua.el]: cua-base.el, cua-rect.el, cua-gmrk.el, and keypad.el
author Kim F. Storm <storm@cua.dk>
date Sun, 28 Apr 2002 21:48:39 +0000
parents
children 829beb9a6a4b
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
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
3 ;; Copyright (C) 1997-2002 Free Software Foundation, Inc.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
4
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
5 ;; 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
6 ;; 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
7
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
8 ;; 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
9
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
10 ;; 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
11 ;; it under the terms of the GNU General Public License as published by
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
13 ;; any later version.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
14
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
15 ;; 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
16 ;; 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
17 ;; 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
18 ;; 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
19
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
20 ;; 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
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
24
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
25
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
26 (provide 'cua-gmrk)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
27
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
28 (eval-when-compile
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
29 (require 'cua-base)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
30 (require 'cua-rect)
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
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
33 ;;; Global Marker
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
34
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
35 ;; 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
36 (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
37
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
38 ;; Global mark position marker.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
39 (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
40
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
41 ;; 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
42 (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
43
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
44 ;; 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
45 (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
46
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
47 ;; 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
48 (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
49
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
50 (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
51 (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
52 (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
53 (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
54 (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
55 (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
56 (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
57 (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
58 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
59 (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
60 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
61 (message "Global Mark Cleared")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
62
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
63 (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
64 (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
65 (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
66 (when (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
67 (insert " ")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
68 (backward-char 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
69 (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
70 (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
71 (move-overlay cua--global-mark-overlay (point) (1+ (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
72 (setq cua--global-mark-overlay
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
73 (make-overlay (point) (1+ (point))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
74 (overlay-put cua--global-mark-overlay 'face 'cua-global-mark-face))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
75 (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
76 (not 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
77 (setq cua--orig-blink-cursor-interval blink-cursor-interval
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
78 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
79 (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
80 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
81 (message "Global Mark Set")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
82
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
83 (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
84 (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
85 (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
86 (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
87 (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
88 nil))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
89
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
90 (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
91 "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
92 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
93 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
94 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
95 If the global marker isn't set, set the global marker at point in the current
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96 buffer. Otherwise jump to the global marker position and cancel it.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
97 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
98 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
99 (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
100 (cua--init-global-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
101 (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
102 (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
103 (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
104 (ding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
105 (message "Cannot set global mark in read-only buffer."))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
106 (when (not stay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
107 (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
108 (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
109 (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
110
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
111 (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
112 ;; 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
113 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
114 (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
115 (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
116 (insert-for-yank str)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
117 (cua--activate-global-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
118 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
119 (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
120 (length str)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
121 (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
122 (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
123
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 (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
125 ;; 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
126 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
127 (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
128 (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
129 (delete-char arg))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
130 (if msg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131 (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
132 (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
133 (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
134
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
135 (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
136 "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
137 (interactive "r")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
138 (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
139 (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
140 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
141 (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
142 (let ((text (buffer-substring-no-properties start end)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
143 (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
144 (insert text))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
145 (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
146 (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
147 (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
148 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 (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
150 (abs (- end start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
151 (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
152 (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
153 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
156 (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
157 "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
158 (interactive "r")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
159 (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
160 (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
161 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
162 (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
163 (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
164 (< (marker-position cua--global-mark-marker) end))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
165 (message "Can't move region into itself.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
166 (let ((text (buffer-substring-no-properties start end))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
167 (p1 (copy-marker start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
168 (p2 (copy-marker end)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
169 (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
170 (insert text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
171 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
172 (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
173 (move-marker p1 nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174 (move-marker p2 nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
175 (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
176 (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
177 (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
178 (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
179 (abs (- end start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
180 (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
181 (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
182 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
183 (set-buffer src-buf)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
184 (delete-region start end))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
185 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
186 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
187
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
188 (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
189 ;; 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
190 (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
191 (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
192 (text (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
194 (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
195 (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
196 (if as-text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197 (while text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 (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
199 (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
200 (insert "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
201 (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
202 (cua--activate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
203 (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
204 (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
205 (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
206 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
207 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
208
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
209 (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
210 ;; 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
211 (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
212 (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
213 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
214 (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
215 (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
216 in-rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
217 (while olist
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
218 (if (eq (overlay-get (car olist) 'face) 'cua-rectangle-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219 (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
220 (setq olist (cdr olist))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
221 (if in-rect
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
222 (message "Can't move rectangle into itself.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
223 (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
224 (cua--delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
225 (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
226 (if as-text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
227 (while text
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
228 (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
229 (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
230 (insert "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
231 (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
232 (cua--activate-global-mark))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
233 (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
234 (cua--delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
235 (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
236 (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
237 (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
238 (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
239 (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
240 (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--activate-global-mark))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
242 (cua--deactivate-global-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
243 (message "No Global Mark")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
244
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
245 (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
246 "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
247 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
248 (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
249 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
250 (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
251 (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
252 (or (<= start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
253 (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
254 (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
255
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
256 (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
257 "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
258 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
259 (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
260 (or (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
261 (let ((p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
262 (goto-char (+ p n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
263 (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
264
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 (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
266 "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
267 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
268 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
269 (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
270 (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
271 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
272 (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
273 (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
274 (or (<= start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
275 (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
276 (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
277
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
278 (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
279 "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
280 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
281 (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
282 (or (eobp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
283 (let ((p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
284 (goto-char (+ p n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
285 (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
286
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
287 (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
288 "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
289 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
290 (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
291
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
292 (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
293 "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
294 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
295 (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
296
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
297 (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
298 "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
299 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
300 (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
301
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
302 (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
303 "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
304 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
305 (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
306
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
307 (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
308 "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
309 (interactive "*")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
310 (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
311 (let (col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 (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
314 (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
315 (setq col (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 (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
318 (indent-to col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
319 (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
320 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
321 (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
322 (move-to-column col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
323 (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
324 (move-overlay cua--global-mark-overlay (point) (1+ (point))))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
325
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
326
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
327 (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
328 "Cancel the global mark."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
329 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
330 (if mark-active
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
331 (cua-cancel)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 (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
333 (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
334 (cua--fallback))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
335
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
336 ;;; 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
337
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
338 (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
339 (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
340 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
341 ;; 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
342 (sit-for 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
343 (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
344 (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
345 (let ((w (selected-window)) (p (point)) h)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
346 ;; The following code is an attempt to keep the global mark visible in
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
347 ;; 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
348 (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
349 (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
350 (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
351 (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
352 (select-window w)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
353 (goto-char p)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
355 ;;; Initialization
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
357 (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
358 (unless (face-background 'cua-global-mark-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
359 (copy-face 'region 'cua-global-mark-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
360 (set-face-foreground 'cua-global-mark-face "black")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
361 (set-face-background 'cua-global-mark-face "cyan"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
362
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 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
364 (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
365 (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
366 (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
367
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-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
369 (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
370
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 [(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
372 (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
373 (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
374 (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
375 (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
376 (define-key cua--global-mark-keymap [remap self-insert-iso] '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
377 (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
378 (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
379 (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
380
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 "\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
382
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 (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
384
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
385 ;;; cua-gmrk.el ends here