From: John A Pershing Jr <pershing@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: Setting truncate-lines based on file type (extension)
Date: Wed, 30 Sep 2009 09:51:51 -0400 [thread overview]
Message-ID: <82zl8cpmko.fsf@alum.mit.edu> (raw)
In-Reply-To: mailman.7740.1254290461.2239.help-gnu-emacs@gnu.org
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
next prev parent reply other threads:[~2009-09-30 13:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-28 20:11 Setting truncate-lines based on file type (extension) amicitas
2009-09-30 6:00 ` Kevin Rodgers
[not found] ` <mailman.7740.1254290461.2239.help-gnu-emacs@gnu.org>
2009-09-30 13:51 ` John A Pershing Jr [this message]
2009-09-30 20:09 ` amicitas
2009-10-01 12:11 ` Kevin Rodgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=82zl8cpmko.fsf@alum.mit.edu \
--to=pershing@alum.mit.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.