unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: boris@gnu.org, emacs-devel@gnu.org
Subject: Re: enriched-mode and switching major modes.
Date: Fri, 10 Sep 2004 21:14:36 -0500 (CDT)	[thread overview]
Message-ID: <200409110214.i8B2EaZ12276@raven.dms.auburn.edu> (raw)
In-Reply-To: <E1C5pOF-0007dn-7X@fencepost.gnu.org> (message from Richard Stallman on Fri, 10 Sep 2004 13:40:51 -0400)

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 <boris@gnu.org>
  ;; 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 <boris@gnu.org>
  ;; 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
============================================================

  reply	other threads:[~2004-09-11  2:14 UTC|newest]

Thread overview: 150+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-04 23:58 enriched-mode and switching major modes Luc Teirlinck
2004-09-05 17:25 ` Richard Stallman
2004-09-06  0:59   ` Luc Teirlinck
2004-09-06 16:42     ` Stefan
2004-09-06 16:53       ` Luc Teirlinck
2004-09-10 17:40     ` Richard Stallman
2004-09-11  2:14       ` Luc Teirlinck [this message]
2004-09-11 16:56         ` Stefan
2004-09-11 21:51           ` Luc Teirlinck
2004-09-11 22:55             ` Stefan
2004-09-12  1:46               ` Luc Teirlinck
2004-09-12 18:18                 ` Stefan
2004-09-12  2:50               ` Luc Teirlinck
2004-09-13  7:00               ` Richard Stallman
2004-09-12  9:10         ` Richard Stallman
2004-09-12 16:51           ` Luc Teirlinck
2004-09-12 17:08             ` Oliver Scholz
2004-09-12 18:36             ` Kim F. Storm
2004-09-12 20:01               ` Luc Teirlinck
2004-09-13  7:32                 ` Kim F. Storm
2004-09-13 23:03             ` Richard Stallman
2004-09-14  3:46               ` Luc Teirlinck
2004-09-14 12:26                 ` Stefan Monnier
2004-09-14 22:12                   ` Luc Teirlinck
2004-09-15  9:32                 ` Richard Stallman
2004-09-17  9:36                 ` Richard Stallman
2004-09-19 20:07                   ` Luc Teirlinck
2004-09-06  7:36   ` Oliver Scholz
2004-09-06 19:01     ` Alex Schroeder
2004-09-10 17:40       ` Richard Stallman
2004-09-10 19:30         ` Oliver Scholz
2004-09-13 23:04           ` Richard Stallman
2004-09-14 14:41             ` Oliver Scholz
2004-09-14 16:31               ` Oliver Scholz
2004-09-15  1:39               ` Luc Teirlinck
2004-09-15  1:47                 ` Luc Teirlinck
2004-09-15  8:06                 ` Oliver Scholz
2004-09-15 15:42               ` Richard Stallman
2004-09-16 13:20                 ` Kai Grossjohann
2004-09-17 23:22                   ` Richard Stallman
2004-09-16 17:04                 ` Oliver Scholz
2004-09-17  5:15                   ` Eli Zaretskii
2004-09-17 14:34                     ` Oliver Scholz
2004-09-17 20:43                       ` Kai Grossjohann
2004-09-17 22:05                         ` Kim F. Storm
2004-09-18 19:07                           ` Richard Stallman
2004-09-18 15:37                         ` Robert J. Chassell
2004-09-18 11:14                       ` Eli Zaretskii
2004-09-18 12:04                         ` David Kastrup
2004-09-18 13:32                           ` Eli Zaretskii
2004-09-18 13:46                             ` David Kastrup
2004-09-18 15:57                               ` Eli Zaretskii
2004-09-19 17:19                                 ` Kai Grossjohann
2004-09-18 22:55                           ` Richard Stallman
2004-09-18 17:08                         ` Oliver Scholz
2004-09-18 17:48                           ` Eli Zaretskii
2004-09-18 20:02                             ` Oliver Scholz
2004-09-18 21:25                               ` Eli Zaretskii
2004-09-18 21:54                                 ` Oliver Scholz
2004-09-20  0:06                                   ` Richard Stallman
2004-09-20 11:48                                     ` Oliver Scholz
2004-09-21 18:30                                       ` Richard Stallman
2004-09-21 19:08                                         ` Eli Zaretskii
2004-09-21 20:06                                           ` Stefan Monnier
2004-09-22  4:54                                             ` Eli Zaretskii
2004-09-22 18:20                                           ` Richard Stallman
2004-09-22 18:39                                             ` Eli Zaretskii
2004-09-23 16:44                                               ` Richard Stallman
2004-09-22 10:01                                         ` Oliver Scholz
2004-09-22 13:08                                           ` Stefan Monnier
2004-09-22 13:11                                           ` Stefan Monnier
2004-09-22 13:14                                             ` Oliver Scholz
2004-09-22 16:27                                               ` Stefan Monnier
2004-09-23  1:48                                               ` Luc Teirlinck
2004-09-23  9:29                                             ` Richard Stallman
2004-09-23  9:48                                               ` David Kastrup
2004-09-23 16:44                                                 ` Richard Stallman
2004-09-23 11:35                                               ` Stefan
2004-09-23 12:46                                                 ` David Kastrup
2004-09-23 12:59                                                 ` Oliver Scholz
2004-09-24 12:08                                                 ` Richard Stallman
2004-09-24 12:50                                                   ` Stefan
2004-09-25 15:34                                                     ` Richard Stallman
2004-09-24 10:59                                           ` Eli Zaretskii
2004-09-24 11:53                                             ` Oliver Scholz
2004-09-24 15:51                                               ` Oliver Scholz
2004-09-24 20:55                                                 ` Alex Schroeder
2004-09-24 21:11                                                   ` Oliver Scholz
2004-09-25 16:36                                                 ` Eli Zaretskii
2004-09-22 10:35                                         ` Oliver Scholz
2004-09-22 18:21                                           ` Richard Stallman
2004-09-20  0:05                               ` Richard Stallman
2004-09-18 22:11                             ` Kim F. Storm
2004-09-19  3:47                               ` Eli Zaretskii
2004-09-20  0:05                               ` Richard Stallman
2004-09-20 11:07                                 ` Oliver Scholz
2004-09-20 11:55                                   ` Kim F. Storm
2004-09-21 18:30                                   ` Richard Stallman
2004-09-22  7:44                                     ` Kim F. Storm
2004-09-22 18:14                                       ` Eli Zaretskii
2004-09-22 21:53                                         ` Kim F. Storm
2004-09-23  4:47                                           ` Eli Zaretskii
2004-09-23  7:13                                             ` Kim F. Storm
2004-09-22 18:20                                       ` Richard Stallman
2004-09-22 21:58                                         ` Kim F. Storm
2004-09-20 12:47                                 ` Kai Grossjohann
2004-09-17 15:08                   ` Robert J. Chassell
2004-09-18 17:34                     ` Oliver Scholz
2004-09-18 23:05                       ` Robert J. Chassell
2004-09-19 11:07                         ` Oliver Scholz
2004-09-19 11:24                           ` David Kastrup
2004-09-19 13:14                           ` Robert J. Chassell
2004-09-20  5:49                           ` Stefan
2004-09-20  6:17                             ` David Kastrup
2004-09-20  6:26                               ` Stefan
2004-09-20 11:00                             ` Oliver Scholz
2004-09-20 13:24                               ` Stefan Monnier
2004-09-20 14:17                                 ` Oliver Scholz
2004-09-20 14:55                                   ` Stefan Monnier
2004-09-20 19:18                                     ` David Kastrup
2004-09-20 19:49                                       ` Stefan Monnier
2004-09-20 19:37                                     ` Oliver Scholz
2004-09-20 20:04                                       ` Stefan Monnier
2004-09-21  9:07                                         ` Oliver Scholz
2004-09-21 14:43                                           ` Robert J. Chassell
2004-09-20 21:44                                   ` Robert J. Chassell
2004-09-17 23:22                   ` Richard Stallman
2004-09-18 16:57                     ` Oliver Scholz
2004-09-18 17:12                       ` Oliver Scholz
2004-09-20  0:05                       ` Richard Stallman
2004-09-20 11:35                         ` Oliver Scholz
2004-09-20 11:47                           ` Kim F. Storm
2004-09-20 13:27                             ` Oliver Scholz
2004-09-20 14:23                               ` Kim F. Storm
2004-09-20 19:35                                 ` Oliver Scholz
2004-09-20 19:35                               ` Oliver Scholz
2004-09-20 20:21                                 ` Kim F. Storm
2004-09-21  9:07                                   ` Oliver Scholz
2004-09-21 11:20                                     ` Kim F. Storm
2004-09-22  7:11                                   ` Richard Stallman
2004-09-21 18:30                             ` Richard Stallman
2004-09-21 20:31                               ` Miles Bader
2004-09-22  3:20                               ` James Clark
2004-09-23  9:30                                 ` Richard Stallman
2004-09-21  9:53                         ` Kai Grossjohann
2004-09-21 11:32                           ` Kim F. Storm
2004-09-21 18:53                           ` Eli Zaretskii
2004-09-21 20:34                             ` Miles Bader
2004-09-22  0:31                             ` David Kastrup
2004-09-22 14:00                           ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200409110214.i8B2EaZ12276@raven.dms.auburn.edu \
    --to=teirllm@dms.auburn.edu \
    --cc=boris@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).