unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* questions about blink-cursor-mode
@ 2009-11-18 18:59 ` Drew Adams
  2009-11-18 23:31   ` Juanma Barranquero
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2009-11-18 18:59 UTC (permalink / raw)
  To: emacs-devel

I need to turn on blink-cursor-mode for a particular major mode.

blink-cursor-mode is a global minor mode. I don't know how to turn it on only
locally. (Is that possible? how?)

So, as a workaround, I save the value of the mode variable `blink-major-mode'
when my major mode is entered, and then restore blinking or not-blinking (by
calling function `blink-major-mode' to reflect the saved value) when the major
mode is exited. In this way, at least whatever behavior the user had before s?he
will get again after the major mode is exited.

But I don't know how to update the saved value that I record, which should
reflect the user's preference, if the user calls blink-cursor-mode (or
customizes the mode var) to change it.

blink-cursor-mode is defined using `define-minor-mode', and the doc for that
says that "It finishes by running the mode hook variable `MODE-hook'." But there
doesn't seem to be any variable `blink-cursor-mode-hook'. How can that be? Why
is that? If there were such a hook, I could presumably use it to update my
variable that reflects the user's preference.

What's the right way (a good way) to do what I need? I don't want to trample the
user's preference for blinking or not blinking, but the major mode in question
really needs a blinking cursor.

And if, as I understand it, there is no way to make the blinking be local to my
major mode, then it could be acceptable to at least make it blink only for the
duration, i.e. until the major mode is exited. That's what I'm doing now, but I
don't know how to pick up any user preference changes - once I've saved the
value of blink-cursor-mode upon entry to my major mode, that saved value stays
the same.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: questions about blink-cursor-mode
  2009-11-18 18:59 ` questions about blink-cursor-mode Drew Adams
@ 2009-11-18 23:31   ` Juanma Barranquero
  2009-11-18 23:39     ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2009-11-18 23:31 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

On Wed, Nov 18, 2009 at 19:59, Drew Adams <drew.adams@oracle.com> wrote:

> blink-cursor-mode is defined using `define-minor-mode', and the doc for that
> says that "It finishes by running the mode hook variable `MODE-hook'." But there
> doesn't seem to be any variable `blink-cursor-mode-hook'. How can that be? Why
> is that? If there were such a hook, I could presumably use it to update my
> variable that reflects the user's preference.

The code for `define-minor-mode' does this:

  (let* (...
	 (hook (intern (concat mode-name "-hook")))
	 (hook-on (intern (concat mode-name "-on-hook")))
	 (hook-off (intern (concat mode-name "-off-hook")))
         ...)

    ...

    ,@body
    ;; The on/off hooks are here for backward compatibility only.
    (run-hooks ',hook (if ,mode ',hook-on ',hook-off))

    ...

so the hook is run even if the symbol is not defvared. Some packages
declare the hook variable, some don't. (Yes, I agree it would be
better to always declare them, if only to add the standard "This is a
normal hook blah blah" docstring.)

    Juanma




^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: questions about blink-cursor-mode
  2009-11-18 23:31   ` Juanma Barranquero
@ 2009-11-18 23:39     ` Drew Adams
  2009-11-19  1:06       ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2009-11-18 23:39 UTC (permalink / raw)
  To: 'Juanma Barranquero'; +Cc: emacs-devel

> > blink-cursor-mode is defined using `define-minor-mode', and 
> > the doc for that says that "It finishes by running the mode
> > hook variable `MODE-hook'." But there doesn't seem to be any
> > variable `blink-cursor-mode-hook'. How can that be?
> 
> The code for `define-minor-mode' does this:
>   (let* (...
> 	 (hook (intern (concat mode-name "-hook")))
> 	 (hook-on (intern (concat mode-name "-on-hook")))
> 	 (hook-off (intern (concat mode-name "-off-hook")))
>          ...)
>     ...
>     ,@body
>     ;; The on/off hooks are here for backward compatibility only.
>     (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
> 
> so the hook is run even if the symbol is not defvared. Some packages
> declare the hook variable, some don't. (Yes, I agree it would be
> better to always declare them, if only to add the standard "This is a
> normal hook blah blah" docstring.)

Thanks, Juanma. Now that I see that explanation, I recall that I knew this at
one time - but I guess I forgot it. Note that not only is it not declared (e.g.
defvar), it is also not bound, which is why `C-h v' doesn't recognize it.

I still have the other questions I posed. In sum, what's the right (or a good)
way to do what I need?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: questions about blink-cursor-mode
  2009-11-18 23:39     ` Drew Adams
@ 2009-11-19  1:06       ` Stefan Monnier
  2009-11-19  1:30         ` Lennart Borgman
  2009-11-19 17:17         ` Drew Adams
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2009-11-19  1:06 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Juanma Barranquero', emacs-devel

> Thanks, Juanma. Now that I see that explanation, I recall that I knew
> this at one time - but I guess I forgot it. Note that not only is it
> not declared (e.g.  defvar), it is also not bound, which is why `C-h
> v' doesn't recognize it.

The first problem is in the docstring:

  It finishes by running the mode hook variable `MODE-hook'.

this repeats a very widespread misconception, which is that those hooks
are variables.  They're not: a hook is a symbol, not a variable.
That's why it can work even if the variable by that name is not bound.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: questions about blink-cursor-mode
  2009-11-19  1:06       ` Stefan Monnier
@ 2009-11-19  1:30         ` Lennart Borgman
  2009-11-19 17:17         ` Drew Adams
  1 sibling, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2009-11-19  1:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Juanma Barranquero, Drew Adams, emacs-devel

On Thu, Nov 19, 2009 at 2:06 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> Thanks, Juanma. Now that I see that explanation, I recall that I knew
>> this at one time - but I guess I forgot it. Note that not only is it
>> not declared (e.g.  defvar), it is also not bound, which is why `C-h
>> v' doesn't recognize it.
>
> The first problem is in the docstring:
>
>  It finishes by running the mode hook variable `MODE-hook'.
>
> this repeats a very widespread misconception, which is that those hooks
> are variables.  They're not: a hook is a symbol, not a variable.
> That's why it can work even if the variable by that name is not bound.


But it is described by describe-variable ...

Maybe we should have a describe-symbol that knows a bit abou these
things? I have a describe-symbol in nXhtml that knows a little bit
(but not hooks).




^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: questions about blink-cursor-mode
  2009-11-19  1:06       ` Stefan Monnier
  2009-11-19  1:30         ` Lennart Borgman
@ 2009-11-19 17:17         ` Drew Adams
  1 sibling, 0 replies; 6+ messages in thread
From: Drew Adams @ 2009-11-19 17:17 UTC (permalink / raw)
  To: 'Stefan Monnier'; +Cc: 'Juanma Barranquero', emacs-devel

> > Thanks, Juanma. Now that I see that explanation, I recall 
> > that I knew this at one time - but I guess I forgot it.
> > Note that not only is it not declared (e.g.  defvar), it
> > is also not bound, which is why `C-h v' doesn't recognize it.
> 
> The first problem is in the docstring:
>   "It finishes by running the mode hook variable `MODE-hook'."
> this repeats a very widespread misconception, which is that 
> those hooks are variables.  They're not: a hook is a symbol,
> not a variable. That's why it can work even if the variable
> by that name is not bound.

1. Yes, fine, correct the doc string if you like. Similarly, the Emacs manual
and Elisp manual need to be corrected, if you deem this important. The Emacs
manual, node Hooks, defined "hook" in its very first sentence this way:

  "Hooks" are an important mechanism for customizing Emacs.
  A hook is a Lisp variable which holds a list of functions,
  to be called on some well-defined occasion.

And the Elisp manual, node Hooks, repeats the same thing (why such repetition,
BTW?):

  A "hook" is a variable where you can store a function or functions
  to be called on a particular occasion by an existing program.

The entire Hooks node in each manual then explains more about such "variables"
("symbol" is never used). If the distinction is truly important here, then we
shouldn't be defining hooks in a way that loses the distinction.

However, for a hook to actually be _used_, `add-hook' or similar must have been
called, so the symbol must have a value. (And even if you then use
`remove-hook', the symbol is not unbound.)

IOW, for any discussion or explanation of the real use of a hook symbol, which
pretty much means for all practical purposes, the symbol is a variable (it has a
value - it must have a value to be useful).

The nuanced explanation helps users like me who forget or are unaware of the
fact that hooks are not bound initially, but I don't know what purpose it serves
otherwise.

So what is the reason that hook symbols are not initialized to nil? Is it simply
to save a little memory? If they were initialized (e.g. by such as
`define-minor-mode'), then they would show up for things like `C-h v', which
helps user discovery. IOW, what is the benefit of not initializing them?


2. My main questions are still out there - the discussion about hooks being
possibly unbound symbols is ancillary. The questions are about
`blink-cursor-mode'. It is a global minor mode. Is there a way (how?) to turn it
on only locally - e.g. for a particular buffer or mode? (`make-local-variable'
won't help.)

If not, what's a good way to get something like that effect? Currently, I just
turn it on when my particular major mode is turned on, and then turn it off when
that mode is exited (or, via `blink-cursor-mode-hook', when the user turns it
off). This is an ugly, approximative hack - I'd love to learn a better approach.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-11-19 17:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <AcpogTg4wgSCDluLRNWONZ0+zkdmZQ==>
2009-11-18 18:59 ` questions about blink-cursor-mode Drew Adams
2009-11-18 23:31   ` Juanma Barranquero
2009-11-18 23:39     ` Drew Adams
2009-11-19  1:06       ` Stefan Monnier
2009-11-19  1:30         ` Lennart Borgman
2009-11-19 17:17         ` Drew Adams

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).