From: Robert Pluim <rpluim@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Native line numbers landed on master
Date: Wed, 09 Oct 2019 09:19:57 +0200 [thread overview]
Message-ID: <m2y2xu8jxe.fsf@gmail.com> (raw)
In-Reply-To: <83blurxw6a.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 08 Oct 2019 15:23:57 +0300")
>>>>> On Tue, 08 Oct 2019 15:23:57 +0300, Eli Zaretskii <eliz@gnu.org> said:
Eli> Instead of "Lisp-level" and "C-level", which IMO are somewhat unclear,
Eli> I'd use the likes of "the name of the variable to be used by Lisp
Eli> programs" and "the name of the variable in the C source".
Done
>> +@item doc
>> +The documentation for the variable, as a C comment.
Eli> Here, please include a cross-reference to the tips about writing doc
Eli> strings.
Done
>> + By convention, when defining variables of a ``native'' type
>> +(@code{int} and @code{bool}), the name of the C variable is the same
>> +as the name of the Lisp variable with ``-'' replaced by ``_''. When
>> +the variable can hold any Lisp object, the convention is
>> +to also prefix the C variable name with ``V''. i.e.
Eli> I think -, _, and V should be in @code or @samp, not in quotes. Also,
Eli> I'd mention explicitly that the C data type of the latter category is
Eli> Lisp_Object.
Done
>> +If you want to define a constant symbol rather than a variable, use
>> +@code{DEFSYM} instead. e.g.
>> +
>> +@smallexample
>> +DEFSYM ("Qmy_symbol", "my-symbol");
>> +@end smallexample
Eli> This is IMO confusing, because it doesn't explain when would the C
Eli> programmer want "to define a constant symbol rather than a variable".
Eli> I think it's important to explain that the symbol corresponding to a
Eli> variable is needed where in Lisp one would use a quoted symbol. A
Eli> good example is the use of specbind which is the equivalent of
Eli> let-binding on the Lisp level.
Not just confusing, my example was wrong. I expanded that bit.
Eli> Bonus points for adding information missing from the above, such as
Eli> how to define buffer-local variables (see init_buffer_once), and how
Eli> to define custom forms for variables defined in C.
Youʼre a hard taskmaster Eli :-) . Iʼve done my best, although I donʼt
see where init_buffer_once comes in.
Thereʼs a sentence further down that talks about cus-start.el, I added
a cross-reference to the defcustom node.
* doc/lispref/internals.texi (Writing Emacs Primitives): Add
description of DEFVAR_* arguments. Describe variable naming
conventions. Explain 'specbind' and how to create buffer-local
variables.
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index c52999e1cd..45725c3c80 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -945,7 +945,7 @@ Writing Emacs Primitives
@anchor{Defining Lisp variables in C}
@vindex byte-boolean-vars
@cindex defining Lisp variables in C
-@cindex @code{DEFVAR_INT}, @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}
+@cindex @code{DEFVAR_INT}, @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}, @code{DEFSYM}
The function @code{syms_of_@var{filename}} is also the place to define
any C variables that are to be visible as Lisp variables.
@code{DEFVAR_LISP} makes a C variable of type @code{Lisp_Object} visible
@@ -956,15 +956,71 @@ Writing Emacs Primitives
defined with @code{DEFVAR_BOOL} are automatically added to the list
@code{byte-boolean-vars} used by the byte compiler.
+ These macros all expect three arguments:
+
+@table @code
+@item lname
+The name of the variable to be used by Lisp programs.
+@item vname
+The name of the variable in the C sources.
+@item doc
+The documentation for the variable, as a C
+comment. @xref{Documentation Basics} for more details.
+@end table
+
+ By convention, when defining variables of a ``native'' type
+(@code{int} and @code{bool}), the name of the C variable is the name
+of the Lisp variable with @code{-} replaced by @code{_}. When the
+variable has type @code{Lisp_Object}, the convention is to also prefix
+the C variable name with ``V''. i.e.
+
+@smallexample
+DEFVAR_INT ("my-int-variable", my_int_variable,
+ doc: /* An integer variable. */);
+
+DEFVAR_LISP ("my-lisp-variable", Vmy_lisp_variable,
+ doc: /* A Lisp variable. */);
+@end smallexample
+
+ There are situations in Lisp where you need to refer to the symbol
+itself rather than the value of that symbol. One such case is when
+temporarily overriding the value of a variable, which in Lisp is done
+with @code{let}. In C sources, this is done by defining a
+corresponding, constant symbol, and using @code{specbind}. By
+convention @code{Qmy_lisp_variable} corresponds to
+@code{Vmy_lisp_variable}; to define it, use the @code{DEFSYM} macro.
+i.e.
+
+@smallexample
+DEFSYM (Qmy_lisp_variable, "my-lisp-variable");
+@end smallexample
+
+ To perform the actual binding:
+
+@smallexample
+specbind (Qmy_lisp_variable, Qt);
+@end smallexample
+
+ Another use for constant symbols is when creating a buffer-local
+variable (@pxref{Buffer-Local Variables}). In C this is done with
+@code{Fmake_variable_buffer_local} in combination with @code{DEFSYM},
+i.e.
+
+@smallexample
+DEFSYM (Qmy_lisp_variable, "my-lisp-variable");
+Fmake_variable_buffer_local (Qmy_lisp_variable);
+@end smallexample
+
@cindex defining customization variables in C
If you want to make a Lisp variable that is defined in C behave
like one declared with @code{defcustom}, add an appropriate entry to
-@file{cus-start.el}.
+@file{cus-start.el}. @xref{Variable Definitions} for a description of
+the format to use.
@cindex @code{staticpro}, protection from GC
- If you define a file-scope C variable of type @code{Lisp_Object},
-you must protect it from garbage-collection by calling @code{staticpro}
-in @code{syms_of_@var{filename}}, like this:
+ If you directly define a file-scope C variable of type
+@code{Lisp_Object}, you must protect it from garbage-collection by
+calling @code{staticpro} in @code{syms_of_@var{filename}}, like this:
@example
staticpro (&@var{variable});
next prev parent reply other threads:[~2019-10-09 7:19 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-08 7:58 Native line numbers landed on master Eli Zaretskii
2017-07-08 8:41 ` martin rudalics
2017-07-08 10:23 ` Eli Zaretskii
2017-07-08 22:38 ` Alex
2017-07-09 14:22 ` Eli Zaretskii
2017-07-09 22:56 ` Alex
2017-07-10 17:50 ` Eli Zaretskii
2017-07-10 20:31 ` Alex
2017-07-11 15:12 ` Eli Zaretskii
2017-07-11 20:44 ` Alex
2017-07-12 14:40 ` Eli Zaretskii
2017-07-16 7:30 ` Alex
2017-07-16 14:10 ` Eli Zaretskii
2017-07-16 19:31 ` Alex
2017-07-17 15:00 ` Eli Zaretskii
2017-07-17 20:34 ` Alex
2017-07-22 9:18 ` Eli Zaretskii
2017-07-10 22:19 ` John Wiegley
2017-07-11 2:29 ` Eli Zaretskii
2017-07-11 15:27 ` Stefan Monnier
2017-07-11 16:04 ` Eli Zaretskii
2017-07-11 16:16 ` Stefan Monnier
2017-07-11 17:23 ` Eli Zaretskii
2017-07-11 17:48 ` Stefan Monnier
2017-07-11 18:04 ` Eli Zaretskii
2017-07-11 18:19 ` Stefan Monnier
2017-07-11 18:18 ` Sharp-quoting function symbols (Was: Native line numbers landed on master) Kaushal Modi
2017-09-30 18:36 ` Philipp Stephani
2017-12-30 21:09 ` Philipp Stephani
2017-07-10 16:51 ` Native line numbers landed on master Filipe Silva
2017-07-11 13:00 ` Robert Pluim
2017-07-11 13:37 ` Jean-Christophe Helary
2017-07-11 13:47 ` Robert Pluim
2017-07-11 14:19 ` Jean-Christophe Helary
2017-07-11 15:24 ` Eli Zaretskii
2017-07-11 15:29 ` Robert Pluim
2017-07-11 16:07 ` Eli Zaretskii
2017-07-11 16:12 ` Robert Pluim
2017-07-11 17:33 ` Eli Zaretskii
2017-07-12 3:23 ` Kaushal Modi
2017-07-12 7:11 ` martin rudalics
2017-07-12 14:27 ` Eli Zaretskii
2017-07-12 15:49 ` martin rudalics
2017-07-15 22:02 ` Yuri D'Elia
2017-07-16 2:34 ` Eli Zaretskii
2017-07-16 14:25 ` Eli Zaretskii
2017-07-17 9:44 ` Yuri D'Elia
2017-07-17 14:16 ` Eli Zaretskii
2019-06-10 2:46 ` Juanma Barranquero
2019-06-10 8:32 ` Yuri D'Elia
2019-06-10 12:38 ` Juanma Barranquero
2019-06-10 15:22 ` Eli Zaretskii
2019-06-10 15:32 ` Juanma Barranquero
2019-06-10 15:33 ` Yuri D'Elia
2019-06-10 15:54 ` Eli Zaretskii
2019-06-10 16:23 ` Yuri D'Elia
2019-06-10 17:41 ` Eli Zaretskii
2019-09-30 10:01 ` Juanma Barranquero
2019-09-30 10:21 ` Eli Zaretskii
2019-10-01 5:44 ` Juanma Barranquero
2019-10-01 7:05 ` Eli Zaretskii
2019-10-01 8:49 ` Juanma Barranquero
2019-10-01 8:55 ` Juanma Barranquero
2019-10-01 9:26 ` Eli Zaretskii
2019-10-01 9:25 ` Eli Zaretskii
2019-10-01 9:09 ` Yuri D'Elia
2019-10-01 9:21 ` Juanma Barranquero
2019-10-01 9:51 ` Yuri D'Elia
2019-10-01 10:23 ` Juanma Barranquero
2019-10-01 10:40 ` Yuri D'Elia
2019-10-01 10:39 ` Eli Zaretskii
2019-10-01 10:47 ` Lars Ingebrigtsen
2019-10-01 11:07 ` Eli Zaretskii
2019-10-01 11:11 ` Juanma Barranquero
2019-10-01 22:52 ` Ergus
2019-10-01 23:51 ` Juanma Barranquero
2019-10-02 3:41 ` Ergus
2019-10-02 9:40 ` Juanma Barranquero
2019-10-02 13:56 ` Ergus
2019-10-02 15:06 ` Eli Zaretskii
2019-10-03 4:11 ` Juanma Barranquero
2019-10-03 8:16 ` martin rudalics
2019-10-03 14:43 ` Juanma Barranquero
2019-10-03 9:10 ` Robert Pluim
2019-10-03 14:47 ` Juanma Barranquero
2019-10-03 15:18 ` Robert Pluim
2019-10-03 20:37 ` Stefan Kangas
2019-10-03 21:48 ` Juanma Barranquero
2019-10-03 22:37 ` Yuri D'Elia
2019-10-04 1:51 ` Juanma Barranquero
2019-10-04 7:45 ` Eli Zaretskii
2019-10-04 9:52 ` Yuri D'Elia
2019-10-04 10:24 ` Juanma Barranquero
2019-10-05 6:26 ` Juanma Barranquero
2019-10-07 0:14 ` Juanma Barranquero
2019-10-07 6:54 ` Robert Pluim
2019-10-07 7:39 ` Juanma Barranquero
2019-10-07 8:09 ` Robert Pluim
2019-10-07 8:39 ` Juanma Barranquero
2019-10-07 18:52 ` Juri Linkov
2019-10-08 0:57 ` Juanma Barranquero
2019-10-19 20:38 ` Juri Linkov
2019-10-07 16:30 ` Eli Zaretskii
2019-10-08 11:15 ` Robert Pluim
2019-10-08 12:23 ` Eli Zaretskii
2019-10-09 7:19 ` Robert Pluim [this message]
2019-10-09 8:16 ` Eli Zaretskii
2019-10-09 12:14 ` Robert Pluim
2019-10-09 12:23 ` Eli Zaretskii
2019-10-09 13:19 ` Robert Pluim
2019-10-09 10:51 ` Juanma Barranquero
2019-10-04 10:22 ` Ergus
2019-10-04 10:26 ` Juanma Barranquero
2019-10-03 12:28 ` Yuri Khan
2019-10-03 14:48 ` Juanma Barranquero
2019-10-03 17:56 ` Yuri D'Elia
2019-10-03 18:40 ` Eli Zaretskii
2019-10-03 19:01 ` Yuri D'Elia
2019-10-04 2:01 ` Juanma Barranquero
2019-10-04 5:01 ` Juanma Barranquero
2019-10-04 15:57 ` Johan Bockgård
2019-10-04 17:28 ` Juanma Barranquero
2019-10-04 19:24 ` Stefan Monnier
2019-10-04 20:12 ` Yuri D'Elia
2019-10-04 22:45 ` Juanma Barranquero
2019-10-06 14:04 ` Juanma Barranquero
2019-10-06 14:45 ` Juanma Barranquero
2019-10-06 18:02 ` Eli Zaretskii
2019-10-01 9:24 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2y2xu8jxe.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).