[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Setting truncate-lines based on file type (extension)
From: |
John A Pershing Jr |
Subject: |
Re: Setting truncate-lines based on file type (extension) |
Date: |
Wed, 30 Sep 2009 09:51:51 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (windows-nt) |
Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> amicitas wrote:
>> For certain types of files I want to set truncate-lines to true. I
>> would like to be able to specify these files based on the file
>> extension. While I know how to set the mode, but how would I go about
>> changing settings?
>
> (defun my-set-truncate-lines () "Set `truncate-lines' to t when visiting
> a file whose extension is \"ext1\", \"ext2\", or \"ext3\"." (when
> (member (file-name-extension buffer-file-name) '("ext1" "ext2" "ext3"))
> (setq truncate-lines t)) ;; return value for find-file-not-found-hooks:
> nil)
>
> (add-hook 'find-file-hook 'my-set-truncate-lines) (add-hook
> find-file-not-found-functions 'my-set-truncate-lines)
If you *really* want this to be based on file extension, then Kevin
Rodgers's suggestion is fine. However, if you actually want to set
truncate-lines (and, prehaps, word-wrap) based on the *type* of the file
(e.g., 'text' versus 'Java'), then note that most (all?) of the major
modes allow you to register hooks for that mode, so you can add a
one-liner (which sets truncate-lines to whatever value you want) to the
various mode hooks. E.g., 'java-mode' sets it to 't, 'text-mode' leaves
it as nil and sets word-wrap to 't, etc.
An additional advantage is that this gets applied to buffers that are
not associated with a file -- e.g., the Gnus message buffer (which is an
extension of 'text-mode').
Note that the "mode" of a buffer is partially related to the file
extension, but can also be determined by several other factors. Using
mode hooks is *probably* what you really want.
-jp