From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.help Subject: Re: How do I initialize globalized minor mode only once? Date: Wed, 11 Jul 2012 18:57:08 +0400 Message-ID: <87r4sipcqj.fsf@yandex.ru> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342018658 7820 80.91.229.3 (11 Jul 2012 14:57:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 11 Jul 2012 14:57:38 +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 16:57:38 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 1SoyMB-0002I7-Kj for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jul 2012 16:57:35 +0200 Original-Received: from localhost ([::1]:35899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoyMA-0000aD-QH for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jul 2012 10:57:34 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoyM1-0000Zs-Pr for help-gnu-emacs@gnu.org; Wed, 11 Jul 2012 10:57:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoyM0-0007AA-0q for help-gnu-emacs@gnu.org; Wed, 11 Jul 2012 10:57:25 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:36545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoyLz-0007A1-Q4 for help-gnu-emacs@gnu.org; Wed, 11 Jul 2012 10:57:23 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SoyLw-0001t5-LJ for help-gnu-emacs@gnu.org; Wed, 11 Jul 2012 16:57:20 +0200 Original-Received: from 178.252.98.87 ([178.252.98.87]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jul 2012 16:57:20 +0200 Original-Received: from dgutov by 178.252.98.87 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jul 2012 16:57:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 178.252.98.87 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (windows-nt) Cancel-Lock: sha1:sB6FTtt8YmmB2Y5NjUO147guKkY= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:85803 Archived-At: Barry Margolin writes: > In article , >> >> 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? The global mode has a corresponding local minor mode which needs to be initialized in each buffer it applies to. That's the initialization I was referring to. See `define-globalized-minor-mode'. >> 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. There is no such function.