From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: How do I initialize globalized minor mode only once? Date: Wed, 11 Jul 2012 09:47:16 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1342014613 964 80.91.229.3 (11 Jul 2012 13:50:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 11 Jul 2012 13:50:13 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 11 15:50:13 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SoxIz-0005bS-3J for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jul 2012 15:50:13 +0200 Original-Received: from localhost ([::1]:54796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoxIy-0002Qk-6Q for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jul 2012 09:50:12 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-2.dfn.de!news.dfn.de!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Injection-Info: barmar.motzarella.org; posting-host="78fb7125a45724f15e21604c94a7d968"; logging-data="18145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EZwJb2bz8nEzSax5i/tpQ" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:GgQmz5ewF0+Bh6A8NjGe3cQaxeI= Original-Xref: usenet.stanford.edu gnu.emacs.help:193410 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85795 Archived-At: In article , Dmitry Gutov wrote: > Barry Margolin writes: > > > In article , > > Dmitry Gutov wrote: > > > >> Hi all, > >> > >> I have written a globalized minor mode which has a relatively costly > >> initialization (external process call), which I need to do when the mode > >> is enabled. > >> > >> But the turn-on function is getting called twice for each new opened > >> buffer, once in default major mode, and once in the final major mode. > >> > >> What's the best way to turn on the minor mode only once? > >> Currently I'm comparing major-mode value to the default value, but > >> that's probably not the best solution, since the minor mode in question > >> can apply to some fundamental-mode (or other default mode) buffers, too. > > > > Why not just set a variable saying whether you've done the > > initialization: > > > > (defvar *my-mode-initialized* nil) > > ... > > > > (if (not *my-mode-initialized*) > > (progn > > ... > > (setq *my-mode-initialized* t))) > > My first reaction was "because major mode change kills all local variables", > but that's not exactly true - with enough sprinkling of 'permanent-local > and 'permanent-local-hook properties, this might work. If this is a global minor mode, why would you use a local variable? > > But what if the user tries to turn off and on the minor mode, or the > global mode, or both? I'd want the initialization performed in these > cases. When or where would I set the variable to nil? In the turn-off function. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***