emacs-devel
[Top][All Lists]
Advanced

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

kmacro.el


From: Luc Teirlinck
Subject: kmacro.el
Date: Mon, 29 Nov 2004 22:00:31 -0600 (CST)

I mentioned a while ago that I had read /man/kmacro.texi, but that
there where still problems left, in particular that the section on the
macro counter was hard to understand.  The reason for that was that
there were several bugs and inconsistencies with the counter, most of
which (or to say something safer, most of which I know about) have
been fixed in the meantime.

I believe inconsistencies with the counter _format_ remain.  The
following patch takes care of those.

I believe that it is not very intuitive that if you change the format
_during definition_ of a macro that this affects all subsequent macros
as well.  I also believe that if you change the format before defining
a keyboard macro and then notice that you still want to execute
another macro before starting the definition, then that should not
change the format of that other macro.

The new behavior is simple, with no surprises:

Changing the format _never_ affects macros defined prior to the
change.  (As already said there currently are situations where
existing macros can be affected.)

Changing the format when no kmacro is being defined or executed
affects all macros defined from then on.  (Until the format is changed
again.)

Changing the format during macro definition changes the format of the
macro being defined from that stage on, during definition and
execution, but (unlike at present) does not affect subsequent macros
still to be defined.

I have the impression that the above described behavior was actually
always the _intended_ behavior and that the fact that the actual
behavior is different is an inadvertent bug, rather than intentional.

The patch also removes the "(printf format)" from the `C-x C-k C-f'
prompt.  This is misleading.  No C style printf format is used but an
Elisp `format' format.  Better no hint than a false hint.  This is
a specialized function intended for more knowledgeable users anyway.

The other two small changes seem obvious:

(and nil ...

makes no sense.  The other `and' arguments are ignored.

In the call to `message' the extra "%s" is necessary, because the user
could have used %s or %o sequences in the macro text, that are
intended literally.  That is, for instance `C-x C-k C-v' will print:

let*: Not enough arguments for format string

when invoked after:

C-x ( %s%s RET C-x )

Something similar actually happened to me in practice (that is how I
noticed), so it is not a far fetched possibility at all.

Once it would be determined that these changes, as well as the changes
I am going to propose to man/kmacro.texi are OK, I also intend to
propose several changes to docstrings that are not very clear, or even
misleading.

===File ~/kmacro.el-diff====================================
*** kmacro.el   01 Nov 2004 17:50:00 -0600      1.24
--- kmacro.el   25 Nov 2004 20:43:20 -0600      
***************
*** 237,242 ****
--- 237,244 ----
  (defvar kmacro-counter 0
    "*Current keyboard macro counter.")
  
+ (defvar kmacro-default-counter-format "%d")
+ 
  (defvar kmacro-counter-format "%d"
    "*Current keyboard macro counter format.")
  
***************
*** 268,279 ****
  
  (defun kmacro-set-format (format)
    "Set macro counter FORMAT."
!   (interactive "sMacro Counter Format (printf format): ")
    (setq kmacro-counter-format
        (if (equal format "") "%d" format))
    ;; redefine initial macro counter if we are not executing a macro.
    (if (not (or defining-kbd-macro executing-kbd-macro))
!       (setq kmacro-counter-format-start kmacro-counter-format)))
  
  
  (defun kmacro-display-counter (&optional value)
--- 270,281 ----
  
  (defun kmacro-set-format (format)
    "Set macro counter FORMAT."
!   (interactive "sMacro Counter Format: ")
    (setq kmacro-counter-format
        (if (equal format "") "%d" format))
    ;; redefine initial macro counter if we are not executing a macro.
    (if (not (or defining-kbd-macro executing-kbd-macro))
!       (setq kmacro-default-counter-format kmacro-counter-format)))
  
  
  (defun kmacro-display-counter (&optional value)
***************
*** 404,411 ****
        (let* ((x 60)
             (m (format-kbd-macro macro))
             (l (length m))
!            (z (and nil trunc (> l x))))
!       (message (format "%s%s: %s%s" (or descr "Macro")
                         (if (= kmacro-counter 0) ""
                           (format " [%s]"
                                   (format kmacro-counter-format-start 
kmacro-counter)))
--- 406,414 ----
        (let* ((x 60)
             (m (format-kbd-macro macro))
             (l (length m))
!            (z (and trunc (> l x))))
!       (message "%s"
!                (format "%s%s: %s%s" (or descr "Macro")
                         (if (= kmacro-counter 0) ""
                           (format " [%s]"
                                   (format kmacro-counter-format-start 
kmacro-counter)))
***************
*** 588,594 ****
              kmacro-initial-counter-value nil
              kmacro-counter-value-start kmacro-counter
              kmacro-last-counter kmacro-counter
!             kmacro-counter-format-start kmacro-counter-format))
  
        (start-kbd-macro append
                       (and append
--- 591,598 ----
              kmacro-initial-counter-value nil
              kmacro-counter-value-start kmacro-counter
              kmacro-last-counter kmacro-counter
!             kmacro-counter-format kmacro-default-counter-format
!             kmacro-counter-format-start kmacro-default-counter-format))
  
        (start-kbd-macro append
                       (and append
============================================================
 LocalWords:  diff




reply via email to

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