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

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

Re: How in .dir-locals.el make association between file extension and Em


From: Tim X
Subject: Re: How in .dir-locals.el make association between file extension and Emacs mode?
Date: Mon, 10 Jan 2011 11:00:02 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Oleksandr Gavenko <gavenkoa@gmail.com> writes:

> On 2011-01-05 1:11, Tim X wrote:
>>> Oleksandr Gavenko<gavenkoa@gmail.com>  writes:
>>> I store collected my tips under same folder with .txt extension.
>>>
>>> Every time when I create new .txt file I forget add:
>>>
>>>    -*- mode: outline; coding: utf-8; fill-column: 80 -*-
>>>
>>> to header. There are nearly 120 files.
>>>
>>> I can fix headers from time to time by script but this require
>>> spending own time, so ugly.
>>>
>>> I expect that Emacs already have mechanism to make this.
>>> Per project configurations which provided by standard Emacs packages.
>>
>> My first comment would be that you should not need to have these headers
>> at all - at least not with a fairly recent version of emacs. I only need
>> these types of file headers for the unusual/special case. What you have
>> in yours looks like the common or standard setup.
>>
> Yes. I want eliminate them.
>
>> 1.  You can add files with extension .txt to auto-file-alist so that all
>> *.txt files will start up with outline mode enabled.  Eliminate need for
>> first setting in your header.
>>
> I prefer save association for '*.txt' to 'text-mode'.
>
> .txt files usually interpreted as text files by many software.
>
> If I make own unique extension I must teach all another soft how
> understand this files (if this is possible )).

No, this would just happen within emacs - no other software would need
to know as yhou are only dealing with text. The setting would only
affect emacs when you opoen a *.txt file. 

However, you have complete freedom. You can adopt a totally different
extension if you wanted. For example, by default org-mode, which is a
text based mode, uses the file extension .org. If you open a file with
the extension .org, emacs will load org-mode for that file. However, if
you then view the file with another program, such a notepad, it will
just look like normal text. 

>
>> 2. UTF-8 is rapidly becoming the default coding system for most systems.
>> Unless you have the need for an alternative coding system because of
>> special characters that are not well supported under utf-8, you probably
>> should set this as your system default. Emacs will use the default
>> platform coding system as its default. So, set your environment to utf-8
>> and eliminate the second option from your header.
>>
> Agree, but how about Russian Windows with it default cp1251?
>

Not sure. Don't use windows and am not familiar with its weird coding
names.

>> 3. You can set the fill column via the custom 8nterface and you can
>> enable filling (wrapping) from the options menu for all text modes. This
>> would eliminate the last of your header settings and you would no longer
>> need the header line at all.
>>
> Set fill-column every time I edit new file is unnecessary work.
>
> And I always forget which value I prefer 78 or 80 or 90 or 120?
>
> As I store files under version control when run 'fill-region'
> with different 'fill-column' I get changes in places where I do
> not edit text.
>

No, you would not need to do this for every file you open. You set up a
default fill column and it is turned on for all files you open in
text-mode. 

>> Another alternative to the above is to just put these settings in your
>> .dir-local file and ensure only *.txt fiels live below that directory.
>>
> I understand how set 'fill-column' via '.dir-local.el'.
>
> But how set coding system and make association between file extension
> and Emacs modes?
>

In dire-local file, the association is based on the mode of the file.
The mode the file opens in is determined by the file-mode-alist
settings. You cannot associate settings in .dir-local based on file
extensions directly. 

>> However, my recommendation for this specific case is that you start using
>> org-mode.
>>
>> I notice you are already using outline mode for your tip/note files, so
>> you will already be familiar with much of org-mode (which is based on
>> outline), plus you get a lot of other really handy things.
>>
>> By default, files with the extension of .org will be palced in org mode,
>> so you can just try it by opening a file with that extension. Org mode
>> is so extremely useful for keeping notes/tips I'm not even sure where to
>> start. Some of its benefits include
>>
>>         * Improved key bindings for cycling through outline levels etc
>>         * Handy table editing support
>>         * Quick capturing of information, with formatting and other bits
>>         * Useful linking and hypertext support
>>         * Support for wiki like markup
>>         * Export to multiple output formats
>>
>>
>> plus much much more. Cannot recommend it highly enough.
> Thanks for interest and tips. I would try org-mode.
>
> Currently I use 'outline-mode' for:
>
>  * colouring headers to make it more visible
>  * folding text to see document structure (only headers shown)
>

Exactly what org-mode does, plus you get a lot of other functionality
you can use if you want. Org-mode is an extension/enhancement of outline
mode.

>
> Sorry, but I repeat question:
>
> How set coding system and make association between file extension
> and Emacs modes per directory?

You cannot. You can only make associations between emacs modes. However,
the mode a file is opened in is controlled by file-mode-alist. 

As you are using .txt as your extension and the default file-mode-alist
for *.txt is text-mode, you would use that to define the associations
i.e.

((text-mode . ((file-column . 79)
               (coding . utf-8)
               (mode . outline))))

The above would set fill column to 79 and coding system to utf-8 for any
file inthe directory which is opened in text-mode. 

The file-mode-alist associates *.txt with text-mode. 

Therefore, any file opened in the directory that has an extension of
*.txt will be setup with folding at column 79 and a utf-8 coding system. 

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

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