tags:

views:

56

answers:

2

As I asked here, I can choose the lisp for running SLIME with prefix argument(C-u), and I is written in here, I see that C-u is a way to insert the output in the current buffer.

I use 'C-u 10 SOMETHING', in order to run SOMETHING 10 times.

What's the usage/purpose of using prefix argument (C-u)? Is C-u the only prefix argument?

+3  A: 

Check out the documentation for prefix command arguments.

But, in short, it's a way to interactively provide more information to the command.

  • for alpha-numberic keys, generally bound to 'self-insert, it tells them how many of that character to insert
  • for some commands (M-x comment-region) it means to invert the command, i.e. C-u M-x comment-region *un*comments the region.
  • for some it just tweaks the behavior, C-u C-s does a 'isearch-forward-regexp instead of a regular 'isearch-forward.

So, it all depends on how the command uses the prefix argument.

As far as other "prefix arguments", there are C--, M--, M-3 (or any other digit), and some others.

Trey Jackson
+1  A: 

Also bear in mind that C-u as a prefix on its own defaults to passing '(4) as the argument, and each C-u that you insert before the command multiplies this by 4.

Thus you can write a quick way of having a few simply choices that are selected between by using ctrl-u prefixes, for example:

(defun insert-date (prefix)
  "Insert the current date. With prefix-argument, use ISO format. With
   two prefix arguments, write out the day and month name."
  (interactive "P")
  (let ((format (cond
                 ((not prefix) "%A, %d %B %Y %H:%M %Z" )
                 ((equal prefix '(4)) "%d/%m/%Y %H:%M")
                 ((equal prefix '(16)) "%d/%m/%Y")
                 ((equal prefix '(64)) "%H:%M:%S")
                 ))
        (system-time-locale "en_GB"))
    (insert (format-time-string format))))

(global-set-key (kbd "C-c d") 'insert-date)

(The above elisp produces a function that inserts a long format date on the key (in this case C-c d), the date + time in short format on C-u C-c d, the short format date on C-u C-u C-c d, and the short format time on C-u C-u C-u C-c d)

You could use this trick to make a 'start-slime' replacement that used clojure by default, but sbcl if you press C-u before the key binding.

NikkiA