From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Niels Giesen Newsgroups: gmane.emacs.help Subject: Re: Trouble using snippet.el with abbrev tables Date: Tue, 05 Feb 2008 20:21:06 +0100 Organization: www.tudelft.nl Message-ID: <87fxw7yztp.fsf@gmail.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1202249154 9907 80.91.229.12 (5 Feb 2008 22:05:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Feb 2008 22:05:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 05 23:06:13 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JMVuZ-0002GF-Ma for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Feb 2008 23:05:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JMVnG-0002Sb-6v for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Feb 2008 16:57:30 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!xlned.com!feeder1.xlned.com!txtfeed2.tudelft.nl!tudelft.nl!binfeed2.tudelft.nl!news2.tudelft.nl!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:/lD7LqvgRQWTD7imn4JsvMZdkno= Original-X-Complaints-To: sysadmin@tudelft.nl Original-Lines: 85 Original-NNTP-Posting-Host: 248pc207.sshunet.nl (145.97.207.248) Original-NNTP-Posting-Date: Tue, 05 Feb 2008 20:19:00 +0100 Original-X-Trace: cdabf47a8b6a434c46a5d07655 Original-Xref: shelby.stanford.edu gnu.emacs.help:155852 X-Mailman-Approved-At: Tue, 05 Feb 2008 16:57:20 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:51233 Archived-At: "Peter Michaux" 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