unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Setting truncate-lines based on file type (extension)
@ 2009-09-28 20:11 amicitas
  2009-09-30  6:00 ` Kevin Rodgers
       [not found] ` <mailman.7740.1254290461.2239.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: amicitas @ 2009-09-28 20:11 UTC (permalink / raw)
  To: help-gnu-emacs

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?

Thanks in advance,

-- amicitas


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting truncate-lines based on file type (extension)
  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>
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2009-09-30  6:00 UTC (permalink / raw)
  To: help-gnu-emacs

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)

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting truncate-lines based on file type (extension)
       [not found] ` <mailman.7740.1254290461.2239.help-gnu-emacs@gnu.org>
@ 2009-09-30 13:51   ` John A Pershing Jr
  2009-09-30 20:09   ` amicitas
  1 sibling, 0 replies; 5+ messages in thread
From: John A Pershing Jr @ 2009-09-30 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting truncate-lines based on file type (extension)
       [not found] ` <mailman.7740.1254290461.2239.help-gnu-emacs@gnu.org>
  2009-09-30 13:51   ` John A Pershing Jr
@ 2009-09-30 20:09   ` amicitas
  2009-10-01 12:11     ` Kevin Rodgers
  1 sibling, 1 reply; 5+ messages in thread
From: amicitas @ 2009-09-30 20:09 UTC (permalink / raw)
  To: help-gnu-emacs

On Sep 29, 11:00 pm, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> 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)
>
> --
> Kevin Rodgers
> Denver, Colorado, USA


Thank you Kevin.  That is precisely what I was looking for.

In my case I am using this to make viewing of certain types of data
and calibration files easier.   These files should be opened in 'text-
mode', except with out wrapping.  Setting a mode hook is therefore not
appropriate.  This seems like a better solution that creating (or
finding) a 'data-mode'.

Thanks again


-- amicitas



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting truncate-lines based on file type (extension)
  2009-09-30 20:09   ` amicitas
@ 2009-10-01 12:11     ` Kevin Rodgers
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2009-10-01 12:11 UTC (permalink / raw)
  To: help-gnu-emacs

amicitas wrote:
> On Sep 29, 11:00 pm, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>> 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)
> 
> Thank you Kevin.  That is precisely what I was looking for.
> 
> In my case I am using this to make viewing of certain types of data
> and calibration files easier.   These files should be opened in 'text-
> mode', except with out wrapping.  Setting a mode hook is therefore not
> appropriate.  This seems like a better solution that creating (or
> finding) a 'data-mode'.

I don't know: define-derived-mode makes it very easy to define your data-mode,
which would set truncate-lines directly.

Alternatively, there's no reason not to put the hook function on
text-mode-hook instead of find-file-hook and find-file-not-found-functions.

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-10-01 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2009-09-30 20:09   ` amicitas
2009-10-01 12:11     ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).