From: "Drew Adams" <drew.adams@oracle.com>
To: "'Andreas Röhler'" <andreas.roehler@easy-emacs.de>,
help-gnu-emacs@gnu.org
Subject: RE: yank-repeat-newline
Date: Tue, 26 Jul 2011 12:32:06 -0700 [thread overview]
Message-ID: <79F08F04553C4C42AAE0804AB5A00E1F@us.oracle.com> (raw)
In-Reply-To: <4E2F11A3.3090102@easy-emacs.de>
> (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")))))
prev parent reply other threads:[~2011-07-26 19:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-26 19:12 yank-repeat-newline Andreas Röhler
2011-07-26 19:19 ` yank-repeat-newline Teemu Likonen
2011-07-26 19:24 ` yank-repeat-newline Andreas Röhler
2011-07-26 19:35 ` yank-repeat-newline Teemu Likonen
2011-07-26 19:45 ` yank-repeat-newline Andreas Röhler
2011-07-26 20:33 ` yank-repeat-newline Drew Adams
2011-07-26 19:32 ` Drew Adams [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=79F08F04553C4C42AAE0804AB5A00E1F@us.oracle.com \
--to=drew.adams@oracle.com \
--cc=andreas.roehler@easy-emacs.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.