From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: How in .dir-locals.el make association between file extension and Emacs mode? Date: Mon, 10 Jan 2011 11:00:02 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <8762tx8w71.fsf@puma.rapttech.com.au> References: <87y670b6y5.fsf@puma.rapttech.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1294620034 31191 80.91.229.12 (10 Jan 2011 00:40:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 10 Jan 2011 00:40:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 10 01:40:30 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pc5oD-0002ee-Sg for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Jan 2011 01:40:30 +0100 Original-Received: from localhost ([127.0.0.1]:34416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pc5oD-00014O-Cg for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Jan 2011 19:40:29 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news-xfer.nntp.sonic.net!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:rIljmMbLMsnfCGo7Ptm+teioVxY= Original-Lines: 155 Original-NNTP-Posting-Host: 54f579e7.news.astraweb.com Original-X-Trace: DXC=d_RCAa9@lM List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78350 Archived-At: Oleksandr Gavenko writes: > On 2011-01-05 1:11, Tim X wrote: >>> Oleksandr Gavenko 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