all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Niels Giesen <niels.giesen@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Trouble using snippet.el with abbrev tables
Date: Tue, 05 Feb 2008 20:21:06 +0100	[thread overview]
Message-ID: <87fxw7yztp.fsf@gmail.com> (raw)
In-Reply-To: mailman.6981.1202176026.18990.help-gnu-emacs@gnu.org

"Peter Michaux" <petermichaux@gmail.com> 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	other threads:[~2008-02-05 19:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6981.1202176026.18990.help-gnu-emacs@gnu.org>
2008-02-05 19:21 ` Niels Giesen [this message]
2008-02-07  5:56   ` Trouble using snippet.el with abbrev tables Peter Michaux
     [not found]   ` <mailman.7103.1202389882.18990.help-gnu-emacs@gnu.org>
2008-02-08  7:57     ` Niels Giesen
2008-02-05  1:09 Peter Michaux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fxw7yztp.fsf@gmail.com \
    --to=niels.giesen@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.