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: Fri, 10 Sep 2004 21:14:36 -0500 (CDT) Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <200409110214.i8B2EaZ12276@raven.dms.auburn.edu> References: <200409042358.i84Nwjt19152@raven.dms.auburn.edu> <200409060059.i860xdo20431@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1094868957 24441 80.91.224.253 (11 Sep 2004 02:15:57 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 11 Sep 2004 02:15:57 +0000 (UTC) Cc: boris@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 11 04:15:47 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 1C5xQZ-00052j-00 for ; Sat, 11 Sep 2004 04:15:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C5xVx-000870-VL for ged-emacs-devel@m.gmane.org; Fri, 10 Sep 2004 22:21:21 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C5xVs-00086v-4G for emacs-devel@gnu.org; Fri, 10 Sep 2004 22:21:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C5xVr-00086h-GC for emacs-devel@gnu.org; Fri, 10 Sep 2004 22:21:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C5xVr-00086b-BM for emacs-devel@gnu.org; Fri, 10 Sep 2004 22:21:15 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C5xPv-0000RI-EP; Fri, 10 Sep 2004 22:15:07 -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 i8B2EuuE001190; Fri, 10 Sep 2004 21:14:59 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id i8B2EaZ12276; Fri, 10 Sep 2004 21:14:36 -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 Fri, 10 Sep 2004 13:40:51 -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:26997 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:26997 Richard Stallman wrote: I think you are on the right track, except for the detail that post-command-hook does the job too late. enriched-mode ought to get reenabled as soon as the new major mode is set up; it should not wait until the command finishes. One way to make this work is by adding a feature to run-mode-hooks. enriched-mode's change-major-mode-hook could then do someting to tell run-mode-hooks to reenable enriched-mode. Want to try that? My previous patch somehow forgot that the command could switch buffers. The new patch below fixes that. I believe that we still have to use post-command-hook to avoid possibly very annoying and confusing inconsistencies that could otherwise arise in the case of error or quit (as well as for major modes that do not use `run-mode-hooks'). With the new function `with-local-quit', there can actually be several quits and hence several inconsistencies as a result of executing a single command. The patches below take all of this into account. Note that `post-command-hook' will only have some non-trivial work to do in case of really exceptional situations, like errors or quits at the wrong moment. In normal circumstances, all it does is a dolist over an empty list. Of course, if we would make Enriched mode into a major mode, then none of this would be necessary. ===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) ============================================================ ===File ~/enriched.el-diff================================== *** enriched.el 02 Jul 2004 21:39:16 -0500 1.4 --- enriched.el 10 Sep 2004 20:25:21 -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,170 ---- The value is a list of \(VAR VALUE VAR VALUE...).") (make-variable-buffer-local 'enriched-old-bindings) + ;; A non-nil value indicates that Enriched mode was temporarily disabled + ;; by `enriched-before-change-major-mode' while switching major modes. + (defvar enriched-change-major-mode-flag nil) + (make-local-variable 'enriched-change-major-mode-flag) + (put 'enriched-change-major-mode-flag 'permanent-local t) + + ;; List of buffers in which Enriched mode was disabled by + ;; `enriched-before-change-major-mode' and was not properly re-enabled. + ;; `post-command-hook' checks this. + (defvar enriched-marked-buffers nil) + ;;; ;;; Define the mode ;;; *************** *** 197,203 **** (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) --- 207,213 ---- (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 (if enriched-change-major-mode-flag 'never nil)) (let ((sticky (plist-get default-text-properties 'front-sticky)) (p enriched-par-props)) (dolist (x p) *************** *** 205,211 **** (if sticky (setq default-text-properties (plist-put default-text-properties ! 'front-sticky sticky))))))) ;;; ;;; Keybindings --- 215,254 ---- (if sticky (setq default-text-properties (plist-put default-text-properties ! 'front-sticky sticky)))) ! (add-hook 'change-major-mode-hook ! 'enriched-before-change-major-mode nil t))) ! (setq enriched-change-major-mode-flag nil) ! (setq enriched-marked-buffers ! (delete (current-buffer) enriched-marked-buffers))) ! ! ;; Enriched mode sets several local variables that are killed when ! ;; changing major modes. They need to be reset. Also, when the major ! ;; mode changes, `enriched-old-bindings' needs to be correctly ! ;; updated. Therefore, we disable Enriched mode before changing the ! ;; major mode and enable it back afterward. ! (defun enriched-before-change-major-mode () ! (when enriched-mode ! (let ((inhibit-quit t)) ! (enriched-mode 0) ! (setq enriched-change-major-mode-flag t) ! (add-to-list 'enriched-marked-buffers (current-buffer))))) ! ! (defun enriched-after-change-major-mode () ! (when enriched-change-major-mode-flag (enriched-mode 1))) ! ! (add-hook 'after-change-major-mode-hook 'enriched-after-change-major-mode) ! ! ;; Have `post-command-hook' check for buffers left in an inconsistent ! ;; state as a result of an error, quit or "local quit" (that is, by ! ;; using `with-local-quit'). ! (defun enriched-check-mode-change-buffers () ! (dolist (buf enriched-marked-buffers) ! (with-current-buffer buf ! (when enriched-change-major-mode-flag (enriched-mode 1)))) ! (setq enriched-marked-buffers nil)) ! ! (add-hook 'post-command-hook 'enriched-check-mode-change-buffers) ;;; ;;; Keybindings ============================================================