Prolog filetype problem

25 views
Skip to first unread message

Gautier DI FOLCO

unread,
Sep 30, 2012, 5:07:34 PM9/30/12
to vim...@googlegroups.com
Hi all,

I write some code in Prolog and some code in Perl, the problem is that these
two languages have the same extension, is their a mean to set the good
filetype not according to their extension, but according to the language
highlighting that find the most tokens?

For your help,
In advance,
Thanks.

Ben Fritz

unread,
Sep 30, 2012, 5:32:24 PM9/30/12
to vim...@googlegroups.com
On Sunday, September 30, 2012 4:07:41 PM UTC-5, Gautier DI FOLCO wrote:
> Hi all,
>
> I write some code in Prolog and some code in Perl, the problem is that these
> two languages have the same extension, is their a mean to set the good
> filetype not according to their extension, but according to the language
>
> highlighting that find the most tokens?
>

It looks like Vim will automatically detect prolog rather than Perl if the first non-blank line contains any of:

1. the word "prolog"
2. a prolog comment, % or /* ... */
3. the prolog :- construct

Otherwise, Vim detects Perl. So for existing files, just get into the habit of starting the file with a header comment and you'll be fine.

I guess new files will always detect as Perl, but there's really not any way I can think of for Vim to detect in a general way what filetype a brand-new empty file should be. You could set up some BufNewFile autocmds based on project directory or something if you like for this.

Gautier DI FOLCO

unread,
Oct 1, 2012, 11:20:20 AM10/1/12
to vim...@googlegroups.com
2012/9/30 Ben Fritz <fritzo...@gmail.com>

It looks like Vim will automatically detect prolog rather than Perl if the first non-blank line contains any of:

1. the word "prolog"
2. a prolog comment, % or /* ... */
3. the prolog :- construct

Otherwise, Vim detects Perl. So for existing files, just get into the habit of starting the file with a header comment and you'll be fine.

I guess new files will always detect as Perl, but there's really not any way I can think of for Vim to detect in a general way what filetype a brand-new empty file should be. You could set up some BufNewFile autocmds based on project directory or something if you like for this.

Clever, thank you.

Eric Marceau

unread,
Oct 10, 2022, 1:12:03 AM10/10/22
to vim_use
On my system (Ubuntu MATE 20.04) there is no default file /etc/magic (per the man for "file").

My local definitions were placed in that file which are interpreted before other system definitions.

The content of my "/etc/magic" file is as follows:

# Magic local data for file(1) command.
# Insert here your local magic data. Format is described in magic(5).
0    string    %%Prolog    Prolog Predicate File (Non-Specific)

0    string    %%gprolog    Prolog Predicate File (GNU Prolog)

0    string    %%swipl        Prolog Predicate File (SWI-Prolog)

0    string    %%yap        Prolog Predicate File (YAP Prolog)

0    string    %%eclipse    Prolog Predicate File (ECLiPSe)

0    string    %%bprolog    Prolog Predicate File (B-Prolog)

0    string    %%poplog    Prolog Predicate File (Poplog)

0    string    %%lpaprolog    Prolog Predicate File (LPA Prolog)

0    string    %%isoprolog    Prolog Predicate File (ISO-Compliant Prolog)

0    string    [Pp][Rr][Oo][Ll][Oo][Gg]    Prolog Predicate File (ISO-Compliant Prolog)

0    search    :-    Prolog Predicate File (Non-Specific :-)

0    search    -->    Prolog Predicate File (Non-Specific -->)
#
#0    search/2048    [Pp][Rr][Oo][Ll][Oo][Gg]    Prolog Predicate File (ISO-Compliant Prolog)
#
#0    string    %     Prolog Predicate File (Non-Specific %)
#
#

As can be seen, I was attempting to specify definitions which would identify the various dialects of Prolog and have "file" report those.  Works splendidly for me!

Doug Kearns

unread,
Oct 11, 2022, 12:28:47 AM10/11/22
to vim...@googlegroups.com
On Mon, 1 Oct 2012 at 07:32, Ben Fritz <fritzo...@gmail.com> wrote:

<snip>

> Otherwise, Vim detects Perl. So for existing files, just get into the habit of starting the file with a header comment and you'll be fine.
>
> I guess new files will always detect as Perl, but there's really not any way I can think of for Vim to detect in a general way what filetype a brand-new empty file should be. You could set up some BufNewFile autocmds based on project directory or something if you like for this.

Setting g:filetype_pl might be helpful here. You could even just
manually set it if you were having a Prolog-only day for example. See
:help filetype-overrule

Regards,
Doug
Reply all
Reply to author
Forward
0 new messages