aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-07-29 12:45:48 +0800
committerChong Yidong2012-07-29 12:45:48 +0800
commit2549c068e14ab1ddfb1f1ea38ca7736c16db7296 (patch)
treedd718a18c5ea030f16f373e4020049634274ea88
parentd8efda90aa36b6bea5cca9bd6765cbb76571d933 (diff)
downloademacs-2549c068e14ab1ddfb1f1ea38ca7736c16db7296.tar.gz
emacs-2549c068e14ab1ddfb1f1ea38ca7736c16db7296.zip
Deactivate the mark on more copy operations, and indicate the copied region.
* lisp/simple.el (indicate-copied-region): New function. (kill-ring-save): Split off from here. * lisp/rect.el (copy-rectangle-as-kill): Call indicate-copied-region. (kill-rectangle): Set deactivate-mark to t on read-only error. * lisp/register.el (copy-to-register, copy-rectangle-to-register): Deactivate the mark, and use indicate-copied-region. (append-to-register, prepend-to-register): Call Fixes: debbugs:10056
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/rect.el5
-rw-r--r--lisp/register.el29
-rw-r--r--lisp/simple.el74
4 files changed, 81 insertions, 39 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e0d6cb825f0..2d737a38f69 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12012-07-29 Chong Yidong <cyd@gnu.org>
2
3 * simple.el (indicate-copied-region): New function.
4 (kill-ring-save): Split off from here.
5
6 * rect.el (copy-rectangle-as-kill): Call indicate-copied-region.
7 (kill-rectangle): Set deactivate-mark to t on read-only error.
8
9 * register.el (copy-to-register, copy-rectangle-to-register):
10 Deactivate the mark, and use indicate-copied-region (Bug#10056).
11 (append-to-register, prepend-to-register): Call
12
12012-07-29 Juri Linkov <juri@jurta.org> 132012-07-29 Juri Linkov <juri@jurta.org>
2 14
3 * simple.el (async-shell-command-buffer): New defcustom. 15 * simple.el (async-shell-command-buffer): New defcustom.
diff --git a/lisp/rect.el b/lisp/rect.el
index 1bf7364e20d..c5e9a790ca2 100644
--- a/lisp/rect.el
+++ b/lisp/rect.el
@@ -219,6 +219,7 @@ even beep.)"
219 (condition-case nil 219 (condition-case nil
220 (setq killed-rectangle (delete-extract-rectangle start end fill)) 220 (setq killed-rectangle (delete-extract-rectangle start end fill))
221 ((buffer-read-only text-read-only) 221 ((buffer-read-only text-read-only)
222 (setq deactivate-mark t)
222 (setq killed-rectangle (extract-rectangle start end)) 223 (setq killed-rectangle (extract-rectangle start end))
223 (if kill-read-only-ok 224 (if kill-read-only-ok
224 (progn (message "Read only text copied to kill ring") nil) 225 (progn (message "Read only text copied to kill ring") nil)
@@ -230,7 +231,9 @@ even beep.)"
230 "Copy the region-rectangle and save it as the last killed one." 231 "Copy the region-rectangle and save it as the last killed one."
231 (interactive "r") 232 (interactive "r")
232 (setq killed-rectangle (extract-rectangle start end)) 233 (setq killed-rectangle (extract-rectangle start end))
233 (setq deactivate-mark t)) 234 (setq deactivate-mark t)
235 (if (called-interactively-p 'interactive)
236 (indicate-copied-region (length (car killed-rectangle)))))
234 237
235;;;###autoload 238;;;###autoload
236(defun yank-rectangle () 239(defun yank-rectangle ()
diff --git a/lisp/register.el b/lisp/register.el
index 52c236e49be..2816c9831de 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -336,7 +336,11 @@ Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
336START and END are buffer positions indicating what to copy." 336START and END are buffer positions indicating what to copy."
337 (interactive "cCopy to register: \nr\nP") 337 (interactive "cCopy to register: \nr\nP")
338 (set-register register (filter-buffer-substring start end)) 338 (set-register register (filter-buffer-substring start end))
339 (if delete-flag (delete-region start end))) 339 (setq deactivate-mark t)
340 (cond (delete-flag
341 (delete-region start end))
342 ((called-interactively-p 'interactive)
343 (indicate-copied-region))))
340 344
341(defun append-to-register (register start end &optional delete-flag) 345(defun append-to-register (register start end &optional delete-flag)
342 "Append region to text in register REGISTER. 346 "Append region to text in register REGISTER.
@@ -350,7 +354,10 @@ START and END are buffer positions indicating what to append."
350 register (cond ((not reg) text) 354 register (cond ((not reg) text)
351 ((stringp reg) (concat reg text)) 355 ((stringp reg) (concat reg text))
352 (t (error "Register does not contain text"))))) 356 (t (error "Register does not contain text")))))
353 (if delete-flag (delete-region start end))) 357 (cond (delete-flag
358 (delete-region start end))
359 ((called-interactively-p 'interactive)
360 (indicate-copied-region))))
354 361
355(defun prepend-to-register (register start end &optional delete-flag) 362(defun prepend-to-register (register start end &optional delete-flag)
356 "Prepend region to text in register REGISTER. 363 "Prepend region to text in register REGISTER.
@@ -364,7 +371,10 @@ START and END are buffer positions indicating what to prepend."
364 register (cond ((not reg) text) 371 register (cond ((not reg) text)
365 ((stringp reg) (concat text reg)) 372 ((stringp reg) (concat text reg))
366 (t (error "Register does not contain text"))))) 373 (t (error "Register does not contain text")))))
367 (if delete-flag (delete-region start end))) 374 (cond (delete-flag
375 (delete-region start end))
376 ((called-interactively-p 'interactive)
377 (indicate-copied-region))))
368 378
369(defun copy-rectangle-to-register (register start end &optional delete-flag) 379(defun copy-rectangle-to-register (register start end &optional delete-flag)
370 "Copy rectangular region into register REGISTER. 380 "Copy rectangular region into register REGISTER.
@@ -374,10 +384,15 @@ To insert this register in the buffer, use \\[insert-register].
374Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG. 384Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG.
375START and END are buffer positions giving two corners of rectangle." 385START and END are buffer positions giving two corners of rectangle."
376 (interactive "cCopy rectangle to register: \nr\nP") 386 (interactive "cCopy rectangle to register: \nr\nP")
377 (set-register register 387 (let ((rectangle (if delete-flag
378 (if delete-flag 388 (delete-extract-rectangle start end)
379 (delete-extract-rectangle start end) 389 (extract-rectangle start end))))
380 (extract-rectangle start end)))) 390 (set-register register rectangle)
391 (when (and (null delete-flag)
392 (called-interactively-p 'interactive))
393 (setq deactivate-mark t)
394 (indicate-copied-region (length (car rectangle))))))
395
381 396
382(provide 'register) 397(provide 'register)
383;;; register.el ends here 398;;; register.el ends here
diff --git a/lisp/simple.el b/lisp/simple.el
index cfcc63e9285..4b6d6c7a73b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3408,38 +3408,50 @@ This command is similar to `copy-region-as-kill', except that it gives
3408visual feedback indicating the extent of the region being copied." 3408visual feedback indicating the extent of the region being copied."
3409 (interactive "r") 3409 (interactive "r")
3410 (copy-region-as-kill beg end) 3410 (copy-region-as-kill beg end)
3411 ;; This use of called-interactively-p is correct 3411 ;; This use of called-interactively-p is correct because the code it
3412 ;; because the code it controls just gives the user visual feedback. 3412 ;; controls just gives the user visual feedback.
3413 (if (called-interactively-p 'interactive) 3413 (if (called-interactively-p 'interactive)
3414 (let ((other-end (if (= (point) beg) end beg)) 3414 (indicate-copied-region)))
3415 (opoint (point)) 3415
3416 ;; Inhibit quitting so we can make a quit here 3416(defun indicate-copied-region (&optional message-len)
3417 ;; look like a C-g typed as a command. 3417 "Indicate that the region text has been copied interactively.
3418 (inhibit-quit t)) 3418If the mark is visible in the selected window, blink the cursor
3419 (if (pos-visible-in-window-p other-end (selected-window)) 3419between point and mark if there is currently no active region
3420 ;; Swap point-and-mark quickly so as to show the region that 3420highlighting.
3421 ;; was selected. Don't do it if the region is highlighted. 3421
3422 (unless (and (region-active-p) 3422If the mark lies outside the selected window, display an
3423 (face-background 'region)) 3423informative message containing a sample of the copied text. The
3424 ;; Swap point and mark. 3424optional argument MESSAGE-LEN, if non-nil, specifies the length
3425 (set-marker (mark-marker) (point) (current-buffer)) 3425of this sample text; it defaults to 40."
3426 (goto-char other-end) 3426 (let ((mark (mark t))
3427 (sit-for blink-matching-delay) 3427 (point (point))
3428 ;; Swap back. 3428 ;; Inhibit quitting so we can make a quit here
3429 (set-marker (mark-marker) other-end (current-buffer)) 3429 ;; look like a C-g typed as a command.
3430 (goto-char opoint) 3430 (inhibit-quit t))
3431 ;; If user quit, deactivate the mark 3431 (if (pos-visible-in-window-p mark (selected-window))
3432 ;; as C-g would as a command. 3432 ;; Swap point-and-mark quickly so as to show the region that
3433 (and quit-flag mark-active 3433 ;; was selected. Don't do it if the region is highlighted.
3434 (deactivate-mark))) 3434 (unless (and (region-active-p)
3435 (let* ((killed-text (current-kill 0)) 3435 (face-background 'region))
3436 (message-len (min (length killed-text) 40))) 3436 ;; Swap point and mark.
3437 (if (= (point) beg) 3437 (set-marker (mark-marker) (point) (current-buffer))
3438 ;; Don't say "killed"; that is misleading. 3438 (goto-char mark)
3439 (message "Saved text until \"%s\"" 3439 (sit-for blink-matching-delay)
3440 (substring killed-text (- message-len))) 3440 ;; Swap back.
3441 (message "Saved text from \"%s\"" 3441 (set-marker (mark-marker) mark (current-buffer))
3442 (substring killed-text 0 message-len)))))))) 3442 (goto-char point)
3443 ;; If user quit, deactivate the mark
3444 ;; as C-g would as a command.
3445 (and quit-flag mark-active
3446 (deactivate-mark)))
3447 (let ((len (min (abs (- mark point))
3448 (or message-len 40))))
3449 (if (< point mark)
3450 ;; Don't say "killed"; that is misleading.
3451 (message "Saved text until \"%s\""
3452 (buffer-substring-no-properties (- mark len) mark))
3453 (message "Saved text from \"%s\""
3454 (buffer-substring-no-properties mark (+ mark len))))))))
3443 3455
3444(defun append-next-kill (&optional interactive) 3456(defun append-next-kill (&optional interactive)
3445 "Cause following command, if it kills, to append to previous kill. 3457 "Cause following command, if it kills, to append to previous kill.