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

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

Re: bundling C-u C-space


From: Emanuel Berg
Subject: Re: bundling C-u C-space
Date: Mon, 12 Oct 2015 00:44:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Tim Johnson <tim@akwebsoft.com> writes:

> I'd like to get the functionality of Control-u
> Control-space in one keystroke (for instance,
> Control-,) but can't wrap my thoughts about how to
> put that in a lambda or use-defined function.

In general, if you want to emulate a function's
behavior in the face of a prefix argument supplying
data, find out what that function is and supply that
data yourself!

C-SPC is `set-mark-command', so that would be

    (set-mark-command '(4))

Why '(4) and not 4? Use the source, Luke!
For set-mark-command, it is

    (interactive "P")

and not "p".

Test this with these - evaluate, and then call with M-x!

(defun test-prefix-from-code (arg)
  (interactive "P")
  (if arg (message "arg is %s - i.e., data is %s" arg (prefix-numeric-value 
arg))
    (message "No arg, dammit!") ))

(defun test-prefix-from-code-not-raw (arg)
  (interactive "p")
  (message "arg is %s - i.e., data is %s" arg (prefix-numeric-value arg)) )
  ;; note: no `if' form! arg will be 1 if not
  ;;       supplied, and not nil as above!

And now something else:

Sometimes the ARG isn't exactly to supply data but to
control behavior. Then instead of supplying the "data"
that by all means get you the behavior you want,
instead you can examine the source - again - and
simply detect the function that does what you want.
If the code is neatly written it shouldn't be
a problem detecting and isolating it.

In this case, is it `pop-to-mark-command'?

Good luck!

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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