all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Adding a hook to sql-mode?
@ 2008-12-09  0:58 Webb S.
  2008-12-09  2:14 ` Chetan
  0 siblings, 1 reply; 6+ messages in thread
From: Webb S. @ 2008-12-09  0:58 UTC (permalink / raw
  To: help-gnu-emacs

Sorry for the slightly tweaked repost, but I am hoping to fix this
before I forget about it...

If I open schema.sql I get funky indentation, where emacs changes my
tabs to a mix of spaces etc.  I can fix this by running the following
in the eval (alt-:) buffer once I have opened a sql file (say
"schema.sql"):

(define-key sql-mode-map (kbd "TAB") 'self-insert-command)
(define-key sql-mode-map (kbd "RET") 'newline-and-indent)
(setq-default default-tab-width 4)

How can I run this as a hook so it always works for sql mode?  I tried
the following to no avail:

(add-hook 'sql-mode-hook
        (lambda()
          (define-key sql-mode-map (kbd "TAB") 'self-insert-command)))

By "to no avail" I mean that when I open foo.sql, <tab> does its
normal weird behavior of lining up with the end of the first word,
inserting spaces in order to do this (yuck!).  Once I run the above
define-key commands from "eval" (alt-:), it behaves how I want, but I
can't get the hook to be installed (I think).

Thx!


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

* Re: Adding a hook to sql-mode?
  2008-12-09  0:58 Adding a hook to sql-mode? Webb S.
@ 2008-12-09  2:14 ` Chetan
  2008-12-09  5:40   ` Webb S.
  0 siblings, 1 reply; 6+ messages in thread
From: Chetan @ 2008-12-09  2:14 UTC (permalink / raw
  To: help-gnu-emacs

"Webb S." <webb.sprague@gmail.com> writes:

> Sorry for the slightly tweaked repost, but I am hoping to fix this
> before I forget about it...
>
> If I open schema.sql I get funky indentation, where emacs changes my
> tabs to a mix of spaces etc.  I can fix this by running the following
> in the eval (alt-:) buffer once I have opened a sql file (say
> "schema.sql"):
>
> (define-key sql-mode-map (kbd "TAB") 'self-insert-command)
> (define-key sql-mode-map (kbd "RET") 'newline-and-indent)
> (setq-default default-tab-width 4)
>
> How can I run this as a hook so it always works for sql mode?  I tried
> the following to no avail:
>
> (add-hook 'sql-mode-hook
>         (lambda()
>           (define-key sql-mode-map (kbd "TAB") 'self-insert-command)))
>
> By "to no avail" I mean that when I open foo.sql, <tab> does its
> normal weird behavior of lining up with the end of the first word,
> inserting spaces in order to do this (yuck!).  Once I run the above
> define-key commands from "eval" (alt-:), it behaves how I want, but I
> can't get the hook to be installed (I think).
>
> Thx!

Looks like what you are looking for is indent with hard tabs with tab
width of 4. The following in the mode hook will do this.

	 (setq indent-tabs-mode t
	       tab-width 4)

You don't need to redefine TAB key then.



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

* Re: Adding a hook to sql-mode?
  2008-12-09  2:14 ` Chetan
@ 2008-12-09  5:40   ` Webb S.
  2008-12-09  7:04     ` Chetan
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Webb S. @ 2008-12-09  5:40 UTC (permalink / raw
  To: help-gnu-emacs


> Looks like what you are looking for is indent with hard tabs with tab
> width of 4. The following in the mode hook will do this.
>
>          (setq indent-tabs-mode t
>                tab-width 4)
>
> You don't need to redefine TAB key then.

Could you show me how to write the add-hook for that?  I think that is
where my problem is, not in the command.  Yours is probably better,
but mine works if I eval it once the file is open.

Thx


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

* Re: Adding a hook to sql-mode?
  2008-12-09  5:40   ` Webb S.
@ 2008-12-09  7:04     ` Chetan
  2008-12-09 17:51     ` Ian Eure
       [not found]     ` <mailman.2343.1228845087.26697.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Chetan @ 2008-12-09  7:04 UTC (permalink / raw
  To: help-gnu-emacs

"Webb S." <webb.sprague@gmail.com> writes:

>> Looks like what you are looking for is indent with hard tabs with tab
>> width of 4. The following in the mode hook will do this.
>>
>>          (setq indent-tabs-mode t
>>                tab-width 4)
>>
>> You don't need to redefine TAB key then.
>
> Could you show me how to write the add-hook for that?  I think that is
> where my problem is, not in the command.  Yours is probably better,
> but mine works if I eval it once the file is open.
>
> Thx

If you are having difficulty with add-hook, setup file local
variables. M-x info will be your friend there.


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

* Re: Adding a hook to sql-mode?
  2008-12-09  5:40   ` Webb S.
  2008-12-09  7:04     ` Chetan
@ 2008-12-09 17:51     ` Ian Eure
       [not found]     ` <mailman.2343.1228845087.26697.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Ian Eure @ 2008-12-09 17:51 UTC (permalink / raw
  To: Webb S.; +Cc: help-gnu-emacs

On Dec 8, 2008, at 9:40 PM, Webb S. wrote:

>
>> Looks like what you are looking for is indent with hard tabs with tab
>> width of 4. The following in the mode hook will do this.
>>
>>          (setq indent-tabs-mode t
>>                tab-width 4)
>>
>> You don't need to redefine TAB key then.
>
> Could you show me how to write the add-hook for that?  I think that is
> where my problem is, not in the command.  Yours is probably better,
> but mine works if I eval it once the file is open.
>

(add-hook 'sql-mode-hook '(lambda () (setq indent-tabs-mode t tab- 
width 4)))

  - Ian




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

* Re: Adding a hook to sql-mode?
       [not found]     ` <mailman.2343.1228845087.26697.help-gnu-emacs@gnu.org>
@ 2008-12-12  3:47       ` Webb S.
  0 siblings, 0 replies; 6+ messages in thread
From: Webb S. @ 2008-12-12  3:47 UTC (permalink / raw
  To: help-gnu-emacs


>
> (add-hook 'sql-mode-hook '(lambda () (setq indent-tabs-mode t tab-
> width 4)))

As a final followup:  this works great to add the hook, but it didn't
get the simple tab inserting behavior I wanted (still lined up the
cursor with the end of the word above it) so I did the following:

(add-hook 'sql-mode-hook '(lambda () (define-key sql-mode-map (kbd
"TAB") 'self-insert-command)))

And it works now

Thanks to everyone!


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

end of thread, other threads:[~2008-12-12  3:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-09  0:58 Adding a hook to sql-mode? Webb S.
2008-12-09  2:14 ` Chetan
2008-12-09  5:40   ` Webb S.
2008-12-09  7:04     ` Chetan
2008-12-09 17:51     ` Ian Eure
     [not found]     ` <mailman.2343.1228845087.26697.help-gnu-emacs@gnu.org>
2008-12-12  3:47       ` Webb S.

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.