[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: |
Fri, 08 Feb 2008 08:57:52 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
NOTE: This mail was sent outside the group for some reason, so I am
(re)posting it here, so that other people can benefit. By the way, Peter
replied that this solved the problem he had with snippets in javascript-mode.
Peter,
there were indeed some flaws in that code. Should've checked with emacs -Q.
Well, I have trimmed my .emacs down to the following bare minimum, which
really works for me (my emacs version is "GNU Emacs 22.1.1 (i486-pc-linux-gnu,
X toolkit, Xaw3d scroll bars) of 2007-11-06 on terranova, modified by
Ubuntu"):
;;this is where my snippet.el and javascript.el reside
(add-to-list 'load-path "~/.emacs.d/nxml/related")
(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(require 'snippet)
;; Apparently the abbrev-table *should* be bound, for
;; snippet-with-abbrev-table not to blurb:
(define-abbrev-table 'javascript-mode-abbrev-table ())
;; Yup, here was a quote missing
(snippet-with-abbrev-table
'javascript-mode-abbrev-table
("for" . "for $${element} in $${sequence}:")
("im" . "import $$")
("if" . "if $${True}:")
("wh" . "while $${True}:"))
(add-hook 'javascript-mode-hook
(lambda ()
(abbrev-mode 1)
;; Here really should NOT be a quote:
(setq local-abbrev-table javascript-mode-abbrev-table)))
Perhaps something in python-mode sets the correct abbrev-table already. By the
way, what strange dialect of JavaScript is that ;) ?
- Show quoted text -
> On Feb 5, 2008 11:21 AM, Niels Giesen <niels.giesen@gmail.com> wrote:
>> "Peter Michaux" <petermichaux@gmail.com> writes:
>
>> > I'm new to Emacs and having trouble getting snippet.el working.
>> >
>> > http://www.kazmier.com/computer/snippet.el
>>
>> (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)))
>
> I tried the above. It threw errors at first because the last two
> instances of javascript-mode-abbrev-table seem to need quoting. When I
> quote those I still don't get the desired snippet behavior when I type
> "for" and then space. I tired many simpler combinations also that
> didn't involve the unless statement. No luck either. Does the above
> code really work for you?
>
> I can get snippets working with python mode.
>
> I have a python-snippets.el file with the following
>
> ; -------------------------------------------------
> (snippet-with-abbrev-table 'python-mode-abbrev-table
> ("for" . "for $${element} in $${sequence}:")
> ("im" . "import $$")
> ("if" . "if $${True}:")
> ("wh" . "while $${True}:")
> )
> (provide 'python-snippets)
> ; --------------------------------------------------
>
> and then in my .emacs file I have just the following because the
> python mode file defines the abbrev table
>
> ; -------------------------------------------------
> (add-hook 'python-mode-hook
> (lambda ()
> (abbrev-mode 1)
> (require 'snippet)
> (require 'python-snippets)
> )
> )
> ; -------------------------------------------------
>
> Any ideas why the JavaScript version doesn't work?
>
> Thanks,
> Peter
--
http://niels.kicks-ass.org