* About the `:variable' keyword in `define-minor-mode'
@ 2013-02-14 14:37 Xue Fuqiao
2013-02-14 15:02 ` Stefan Monnier
[not found] ` <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: Xue Fuqiao @ 2013-02-14 14:37 UTC (permalink / raw)
To: help-gnu-emacs
In the docstring of `define-minor-mode':
[...]
:variable PLACE [...]
PLACE can also be of the form (GET . SET), where GET is
an expression that returns the current state, and SET
is a function that takes one argument, the new state,
and sets it.
I don't understand the meaning of GET. The docstring says it returns
the current state, but where will it return?
--
Best regards, Xue Fuqiao.
http://www.emacswiki.org/emacs/XueFuqiao
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: About the `:variable' keyword in `define-minor-mode'
2013-02-14 14:37 About the `:variable' keyword in `define-minor-mode' Xue Fuqiao
@ 2013-02-14 15:02 ` Stefan Monnier
[not found] ` <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-02-14 15:02 UTC (permalink / raw)
To: help-gnu-emacs
> In the docstring of `define-minor-mode':
> [...]
> :variable PLACE [...]
> PLACE can also be of the form (GET . SET), where GET is
> an expression that returns the current state, and SET
> is a function that takes one argument, the new state,
> and sets it.
> I don't understand the meaning of GET. The docstring says it returns
> the current state, but where will it return?
It will return it to the context?
The following expression:
(+ 1 2)
is an expression that returns 3, and we don't care where it returns
it, really.
Does this explanation help?
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>]
* Re: About the `:variable' keyword in `define-minor-mode'
[not found] ` <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>
@ 2013-02-14 15:53 ` Michael Heerdegen
2013-02-14 15:53 ` Michael Heerdegen
1 sibling, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2013-02-14 15:53 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > In the docstring of `define-minor-mode':
> > [...]
> > :variable PLACE [...]
> > PLACE can also be of the form (GET . SET), where GET is
> > an expression that returns the current state, and SET
> > is a function that takes one argument, the new state,
> > and sets it.
>
> > I don't understand the meaning of GET. The docstring says it returns
> > the current state, but where will it return?
>
> It will return it to the context?
I think he wanted to know where and how it is referenced/used (in the code).
Xue, please have a look at the definition of the macro
`define-minor-mode'. The GET part is used in the defun of the modefun,
after these lines:
;; The actual function.
(defun ,modefun (&optional arg ,@extra-args)
There, the variable `mode' is bound to the GET expression. It is mainly
used to check if the mode is on or off, but it is also `setf'ed if SET
is nil.
So, if e.g. GET is `(car foo)', the car of the value of the variable
`foo' will be looked at to decide whether the mode is turned on or off.
Does this help?
Regards,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: About the `:variable' keyword in `define-minor-mode'
[not found] ` <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>
2013-02-14 15:53 ` Michael Heerdegen
@ 2013-02-14 15:53 ` Michael Heerdegen
1 sibling, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2013-02-14 15:53 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > In the docstring of `define-minor-mode':
> > [...]
> > :variable PLACE [...]
> > PLACE can also be of the form (GET . SET), where GET is
> > an expression that returns the current state, and SET
> > is a function that takes one argument, the new state,
> > and sets it.
>
> > I don't understand the meaning of GET. The docstring says it returns
> > the current state, but where will it return?
>
> It will return it to the context?
I think he wanted to know where and how it is referenced/used (in the code).
Xue, please have a look at the definition of the macro
`define-minor-mode'. The GET part is used in the defun of the modefun,
after these lines:
;; The actual function.
(defun ,modefun (&optional arg ,@extra-args)
There, the variable `mode' is bound to the GET expression. It is mainly
used to check if the mode is on or off, but it is also `setf'ed if SET
is nil.
So, if e.g. GET is `(car foo)', the car of the value of the variable
`foo' will be looked at to decide whether the mode is turned on or off.
Does this help?
Regards,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: About the `:variable' keyword in `define-minor-mode'
@ 2013-02-14 23:50 Xue Fuqiao
0 siblings, 0 replies; 5+ messages in thread
From: Xue Fuqiao @ 2013-02-14 23:50 UTC (permalink / raw)
To: help-gnu-emacs
Thanks for Stefan and Michael.
> > > In the docstring of `define-minor-mode':
> > > [...]
> > > :variable PLACE [...]
> > > PLACE can also be of the form (GET . SET), where GET is
> > > an expression that returns the current state, and SET
> > > is a function that takes one argument, the new state,
> > > and sets it.
> >
> > > I don't understand the meaning of GET. The docstring says it returns
> > > the current state, but where will it return?
> >
> > It will return it to the context?
> I think he wanted to know where and how it is referenced/used (in the code).
That's true.
> So, if e.g. GET is `(car foo)', the car of the value of the variable
> `foo' will be looked at to decide whether the mode is turned on or off.
> Does this help?
I see, that helps.
--
Best regards, Xue Fuqiao.
http://www.emacswiki.org/emacs/XueFuqiao
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-14 23:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-14 14:37 About the `:variable' keyword in `define-minor-mode' Xue Fuqiao
2013-02-14 15:02 ` Stefan Monnier
[not found] ` <mailman.19937.1360854183.855.help-gnu-emacs@gnu.org>
2013-02-14 15:53 ` Michael Heerdegen
2013-02-14 15:53 ` Michael Heerdegen
-- strict thread matches above, loose matches on Subject: below --
2013-02-14 23:50 Xue Fuqiao
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.