emacs-devel
[Top][All Lists]
Advanced

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

Re: highlight-changes-mode


From: rsharman
Subject: Re: highlight-changes-mode
Date: Wed, 6 Dec 2006 01:25:40 -0500

Nick Roberts writes:
 > 
 >  Also it might be a good idea to use
 > define-minor-mode to define highlight-changes-mode.
 > 

Thanks,  that's nice.

It looks as if I could simplify a lot by using define-global-minor-mode 
for global-highlight-changes.  However, to keep the existing functionality
where variable highlight-changes-global-changes-existing-buffers
allows existing buffers to be left alone and only new ones changed,
I need a minor change to define-global-minor-mode.

I added a new keyword :only-new EXPR which allows restricting
a change of mode to new only new buffers if EXPR is non-nil.
(So the default behaviour, without this keyword, is unchanged.)

With this I can remove nearly all the code for the global
highlight-changes.

Is this acceptable?  Here's the change to easy-mmode.el that
implements what I need:


 
========================================================================
*** easy-mmode.el.orig  Thu Aug 31 19:14:26 2006
--- easy-mmode.el       Wed Dec  6 01:16:35 2006
***************
*** 278,290 ****
  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.  As the minor mode
!   defined by this function is always global, any :global keyword is
!   ignored.  Other keywords have the same meaning as in `define-minor-mode',
!   which see.  In particular, :group specifies the custom group.
!   The most useful keywords are those that are passed on to the
!   `defcustom'.  It normally makes no sense to pass the :lighter
!   or :keymap keywords to `define-global-minor-mode', since these
!   are usually passed to the buffer-local version of the minor mode.
  
  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
--- 278,292 ----
  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.  As the minor mode
!   defined by this function is always global, any :global keyword
!   is ignored.  Keyword :only-new EXPR means don't change existing
!   buffers if EXPR is non-nil.  Other keywords have the same
!   meaning as in `define-minor-mode', which see.  In particular, 
!   :group specifies the custom group.  The most useful keywords
!   are those that are passed on to the `defcustom'.  It normally
!   makes no sense to pass the :lighter or :keymap keywords to
!   `define-global-minor-mode', since these are usually passed to
!   the buffer-local version of the minor mode.
  
  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
***************
*** 304,309 ****
--- 306,312 ----
          (intern (concat global-mode-name "-check-buffers")))
         (MODE-cmhh (intern (concat global-mode-name "-cmhh")))
         (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
+        (only-new nil)
         keyw)
  
      ;; Check keys.
***************
*** 312,317 ****
--- 315,321 ----
        (case keyw
        (:group (setq group (nconc group (list :group (pop keys)))))
        (:global (setq keys (cdr keys)))
+       (:only-new (setq only-new (pop keys)))
        (t (push keyw extra-keywords) (push (pop keys) extra-keywords))))
  
      (unless group
***************
*** 344,352 ****
           (remove-hook 'change-major-mode-hook ',MODE-cmhh))
  
         ;; Go through existing buffers.
!        (dolist (buf (buffer-list))
!          (with-current-buffer buf
!            (if ,global-mode (,turn-on) (when ,mode (,mode -1))))))
  
         ;; Autoloading define-global-minor-mode autoloads everything
         ;; up-to-here.
--- 348,357 ----
           (remove-hook 'change-major-mode-hook ',MODE-cmhh))
  
         ;; Go through existing buffers.
!        (unless ,only-new
!          (dolist (buf (buffer-list))
!            (with-current-buffer buf
!              (if ,global-mode (,turn-on) (when ,mode (,mode -1)))))))
  
         ;; Autoloading define-global-minor-mode autoloads everything
         ;; up-to-here.
========================================================================

Richard




reply via email to

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