Re: When using undefined filetypes ...

Bram Moolenaar <[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Adriaan de Groot wrote:

> While messing about with recipes for new filetypes - and in particular
> actions for filetypes that have no specific extension, or for which I
> just haven't bothered to introduce a suffix rule - I'm regularly
> bitten by typos. I declare an action :compile ltobject cpp and then
> :route cpp ltlibobject. So I thought it would be useful if AAP would
> warn the user when he or she uses an unknown filetype (one that hasn't
> appeared anywhere in a :filetype command).  Then it shows up
> immediately when your :route command doesn't make sense, or there's a
> typo in your :action.
> 
> The attached patches do just that.

Detecting user mistakes is certainly a good idea.  It seems the
implementation is a bit complicated, but since you have already done it,
it must be worth the effort.

> action.diff adds the checking part to the :action rule. I don't know
> how to print a sensible warning (there's aap_error(), but no
> aap_warning()), though.

Internally the msg_xxx() functions can be used.  In this case
msg_warning().  For a recipe the ":print" command can be used for
warnings.  I haven't seen a good reason to add a specific ":warning"
command, since it would not do something different from ":print
Warning:".

By the way, instead of

	for i in intypes:
		...
	for i in outtypes:
	        ...

You can use:

	for i in intypes + outtypes:
	       ...

> commands.diff adds the same to :route.
> 
> filetype.diff does the main work. Ik adds a ft_known() funtion to the API of 
[...]

This is the main work of the patch.  All looks OK.  I just changed a few
minor things (insert spaces in "var=1" and using single # comments
instead of ###).

> There is one minor issue with this whole patch: ft_known calls __init__ (to 
> initialize the lists of filetypes). Previously, __init__ wasn't called until 
> the first add_rules or ft_detect was done. Now, in ft_known, there is no 
> recdict parameter, so None is passed to __init__. It doesn't look like the 
> recdict parameter to __init__ is of great importance -- it's used only to 
> pass to add_rules, which only uses it to pass it back to __init__. But if 
> there is some secret very important reason for that parameter to be there, 
> let me know.

The original intent was to use "recdict" for error messages.  But since
no messages are given it is not used.  I'll remove it.

> doc.diff documents the additional :filetype declare rule, which might be 
> needed for suppressing warnings for filetypes that have no other filetype 
> rule at all (such as python-detected types).

I notice ":filetype" wasn't mentioned yet in the ref-filetype chapter.
I'll add a short note about it.

-- 
hundred-and-one symptoms of being an internet addict:
204. You're being audited because you mailed your tax return to the IRC.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///


-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.