From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Eric M. Ludlam" Newsgroups: gmane.emacs.devel Subject: Re: How to make a mode dependent operation ? Date: Sat, 04 Dec 2010 15:54:04 -0500 Message-ID: <4CFAAA6C.80001@siege-engine.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291496296 23574 80.91.229.12 (4 Dec 2010 20:58:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Dec 2010 20:58:16 +0000 (UTC) Cc: "Emacs Dev \[emacs-devel\]" To: Fren Zeee Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 04 21:58:12 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POzBK-0007jT-DY for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 21:58:11 +0100 Original-Received: from localhost ([127.0.0.1]:46103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POzBJ-0005qj-Iq for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 15:58:09 -0500 Original-Received: from [140.186.70.92] (port=35526 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POz7V-0003ol-IJ for emacs-devel@gnu.org; Sat, 04 Dec 2010 15:54:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POz7T-0000n3-Pi for emacs-devel@gnu.org; Sat, 04 Dec 2010 15:54:12 -0500 Original-Received: from bird.interbax.net ([75.126.100.114]:47363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POz7T-0000mK-LF for emacs-devel@gnu.org; Sat, 04 Dec 2010 15:54:11 -0500 Original-Received: (qmail 22439 invoked from network); 4 Dec 2010 13:54:05 -0700 Original-Received: from static-71-184-83-10.bstnma.fios.verizon.net (HELO ?192.168.1.201?) (71.184.83.10) by interbax.net with SMTP; 4 Dec 2010 13:54:05 -0700 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.3a1pre) Gecko/20091222 Shredder/3.1a1pre In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Windows 98 (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133419 Archived-At: Hi, To create a mode-specific operation, or a function that has different behaviors based on the major-mode of a given buffer, you can use 'mode-local'. Mode-local is a part of Emacs 23.2, and you can use define-overloadable-function to create the default behavior. Then for each mode, use define-mode-local-override to create an implementation for that mode. If you are specifically looking into template insertion, there is SRecode which is just another template system like skeleton, tempo, etc. It is targeted at mode independent code generation, and has some templates for C, lisp, and Java already for basic function creation. Tools like autocomplete or yasnippet has a better UI if you want to insert random small bits of text. To turn on SRecode, use global-srecode-minor-mode. Eric On 12/04/2010 02:50 PM, Fren Zeee wrote: > Here is a simple newbie problem : > > In c-mode, I want to insert a skeleton of function as > > > () { > > > > } > > > and In lisp-mode, I want > > ( defun () > "" > > > ) > > > and similarly in scheme, java, python, haskell, pascal ... > > > What is the quick but maybe not the dirty way to do it ? > > > What is the PRO way to do it ? I have heard a little about the hooking > hooks :) > > > What is a hook and what is proper place of use ? Is it appropriate for > this kind of private customization ? > > > Franz > >