all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* auto-mode-alist, adding two modes
@ 2007-10-08 15:33 Gijs Hillenius
  2007-10-08 15:37 ` weber
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Gijs Hillenius @ 2007-10-08 15:33 UTC (permalink / raw)
  To: help-gnu-emacs

Hi

I would like to get emacs to use longlines-mode *and* flyspell-mode
for all files ending in .txt

If I add this in my .emacs 

(add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))

followed by a similar line for flyspell, ignores the first, and uses
only the latter.

I've tried several more complicated incantations, but I'm not exactly
fluent in lisp.

Would appreciate a hint or two..

Thx

Gijs




-- 
The genius of our ruling class is that it has kept a majority of the
people from ever questioning the inequity of a system where most people
drudge along paying heavy taxes for which they get nothing in return.
		-- Gore Vidal

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 15:33 auto-mode-alist, adding two modes Gijs Hillenius
@ 2007-10-08 15:37 ` weber
  2007-10-08 16:01 ` Joost Kremers
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: weber @ 2007-10-08 15:37 UTC (permalink / raw)
  To: help-gnu-emacs

On Oct 8, 12:33 pm, Gijs Hillenius <gijs-nops...@hillenius.net> wrote:
> Hi
>
> I would like to get emacs to use longlines-mode *and* flyspell-mode
> for all files ending in .txt
>
> If I add this in my .emacs
>
> (add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))
>
> followed by a similar line for flyspell, ignores the first, and uses
> only the latter.
>
> I've tried several more complicated incantations, but I'm not exactly
> fluent in lisp.
>
> Would appreciate a hint or two..
>
> Thx
>
> Gijs
>
> --
> The genius of our ruling class is that it has kept a majority of the
> people from ever questioning the inequity of a system where most people
> drudge along paying heavy taxes for which they get nothing in return.
>                 -- Gore Vidal

Maybe something like this would suffice?

(add-hook 'text-mode-hook '(lambda () (longlines-mode 1) (flyspell-
mode 1))

Just turn on those minor modes when a text-mode file shows up (txt
would be associated with text-mode like in your example)

HTH
weber

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 15:33 auto-mode-alist, adding two modes Gijs Hillenius
  2007-10-08 15:37 ` weber
@ 2007-10-08 16:01 ` Joost Kremers
  2007-10-08 17:55   ` Gijs Hillenius
  2007-10-09  2:22   ` Barry Margolin
  2007-10-09 21:34 ` Edward O'Connor
       [not found] ` <mailman.1891.1191965685.18990.help-gnu-emacs@gnu.org>
  3 siblings, 2 replies; 10+ messages in thread
From: Joost Kremers @ 2007-10-08 16:01 UTC (permalink / raw)
  To: help-gnu-emacs

Gijs Hillenius wrote:
> I would like to get emacs to use longlines-mode *and* flyspell-mode
> for all files ending in .txt
>
> If I add this in my .emacs 
>
> (add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))
>
> followed by a similar line for flyspell, ignores the first, and uses
> only the latter.

you should read the documentation of auto-mode-alist. it says quite clearly
that it is a list for specifying *major* modes. both longline-mode and
flyspell-mode are minor modes, and should therefore be specified in a
different way.

not explicitly stated, but still deducible from the documentation is the
fact that only the *first* matching regexp in auto-mode-alist is used. so
once flyspell-mode has been found, the list is not searched further
anymore.[1] this makes sense, because a buffer can only have one major
mode.

note that auto-mode-alist already specifies a major mode with files ending
in .txt, namely text-mode. your customisation therefore disables text-mode
for .txt files, which is probably not what you want.

to do what you want, you may add flyspell-mode and longlines-mode to
text-mode-hook:

(add-hook 'text-mode-hook 'longlines-mode)
(add-hook 'text-mode-hook 'flyspell-mode)

adding these two minor modes to text-mode-hook makes sure that they are
always turned on when text-mode is selected.

see (info "(emacs)Hooks") for details on hooks.[2]

HTH

joost



Footnotes: 
[1]  note that add-to-list normally adds items to the front of a list, so
that flyspell-mode is indeed the first match found.

[2]  or type: C-h i m emacs RET m hooks RET

-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 16:01 ` Joost Kremers
@ 2007-10-08 17:55   ` Gijs Hillenius
  2007-10-08 18:20     ` Joost Kremers
  2007-10-09  2:22   ` Barry Margolin
  1 sibling, 1 reply; 10+ messages in thread
From: Gijs Hillenius @ 2007-10-08 17:55 UTC (permalink / raw)
  To: help-gnu-emacs

On  8 Oct 2007, Joost Kremers wrote:

> Gijs Hillenius wrote:
>> I would like to get emacs to use longlines-mode *and* flyspell-mode
>> for all files ending in .txt
>>
>> If I add this in my .emacs 
>>
>> (add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))
>>
>> followed by a similar line for flyspell, ignores the first, and uses
>> only the latter.

> you should read the documentation of auto-mode-alist. it says quite
> clearly that it is a list for specifying *major* modes. both
>
> longline-mode and flyspell-mode are minor modes, and should
> therefore be specified in a different way.
>
> not explicitly stated, but still deducible from the documentation is
> the fact that only the *first* matching regexp in auto-mode-alist is
> used. so once flyspell-mode has been found, the list is not searched
> further anymore.[1] this makes sense, because a buffer can only have
> one major mode.
>
> note that auto-mode-alist already specifies a major mode with files
> ending in .txt, namely text-mode. your customisation therefore
> disables text-mode for .txt files, which is probably not what you
> want. 
>
> to do what you want, you may add flyspell-mode and
> longlines-mode to text-mode-hook: 
>
> (add-hook 'text-mode-hook 'longlines-mode)
> (add-hook 'text-mode-hook 'flyspell-mode)
>
> adding these two minor modes to text-mode-hook makes sure that they are
> always turned on when text-mode is selected.
> 
> see (info "(emacs)Hooks") for details on hooks.[2]

Thanks for these speedy replies.

I do *not* want to add both of these minor modes to text-mode, for
this messes up other applications, such as my dear gnus.

So, I settled on 

(add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))
(add-hook 'longlines-mode-hook 'flyspell-mode)

The latter of which, if I understand it correctly, adds a fly-spell
wherever I have longlines-mode. Which is something I can live with,
for now.

Gijs

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 17:55   ` Gijs Hillenius
@ 2007-10-08 18:20     ` Joost Kremers
  0 siblings, 0 replies; 10+ messages in thread
From: Joost Kremers @ 2007-10-08 18:20 UTC (permalink / raw)
  To: help-gnu-emacs

Gijs Hillenius wrote:
> I do *not* want to add both of these minor modes to text-mode, for
> this messes up other applications, such as my dear gnus.
>
> So, I settled on 
>
> (add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))

however, this is just plain wrong. auto-mode-alist is for *major* modes,
and longlines-mode is not a major mode. while it may work right now,
chances are it'll come back to bite you at some point in the future, and
may then be all the harder to debug, because you're doing something that's
not intended.

> (add-hook 'longlines-mode-hook 'flyspell-mode)
>
> The latter of which, if I understand it correctly, adds a fly-spell
> wherever I have longlines-mode. Which is something I can live with,
> for now.

yes, that is what it does.

if you don't want to add longlines-mode and flyspell-mode to
text-mode-hook, there is always the possibility to create a derived major
mode, which is easier than you might think:

(define-derived-mode my-text-mode
  text-mode "Text"
  "Modified text-mode, includes longlines-mode and flyspell-mode"
  (longlines-mode 1)
  (flyspell-mode 1))

then:

(add-to-list 'auto-mode-alist '("\\.txt\'" . my-text-mode))

this should do what you want without messing up gnus.

HTH

-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 16:01 ` Joost Kremers
  2007-10-08 17:55   ` Gijs Hillenius
@ 2007-10-09  2:22   ` Barry Margolin
  2007-10-09 11:01     ` Joost Kremers
  1 sibling, 1 reply; 10+ messages in thread
From: Barry Margolin @ 2007-10-09  2:22 UTC (permalink / raw)
  To: help-gnu-emacs

In article 
<slrnfgkl1e.2ps.joostkremers@j.kremers4.news.arnhem.chello.nl>,
 Joost Kremers <joostkremers@yahoo.com> wrote:

> Gijs Hillenius wrote:
> > I would like to get emacs to use longlines-mode *and* flyspell-mode
> > for all files ending in .txt
> >
> > If I add this in my .emacs 
> >
> > (add-to-list 'auto-mode-alist '("\\.txt\\'" . longlines-mode ))
> >
> > followed by a similar line for flyspell, ignores the first, and uses
> > only the latter.
> 
> you should read the documentation of auto-mode-alist. it says quite clearly
> that it is a list for specifying *major* modes. both longline-mode and
> flyspell-mode are minor modes, and should therefore be specified in a
> different way.

I don't think this is really that important.  It's just an alist that 
maps filename patterns to functions to call when loading the file into a 
buffer.  While this is intended to set the major mode, this is really 
just a convention.  Nothing really cares what the function does.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

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

* Re: auto-mode-alist, adding two modes
  2007-10-09  2:22   ` Barry Margolin
@ 2007-10-09 11:01     ` Joost Kremers
  0 siblings, 0 replies; 10+ messages in thread
From: Joost Kremers @ 2007-10-09 11:01 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin wrote:
>> you should read the documentation of auto-mode-alist. it says quite clearly
>> that it is a list for specifying *major* modes. both longline-mode and
>> flyspell-mode are minor modes, and should therefore be specified in a
>> different way.
>
> I don't think this is really that important.  It's just an alist that 
> maps filename patterns to functions to call when loading the file into a 
> buffer.  While this is intended to set the major mode, this is really 
> just a convention.  Nothing really cares what the function does.

still, i do believe it's better to follow the convention, especially given
that there are other ways of achieving what the OP wants. note that with
his solution, no major mode is set anymore for .txt files, probably not a
desirable side-effect. and if the OP gets into the habit of specifying
minor modes in this manner, who knows what kinds of problems it will cause
in the future? problems that, because he's not following conventions, will
be all the more difficult to track down.

IMHO it's a useful (and otherwise harmless) convention, and unless you know
exactly what you're doing, it's best to follow it.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

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

* Re: auto-mode-alist, adding two modes
  2007-10-08 15:33 auto-mode-alist, adding two modes Gijs Hillenius
  2007-10-08 15:37 ` weber
  2007-10-08 16:01 ` Joost Kremers
@ 2007-10-09 21:34 ` Edward O'Connor
       [not found] ` <mailman.1891.1191965685.18990.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 10+ messages in thread
From: Edward O'Connor @ 2007-10-09 21:34 UTC (permalink / raw)
  To: help-gnu-emacs

> I would like to get emacs to use longlines-mode *and* flyspell-mode
> for all files ending in .txt

You might want to define a derived mode in this sort of case.

Something like this should do the trick. Untested, of course.

(define-derived-mode gijs-text-mode text-mode "Gijs"
  "Major mode for editing text files.")

(add-to-list 'auto-mode-alist '("\\.txt\\'" . gijs-text-mode))

(add-hook 'gijs-text-mode-hook 'longlines-mode)
(add-hook 'gijs-text-mode-hook 'flyspell-mode)

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

* Re: auto-mode-alist, adding two modes
       [not found] ` <mailman.1891.1191965685.18990.help-gnu-emacs@gnu.org>
@ 2007-10-10 23:47   ` Johan Bockgård
  2007-10-12  5:37     ` Gijs Hillenius
  0 siblings, 1 reply; 10+ messages in thread
From: Johan Bockgård @ 2007-10-10 23:47 UTC (permalink / raw)
  To: help-gnu-emacs

Edward O'Connor <hober0@gmail.com> writes:

>> I would like to get emacs to use longlines-mode *and* flyspell-mode
>> for all files ending in .txt
>
> You might want to define a derived mode in this sort of case.
>
> Something like this should do the trick. Untested, of course.
>
> (define-derived-mode gijs-text-mode text-mode "Gijs"
>   "Major mode for editing text files.")
>
> (add-to-list 'auto-mode-alist '("\\.txt\\'" . gijs-text-mode))


> (add-hook 'gijs-text-mode-hook 'longlines-mode)
> (add-hook 'gijs-text-mode-hook 'flyspell-mode)

Don't do that. This *toggles* {longlines,flyspell}-mode. If the parent
mode hook (text-mode-hook) turned it on, this will turn it off again.

-- 
Johan Bockgård

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

* Re: auto-mode-alist, adding two modes
  2007-10-10 23:47   ` Johan Bockgård
@ 2007-10-12  5:37     ` Gijs Hillenius
  0 siblings, 0 replies; 10+ messages in thread
From: Gijs Hillenius @ 2007-10-12  5:37 UTC (permalink / raw)
  To: help-gnu-emacs

On 11 Oct 2007, Johan Bockgård wrote:

>> (add-hook 'gijs-text-mode-hook 'longlines-mode)
>> (add-hook 'gijs-text-mode-hook 'flyspell-mode)
>
> Don't do that. This *toggles* {longlines,flyspell}-mode. If the parent
> mode hook (text-mode-hook) turned it on, this will turn it off again.


Here's how it currently (seems to) work(s) just fine. Thanks to the
posters in the group:

(define-derived-mode my-text-mode
  text-mode "Text"
  "Modified text-mode, includes longlines-mode and flyspell-mode"
  (longlines-mode 1)
  (flyspell-mode 1))


-- 
I knew then (in 1970) that a 4-kbyte minicomputer would cost as much as
a house.  So I reasoned that after college, I'd have to live cheaply in
an apartment and put all my money into owning a computer.
                -- Apple co-founder Steve Wozniak, 
                   EE Times, June 6, 1988, pg 45

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

end of thread, other threads:[~2007-10-12  5:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-08 15:33 auto-mode-alist, adding two modes Gijs Hillenius
2007-10-08 15:37 ` weber
2007-10-08 16:01 ` Joost Kremers
2007-10-08 17:55   ` Gijs Hillenius
2007-10-08 18:20     ` Joost Kremers
2007-10-09  2:22   ` Barry Margolin
2007-10-09 11:01     ` Joost Kremers
2007-10-09 21:34 ` Edward O'Connor
     [not found] ` <mailman.1891.1191965685.18990.help-gnu-emacs@gnu.org>
2007-10-10 23:47   ` Johan Bockgård
2007-10-12  5:37     ` Gijs Hillenius

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.