[Top][All Lists]

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

more than one prefix argument

From: Andreas Röhler
Subject: more than one prefix argument
Date: Tue, 26 Jul 2011 21:59:08 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv: Gecko/20110616 SUSE/3.1.11 Thunderbird/3.1.11


what about allowing more than one prefix argument
by making interactive codes "p" and "P" sending
truly separated.

Would reserve "p" for numerical args, while "P"
basically should send a kind of exception flag,
branching execution.

Below a use-case for it, yank-repeat should add
newlines if C-u follows the numeric argument.

As both inputs interfere, that's not possible that way
for now.

;; not working now
(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))))))

Drew presented a solution at address@hidden:


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).


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")))))


However, that solution seems too complicated for a
part of non-programmers, it's not mnemonic, rather
tricky - even not uncommon in Emacs.

Would be glad to have C-u as general branch key.

Thanks all,



reply via email to

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