From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John A Pershing Jr Newsgroups: gmane.emacs.help Subject: Re: Setting truncate-lines based on file type (extension) Date: Wed, 30 Sep 2009 09:51:51 -0400 Organization: Optimum Online Message-ID: <82zl8cpmko.fsf@alum.mit.edu> References: <1f1c52b2-58c2-4674-98b0-836acf647b33@v25g2000yqk.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1254363887 21005 80.91.229.12 (1 Oct 2009 02:24:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 Oct 2009 02:24:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Oct 01 04:24:40 2009 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.50) id 1MtBLU-00074u-0O for geh-help-gnu-emacs@m.gmane.org; Thu, 01 Oct 2009 04:24:40 +0200 Original-Received: from localhost ([127.0.0.1]:58457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtBLT-0004qu-Gy for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Sep 2009 22:24:39 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!newsfeed.news2me.com!nx02.iad01.newshosting.com!newshosting.com!69.16.185.51.MISMATCH!tmp-post01.iad!news.highwinds-media.com!news.cv.net!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (windows-nt) Cancel-Lock: sha1:w5IG9skRNR+MJgAMSeTsnQRzHi4= Original-Lines: 34 Original-NNTP-Posting-Host: 74.88.209.219 Original-X-Complaints-To: abuse@cv.net Original-Xref: news.stanford.edu gnu.emacs.help:173452 X-Mailman-Approved-At: Wed, 30 Sep 2009 22:23:18 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor 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:68581 Archived-At: Kevin Rodgers 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