emacs-devel
[Top][All Lists]
Advanced

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

Re: org-mode and mode hooks.


From: Luc Teirlinck
Subject: Re: org-mode and mode hooks.
Date: Fri, 27 May 2005 20:58:48 -0500 (CDT)

My original patch for font-lock.el had problems.  It did not work well
for modes that only use font-lock for font-lock-face and it did not
work for modes with a non-standard font-lock-function.  I now propose
to leave font-lock.el unchanged and to apply the patch below to
font-core.el instead.

I also propose a slightly changed second paragraph to the
`define-global-minor-mode' docstring.  The revised patch to cwarn.el
is completely equivalent to my original.  It just adapts the changes
to the revised `define-global-minor-mode' docstring.

Revised second paragraph of `define-global-minor-mode' docstring:

If the minor mode's set-up depends on the major mode, then enabling
the minor mode should store the value of the variable `major-mode' in
the variable MODE-stored-mode.  This is used to catch bugs where MODE
is set up for the wrong mode.  `define-global-minor-mode' provides
a defvar for MODE-stored-hook, with initial value nil, and makes it
automatically buffer-local.  If MODE's set-up is independent of
the major mode, the value of the variable should stay nil.

New patches to font-core.el and cwarn.el:

===File ~/font-core-diff====================================
*** font-core.el        22 May 2005 16:46:07 -0500      1.28
--- font-core.el        27 May 2005 20:01:05 -0500      
***************
*** 88,93 ****
--- 88,95 ----
  It will be passed one argument, which is the current value of
  `font-lock-mode'.")
  
+ ;; The mode for which font-lock was initialized, or nil if none.
+ (defvar font-lock-mode-stored-mode)
  (define-minor-mode font-lock-mode
    "Toggle Font Lock mode.
  With arg, turn Font Lock mode off if and only if arg is a non-positive
***************
*** 156,162 ****
    ;; Arrange to unfontify this buffer if we change major mode later.
    (if font-lock-mode
        (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t)
!     (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)))
  
  ;; Get rid of fontification for the old major mode.
  ;; We do this when changing major modes.
--- 158,165 ----
    ;; Arrange to unfontify this buffer if we change major mode later.
    (if font-lock-mode
        (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t)
!     (remove-hook 'change-major-mode-hook 'font-lock-change-mode t))
!   (when font-lock-mode (setq font-lock-mode-stored-mode major-mode)))
  
  ;; Get rid of fontification for the old major mode.
  ;; We do this when changing major modes.
***************
*** 203,209 ****
    (when (or font-lock-defaults
            (and (boundp 'font-lock-keywords) font-lock-keywords)
            (with-no-warnings
!            (cdr (assq major-mode font-lock-defaults-alist))))
      (font-lock-mode-internal mode)))
  
  (defun turn-on-font-lock ()
--- 206,217 ----
    (when (or font-lock-defaults
            (and (boundp 'font-lock-keywords) font-lock-keywords)
            (with-no-warnings
!             (cdr (assq major-mode font-lock-defaults-alist)))
!           (and (boundp 'font-lock-set-defaults)
!                font-lock-set-defaults
!                (not (eq font-lock-mode-stored-mode major-mode))))
!     (unless (eq font-lock-mode-stored-mode major-mode)
!       (setq  font-lock-set-defaults nil))
      (font-lock-mode-internal mode)))
  
  (defun turn-on-font-lock ()
============================================================

===File ~/cwarn-diff========================================
*** cwarn.el    04 Apr 2005 07:03:09 -0500      1.9
--- cwarn.el    27 May 2005 20:03:24 -0500      
***************
*** 184,189 ****
--- 184,190 ----
  ;;}}}
  ;;{{{ The modes
  
+ (defvar cwarn-mode-stored-mode)
  ;;;###autoload
  (define-minor-mode cwarn-mode
    "Minor mode that highlights suspicious C and C++ constructions.
***************
*** 195,201 ****
  With ARG, turn CWarn mode on if and only if arg is positive."
    :group 'cwarn :lighter cwarn-mode-text
    (cwarn-font-lock-keywords cwarn-mode)
!   (if font-lock-mode (font-lock-fontify-buffer)))
  
  ;;;###autoload
  (defun turn-on-cwarn-mode ()
--- 196,203 ----
  With ARG, turn CWarn mode on if and only if arg is positive."
    :group 'cwarn :lighter cwarn-mode-text
    (cwarn-font-lock-keywords cwarn-mode)
!   (if font-lock-mode (font-lock-fontify-buffer))
!   (when cwarn-mode (setq cwarn-mode-stored-mode major-mode)))
  
  ;;;###autoload
  (defun turn-on-cwarn-mode ()
============================================================




reply via email to

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