* Trouble using snippet.el with abbrev tables
@ 2008-02-05 1:09 Peter Michaux
0 siblings, 0 replies; 4+ messages in thread
From: Peter Michaux @ 2008-02-05 1:09 UTC (permalink / raw)
To: help-gnu-emacs
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}:"))
))
Not only does it not work but it seems horribly inefficient to define
a new abbrev table each time the JavaScript mode starts.
Any ideas? Does anyone have it working?
Thanks,
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble using snippet.el with abbrev tables
[not found] <mailman.6981.1202176026.18990.help-gnu-emacs@gnu.org>
@ 2008-02-05 19:21 ` Niels Giesen
2008-02-07 5:56 ` Peter Michaux
[not found] ` <mailman.7103.1202389882.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 4+ messages in thread
From: Niels Giesen @ 2008-02-05 19:21 UTC (permalink / raw)
To: help-gnu-emacs
"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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble using snippet.el with abbrev tables
2008-02-05 19:21 ` Trouble using snippet.el with abbrev tables Niels Giesen
@ 2008-02-07 5:56 ` Peter Michaux
[not found] ` <mailman.7103.1202389882.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Peter Michaux @ 2008-02-07 5:56 UTC (permalink / raw)
To: Niels Giesen; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Trouble using snippet.el with abbrev tables
[not found] ` <mailman.7103.1202389882.18990.help-gnu-emacs@gnu.org>
@ 2008-02-08 7:57 ` Niels Giesen
0 siblings, 0 replies; 4+ messages in thread
From: Niels Giesen @ 2008-02-08 7:57 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-02-08 7:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.6981.1202176026.18990.help-gnu-emacs@gnu.org>
2008-02-05 19:21 ` Trouble using snippet.el with abbrev tables Niels Giesen
2008-02-07 5:56 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).