Subject: builtin command aliases

From: Dominik Vogt <[email-masked]>
Date: Wed, 19 Jun 2002 13:32:33 +0200

I'd like to add command name aliases to fvwm, e.g.

  Alias GotoDesk MyGotoDesk

and to get the builtin command:

  Builtin GotoDesk

and of course

  Unalias GotoDesk

This way it would be possible to replace a builtin command with a
specifically tuned complex function.  Is that a good idea?  I
think alias expansion should be done for the first word on the
command line only and before anything else.  That feature would
certainly add a lot of flexibility as well as unlimited ways to
break your config.

Bye

Dominik ^_^  ^_^

-- 
Dominik Vogt, email: [email-masked]
LifeBits Aktiengesellschaft, Albrechtstr. 9, D-72072 Tuebingen
fon: ++49 (0) 7071/7965-0, fax: ++49 (0) 7071/7965-20
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 19 Jun 2002 12:31:27 +0000

> certainly add a lot of flexibility as well as unlimited ways to

It seems this will be abused a lot.

Example, there are more than one way to change pages, not only using
GotoPage, but also GotoDesk, GotoDeskAndPage, interactove Move.
The correct way to handle a page change is to listen to new_page event.
Not by using aliases.

But of course there are usages where the _current_ events are not good,
for example you want to be able to control whether a window goes away
or not. You get destroy_window when it is too late, a window does not
exist any more. So here is an alternative. To alias Delete, Close and
Destroy, or to introduce a new event.

Aliases are powerful. but I think they will be used for tasks that should
be solved differently. Something like synchronous events (when a module
returns an event result) comes to a mind.

Aliases may be implemented by simply storing a pointer to a function
(initially NULL) for every command. On any problem (function destroyed) an
alias is removed. If we don't remove alias on DestroyFunc there may be bad
cases when an other module executes an aliased command before the entire
function is defined.

Please don't start this before 2.5.2.

Regards,
Mikhael.

---

From: Tim Phipps <[email-masked]>
Date: Wed, 19 Jun 2002 13:37:41 +0100

>  Alias GotoDesk MyGotoDesk

How would this be different to just reversing to order of command look 
up? i.e. look for functions before built in commands.

Cheers,
Tim.

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 19 Jun 2002 13:28:13 +0000

> up? i.e. look for functions before built in commands.

We still need Builtin, because an overriding function will usually like
to call an original.

Having "Unalias *" as in Dominik's solution looks good.

Storing only correct aliases (already defined functions) is good, because
replacing builtins (Exec, Menu, GotoPage, Close, Quit) is dangerous.

Some builtins should never be replaced: Function, Module, Builtin. (?)

Regards,
Mikhael.

---

From: Dan Espen <[email-masked]>
Date: Wed, 19 Jun 2002 09:45:08 -0400

> > >  Alias GotoDesk MyGotoDesk

To be consistent, shouldn't Unalias be:

Alias GotoDesk -

I'd guess only Builtins could be aliased?

This wouldn't nest:

Alias Move MyMove
Alias Move MyMove1

-- 
Dan Espen                           E-mail: [email-masked]
444 Hoes Lane  Room RRC 1C-214      Phone: (732) 699-5570
Piscataway, NJ 08854
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 19 Jun 2002 16:59:26 +0200

> up? i.e. look for functions before built in commands.

I don't think there would be big differences.

Bye

Dominik ^_^  ^_^

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 19 Jun 2002 17:08:39 +0200

> To be consistent, shouldn't Unalias be:

But "-" is a valid function name.
 
> I'd guess only Builtins could be aliased?

Yes, with the wrong aliases it will be very easy to make fvwm
completely unusable.  It's at least as bad as anything you can do
with a normal shell - but you can cut yourself off from the fvwm
console easily.

Bye

Dominik ^_^  ^_^

---

From: Dan Espen <[email-masked]>
Date: Wed, 19 Jun 2002 10:18:54 -0400

> But "-" is a valid function name.

LOL.

Anyone using "-" as a function name shouldn't be surprised
when it causes a problem.

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 19 Jun 2002 14:49:09 +0000

> when it causes a problem.

Actually, "-" is a builtin prefix.
So it is a bit problematic to have a function named "-" or "-abc".

And it causes a real problem with FvwmPerl and some other modules.
Dominik, is it possible to use "=" as a prefix if we are at it.
At least "=" is not used as a start of an option. Consider this:

  Module FvwmAuto -passid -raise -lower

Is "-raise" an option or an fvwm command that should not be expanded?

Regards,
Mikhael.

---

From: Dave Trollope <[email-masked]>
Date: Wed, 19 Jun 2002 20:09:54 -0500

Hi,

At first I thought the idea of implementing alias' was very good but I
fear that limiting it to the first word would be too limiting to be
really useful. Take for example:

*FvwmButtonsGeometry 520x100-1-1
*FvwmButtonsBack bisque3
*FvwmButtons(Padding 2 2 Container(Rows 1 Columns 4 Frame 1 Padding 10
0))
 *FvwmButtons(Frame -2 Container(Rows 5,Frame 1))

I would find it really useful to alias the above in to:

Alias FB *FvwmButtons
FBGeometry 520x100-1-
FBBack bisque
FB(Padding 2 2 Container ...)
FB(Frame -2 Container...)

However this implies a more preprocessor like parsing than direct
aliasing. To break the preprocessing approach we could take C style ##
to join an alias with some text:

FB##Geometry 520x100-1-
FB##Back bisque
FB(...
FB(...

Also, it would be really useful to do aliases with more than the first
word - take:

AddToMenu Red_Hat_Linux "Programs" Title
Style "*"           FocusFollowsMouse

It would be really useful to alias the first two args and make the
config much more readable to new users:

Alias AddToLinux AddToMenu Red_Hat_Linux
Alias DefStyle Style "*"
AddToLinux "Programs" Title
DefStyle           FocusFollowsMouse

This kind of ability would be much more useful than straight aliases.

However, Alias' are typically a poor mans solution to other problems.
For example, a better functionality would be to implement a "With XXX
...." functionality which would also constrain the impact to the area of
the file instead of being applied globally:

With *FvwmButtons
    Geometry 520x100-1-1
    Back bisque3
    (Padding 2 2 Container(Rows 1 Columns 4 Frame 1 Padding 10 0))
    (Frame -2 Container(Rows 5,Frame 1))
EndWith

Perhaps there is a place for alias' but there are also other solutions
to problems that Alias are often used to solve.  In general constructs
that have global scope are misused. Perhaps constraining it to one word
will prevent abuse and then implementing better solutions that people
can use to solve different problems would be a good approach? Another
constraint could be to limit an alias to the file that it is defined in
like static in C.

This is somewhat of a brain dump so forgive me for being verbose and on
several tangents.....
Cheers
Dave

---

From: Mikhael Goikhman <[email-masked]>
Date: Thu, 20 Jun 2002 05:31:28 +0000

On 19 Jun 2002 20:09:54 -0500, Dave Trollope wrote:
> *FvwmButtons(Padding 2 2 Container(Rows 1 Columns 4 Frame 1 Padding 10 0))

Dave, in all your examples with no exception you either want functions or
preprocessing, both are already available. You don't need a new alias
functionality for this. Aliases only needed to be able to configure
hardcoded builtins that fvwm and modules have in the code, for other cases
there are other solutions.

> to join an alias with some text:

Use:

  AddToFunc FB
  + I *FvwmButtons: $*

  FB Geometry 520x100-0-0
  FB (Padding 2 2, Container ...)

> DefStyle           FocusFollowsMouse

Use:

  AddToFunc AddToLinux I AddToMenu Red_Hat_Linux $*
  AddToFunc DefStyle I Style * $*

  AddToLinux "Programs" Title
  DefStyle FocusFollowsMouse, OLDecor

>     (Frame -2 Container(Rows 5,Frame 1))

FvwmButtons has such ability, create a file containing the lines above
and use *FvwmButtons: File myfb.fvwmrc
Or use functions, or preprocessors. For example, create this file:

sub With ($$) { foreach (split(/\n/, $_[1]) { command("*$_[0]: $_"); } }

With "FvwmButtons", '
	Geometry 520x100-1-1
	(Padding 2 2, Container(Rows 1, Columns 4, Frame 1, Padding 10 0))
';

With "FvwmPager", q{
	Geometry ...
};

Then put one line in your fvwm2rc: FvwmPerl --load mymodules.fpl
If you really want I may add something like this to FvwmPerl --preprocess
so you should not write a definition of With yourself.

> can use to solve different problems would be a good approach?

Here I can only agree.

> Another constraint could be to limit an alias to the file that it is
> defined in like static in C.

I don't think that a concept of aliases as Dominik defined it (replacing
builtins) has something to do with a file scope, it is a dynamic thing,
while files are static.

Regards,
Mikhael.

---

From: Dave Trollope <[email-masked]>
Date: Thu, 20 Jun 2002 13:05:31 -0500

Hi Mikhael

> there are other solutions.

I buy that. I missed that the Alias would only apply to builtins. I think that
is a good thing.

> [Examples Snipped]

I think I just had a quick lesson! Thanks for these solutions I will think about
using them on my config.

> and use *FvwmButtons: File myfb.fvwmrc

A general solution is better than module specific ones - I was aiming for
general solutions.

> so you should not write a definition of With yourself.

I haven't used Perl in my configuration because I like to keep config processing
to a simple level. I like to minimise modules etc loaded at startup. It seems
that With would a nice thing to have built in without FvwmPerl, but perhaps its
a good reason to use FvwmPerl for this. I like your idea of adding to
--preprocess that has With builtin. It would be much simpler than trying to do
it any other way. I guess its time for me to start using FvwmPerl....

> builtins) has something to do with a file scope, it is a dynamic thing,

I agree it is a dynamic thing, but there is no way to "close" the dynamism so
the Alias' get left hanging. Sometimes you only want a quick and dirty alias in
a file and forget to UnAlias. I like to minimise the number of actions that
default to a global scope forcing users to explicitely make things global.

Would Alias within a function be constrained to that function?

Either way I think its good - just wanted to promote some discussion on it.
Cheers
Dave