emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enriched-mode and switching major modes.


From: Luc Teirlinck
Subject: Re: enriched-mode and switching major modes.
Date: Sun, 5 Sep 2004 19:59:39 -0500 (CDT)

Richard Stallman wrote:

         `enriched-mode' sets
       buffer-local values for these variables, but when the major mode is
       set by `after-find-file', these variables are killed.

   It sounds like enriched-mode is called too early.
   What is the command that you give?

C-x C-f on a file called enriched.text.  But any time one switches
major modes in a buffer in Enriched mode, the same problems arise.

I now believe that Enriched mode should be temporarily disabled when
switching major modes and later re-enabled by post-command-hook.  That
not only resets all killed local variables, it also seems to be the
only way to correctly update `enriched-old-bindings', which is
necessary when switching major modes.  The following patch implements
this.  It should work OK even in case the user quits or an error
occurs.  I can install it if it looks OK.

===File ~/enriched.el-diff==================================
*** enriched.el 02 Jul 2004 21:39:16 -0500      1.4
--- enriched.el 05 Sep 2004 19:16:50 -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 <address@hidden>
  ;; 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 <address@hidden>
  ;; Keywords: wp, faces
***************
*** 155,160 ****
--- 155,164 ----
  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)
+ 
  ;;;
  ;;; 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)
--- 201,207 ----
         (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
--- 209,234 ----
           (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))
! 
! ;; 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))))
! 
! (defun enriched-after-change-major-mode ()
!   (when enriched-change-major-mode-flag (enriched-mode 1)))
! 
! (add-hook 'post-command-hook 'enriched-after-change-major-mode)
  
  ;;;
  ;;; Keybindings
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]