help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: yank-repeat-newline


From: Drew Adams
Subject: RE: yank-repeat-newline
Date: Tue, 26 Jul 2011 12:32:06 -0700

> (defun yank-repeat-newline (arg &optional nl)
>    "With numerical ARG, repeat last yank ARG times.
> With optional arg NL, also insert newlines. "
>    (interactive "p\nP*")
>    (let ((nl nl)
>          (num arg))
>      (dotimes (i num)
>        (if nl
>            (insert (concat (car kill-ring) "\n"))
>          (insert (car kill-ring))))))

You don't need the `let'.

But you cannot do what your doc string claims, at least not the way you're
trying.

As Teemu explained, there is only _one_ prefix arg. You can look at either its
numeric value or its raw value or both, but there is only ONE prefix arg.

You apparently want to have a prefix arg express both a numeric quantity and a
boolean.  If the user uses C-u (or its variants) to specify a (non-nil) prefix
arg then, well, the raw value is non-nil.  If the raw value is nil, then the
user did not use C-u (or its variants).

If you want to let the user specify a numeric value, default 1, and also specify
whether to add a newline, then one way to do that is to distinguish positive
from negative prefix arg (there's your boolean).

E.g.:

M-x yank...    -> just one, no newline
M-- yank...    -> one, newline
C-u -1 yank... -> one, newline
C-u -2 yank... -> two, newlines
C-u  2 yank... -> two, no newlines

Something like this:

(defun myyank (&optional arg)
  (interactive "p")
  (dotimes (i (abs arg))
    (if (natnump arg)
        (insert (car kill-ring))
      (insert (concat (car kill-ring) "\n")))))




reply via email to

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