* minor mode problem
@ 2008-06-26 23:06 Stephen Berman
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Berman @ 2008-06-26 23:06 UTC (permalink / raw)
To: help-gnu-emacs
In GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.0) of
2008-06-25 on escher I start with -Q and evaluate the following minor
mode definition:
(define-minor-mode srb-mode
"Toggle srb mode."
:lighter " srb"
(if srb-mode
(progn
(message "font-lock-mode: %s" font-lock-mode)
(sit-for 1)
(if font-lock-mode (font-lock-mode -1))
(message "font-lock-mode: %s" font-lock-mode))
(unless font-lock-mode (font-lock-mode 1))
(message "font-lock-mode: %s" font-lock-mode)))
I write the following files to disk:
,----[ /tmp/srb-test1.el ]
| ;; blah
`----
,----[ /tmp/srb-test1 ]
| ;; blah
|
| ;; Local Variables:
| ;; mode: emacs-lisp
| ;; End:
`----
,----[ /tmp/srb-test2 ]
| ;; blah
`----
Now I evaluate the following function definitions:
(defun srb-mode-test (file)
"Enable srb-mode."
(interactive "fFile: ")
(find-file file)
(srb-mode 1))
(defun srb-mode-test2 ()
"Put a file in Emacs Lisp mode and enable srb-mode."
(interactive)
(find-file "/tmp/srb-test2")
(emacs-lisp-mode)
(srb-mode 1))
(1) I then call srb-mode-test twice, passing it first the file
/tmp/srb-test1.el and then the file /tmp/srb-test1. In both cases I
first see the buffer text fontified with font-lock-comment-face, then
after a second the fontification turns off. This is as I expect.
(2) Then I call srb-mode-test2: I see the text in font-lock-comment-face
and the message "font-lock-mode: t", then a second later the message
"font-lock-mode: nil", but the text remains fontified, and `C-h v
font-lock-mode' in that buffer says its value is t, although it was nil
according to the last message. This I did not expect and do not
understand.
(3) Next I try edebugging srb-mode-test2.
(a) When I execute each sexp (with `f'), after (emacs-lisp-mode) I see
the buffer text become fontified with font-lock-comment-face, and after
(srb-mode 1) it loses fontification. This is what I expect but, again,
not what happens when I execute the whole function outside of edebug.
(b) However, when I step into rather than over (emacs-lisp-mode) (`i'
instead of `f') and then execute each sexp of that function, the buffer
text never displays font-lock-comment-face.
(c) And finally, when I instrument srb-mode but not srb-mode-test2, then
when edebug stops execution at srb-mode, the buffer text displays
font-lock-comment-face, and when I step through srb-mode, I see the
buffer text lose fontification at the end of the progn, but when I then
continue stepping through to the end of srb-mode, the fontification
returns, so the result is as in (2) above.
(4) As a last case, I write the following file to disk:
,----[ /tmp/srb-test3 ]
| ;; blah
|
| ;; Local Variables:
| ;; mode: emacs-lisp
| ;; mode: srb
| ;; End:
`----
(a) When I do `C-x C-f /tmp/srb-test3', the result is as in (2).
(b) When I instrument emacs-lisp-mode, and after typing `C-x C-f
/tmp/srb-test3' step over it in edebug, the result is as in (3b).
(c) When I instrument srb-mode, and after typing `C-x C-f
/tmp/srb-test3' step over it in edebug, the result is as in (3a) (not as
in (3c)).
Can anyone explain what's happening in (2)-(4) (especially cases (2) and
(4a)), or at least offer some advice about how to debug them better?
Thanks.
Steve Berman
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: minor mode problem
[not found] <mailman.13882.1214521609.18990.help-gnu-emacs@gnu.org>
@ 2008-07-05 11:25 ` Johan Bockgård
0 siblings, 0 replies; 2+ messages in thread
From: Johan Bockgård @ 2008-07-05 11:25 UTC (permalink / raw)
To: help-gnu-emacs
Stephen Berman <stephen.berman@gmx.net> writes:
> In GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.0) of
> 2008-06-25 on escher I start with -Q and evaluate the following minor
> mode definition:
>
> (define-minor-mode srb-mode
> "Toggle srb mode."
> :lighter " srb"
> (if srb-mode
> (progn
> (message "font-lock-mode: %s" font-lock-mode)
> (sit-for 1)
> (if font-lock-mode (font-lock-mode -1))
> (message "font-lock-mode: %s" font-lock-mode))
> (unless font-lock-mode (font-lock-mode 1))
> (message "font-lock-mode: %s" font-lock-mode)))
[...]
> (2) Then I call srb-mode-test2: I see the text in
> font-lock-comment-face and the message "font-lock-mode: t", then a
> second later the message "font-lock-mode: nil", but the text remains
> fontified, and `C-h v font-lock-mode' in that buffer says its value is
> t, although it was nil according to the last message. This I did not
> expect and do not understand.
(defun print-font-lock-mode-1 ()
(message "FONT-LOCK-MODE: %s" font-lock-mode)
(remove-hook 'post-command-hook 'print-font-lock-mode-1))
(defun print-font-lock-mode-2 ()
(message "FONT-LOCK-MODE: %s" font-lock-mode)
(remove-hook 'post-command-hook 'print-font-lock-mode-2))
(defun srb-mode-test3 ()
"Turn on Emacs Lisp mode and enable srb-mode."
(interactive)
(emacs-lisp-mode)
(srb-mode 1)
(add-hook 'post-command-hook 'print-font-lock-mode-1)
(add-hook 'post-command-hook 'print-font-lock-mode-2 t))
M-x srb-mode-test3 RET
=>
font-lock-mode: t
font-lock-mode: nil
FONT-LOCK-MODE: nil
FONT-LOCK-MODE: t
See define-globalized-minor-mode (MODE-cmhh, MODE-check-buffers,
MODE-enable-in-buffers).
--
Johan Bockgård
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-07-05 11:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.13882.1214521609.18990.help-gnu-emacs@gnu.org>
2008-07-05 11:25 ` minor mode problem Johan Bockgård
2008-06-26 23:06 Stephen Berman
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).