From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: enriched-mode and switching major modes. Date: Mon, 13 Sep 2004 22:46:28 -0500 (CDT) Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <200409140346.i8E3kSk19152@raven.dms.auburn.edu> References: <200409042358.i84Nwjt19152@raven.dms.auburn.edu> <200409060059.i860xdo20431@raven.dms.auburn.edu> <200409110214.i8B2EaZ12276@raven.dms.auburn.edu> <200409121651.i8CGpAE14303@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1095133657 17664 80.91.229.6 (14 Sep 2004 03:47:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Sep 2004 03:47:37 +0000 (UTC) Cc: boris@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 14 05:47:24 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C74Hs-0001ez-00 for ; Tue, 14 Sep 2004 05:47:24 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C74NQ-0004Rf-Aa for ged-emacs-devel@m.gmane.org; Mon, 13 Sep 2004 23:53:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C74NK-0004RZ-7u for emacs-devel@gnu.org; Mon, 13 Sep 2004 23:53:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C74NJ-0004RM-D6 for emacs-devel@gnu.org; Mon, 13 Sep 2004 23:53:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C74NJ-0004RJ-B1 for emacs-devel@gnu.org; Mon, 13 Sep 2004 23:53:01 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C74HY-0005cH-O2; Mon, 13 Sep 2004 23:47:05 -0400 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i8E3kwuE017691; Mon, 13 Sep 2004 22:46:58 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id i8E3kSk19152; Mon, 13 Sep 2004 22:46:28 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: rms@gnu.org In-reply-to: (message from Richard Stallman on Mon, 13 Sep 2004 19:03:34 -0400) 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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:27099 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:27099 Richard Stallman wrote: Even if `kill-all-local-variables' does not kill these variables, the major mode can override them. In the case of `indent-line-function', most modes that are usually combined with Enriched mode will. Maybe that one shouldn't be set by Enriched mode. I think the motive for setting it was to make it easy to preserve the left-margin indent of a paragraph. Without this particular setting, how easy is it to do that? It would not properly update `enriched-old-bindings'. Also, while it is unlikely that a major mode would try to override `buffer-display-table' or `default-text-properties', the fact remains that if `enriched-mode' continues to grow, the danger of one of its variables being overridden by the major mode increases. The following improved version of my original patch avoids these two problems. The improvements are that it is a lot simpler and no longer relies on post-command-hook. I noticed though that fundamental-mode needs to be treated specially, since it does not run `run-mode-hooks'. I guess that if any other major mode does not run `run-mode-hooks', then this is a bug that needs to be fixed. The patch to subr.el is unchanged. ===File ~/enriched.el-new-diff============================== *** enriched.el 02 Jul 2004 21:39:16 -0500 1.4 --- enriched.el 13 Sep 2004 21:34:52 -0500 *************** *** 1,6 **** ;;; enriched.el --- read and save files in text/enriched format ! ;; Copyright (c) 1994, 1995, 1996, 2002 Free Software Foundation, Inc. ;; Author: Boris Goldowsky ;; Keywords: wp, faces --- 1,6 ---- ;;; enriched.el --- read and save files in text/enriched format ! ;; Copyright (c) 1994, 1995, 1996, 2002, 2004 Free Software Foundation, Inc. ;; Author: Boris Goldowsky ;; Keywords: wp, faces *************** *** 141,147 **** ;;; Internal variables - (defcustom enriched-mode-hook nil "Hook run after entering/leaving Enriched mode. If you set variables in this hook, you should arrange for them to be restored --- 141,146 ---- *************** *** 155,160 **** --- 154,164 ---- The value is a list of \(VAR VALUE VAR VALUE...).") (make-variable-buffer-local 'enriched-old-bindings) + ;; Technical internal variable. Bound to t if `enriched-mode' is + ;; being rerun by a major mode to allow it to restore buffer-local + ;; variables and to correctly adjust `enriched-old-bindings'. + (defvar rerun-flag nil) + ;;; ;;; Define the mode ;;; *************** *** 181,203 **** (while enriched-old-bindings (set (pop enriched-old-bindings) (pop enriched-old-bindings)))) ! ((memq 'text/enriched buffer-file-format) ;; Mode already on; do nothing. nil) (t ; Turn mode on ! (push 'text/enriched buffer-file-format) ;; Save old variable values before we change them. ;; These will be restored if we exit Enriched mode. (setq enriched-old-bindings (list 'buffer-display-table buffer-display-table - 'indent-line-function indent-line-function 'default-text-properties default-text-properties)) - (make-local-variable 'indent-line-function) (make-local-variable 'default-text-properties) ! (setq indent-line-function 'indent-to-left-margin ;WHY?? -sm ! buffer-display-table enriched-display-table) ! (use-hard-newlines 1 nil) (let ((sticky (plist-get default-text-properties 'front-sticky)) (p enriched-par-props)) (dolist (x p) --- 185,205 ---- (while enriched-old-bindings (set (pop enriched-old-bindings) (pop enriched-old-bindings)))) ! ((and (memq 'text/enriched buffer-file-format) ! (not rerun-flag)) ;; Mode already on; do nothing. nil) (t ; Turn mode on ! (add-to-list 'buffer-file-format 'text/enriched) ;; Save old variable values before we change them. ;; These will be restored if we exit Enriched mode. (setq enriched-old-bindings (list 'buffer-display-table buffer-display-table 'default-text-properties default-text-properties)) (make-local-variable 'default-text-properties) ! (setq buffer-display-table enriched-display-table) ! (use-hard-newlines 1 (if rerun-flag 'never nil)) (let ((sticky (plist-get default-text-properties 'front-sticky)) (p enriched-par-props)) (dolist (x p) *************** *** 207,212 **** --- 209,228 ---- (plist-put default-text-properties 'front-sticky sticky))))))) + (defun enriched-before-change-major-mode () + (when enriched-mode + (while enriched-old-bindings + (set (pop enriched-old-bindings) (pop enriched-old-bindings))))) + + (add-hook 'change-major-mode-hook 'enriched-before-change-major-mode) + + (defun enriched-after-change-major-mode () + (when enriched-mode + (let ((rerun-flag t)) + (enriched-mode 1)))) + + (add-hook 'after-change-major-mode-hook 'enriched-after-change-major-mode) + ;;; ;;; Keybindings ;;; ============================================================ ===File ~/simple.el-diff==================================== *** simple.el 12 Sep 2004 15:43:59 -0500 1.660 --- simple.el 13 Sep 2004 22:16:08 -0500 *************** *** 282,288 **** "Major mode not specialized for anything in particular. Other major modes are defined by comparison with this one." (interactive) ! (kill-all-local-variables)) ;; Making and deleting lines. --- 282,289 ---- "Major mode not specialized for anything in particular. Other major modes are defined by comparison with this one." (interactive) ! (kill-all-local-variables) ! (run-hooks 'after-change-major-mode-hook)) ;; Making and deleting lines. ============================================================ ===File ~/subr.el-diff====================================== *** subr.el 08 Sep 2004 11:29:29 -0500 1.407 --- subr.el 10 Sep 2004 14:39:21 -0500 *************** *** 1937,1942 **** --- 1937,1946 ---- (make-variable-buffer-local 'delayed-mode-hooks) (put 'delay-mode-hooks 'permanent-local t) + (defvar after-change-major-mode-hook nil + "Mode independent hook run after changing major modes. + This is run just before the mode dependent hooks.") + (defun run-mode-hooks (&rest hooks) "Run mode hooks `delayed-mode-hooks' and HOOKS, or delay HOOKS. Execution is delayed if `delay-mode-hooks' is non-nil. *************** *** 1948,1953 **** --- 1952,1958 ---- ;; Normal case, just run the hook as before plus any delayed hooks. (setq hooks (nconc (nreverse delayed-mode-hooks) hooks)) (setq delayed-mode-hooks nil) + (run-hooks 'after-change-major-mode-hook) (apply 'run-hooks hooks))) (defmacro delay-mode-hooks (&rest body) ============================================================