From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kim Storm Newsgroups: gmane.emacs.bugs Subject: bug#18886: 24.4; M-v no longer works in CUA-mode. Date: Thu, 30 Oct 2014 17:46:15 +0100 Message-ID: <54526B57.8080508@cua.dk> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1414777159 13864 80.91.229.3 (31 Oct 2014 17:39:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Oct 2014 17:39:19 +0000 (UTC) Cc: 18886@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 31 18:39:12 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XkGAI-00082c-S5 for geb-bug-gnu-emacs@m.gmane.org; Fri, 31 Oct 2014 18:39:11 +0100 Original-Received: from localhost ([::1]:40051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkGAI-0003iI-Di for geb-bug-gnu-emacs@m.gmane.org; Fri, 31 Oct 2014 13:39:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkEHJ-0001pZ-BL for bug-gnu-emacs@gnu.org; Fri, 31 Oct 2014 11:39:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XjstH-0001Op-6R for bug-gnu-emacs@gnu.org; Thu, 30 Oct 2014 12:48:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48616) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjstH-0001Ol-1v for bug-gnu-emacs@gnu.org; Thu, 30 Oct 2014 12:48:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XjstG-0007lI-Gq for bug-gnu-emacs@gnu.org; Thu, 30 Oct 2014 12:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kim Storm Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Oct 2014 16:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18886 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 18886-submit@debbugs.gnu.org id=B18886.141468765829800 (code B ref 18886); Thu, 30 Oct 2014 16:48:02 +0000 Original-Received: (at 18886) by debbugs.gnu.org; 30 Oct 2014 16:47:38 +0000 Original-Received: from localhost ([127.0.0.1]:40714 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xjssq-0007kZ-W5 for submit@debbugs.gnu.org; Thu, 30 Oct 2014 12:47:37 -0400 Original-Received: from ispc3.dotserv.com ([178.20.216.13]:39795) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xjssm-0007kF-9s for 18886@debbugs.gnu.org; Thu, 30 Oct 2014 12:47:33 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by ispc3.dotserv.com (Postfix) with ESMTP id D8BF980347849; Thu, 30 Oct 2014 17:47:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ispc3.dotserv.com Original-Received: from ispc3.dotserv.com ([127.0.0.1]) by localhost (ispc3.dotserv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3yEbASih+WXF; Thu, 30 Oct 2014 17:47:17 +0100 (CET) Original-Received: from [10.1.82.9] (1405ds6-amb.0.fullrate.dk [90.184.76.141]) (Authenticated sender: storm@cua.dk) by ispc3.dotserv.com (Postfix) with ESMTPSA id 560B680130A9C; Thu, 30 Oct 2014 17:47:17 +0100 (CET) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:95307 On 2014-10-30 01:47, Stefan Monnier wrote: > Hi Kim, > > Nice to hear from you again. Yes, I wish I had more time to dedicate to emacs ... but there is just too much to do running my own business. From my first impressions with 24.4, I can see that emacs developments are still going strong! Good work! I have taken a shot at adding the missing cua features to 24.4 I don't have time to try to get up to date with the repository stuff, so I have just included some patches for you to look at -- please commit them if you think they are acceptable (they are only lightly tested so far). Note that the new defcustom is unconditionally set to ?0 by cua-mode if cua-mode-copy-to-register-0 is enabled (default), Also, the new replace command only works if save-to-register is non-nil, as it uses the old-text copy in that register (instead of saving another copy as the original code in cua did). Finally, using a C-u arg should replace until eob according to the doc string -- it actually replaces max 1000000 instances; this is just laziness on my part. Kim --- orig.delsel.el 2014-10-30 14:58:32.000000000 +0100 +++ delsel.el 2014-10-30 17:28:41.000000000 +0100 @@ -54,6 +54,15 @@ ;;; Code: +(defcustom delete-selection-save-to-register + nil + "If non-nil, deleted region text is stored in this register. +Value must be the register (key) to use." + :type '(choice + (const :tag "None" nil) + (character :tag "Register (Key)")) + :group 'editing-basics) + ;;;###autoload (defalias 'pending-delete-mode 'delete-selection-mode) @@ -72,16 +81,73 @@ (remove-hook 'pre-command-hook 'delete-selection-pre-hook) (add-hook 'pre-command-hook 'delete-selection-pre-hook))) +(defvar delsel--replace-text-or-position nil) + (defun delete-active-region (&optional killp) "Delete the active region. If KILLP in not-nil, the active region is killed instead of deleted." - (if killp - ;; Don't allow `kill-region' to change the value of `this-command'. - (let (this-command) - (kill-region (point) (mark) t)) - (funcall region-extract-function 'delete-only)) + (message "delete") + (cond (killp + ;; Don't allow `kill-region' to change the value of `this-command'. + (let (this-command) + (kill-region (point) (mark) t))) + (delete-selection-save-to-register + (set-register delete-selection-save-to-register + (funcall region-extract-function t)) + (setq delsel--replace-text-or-position + (cons (current-buffer) + (and (consp buffer-undo-list) (car buffer-undo-list)))) + ) + (t + (funcall region-extract-function 'delete-only))) t) +(defun delete-selection-repeat-replace-region (arg) + "Repeat replacing text of highlighted region with typed text. +Search for the next stretch of text identical to the region last replaced +by typing text over it and replaces it with the same stretch of text. +With arg, repeat that many times. C-u means until end of buffer." + (interactive "P") + (let ((old-text (and delete-selection-save-to-register + (get-register delete-selection-save-to-register))) + (count (if (consp arg) 1000000 (or (prefix-numeric-value current-prefix-arg) 1)))) + (message "old %s" old-text) + (when (and old-text (> (length old-text) 0)) + ;; If this is the first use after overwriting regions, + ;; find the replacement text by looking at the undo list + (when (consp delsel--replace-text-or-position) + (let ((buffer (car delsel--replace-text-or-position)) + (elt (cdr delsel--replace-text-or-position))) + (setq delsel--replace-text-or-position nil) + (with-current-buffer buffer + (save-restriction + (widen) + ;; Find the text that replaced the region via the undo list. + (let ((ul buffer-undo-list) u s e) + (when elt + (while (consp ul) + (setq u (car ul) ul (cdr ul)) + (cond + ((eq u elt) ;; got it + (setq ul nil)) + ((and (consp u) (integerp (car u)) (integerp (cdr u))) + (if (and s (= (cdr u) s)) + (setq s (car u)) + (setq s (car u) e (cdr u))))))) + (cond ((and s e (<= s e) (= s (mark t))) + (setq delsel--replace-text-or-position (filter-buffer-substring s e)) + (set-text-properties 0 (length delsel--replace-text-or-position) + nil delsel--replace-text-or-position)) + ((and (null s) (eq u elt)) ;; nothing inserted + (setq delsel--replace-text-or-position "")) + (t + (message "Cannot locate replacement text")))))))) + (while (and (> count 0) + delsel--replace-text-or-position + (search-forward old-text nil t nil)) + (replace-match delsel--replace-text-or-position nil t) + (setq count (1- count)))))) + (defun delete-selection-helper (type) "Delete selection according to TYPE: `yank' --- orig.cua-base.el 2014-10-30 15:40:12.000000000 +0100 +++ cua-base.el 2014-10-30 16:16:08.000000000 +0100 @@ -277,7 +277,7 @@ (defcustom cua-remap-control-v t "If non-nil, C-v binding is used for paste (yank). -Also, M-v is mapped to `cua-repeat-replace-region'." +Also, M-v is mapped to `delete-selection-repeat-replace-region'." :type 'boolean :group 'cua) @@ -961,46 +961,6 @@ (if cua--rectangle (cua--rectangle-corner 0)))))) -;; Typed text that replaced the highlighted region. -(defvar cua--repeat-replace-text nil) - -(defun cua-repeat-replace-region (arg) - "Repeat replacing text of highlighted region with typed text. -Searches for the next stretch of text identical to the region last -replaced by typing text over it and replaces it with the same stretch -of text." - (interactive "P") - (when cua--last-deleted-region-pos - (with-current-buffer (car cua--last-deleted-region-pos) - (save-restriction - (widen) - ;; Find the text that replaced the region via the undo list. - (let ((ul buffer-undo-list) - (elt (cdr cua--last-deleted-region-pos)) - u s e) - (when elt - (while (consp ul) - (setq u (car ul) ul (cdr ul)) - (cond - ((eq u elt) ;; got it - (setq ul nil)) - ((and (consp u) (integerp (car u)) (integerp (cdr u))) - (if (and s (= (cdr u) s)) - (setq s (car u)) - (setq s (car u) e (cdr u))))))) - (cond ((and s e (<= s e) (= s (mark t))) - (setq cua--repeat-replace-text (cua--filter-buffer-noprops s e))) - ((and (null s) (eq u elt)) ;; nothing inserted - (setq cua--repeat-replace-text - "")) - (t - (message "Cannot locate replacement text")))))) - (setq cua--last-deleted-region-pos nil)) - (if (and cua--last-deleted-region-text - cua--repeat-replace-text - (search-forward cua--last-deleted-region-text nil t nil)) - (replace-match cua--repeat-replace-text arg t))) - (defun cua-help-for-region (&optional help) "Show region specific help in echo area." (interactive) @@ -1333,7 +1293,7 @@ (define-key cua--cua-keys-keymap [(control z)] 'undo)) (when cua-remap-control-v (define-key cua--cua-keys-keymap [(control v)] 'yank) - (define-key cua--cua-keys-keymap [(meta v)] 'cua-repeat-replace-region)) + (define-key cua--cua-keys-keymap [(meta v)] 'delete-selection-repeat-replace-region)) (define-key cua--prefix-override-keymap [(control x)] 'cua--prefix-override-handler) (define-key cua--prefix-override-keymap [(control c)] 'cua--prefix-override-handler) @@ -1469,6 +1429,7 @@ (if (and (boundp 'delete-selection-mode) delete-selection-mode) (delete-selection-mode -1))) (if cua-highlight-region-shift-only (transient-mark-mode -1)) + (if cua-delete-copy-to-register-0 (setq delete-selection-save-to-register ?0)) (cua--deactivate)) (cua--saved-state (if (nth 0 cua--saved-state)