* bug#18886: 24.4; M-v no longer works in CUA-mode.
@ 2014-10-29 16:54 Kim F. Storm
2014-10-30 0:47 ` Stefan Monnier
2016-06-26 17:55 ` Noam Postavsky
0 siblings, 2 replies; 7+ messages in thread
From: Kim F. Storm @ 2014-10-29 16:54 UTC (permalink / raw)
To: 18886
I have just upgraded from 23.? to 24.4, and found that two (for me)
essintial features of cua-mode no longer works:
- Deleted text is not saved automatically in register 0 when overwriting
highlighted region.
- M-v no longer performs the "repeat last replacement" functionality.
Both functions are documented in cua-base.el:
;; Typing text replaces the region
;; -------------------------------
;; When the region is active, i.e. highlighted, the text in region is
;; replaced by the text you type.
;; The replaced text is saved in register 0 which can be inserted using
;; the key sequence M-0 C-v (see the section on register support below).
;; If you have just replaced a highlighted region with typed text,
;; you can repeat the replace with M-v. This will search forward
;; for a stretch of text identical to the previous contents of the
;; region (i.e. the contents of register 0) and replace it with the
;; text you typed to replace the original region. Repeating M-v will
;; replace the next matching region and so on.
;;
;; Example: Suppose you have a line like this
;; The redo operation will redo the last redoable command
;; which you want to change into
;; The repeat operation will repeat the last repeatable command
;; This is done by highlighting the first occurrence of "redo"
;; and type "repeat" M-v M-v.
Since the basic functionality has now been split from cua-mode,
I think that those functions belongs in delsel (if anywhere).
Of course, the M-v binding should still only be active in cua-mode
(since cua-mode takes over C-v it can also use M-v).
I guess the functionality could be restored by suitable tweaking of
the region-extract-function -- I will look into that possibility.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-29 16:54 bug#18886: 24.4; M-v no longer works in CUA-mode Kim F. Storm
@ 2014-10-30 0:47 ` Stefan Monnier
2014-10-30 16:46 ` Kim Storm
2016-06-26 17:55 ` Noam Postavsky
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-10-30 0:47 UTC (permalink / raw)
To: Kim F. Storm; +Cc: 18886
Hi Kim,
Nice to hear from you again.
> I have just upgraded from 23.? to 24.4, and found that two (for me)
> essential features of cua-mode no longer works:
Hmm.. indeed these have been lost in the move to delsel.el.
> Since the basic functionality has now been split from cua-mode,
> I think that those functions belongs in delsel (if anywhere).
That's right.
> Of course, the M-v binding should still only be active in cua-mode
> (since cua-mode takes over C-v it can also use M-v).
delsel.el can provide the command, and then cua-mode can bind it to M-v.
> I guess the functionality could be restored by suitable tweaking of
> the region-extract-function -- I will look into that possibility.
I think extending delsel.el directly will be easier.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-30 0:47 ` Stefan Monnier
@ 2014-10-30 16:46 ` Kim Storm
2014-10-30 19:23 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Kim Storm @ 2014-10-30 16:46 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 18886
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-30 16:46 ` Kim Storm
@ 2014-10-30 19:23 ` Stefan Monnier
2014-10-30 20:39 ` Kim Storm
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-10-30 19:23 UTC (permalink / raw)
To: Kim Storm; +Cc: 18886
> 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).
Thanks, installed into emacs-24, with minor changes (mostly I demoted
the defcustom to a defvar, because I think the right fix will be to move
the setting to simple.el where it will be configured yet differently
(probably allowing delete-active-region to be set to a character)).
I think further changes will be needed, tho. E.g. cua-delete-region
should probably disappear (i.e. be an alias for delete-active-region).
> Note that the new defcustom is unconditionally set to ?0
> by cua-mode if cua-mode-copy-to-register-0 is enabled (default),
Right, I added a FIXME about it.
> 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).
BTW, I think that instead of scavenging the undo log we should place an
overlay at the last delete so we can directly grab the "replacement text".
> 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.
I used (point-max) which should work well and is only 4 extra characters ;-)
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-30 19:23 ` Stefan Monnier
@ 2014-10-30 20:39 ` Kim Storm
2014-11-02 17:04 ` Kim Storm
0 siblings, 1 reply; 7+ messages in thread
From: Kim Storm @ 2014-10-30 20:39 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 18886
On 2014-10-30 20:23, Stefan Monnier wrote:
>> 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).
> Thanks, installed into emacs-24, with minor changes (mostly I demoted
> the defcustom to a defvar, because I think the right fix will be to move
> the setting to simple.el where it will be configured yet differently
> (probably allowing delete-active-region to be set to a character)).
Thank you.
>
> I think further changes will be needed, tho. E.g. cua-delete-region
> should probably disappear (i.e. be an alias for delete-active-region).
Yes, it should definitely go away.
>> Note that the new defcustom is unconditionally set to ?0
>> by cua-mode if cua-mode-copy-to-register-0 is enabled (default),
> Right, I added a FIXME about it. Good.
>
>> 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).
> BTW, I think that instead of scavenging the undo log we should place an
> overlay at the last delete so we can directly grab the "replacement text".
Yes - I would like to do that, as the current code is deficient in the sense
that any movement or editing will terminate the "replacement text".
I will try it when I have some time to improve on it.
>
>> 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.
> I used (point-max) which should work well and is only 4 extra characters ;-)
Nice !
Kim
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-30 20:39 ` Kim Storm
@ 2014-11-02 17:04 ` Kim Storm
0 siblings, 0 replies; 7+ messages in thread
From: Kim Storm @ 2014-11-02 17:04 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 18886
On 2014-10-30 21:39, Kim Storm wrote:
> On 2014-10-30 20:23, Stefan Monnier wrote:
>> BTW, I think that instead of scavenging the undo log we should place an
>> overlay at the last delete so we can directly grab the "replacement
>> text".
> Yes - I would like to do that, as the current code is deficient in the
> sense
> that any movement or editing will terminate the "replacement text".
> I will try it when I have some time to improve on it.
Hi Stefan,
I have made some progress on this:
The following patch eliminates the undo-list hack. It works much better
than before, as it is now possible to edit the replacement text before
repeating the substitution using M-v.
This has always been annoying for me, so I really appreciate your
suggestion.
Since there is only one active replacement text across all buffers, it makes
more sense for me to use an overlay to keep track of the replacement text.
If you could install this, I would appreciate it very much.
Kim
|2014-11-02 Kim F. Storm <storm@cua.dk>
* delsel.el (|||delsel--replace-text-or-position): Delete var.
||||| (delete-selection-replacement-face): New defcustom.
||| (delsel--replace-text, delsel--replace-overlay): New vars.
| (delete-active-region, delete-selection-repeat-replace-region):
Use overlay to track replacement text instead of abusing the
undo-list; this allows the text to be edited before it is
used for substitutions. Add highlight to the replacement text.
|
--- tmp/delsel.el 2014-11-02 17:45:25.440201850 +0100
+++ delsel.el 2014-11-02 17:49:49.000000000 +0100
@@ -54,9 +54,23 @@
;;; Code:
-(defvar delete-selection-save-to-register nil
+(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.")
+Value must be the register (key) to use."
+ :type '(choice
+ (const :tag "None" nil)
+ (character :tag "Register (Key)"))
+ :group 'editing-basics)
+
+(defcustom delete-selection-replacement-face 'highlight
+ "If non-nil, active region replacement text is shown in this face.
+The highlighted text is the text that will be inserted by
+the `delete-selection-repeat-replace-region' command."
+ :type 'face
+ :group 'editing-basics
+ :set (lambda (symbol value)
+ (if delsel--replace-overlay
+ (overlay-put delsel--replace-overlay 'face value))))
;;;###autoload
(defalias 'pending-delete-mode 'delete-selection-mode)
@@ -76,7 +90,8 @@
(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)
+(defvar delsel--replace-overlay nil) ;overlay
+(defvar delsel--replace-text nil) ;text from overlay
(defun delete-active-region (&optional killp)
"Delete the active region.
@@ -89,9 +104,14 @@
(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)))))
+ (if delsel--replace-overlay
+ (move-overlay delsel--replace-overlay (point) (point) (current-buffer))
+ (setq delsel--replace-overlay
+ (make-overlay (point) (point) (current-buffer) nil t))
+ (if delete-selection-replacement-face
+ (overlay-put delsel--replace-overlay 'face
+ delete-selection-replacement-face)))
+ (setq delsel--replace-text nil))
(t
(funcall region-extract-function 'delete-only)))
t)
@@ -106,47 +126,30 @@
(get-register delete-selection-save-to-register)))
(count (if (consp arg) (point-max)
(prefix-numeric-value current-prefix-arg))))
- (if (not (and old-text
- (> (length old-text) 0)
- (or (stringp delsel--replace-text-or-position)
- (buffer-live-p (car
delsel--replace-text-or-position)))))
+ (if (not (and old-text (> (length old-text) 0)))
(message "No known previous replacement")
;; 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))
- (replace-match delsel--replace-text-or-position nil t)
- (setq count (1- count))))))
+ (when (and (null delsel--replace-text)
+ delsel--replace-overlay
+ (buffer-live-p (overlay-buffer delsel--replace-overlay)))
+ (with-current-buffer (overlay-buffer delsel--replace-overlay)
+ (let ((s (overlay-start delsel--replace-overlay))
+ (e (overlay-end delsel--replace-overlay)))
+ (when (/= s e)
+ (setq delsel--replace-text
+ (filter-buffer-substring s e))
+ (set-text-properties
+ 0 (length delsel--replace-text)
+ nil delsel--replace-text))))
+ (delete-overlay delsel--replace-overlay))
+ (if delsel--replace-text
+ (while (and (> count 0)
+ delsel--replace-text
+ (search-forward old-text nil t))
+ (replace-match delsel--replace-text nil t)
+ (setq count (1- count)))
+ (message "Cannot locate replacement text")))))
(defun delete-selection-helper (type)
"Delete selection according to TYPE:
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#18886: 24.4; M-v no longer works in CUA-mode.
2014-10-29 16:54 bug#18886: 24.4; M-v no longer works in CUA-mode Kim F. Storm
2014-10-30 0:47 ` Stefan Monnier
@ 2016-06-26 17:55 ` Noam Postavsky
1 sibling, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2016-06-26 17:55 UTC (permalink / raw)
To: 18886-done
Version: 24.5
Fixes seem to have been applied in 24.5
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-06-26 17:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29 16:54 bug#18886: 24.4; M-v no longer works in CUA-mode Kim F. Storm
2014-10-30 0:47 ` Stefan Monnier
2014-10-30 16:46 ` Kim Storm
2014-10-30 19:23 ` Stefan Monnier
2014-10-30 20:39 ` Kim Storm
2014-11-02 17:04 ` Kim Storm
2016-06-26 17:55 ` Noam Postavsky
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.