emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address@hidden: cua-mode scrambles buffer content with apply-macro-t


From: Kim F. Storm
Subject: Re: address@hidden: cua-mode scrambles buffer content with apply-macro-to-region-lines]
Date: 09 Sep 2002 15:03:05 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

address@hidden (Kim F. Storm) writes:

> From: address@hidden
> > 
> > It seems that the function apply-macro-to-region-lines doesn't work in
> > the context of cua-mode. After invoking the function
> > apply-macro-to-region-lines the contents of the specified region looks
> > scrambled.

The problem you observe with apply-macro-to-region-lines and cua-mode
is that when the region is active, any insertion in the buffer will
replace the active region...  so if the macro does insertion [your
example does], the region is cleared... making the end-result quite
obscure.

The same problem exists if you just enable delete-selection-mode, so
it is not cua-mode specific.

The proper fix seems to be to make sure the mark isn't active when we
call the macro in apply-macro-to-region-lines; then the
delete-selection (and cua) behaviour is inhibited.

Please try this version:

(defun apply-macro-to-region-lines (top bottom &optional macro)
  "..."
  (interactive "r")
  (or macro
      (progn
        (if (null last-kbd-macro)
            (error "No keyboard macro has been defined"))
        (setq macro last-kbd-macro)))
  (save-excursion
    (let ((end-marker (progn
                        (goto-char bottom)
                        (beginning-of-line)
                        (point-marker)))
          next-line-marker)
      (goto-char top)
      (if (not (bolp))
          (forward-line 1))
      (setq next-line-marker (point-marker))
      (while (< next-line-marker end-marker)
        (goto-char next-line-marker)
        (save-excursion
          (forward-line 1)
          (set-marker next-line-marker (point)))
        (save-excursion
          (let ((mark-active nil))
            (execute-kbd-macro (or macro last-kbd-macro)))))
      (set-marker end-marker nil)
      (set-marker next-line-marker nil))))


Or apply the following patch:

Index: macros.el
===================================================================
RCS file: /cvs/emacs/lisp/macros.el,v
retrieving revision 1.37
diff -c -r1.37 macros.el
*** macros.el   15 Jul 2001 16:15:34 -0000      1.37
--- macros.el   9 Sep 2002 11:54:38 -0000
***************
*** 299,305 ****
          (forward-line 1)
          (set-marker next-line-marker (point)))
        (save-excursion
!         (execute-kbd-macro (or macro last-kbd-macro))))
        (set-marker end-marker nil)
        (set-marker next-line-marker nil))))
  
--- 299,306 ----
          (forward-line 1)
          (set-marker next-line-marker (point)))
        (save-excursion
!         (let ((mark-active nil))
!           (execute-kbd-macro (or macro last-kbd-macro)))))
        (set-marker end-marker nil)
        (set-marker next-line-marker nil))))

-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]