emacs-devel
[Top][All Lists]
Advanced

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

RE: Why is `C-M-x' only for top-level defuns?


From: Drew Adams
Subject: RE: Why is `C-M-x' only for top-level defuns?
Date: Wed, 11 Jan 2012 19:42:14 -0800

> >> My question is whether we really want `C-M-x' to do what it does
> >> instead of just pick up the innermost def* containing point.
> > 
> > One problem is to define what is "the innermost def* 
> > containing point".  I suspect it's difficult to formally
> > define it in a way that always corresponds to the intuitive
> > meaning.
> 
> Right. Consider:
> (unless (featurep 'deffoo)
>   (defmacro deffoo (bar)
>     `(defun ,bar () POINT)))

I did not literally mean "def*".  I was trying to abbreviate the definitions
that are treated specially by `C-M-x' (as opposed to, say, `C-x C-e').

I was thinking, in particular, of defface, defvar, and defcustom.  Perhaps there
are additional forms for which `C-M-x' does something special (redefines)
currently, but those are the ones I'm aware of and was thinking of.

But not defun or defmacro, because `C-M-x' does nothing special for them.  They
are always redefined whenever they are re-evaluated in any manner.  Not so,
defface, defvar, and defcustom.

For defface, defvar, and defcustom, AFAIK, only `C-M-x' redefines the face or
variable - `C-x C-e' or `eval-region' does not.  The idea is to get this special
redefining behavior of `C-M-x' without a workaround when the defining form does
not happen to start in column 0.

As for code that generates code (as in your example, but with the `defun' form
replaced by a `defface' form), I wouldn't have a problem with `C-M-x' trying to
evaluate and redefine it, if that's what the users asked for.  That would in
some cases raise an error (e.g. embedded `,' or `,@'), but that's not a problem,
IMO.  The user would be in control (it's on demand, the user positions point,
etc.).

It does not really need to be the key sequence `C-M-x' that provides this
feature, if there is some good reason why what `C-M-x' does now is preferred
(still asking that question - no answer so far).  My thought is that it would be
convenient to have some key for this; that's all.

Stefan might be right that it would be difficult to get right - dunno.  Off the
top of my head, however, I'd guess that just going `uplist' from point till
finding `defface', `defcustom', or `defvar' as the car might be good enough.

That doesn't mean that all such contexts would necessarily be valid face or var
definitions.  But again, this is interactive and visible.  The user would be in
control, asking for it with point where it is etc.  You would get what you ask
for.




reply via email to

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