help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble using snippet.el with abbrev tables


From: Niels Giesen
Subject: Re: Trouble using snippet.el with abbrev tables
Date: Tue, 05 Feb 2008 20:21:06 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

"Peter Michaux" <address@hidden> writes:

> Hi,
>
> I'm new to Emacs and having trouble getting snippet.el working.
>
> http://www.kazmier.com/computer/snippet.el
>
> The instruction in the file may be good for an Emacs expert but I'm
> still missing something.
>
> I've tried various combinations of the following configuration in my
> .emacs file with no luck.
>
> (autoload 'javascript-mode "javascript" nil t)
> (add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
>
> (load "snippet")
>
> (add-hook 'javascript-mode-hook
>           (lambda ()
>
>               ; someone suggested the following line but it seems redundant
>               (require 'javascript-mode)
>               (abbrev-mode 1)
>               (define-abbrev-table 'javascript-mode-abbrev-table ())
>               (snippet-with-abbrev-table 'javascript-mode-abbrev-table
>                 ("for" .  "for $${element} in $${sequence}:")
>                 ("im"  .  "import $$")
>                 ("if"  .  "if $${True}:")
>                 ("wh"  .  "while $${True}:"))
>
>             ))
>

(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(require 'snippet)

(add-hook 'javascript-mode-hook
          (lambda ()
            (abbrev-mode 1)
            (unless (boundp 'javascript-mode-abbrev-table)
              (define-abbrev-table 'javascript-mode-abbrev-table ())
              (snippet-with-abbrev-table
               javascript-mode-abbrev-table
               ("for" .  "for $${element} in $${sequence}:")
               ("im"  .  "import $$")
               ("if"  .  "if $${True}:")
               ("wh"  .  "while $${True}:")))
            (setq local-abbrev-table javascript-mode-abbrev-table)))

> Not only does it not work but it seems horribly inefficient to define
> a new abbrev table each time the JavaScript mode starts.
>
Probably it is inefficient indeed. The (unless (boundp ... stuff in the above
takes care of that.

Key here (to make it work) is to set local-abbrev-table (which becomes
buffer-local when set) to your snippetised one.

You can optionally put (require 'snippet) in your hook too, just before or
after (abbrev-mode 1). A (require ...) loads a file just once, so it does not
matter much to put it in the hook, plus it cuts down startup time if you put it
in the hook.  Or place an autoload like (autoload 'snippet-with-abbrev-table
"snippet") outside of the hook. Then if you define snippets for another
language, you do not have to require it in every other hook.

Actually I have struggled with the snippet code too myself, and your post
reminded me that this was something I still had to look into. So I am no expert
and might be missing something out, and telling you a wrong way to do something
good.  Anyway, this seems to work for me.

> Any ideas? Does anyone have it working?

Apparently, and loving it.
> Thanks,
> Peter
>
Good luck!
niels
>

-- 
http://niels.kicks-ass.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]