From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: yary Newsgroups: gmane.emacs.bugs Subject: bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode Date: Sat, 19 Oct 2013 20:22:33 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1382228646 24647 80.91.229.3 (20 Oct 2013 00:24:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Oct 2013 00:24:06 +0000 (UTC) To: 15659@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 20 02:24:11 2013 Return-path: Envelope-to: geb-bug-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 1VXgoU-0005pl-0m for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Oct 2013 02:24:10 +0200 Original-Received: from localhost ([::1]:34763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgoT-0005oM-Kh for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 Oct 2013 20:24:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgoP-0005oH-Cp for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:24:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXgoN-0001AP-Sx for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:24:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgoN-0001AL-P7 for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:24:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VXgoN-0005l4-6P for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:24:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: yary Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Oct 2013 00:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15659 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.138222859122055 (code B ref -1); Sun, 20 Oct 2013 00:24:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Oct 2013 00:23:11 +0000 Original-Received: from localhost ([127.0.0.1]:58383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VXgnW-0005je-5p for submit@debbugs.gnu.org; Sat, 19 Oct 2013 20:23:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49034) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VXgnQ-0005iz-SD for submit@debbugs.gnu.org; Sat, 19 Oct 2013 20:23:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXgnK-00010C-5c for submit@debbugs.gnu.org; Sat, 19 Oct 2013 20:22:59 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:56718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgnK-000106-1V for submit@debbugs.gnu.org; Sat, 19 Oct 2013 20:22:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgnI-0005Ac-IL for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:22:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXgnG-0000zd-J0 for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:22:56 -0400 Original-Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:41278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXgnG-0000zY-Bw for bug-gnu-emacs@gnu.org; Sat, 19 Oct 2013 20:22:54 -0400 Original-Received: by mail-wg0-f46.google.com with SMTP id m15so5089316wgh.1 for ; Sat, 19 Oct 2013 17:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=h3A75cXs7UKnmeJFyQbM4kr7bqV0uAIyMIPBVB1Z2Bk=; b=VjtjDFE+6jWN8JHAQKGl+wA3Ejc/WseU+efHz36R029p4cdyFPzlpw9WGMTcFsv983 u9xCs7YUVWw6ZA8SWl/bulEkzLvjAbjWFH/VC24u/PurLWFTwQhNwoaPj/pKrzoVBgWq bxNCe7v5PC+iJGHQH8sbhcTxu7OTjtEoJl/RHNQExpfHx/sGUSGFSp5+X3dWMtBfrPM/ 3gkNwC5PIU2m3FAJk6ewE5ZZSeKOfYsvy6tRR9Ippa9HqkuqXXnV64RWgMTWv7m+zzUu 3PsafJlGtUbfGsVbtGXerygJjFVWAqbrwTb0zqiocfdGToWePYXX2fM3KtJP52B8fFMw njbw== X-Received: by 10.194.222.2 with SMTP id qi2mr8128290wjc.14.1382228573470; Sat, 19 Oct 2013 17:22:53 -0700 (PDT) Original-Received: by 10.194.83.72 with HTTP; Sat, 19 Oct 2013 17:22:33 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:79410 Archived-At: There are times when I wish to set a minor-mode permanently for a buffer, even through major-mode changes. They are display-related minor-modes, such as buffer-face-mode or text-scale-mode. Ideally I'd like a simple way to preserve a minor-mode between major-mode changes. I started discussing this in Bug #15577, which is about dir-locals, but am moving it here as this is a separate issue. Also bug #15396 "permanent-local truncate-lines" is related, Stefan sets a display-related local variable and would like it preserved across mode changes (or in this case, revert-buffer). Yet setting `permanent-local' on the `truncate-lines' variable does not protect it: `toggle-truncate-lines' behaves like a minor mode. A function could take a minor-mode to preserve, and then either set up hooks needed to re-enable it after a major-mode change, or prevent `kill-all-local-variables' from disabling it in the first place. Or perhaps marking the minor-mode's function-symbol itself as `permanent-local' could protect it, along with all its buffer-locals. I have a personal workaround which works for modes I use posted at http://stackoverflow.com/a/19439236/379333 - though it isn't fully generalized and has other flaws. It checks if specified minor-modes are active during `change-major-mode-hook', and if so, then tries to figure out which variables they use, and then restores those variables and minor modes in the `after-change-major-mode-hook' Answering a question from bug #15577 about this issue: >> a. Get all of that mode's customizable buffer-locals. > >Not sure what that is. The modes I wanted to preserve have buffer-locals for the face, and for the size adjustment. It's not enough to just re-enable the modes, we have to know which buffer-locals the mode reads. >> Ideally the minor-mode, or emacs core, would provide a function for >> that purpose. > >It's probably not possible (not reliably at least) with the way minor >modes are defined currently. Tho depending on what you mean it might be >a non-issue. What I meant was, since any proposed minor-mode-preserving mechanism needs to know what buffer-local variables also would need to be set `permanent-local', then "Ideally the minor-mode, or emacs core, would provide a function" listing those variables. So for example, the `define-minor-mode' macro might get a `:local-variables' keyword allowing the author to declare that mode's buffer-locals, along with their documentation and defaults. Would not be required in general, but would make it easier for anything that wants to manipulate minor modes. >> b. Mark those variables as permanent-local > >There's no such thing, currently (we instead have to use a hack with >change-major-mode-hook, along the lines of what you did). Must be a mis-communication here. The docs to `kill-all-local-variables' say: As a special exception, local variables whose names have a non-nil `permanent-local' property are not eliminated by this function. I just tried (put 'foo 'permanent-local 't) and `foo' survived `kill-all-local-variables' and several mode changes. So we do have the `permanent-local' property for keeping local variables around. >But there are some issues: >- we have to find out which buffer-local minor-modes are enabled, which > presumes we have some kind of list of minor-modes. We can probably > use minor-mode-list for that, tho. Searching minor-mode-list would work, as would checking that the symbol "name-of-minor-mide' is buffer-local and has a non-nil value. >- some minor modes are mode-specific; e.g. it doesn't make much sense to > preserve reftex-mode when switching from latex-mode to haskell-mode. This sounds like another mis-communication- proposal is to let a user (or by extension a minor-mode-author) to easily mark a minor-mode as "to-be-preserved." As another example, I do not want flymake still on when switching into css-mode. It's not up to this method to decide which minor-modes to preserve; it is up to the user. -y