unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, mmaug@yahoo.com,
	Lute.Kamstra.lists@xs4all.nl, dominik@science.uva.nl
Subject: Re: org-mode and mode hooks.
Date: Sun, 29 May 2005 20:43:39 -0500 (CDT)	[thread overview]
Message-ID: <200505300143.j4U1hdj13485@raven.dms.auburn.edu> (raw)
In-Reply-To: <E1DcMX1-0006yW-Tp@fencepost.gnu.org> (message from Richard Stallman on Sun, 29 May 2005 08:04:39 -0400)

Here is still another patch to easy-mmode.  It gets rid of the new
MODE-stored-mode variable, replacing it with the condition that dis-
and re-enabling MODE should adapt MODE reliably to the current major
mode.  That means that one way or the other, we have to take care of
Font Lock, which currently does not satisfy this condition.  Either we
make it satisfy the condition, or we still need a
font-lock-mode-stored-hook and an associated error message.

Note that even after this patch, there is one potentially troublesome
case left.  It concerns the case of a major mode that gets enabled by
a timer or process for a non-file visiting buffer.  (Even in this case
it is only likely to occur for major modes that do not follow the new
conventions.)  It is easy to get rid of this remaining problem.
However, it would require that not only the final check by
find-file-hook or after-command-hook, but also the check by
after-change-major-mode-hook, disables the mode if it already is
enabled and then re-enables it.  The patch below will sometimes, but
only in a _very_ small minority of the cases, _unnecessarily_ disable
and re-enable the mode.  To get rid of the remaining problem, we would
have to do such an unnecessary procedure nearly every time and
occasionally we would disable and re-enable unnecessarily more than
once.  In practice, the remaining case probably only affects
autoreverting of non-file buffers, so it means that each time we
autorevert an additional non-file type, we would need to check that
its usual major mode and its parent modes adhere to the new major mode
conventions and do not cause trouble in some other freakish way.  Again,
if we are willing to pay a price in efficiency, getting rid of the
remaining (rare) problem is easy.

===File ~/easy-mmode-diff===================================
*** easy-mmode.el	22 May 2005 16:50:33 -0500	1.63
--- easy-mmode.el	29 May 2005 17:52:33 -0500	
***************
*** 271,283 ****
  TURN-ON is a function that will be called with no args in every buffer
    and that should try to turn MODE on if applicable for that buffer.
  KEYS is a list of CL-style keyword arguments:
! :group to specify the custom group."
    (let* ((global-mode-name (symbol-name global-mode))
  	 (pretty-name (easy-mmode-pretty-mode-name mode))
  	 (pretty-global-name (easy-mmode-pretty-mode-name global-mode))
  	 (group nil)
  	 (extra-args nil)
  	 (buffers (intern (concat global-mode-name "-buffers")))
  	 (cmmh (intern (concat global-mode-name "-cmmh"))))
  
      ;; Check keys.
--- 271,291 ----
  TURN-ON is a function that will be called with no args in every buffer
    and that should try to turn MODE on if applicable for that buffer.
  KEYS is a list of CL-style keyword arguments:
! :group to specify the custom group.
! 
! If MODE's set-up depends on the major mode in effect when it was
! enabled, then disabling and reenabling MODE should make MODE work
! correctly with the current major mode.  This is important to
! prevent problems with derived modes, that is, major modes that
! call another major mode in their body."
! 
    (let* ((global-mode-name (symbol-name global-mode))
  	 (pretty-name (easy-mmode-pretty-mode-name mode))
  	 (pretty-global-name (easy-mmode-pretty-mode-name global-mode))
  	 (group nil)
  	 (extra-args nil)
  	 (buffers (intern (concat global-mode-name "-buffers")))
+ 	 (buffers-check (intern (concat global-mode-name "-check-buffers")))
  	 (cmmh (intern (concat global-mode-name "-cmmh"))))
  
      ;; Check keys.
***************
*** 307,314 ****
--- 315,324 ----
  	 (if ,global-mode
  	     (progn
  	       (add-hook 'after-change-major-mode-hook ',buffers)
+ 	       (add-hook 'find-file-hook ',buffers-check)
  	       (add-hook 'change-major-mode-hook ',cmmh))
  	   (remove-hook 'after-change-major-mode-hook ',buffers)
+ 	   (remove-hook 'find-file-hook ',buffers-check)
  	   (remove-hook 'change-major-mode-hook ',cmmh))
  
  	 ;; Go through existing buffers.
***************
*** 325,341 ****
  
         ;; The function that calls TURN-ON in each buffer.
         (defun ,buffers ()
! 	 (remove-hook 'post-command-hook ',buffers)
  	 (while ,buffers
  	   (let ((buf (pop ,buffers)))
  	     (when (buffer-live-p buf)
! 	       (with-current-buffer buf (,turn-on))))))
!        (put ',buffers 'definition-name ',global-mode)
  
         ;; The function that catches kill-all-local-variables.
         (defun ,cmmh ()
  	 (add-to-list ',buffers (current-buffer))
! 	 (add-hook 'post-command-hook ',buffers))
         (put ',cmmh 'definition-name ',global-mode))))
  
  ;;;
--- 335,361 ----
  
         ;; The function that calls TURN-ON in each buffer.
         (defun ,buffers ()
! 	 (dolist (buf ,buffers)
! 	   (when (buffer-live-p buf)
! 	     (with-current-buffer buf
! 	       (unless ,mode
! 		 (,turn-on))))))
!        (put ',buffers 'definition-name ',global-mode)
! 
!        (defun ,buffers-check ()
! 	 (remove-hook 'post-command-hook ',buffers-check)
  	 (while ,buffers
  	   (let ((buf (pop ,buffers)))
  	     (when (buffer-live-p buf)
! 	       (with-current-buffer buf
! 		 (when ,mode (,mode -1))
! 		 (,turn-on))))))
!        (put ',buffers-check 'definition-name ',global-mode)
  
         ;; The function that catches kill-all-local-variables.
         (defun ,cmmh ()
  	 (add-to-list ',buffers (current-buffer))
! 	 (add-hook 'post-command-hook ',buffers-check))
         (put ',cmmh 'definition-name ',global-mode))))
  
  ;;;
============================================================

  parent reply	other threads:[~2005-05-30  1:43 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-25 13:31 org-mode and mode hooks Lute Kamstra
2005-05-25 14:45 ` Stefan Monnier
2005-05-25 15:20   ` Carsten Dominik
2005-05-25 15:44   ` Lute Kamstra
2005-05-25 16:36     ` Luc Teirlinck
2005-05-25 17:01       ` Lute Kamstra
2005-05-25 17:12         ` Luc Teirlinck
2005-05-25 17:28           ` Lute Kamstra
2005-05-25 17:45             ` Luc Teirlinck
2005-05-25 16:24   ` Luc Teirlinck
2005-05-26  6:00     ` Richard Stallman
2005-05-26 10:31       ` Lute Kamstra
2005-05-26 17:31         ` Lute Kamstra
2005-05-27 14:18           ` Richard Stallman
2005-06-27  8:25             ` Lute Kamstra
2005-06-28  4:16               ` Richard M. Stallman
2005-05-27  3:39         ` Richard Stallman
2005-05-27  8:07           ` Juri Linkov
2005-06-27  8:28             ` Lute Kamstra
2005-05-25 17:30   ` Luc Teirlinck
2005-05-25 21:35   ` Luc Teirlinck
2005-05-25 22:15     ` Stefan Monnier
2005-05-26  3:59       ` Luc Teirlinck
2005-05-26 14:08         ` Stefan Monnier
2005-05-26 15:01           ` Luc Teirlinck
2005-05-26 17:04             ` Stefan Monnier
2005-05-27 17:17               ` Luc Teirlinck
2005-05-27 17:27                 ` Luc Teirlinck
2005-05-28 11:53                 ` Richard Stallman
2005-05-29  1:57                   ` Luc Teirlinck
2005-05-29 12:04                     ` Richard Stallman
2005-05-29 23:54                       ` Luc Teirlinck
2005-05-31  4:18                         ` Richard Stallman
2005-05-31 15:44                           ` Luc Teirlinck
2005-05-31 19:08                             ` Stefan Monnier
2005-06-01  3:50                               ` Luc Teirlinck
2005-06-01 17:22                               ` Richard Stallman
2005-06-01 19:11                                 ` Luc Teirlinck
2005-06-01 21:21                                   ` Stefan Monnier
2005-06-01 22:42                                     ` Luc Teirlinck
2005-06-01 22:55                                       ` Stefan Monnier
2005-06-01 23:26                                         ` Luc Teirlinck
2005-06-01 23:43                                           ` Stefan Monnier
2005-06-01 23:55                                             ` Luc Teirlinck
2005-06-01 23:57                                             ` Luc Teirlinck
2005-06-01 23:58                                             ` David Kastrup
2005-06-02  0:15                                             ` Luc Teirlinck
2005-06-01 23:49                                         ` Luc Teirlinck
2005-06-03  8:01                                           ` Richard Stallman
2005-06-03 14:59                                             ` Luc Teirlinck
2005-06-03 15:05                                             ` Luc Teirlinck
2005-06-04 10:16                                               ` Richard Stallman
2005-06-04 14:54                                                 ` Luc Teirlinck
2005-06-04 16:33                                                   ` Stefan Monnier
2005-06-04 17:48                                                     ` Luc Teirlinck
2005-06-05  0:36                                                       ` David Kastrup
2005-06-05  9:47                                                   ` Richard Stallman
2005-06-07  0:23                                                     ` Luc Teirlinck
2005-06-04 15:17                                                 ` Luc Teirlinck
2005-06-05  9:47                                                   ` Richard Stallman
2005-06-06 23:28                                                     ` Luc Teirlinck
2005-06-07 18:15                                                       ` Stefan Monnier
2005-06-07 19:08                                                         ` Luc Teirlinck
2005-06-07 22:10                                                           ` Stefan Monnier
2005-06-08  1:36                                                             ` Luc Teirlinck
2005-06-08 16:15                                                               ` Stefan Monnier
2005-06-09  1:06                                                                 ` Luc Teirlinck
2005-06-08 12:02                                                       ` Richard Stallman
2005-06-02  6:15                                   ` Carsten Dominik
2005-06-01 19:14                                 ` Luc Teirlinck
2005-06-01 19:19                                 ` Luc Teirlinck
2005-06-01 21:24                                 ` Stefan Monnier
2005-05-31 16:30                           ` Luc Teirlinck
2005-06-01  2:33                           ` Luc Teirlinck
2005-06-01 17:23                             ` Richard Stallman
2005-06-01 17:48                               ` Luc Teirlinck
2005-06-01  2:42                           ` Luc Teirlinck
2005-06-01 17:23                             ` Richard Stallman
2005-06-01 18:05                               ` Luc Teirlinck
2005-06-01  2:47                           ` Luc Teirlinck
2005-06-01 17:23                             ` Richard Stallman
2005-06-02  3:21                               ` Luc Teirlinck
2005-06-03 22:32                                 ` Richard Stallman
2005-06-03 23:08                                   ` Luc Teirlinck
2005-06-04 18:00                                     ` Richard Stallman
2005-06-01  3:01                           ` Luc Teirlinck
2005-05-30  1:43                       ` Luc Teirlinck [this message]
2005-05-30  2:50                       ` Luc Teirlinck
2005-05-30 15:31                         ` Luc Teirlinck
2005-05-30 16:52                           ` Luc Teirlinck
2005-05-30 17:24                             ` Luc Teirlinck
2005-05-30  3:35                       ` Luc Teirlinck
2005-05-29  2:20                   ` Luc Teirlinck
2005-05-29 12:04                     ` Richard Stallman
2005-05-30  0:42                       ` Luc Teirlinck
2005-05-30  1:58                       ` Luc Teirlinck
2005-05-28  1:58               ` Luc Teirlinck
2005-05-27 14:49             ` Michael Mauger
2005-05-27 15:35               ` Luc Teirlinck
2005-05-27 16:40               ` Luc Teirlinck
2005-05-27 17:15               ` Stefan Monnier
2005-05-27 19:13               ` Luc Teirlinck
2005-05-31 18:25                 ` Michael Mauger
2005-05-27 19:43               ` Luc Teirlinck
2005-05-28 11:53                 ` Richard Stallman
2005-05-28 18:48                   ` Luc Teirlinck
2005-06-07  1:19                   ` Luc Teirlinck
2005-06-07  1:49                     ` Miles Bader
2005-06-07  1:55                       ` Luc Teirlinck
2005-06-07  2:01                         ` Miles Bader
2005-06-07 18:23                           ` Stefan Monnier
2005-06-07 18:17                       ` Stefan Monnier
2005-06-08 12:01                       ` Richard Stallman
2005-05-26 14:53         ` Richard Stallman
2005-05-26 15:06           ` Luc Teirlinck
2005-05-26  4:16       ` Luc Teirlinck
2005-05-25 22:22     ` Lute Kamstra
     [not found] ` <17044.33688.784219.190965@sam.science.uva.nl>
2005-05-25 15:37   ` Lute Kamstra
2005-05-25 15:49     ` Carsten Dominik
2005-05-26  5:59 ` Richard Stallman
     [not found] <87sm07o3oz.fsf-monnier+emacs@gnu.org>
2005-05-29  2:00 ` Luc Teirlinck

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=200505300143.j4U1hdj13485@raven.dms.auburn.edu \
    --to=teirllm@dms.auburn.edu \
    --cc=Lute.Kamstra.lists@xs4all.nl \
    --cc=dominik@science.uva.nl \
    --cc=emacs-devel@gnu.org \
    --cc=mmaug@yahoo.com \
    --cc=monnier@iro.umontreal.ca \
    /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).