all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Different options for different modes?
@ 2011-09-23 14:24 winkerbean
  2012-03-29  9:51 ` Philipp Haselwarter
       [not found] ` <mailman.53.1333014742.20052.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: winkerbean @ 2011-09-23 14:24 UTC (permalink / raw
  To: help-gnu-emacs

Hi,

Can Someone point Me in the direction of documentation which shows how
to set different options for different modes? (e.g., preserving tabs
as tabs in a ruby file while converting tabs to four ' ' characters in
a c file) I have searched thru the docs Myself and, though I may have
missed it, I did not see the information. I am using 23.3.

Thanks in advance.


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

* Re: Different options for different modes?
  2011-09-23 14:24 Different options for different modes? winkerbean
@ 2012-03-29  9:51 ` Philipp Haselwarter
       [not found] ` <mailman.53.1333014742.20052.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Philipp Haselwarter @ 2012-03-29  9:51 UTC (permalink / raw
  To: help-gnu-emacs

to set options for certain modes emacs uses `hooks', usually following
the naming scheme `foo-mode-hook' where "foo" is the mode in question.

Check out the section on hooks in the emacs info manual:

C-h i m Emacs m Hooks

a quick example could be
#+begin_src: elisp
(defun my-ruby-coding-style nil
  (setq indent-tabs-mode t))

(defun my-c-coding-style nil
  (setq indent-tabs-mode nil
        tab-width 4))

(add-hook 'c-mode-hook 'my-c-coding-style)
(add-hook 'ruby-mode-hook 'my-ruby-coding-style)
#+end_src

-- 
Philipp Haselwarter




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

* Re: Different options for different modes?
       [not found] ` <mailman.53.1333014742.20052.help-gnu-emacs@gnu.org>
@ 2012-03-29 13:00   ` rusi
  2012-04-04  0:59     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: rusi @ 2012-03-29 13:00 UTC (permalink / raw
  To: help-gnu-emacs

Stefan Monnier wrote:
> The general approach is to use something like
>
>    (add-hook 'MAJOR-MODE-hook
>              (lambda ()
>                (set (make-local-variable 'VAR) VAL)))

I wonder when this is used and when this:

(eval-after-load 'MAJOR_MODE (setq VAR VAL))


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

* Re: Different options for different modes?
  2012-03-29 13:00   ` rusi
@ 2012-04-04  0:59     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2012-04-04  0:59 UTC (permalink / raw
  To: help-gnu-emacs

>> (add-hook 'MAJOR-MODE-hook
>>           (lambda ()
>>             (set (make-local-variable 'VAR) VAL)))

> I wonder when this is used and when this:
> (eval-after-load 'MAJOR_MODE (setq VAR VAL))

Your code will be run once when loading the `MAJOR_MODE' package
(i.e. usually the first time `MAJOR_MODE' is used), whereas the code
I quoted is run every time `MAJOR-MODE' is enabled.

If you use Emacs for a single file at a time, the difference between the
two may be unnoticeable.  But if you do use several files in the same
Emacs session (which is the normal way to use Emacs), then the
difference is important.


        Stefan


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

end of thread, other threads:[~2012-04-04  0:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-23 14:24 Different options for different modes? winkerbean
2012-03-29  9:51 ` Philipp Haselwarter
     [not found] ` <mailman.53.1333014742.20052.help-gnu-emacs@gnu.org>
2012-03-29 13:00   ` rusi
2012-04-04  0:59     ` Stefan Monnier

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.