unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* In C code, how do I create and access a (lisp) variable?
@ 2015-11-04 21:04 Alan Mackenzie
  2015-11-04 21:20 ` Aurélien Aptel
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2015-11-04 21:04 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

Sorry to trouble you all with such a basic question, but I'm feeling
confused about it.

In C code, I want to create a lisp variable, and access its value (which
may have become buffer local, or have become aliased to whatever, or
whatnot).

Is DEFVAR_LISP the right way to define the variable?  This looks fine,
except most uses of the variable `foo', defined by

   DEFVAR_LISP ("foo", Vfoo, doc: /* Doc string*/)

are direct accesses to the C variable `Vfoo'.  Does `Vfoo" contain buffer
local values, for example?  Or do I need to use something like
Fsymbol_value?  If so, where do I get the symbol from (since, there's no
"Sfoo" in the above DEFVAR_LISP.)

If I've missed some documentation somewhere which answers my questions,
apologies, and please direct me to it.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: In C code, how do I create and access a (lisp) variable?
  2015-11-04 21:04 In C code, how do I create and access a (lisp) variable? Alan Mackenzie
@ 2015-11-04 21:20 ` Aurélien Aptel
  2015-11-04 23:39   ` Andreas Schwab
  2015-11-05 16:43   ` Alan Mackenzie
  0 siblings, 2 replies; 5+ messages in thread
From: Aurélien Aptel @ 2015-11-04 21:20 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Emacs development discussions

I think you're supposed to use DEFVAR_PER_BUFFER for definition and
BVAR for access.



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

* Re: In C code, how do I create and access a (lisp) variable?
  2015-11-04 21:20 ` Aurélien Aptel
@ 2015-11-04 23:39   ` Andreas Schwab
  2015-11-05 11:28     ` Aurélien Aptel
  2015-11-05 16:43   ` Alan Mackenzie
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2015-11-04 23:39 UTC (permalink / raw)
  To: Aurélien Aptel; +Cc: Alan Mackenzie, Emacs development discussions

Aurélien Aptel <aurelien.aptel+emacs@gmail.com> writes:

> I think you're supposed to use DEFVAR_PER_BUFFER for definition and
> BVAR for access.

DEFVAR_PER_BUFFER and BVAR are only for variables that are part of
struct buffer.  An ordinary variable can be made buffer-local even if
not part of struct buffer.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: In C code, how do I create and access a (lisp) variable?
  2015-11-04 23:39   ` Andreas Schwab
@ 2015-11-05 11:28     ` Aurélien Aptel
  0 siblings, 0 replies; 5+ messages in thread
From: Aurélien Aptel @ 2015-11-05 11:28 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Alan Mackenzie, Emacs development discussions

On Thu, Nov 5, 2015 at 12:39 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Aurélien Aptel <aurelien.aptel+emacs@gmail.com> writes:
>
>> I think you're supposed to use DEFVAR_PER_BUFFER for definition and
>> BVAR for access.
>
> DEFVAR_PER_BUFFER and BVAR are only for variables that are part of
> struct buffer.  An ordinary variable can be made buffer-local even if
> not part of struct buffer.

Correct. A similar question was asked (and answered) in emacs-devel.
Here's the link the archived thread (look for Stephan replies).

    https://lists.gnu.org/archive/html/emacs-devel/2015-09/msg00578.html

I'll quote him:

>> (defvar-local undo-buffer-undoably-changed nil
>>   "Non-nil means that that the buffer has had a recent undo-able change.
>
> This macroexpands to defvar + make-variable-buffer-local.
>
> In C defvar turns into DEFVAR_LISP, and make-variable-buffer-local turns
> into Fmake_variable_buffer_local.

And

>> Fsetq(Qfontification_functions,Qt)
>
> BTW, one notable difference (other than performance) between
>
>     Fset (Qfontification_functions, Qt);
> and
>     Vfontification_functions = Qt;
>
> is that the former will obey make-variable-buffer-local while the
> latter won't.  So if you want the var to be buffer-local, either use the
> former, or make sure to call Fmake_local_variable explicitly at
> some point.



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

* Re: In C code, how do I create and access a (lisp) variable?
  2015-11-04 21:20 ` Aurélien Aptel
  2015-11-04 23:39   ` Andreas Schwab
@ 2015-11-05 16:43   ` Alan Mackenzie
  1 sibling, 0 replies; 5+ messages in thread
From: Alan Mackenzie @ 2015-11-05 16:43 UTC (permalink / raw)
  To: Aurélien Aptel; +Cc: Emacs development discussions

Hello, Aurélien.

On Wed, Nov 04, 2015 at 10:20:55PM +0100, Aurélien Aptel wrote:
> I think you're supposed to use DEFVAR_PER_BUFFER for definition and
> BVAR for access.

In the end, I was able to find a model to emulate, namely that of
Vfontification_functions.

That involved doing all of the following:
o - Invoking DEFSYM for Qfoo;
o - Invoding DEFVAR_LIP for Vfoo;
o - Initialising Vfoo to Qnil;
o - Calling Fmake_variable_buffer_local (Qfoo).

It seems to have worked.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

end of thread, other threads:[~2015-11-05 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04 21:04 In C code, how do I create and access a (lisp) variable? Alan Mackenzie
2015-11-04 21:20 ` Aurélien Aptel
2015-11-04 23:39   ` Andreas Schwab
2015-11-05 11:28     ` Aurélien Aptel
2015-11-05 16:43   ` Alan Mackenzie

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