unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* more than one prefix argument
@ 2011-07-26 19:59 Andreas Röhler
  2011-07-26 20:10 ` Daniel Colascione
  0 siblings, 1 reply; 17+ messages in thread
From: Andreas Röhler @ 2011-07-26 19:59 UTC (permalink / raw)
  To: Emacs developers

Hi,

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 help-gnu-emacs@gnu.org:

;;;;;;;;;;;;;;;;;

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

;;;;;;;;;;;;;

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,

Andreas

--
https://launchpad.net/python-mode
https://launchpad.net/s-x-emacs-werkstatt/



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2011-07-27 15:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-26 19:59 more than one prefix argument Andreas Röhler
2011-07-26 20:10 ` Daniel Colascione
2011-07-26 20:36   ` Andreas Röhler
2011-07-26 20:57     ` Drew Adams
2011-07-26 20:36   ` Drew Adams
2011-07-27  6:25     ` Andreas Röhler
2011-07-27  9:25       ` Tim Cross
2011-07-27  9:37         ` Andreas Röhler
2011-07-27  9:48           ` Tim Cross
2011-07-27 10:21             ` Andreas Röhler
2011-07-27 11:21               ` Andreas Schwab
2011-07-27 11:46                 ` Andreas Röhler
2011-07-27 12:39                   ` Andreas Schwab
2011-07-27 12:51                   ` Tim Cross
2011-07-27 12:46               ` Tim Cross
2011-07-27 15:09               ` Drew Adams
2011-07-27  9:38         ` Tim Cross

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).