Compare commits

..

138 commits

Author SHA1 Message Date
Gerd Möllmann
716d676747 Merge remote-tracking branch 'origin/master' into scratch/pkg 2022-12-31 09:04:56 +01:00
Gerd Möllmann
54ec3973e2 Merge remote-tracking branch 'origin/master' into scratch/pkg 2022-12-19 14:25:27 +01:00
Gerd Möllmann
b182f18017 Merge remote-tracking branch 'origin/master' into scratch/pkg 2022-12-05 09:37:20 +01:00
Gerd Möllmann
7ac023aa1f Fix calls to intern_c_string_1
* src/treesit.c (treesit_predicates_for_pattern):
(Ftreesit_query_capture): Call intern_c_string_1 with additionla arg.
2022-11-28 09:29:43 +01:00
Gerd Möllmann
2848b97d0e Merge remote-tracking branch 'origin/master' into feature/pkg 2022-11-28 09:14:40 +01:00
Gerd Möllmann
e148d8c49e Merge remote-tracking branch 'origin/master' into feature/pkg 2022-11-22 09:19:06 +01:00
Gerd Möllmann
545cf39307 Merge branch 'master' into feature/pkg 2022-11-14 08:04:22 +01:00
Gerd Möllmann
1a235a2fd6 Improve the writeup a bit 2022-10-31 07:57:17 +01:00
Gerd Möllmann
713aed3058 Some additions to notes 2022-10-29 15:05:42 +02:00
Gerd Möllmann
403f69511a Fix byte-compiler warnings in tests
* test/src/pkg-tests.el (pkg-tests-*package*): Fix empty let.
(pkg-tests-use-package): Make local var status ignored.
2022-10-29 14:26:28 +02:00
Gerd Möllmann
9b7f39026f Merge remote-tracking branch 'origin/master' into feature/pkg 2022-10-29 14:10:17 +02:00
Gerd Möllmann
7da73fea98 Improve notes 2022-10-29 11:40:41 +02:00
Gerd Möllmann
a8674a4b29 Improve check for binding etc *package*
* src/pkg.c (Fwatch_earmuffs_package): Check the makunbound case specially.
(syms_of_pkg): Remove duplicate code.
* test/src/pkg-tests.el (pkg-tests-*package*): Add tests.
2022-10-28 15:38:36 +02:00
Gerd Möllmann
a94690e6b5 Add a test
* test/src/pkg-tests.el (pkg-tests-*package*): Test that *package*
cannot be bound to a non-package.
2022-10-28 08:19:20 +02:00
Gerd Möllmann
6346fc7829 Prevent dangerous bindings of *package*
* src/pkg.c (Fwatch_earmuffs_package): New function.
(init_pkg_once): DEFSYM.
(syms_of_pkg): Add variable watcher to *package*.
2022-10-27 15:53:28 +02:00
Gerd Möllmann
160dcd51d0 First traces of defpackage
* lisp/emacs-lisp/pkg.el (pkg--ensure-symbol): New function.
(do-external-symbols): Prevent byte-compiler warnings.
(pkg-defpackage): New.
(defpackage): New.
2022-10-27 14:55:29 +02:00
Gerd Möllmann
ec4619747a Minor improvements in pkg.el
* lisp/emacs-lisp/pkg.el (register-package): Add autoload cookie.
(unregiter-package): New function.
(use-package): Add doc string.
(unuse-package): Add doc string.
(in-package*): Change doc string.
2022-10-27 14:20:53 +02:00
Gerd Möllmann
9d7207bbef Minto cleanup in pkg.el
* lisp/emacs-lisp/pkg.el (pkg--check-name-conflicts): Removed.
(pkg--add-to-registry): Removed.
(register-package): Add code of the removed functions.
(rename-package): Use register-package.
2022-10-27 14:12:20 +02:00
Gerd Möllmann
93d4797345 Allow experimenting with in-package
* lisp/emacs-lisp/pkg.el (in-package*): New interactive function.
2022-10-27 10:50:51 +02:00
Gerd Möllmann
40901257ce Make symbols in Emacs package external by default
* src/pkg.c (pkg_intern_symbol1): If package equals Vemacs_package,
make symbol externally visible.
2022-10-26 15:41:52 +02:00
Gerd Möllmann
29321aeb89 Add user package
* src/pkg.c (init_pkg_once): New Vemacs_user_package.
(syms_of_pkg): DEFVAR_LISP it.
2022-10-26 15:30:29 +02:00
Gerd Möllmann
c95a7090fe Reading qualified symbols
* src/pkg.c (pkg_qualified_symbol): Intern x::y in x.
* test/src/pkg-tests.el (pkg-tests-read): New.
2022-10-26 14:57:01 +02:00
Gerd Möllmann
5b6ca7fe73 Add :register to make-package
* lisp/emacs-lisp/pkg.el (make-package): Add keyword argument
:register.  If true, add new package to package registry.
* test/src/pkg-tests.el (pkg-tests-make-package): Extend.
2022-10-26 14:15:36 +02:00
Gerd Möllmann
0d6677f04e Add register-package
* lisp/emacs-lisp/pkg.el (register-package): New function.
2022-10-26 14:05:01 +02:00
Gerd Möllmann
ed2eeee538 Make *pacakge* buffer-local
* src/pkg.c (syms_of_pkg): Use Fmake_variable_buffer_local
for Qearmuffs_package.
2022-10-26 13:54:14 +02:00
Gerd Möllmann
08bff31081 Prevent accidentally unregistering packages
* lisp/emacs-lisp/pkg.el (pkg--remove-from-registry): Check
for package being eq to a registered package.
2022-10-25 14:04:36 +02:00
Gerd Möllmann
ab77d86bc3 Some tests commented out
These leaves a failing test esh-var-tests, which is broken in
master.

* test/lisp/emacs-lisp/gv-tests.el (gv-plist-get): Don't make the
implicit assumption that keyword names contain colons.
* test/src/fns-tests.el (test-plist): Same.
2022-10-25 13:33:37 +02:00
Gerd Möllmann
b5099948bc Merge remote-tracking branch 'origin/master' into feature/pkg 2022-10-25 10:31:23 +02:00
Gerd Möllmann
2b5127902d Fix byte-compiler warning in do-symbols
* lisp/emacs-lisp/pkg.el (do-symbols): Make VAR used when evaluating
RESULT-FORM.
2022-10-25 09:55:56 +02:00
Gerd Möllmann
c0bd4f3979 Fix warnings in pkg.el 2022-10-25 09:31:58 +02:00
Gerd Möllmann
7a1eba3576 Reset symbol home packages
* lisp/emacs-lisp/pkg.el (delete-package): Set the package of
symbols whose home package is the deleted package to nil.
* test/src/pkg-tests.el (pkg-tests-delete-package):
(pkg-tests-use-package): Modify because we don't have export yet.
2022-10-25 09:02:52 +02:00
Gerd Möllmann
3c5c210808 lkjlkj
* src/pkg.c (pkg_find_symbol): Simplify.
(Fpackage_percent_set_name): Prevent changing the name of standard
packages.
(Fpackage_percent_set_symbol_package): Allow nil for packages.
2022-10-25 08:48:21 +02:00
Gerd Möllmann
27c86f5e2a Print symbols habing a deleted home package
This can't happen in normal circumstances, but it might while
working on the package implementation itself.

* src/print.c (print_symbol): Handle symbol-packages that are
deleted, that is have a nil home package.
* src/lisp.h (PACKAGE_USE_LIST): New macro.
2022-10-25 08:47:41 +02:00
Gerd Möllmann
41042ad3a2 Fix error with ImageMagick
* src/image.c (imagemagick_filename_hint): Don't assume QCformat
is available.
2022-10-24 18:37:37 +02:00
Gerd Möllmann
0d16f57476 shodow
* lisp/emacs-lisp/pkg.el (package-shadowing-symbols): Implement.
(shadow): Implement.
* src/pkg.c (Fpackage_percent_set_symbol_package): New function.
(syms_of_pkg): defsubr it.
* test/src/pkg-tests.el (pkg-tests-use-package): Fix byte compiler
warning.
2022-10-24 15:39:05 +02:00
Gerd Möllmann
c8d6819512 do-symbols, do-external-symbols, do-all-symbols
* lisp/emacs-lisp/pkg.el (do-symbols): New macro.
(do-external-symbols): New macro.
(do-all-symbols): New macro.
2022-10-24 13:32:20 +02:00
Gerd Möllmann
a2f9aa8e56 Prepare for testing find-symbol
* src/pkg.c (pkg_find_symbol1): Remove.
(pkg_find_symbol): Lookup symbols differently.
* lisp/emacs-lisp/pkg.el: Prepare for find-symbol tests.
* test/src/pkg-tests.el (pkg-tests-use-package): New.
2022-10-24 10:59:13 +02:00
Gerd Möllmann
72279265b0 More work on Lisp and tests 2022-10-23 13:21:25 +02:00
Gerd Möllmann
15c813b00a Ongoing work on the Lisp side and tests 2022-10-23 12:21:55 +02:00
Gerd Möllmann
89114e37f6 Uncomment tests after fixing bug#58714 2022-10-23 10:25:33 +02:00
Gerd Möllmann
c9625d96b4 Fix &key parameters called without arguments (bug#58714)
* lisp/emacs-lisp/cl-macs.el (cl--do-arglist): Check for missing
argument.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-&key-arguments): New test.
2022-10-23 10:14:10 +02:00
Gerd Möllmann
a63b04582c One more place with ":..." in C strings
* src/font.c (font_unparse_fcname): Use LISP_SYMBOL_NAME.
(font_filter_properties): Use LISP_SYMBOL_NAME.
2022-10-23 09:40:44 +02:00
Gerd Möllmann
b7b18f4768 Fix error opening Gnus gmail imap connection
The error is caused by comparing names of (possibly) keyword symbols
with a table of symbols names containing ":" for symbol names.

* src/process.c (set_socket_option): Use LISP_SYMBOL_NAME.
2022-10-23 09:21:30 +02:00
Gerd Möllmann
ad00b68fd8 Fix some pkg-tests
Don't define tests that consist of should nil only.  Don't assume
packages are registered by make-package.
2022-10-22 15:23:30 +02:00
Gerd Möllmann
06fa6b1e39 Fixes in package functions
* lisp/emacs-lisp/pkg.el (pkg-stringify-names): De-duplicate names.
(delete-package): Unregister package.
2022-10-22 15:21:40 +02:00
Gerd Möllmann
f54440761b Improve Lisp interface on the C side of packages
* src/pkg.c (Fpackage_percent_set_name): Allow nil as name.
(Fpackage_percent_register): Return the package.
2022-10-22 15:20:46 +02:00
Gerd Möllmann
9319a2df89 Expose package-%register to Lisp
* src/pkg.c (Fpackage_percent_register): New DEFUN.
(syms_of_pkg): defsubr it.
2022-10-22 13:06:57 +02:00
Gerd Möllmann
93b101a7b9 Mark module--test-assertions--call-emacs-from-gc unstable
This test succeeds for me with --enable-checking and fails otherwise
with a segfault.  See also comment there.

* test/src/emacs-module-tests.el
(module--test-assertions--call-emacs-from-gc): Mark unstable
if feature symbol-packages is present.
2022-10-22 12:50:56 +02:00
Gerd Möllmann
395c5d1c2f Remove an invalid eassert
* src/pkg.c (pkg_emacs_intern): Don't assert that symbol names
can never start with a colon.
2022-10-22 12:37:17 +02:00
Stefan Kangas
940722fdfc Add tests for packagep and package-name
* test/src/pkg-tests.el (pkg-tests-packagep)
(pkg-tests-package-name): New tests.
(pkg-tests-list-all-packages): Expand test.
2022-10-22 11:48:20 +02:00
Stefan Kangas
9d35b05ccb Fix cl-intern/cl-unintern tests
* test/src/pkg-tests.el (pkg-tests-cl-intern)
(pkg-tests-cl-unintern): Fix tests.
2022-10-22 11:23:33 +02:00
Stefan Kangas
416af60370 * src/lisp.h (pkg_error): Fix GCC warning in declaration. 2022-10-22 11:23:33 +02:00
Gerd Möllmann
647046687a Fix priting of :1
* src/print.c (print_symbol_name, print_symbol): Don't check for
symbol names looking like a number when we have already printed a
package prefix.
* test/src/editfns-tests.el (format-%s-keywords): Test for :1.
2022-10-22 09:26:07 +02:00
Gerd Möllmann
7e336b4e76 Make format %s for keywords compatible
* src/editfns.c (styled_format): Use LISP_SYMBOL_NAME.
2022-10-22 08:48:02 +02:00
Gerd Möllmann
24fa8e8e8a Add test for format %s with keywords
* test/src/editfns-tests.el (format-%s-keywords): New test.
2022-10-22 08:29:48 +02:00
Gerd Möllmann
048aa627e4 Make lisp/progmodes/elisp-mode-tests succeed
Shorthands are not supported with packages.  Add :expected-result
accordingly.

* test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-read-buffer):
(elisp-shorthand-read-from-string):
(elisp-shorthand-load-a-file):
(elisp-shorthand-byte-compile-a-file):
(elisp-shorthand-completion-at-point):
(elisp-shorthand-escape):
(elisp-dont-shadow-punctuation-only-symbols): Expect to fail
if (featurep 'symbol-packages).
2022-10-21 17:35:56 +02:00
Gerd Möllmann
a84e581b71 Provide 'symbol-packages'
* src/pkg.c (init_pkg_once): DEFSYM Qsymbol_packages.
(syms_of_pkg): Fprovide it.
2022-10-21 17:19:12 +02:00
Gerd Möllmann
715c76f3c6 Fixes for minibuf-tests
This was a remnant of a time when I made obarrays packages.

* src/minibuf.c (Ftry_completion): Handle case collection being obarray.
(Fall_completions): Same.
(Ftest_completion): And same again.
2022-10-21 16:57:20 +02:00
Gerd Möllmann
d6d92270be Fixes for obarray-tests
* src/pkg.c (pkg_emacs_unintern): Take args, and return a value
consistent with traditional unintern.
2022-10-21 16:14:48 +02:00
Gerd Möllmann
c2d5866345 Fix printing of empty keywords
* src/print.c (print_symbol): Don't print ## for keywords with
empty symbol name.
2022-10-21 13:55:06 +02:00
Gerd Möllmann
ec0959f516 print-tests failure for esoteric symbols
* src/print.c (print_symbol_name): Fix printing of symbols that
look like numbers.
2022-10-21 13:32:55 +02:00
Gerd Möllmann
671078f30f print-test fixes
* src/print.c (print_symbol): Fix printing of empty symbol names
to be compatible.
2022-10-21 13:23:06 +02:00
Gerd Möllmann
a93ec52542 Work on Lisp interface 2022-10-21 06:14:52 +02:00
Gerd Möllmann
4d4690f8cf Handle keywords in image specs
* src/image.c (parse_image_spec): Don't assume that keywords have
a ':' in their symbol name.
2022-10-20 19:04:11 +02:00
Gerd Möllmann
74da61ff09 Remove a call to pkg_break 2022-10-20 19:03:17 +02:00
Gerd Möllmann
cc6095482b Add pkg_set_status and Lisp defun for it 2022-10-20 15:38:39 +02:00
Gerd Möllmann
62582ea927 Fix completion for new symbol table layout 2022-10-20 14:38:21 +02:00
Gerd Möllmann
51cd0e05d6 De-duplicate packages for mapatoms 2022-10-20 14:18:39 +02:00
Gerd Möllmann
9ab00f542f Introduce PACKAGE_NAMEX
PACKAGE_NAME Is already taken :-(.
2022-10-20 13:06:46 +02:00
Gerd Möllmann
55cef2c78c Some cleanup in pkg.c and lisp.h 2022-10-20 12:59:27 +02:00
Gerd Möllmann
7acb6c5ca1 Intrdduce pkg_find_symbol 2022-10-20 11:26:29 +02:00
Gerd Möllmann
6b0304f2dd Print package prefixes right 2022-10-20 10:21:55 +02:00
Gerd Möllmann
df9417ac57 Remove Lisp_Symbol::external 2022-10-20 10:21:34 +02:00
Gerd Möllmann
0f4b419fa3 Remove unused function prototype from lisp.h 2022-10-20 09:19:17 +02:00
Gerd Möllmann
73b617eaa9 Change package symbol table layout
The symbol table now stored symbol as key, and symbol
status (:internal, :external) as values.

Quite some changes due to that.
2022-10-20 09:16:56 +02:00
Gerd Möllmann
051a17f540 Fix some warnings 2022-10-19 17:00:35 +02:00
Gerd Möllmann
07f0b758ae hash_remove_from_table returns bool
* src/fns.c (hash_remove_from_table): Return true if something was
deleted.
* src/lisp.h: Change declaration.
2022-10-19 16:47:31 +02:00
Gerd Möllmann
1424d2c6b7 Fix intern-soft
* src/pkg.c (conflicting_package): Remove unused function.
(pkg_emacs_intern_soft): If checking a symbol, return non-nil only if
we found exactly that symbol.
2022-10-19 16:34:50 +02:00
Gerd Möllmann
76d59f8a03 Fix missing ')' 2022-10-19 16:34:20 +02:00
Gerd Möllmann
90c070fec6 Restore obarray.el to return vectors 2022-10-19 16:15:08 +02:00
Gerd Möllmann
132f070747 New predefined hash table test for string-equal
* src/fns.c (cmpfn_string_equal): New.
(hashfn_string_equal): New.
(hashtest_string_equal): New.
(Fmake_hash_table): Recognize test type Qstring_equal.
(syms_of_fns): DEFSYM Qstring_qual.
2022-10-19 07:27:52 +02:00
Gerd Möllmann
9a263a0782 Move more package stuff to Lisp 2022-10-19 07:05:38 +02:00
Gerd Möllmann
fc936470cd Move make-package to Lisp
* lisp/emacs-lisp/pkg.el: Implement make-package.
* lisp/obarray.el (obarray-make): Use make-%package.
* src/pkg.c: Various changes to move make-package to Lisp.
2022-10-18 16:49:47 +02:00
Gerd Möllmann
c4922c4f08 Make faces work with keywords not having : in symbol names
* src/xfaces.c (set_lface_from_font): Use LISP_SYMBOL_NAME.
(merge_face_vectors): Use LISP_SYMBOL_NAME.
(merge_face_ref): Use SYMBOL_KEYWORD_P instead of checking ':'.
(gui_supports_face_attributes_p): Use LISP_SYMBOL_NAME.
2022-10-18 15:09:26 +02:00
Gerd Möllmann
8a59cc12da Add amcros for keyword symbols
* src/lisp.h (SYMBOL_KEYWORD_P): Returns true if symbol is a keyword.
(LISP_SYMBOL_NAME): Basically the same as Fsymbol_name, a shortcut.
* src/data.c (Fsymbol_name): Use SYMBOL_KEYWORD_P.
* src/pkg.c (pkg_intern_keyword): Use SYMBOL_KEYWORD_P.
2022-10-18 15:07:47 +02:00
Gerd Möllmann
0a345a1181 Make internals of Lisp_Package visible to Lisp
Done to be able to do as much as possible from Lisp.

* src/lisp.h (Lisp_Package): Rename used_packages to use_list.
* src/pkg.c: Rename used_packages to use_list.
(Fpackage_percent_name): (Fpackage_percent_set_name):
(Fpackage_percent_nicknames):
(Fpackage_percent_set_nicknames):
(Fpackage_percent_use_list):
(Fpackage_percent_set_use_list):
(Fpackage_percent_shadowing_symbols):
(Fpackage_percent_set_shadowing_symbols):
(Fpackage_percent_symbols): New functions for getting and setting
internals of Lisp_Package.
(syms_of_pkg): defsubr them.
2022-10-18 14:36:01 +02:00
Gerd Möllmann
8ca1c93b67 Work on defpackage 2022-10-18 14:00:00 +02:00
Gerd Möllmann
9e3cfff902 Increase default symbol-table sizes
* src/pkg.c (Fpackage_symbols): New function.
(syms_of_pkg): defsubr it.
(init_pkg_once): Up symbol table sizes.
2022-10-18 12:49:33 +02:00
Gerd Möllmann
c98a69d650 DEFVAR some variables
* src/lisp.h: Remove extern declarations for some vars.
* src/pkg.c (syms_of_pkg): DEFVAR_LISP_NOPRO some variables.
*package*, *package-registry*, *emacs-package*,
*keyword-package*, package-prefixes
2022-10-18 12:33:35 +02:00
Gerd Möllmann
4f7c171fb4 Support specifying package size 2022-10-18 09:52:41 +02:00
Gerd Möllmann
e9b97a1f7d Revert some unimportant changes 2022-10-18 08:55:11 +02:00
Gerd Möllmann
13010d7bd0 Partially revert "Remove obarrays" 2022-10-18 08:35:41 +02:00
Gerd Möllmann
b6489ecb72 More scribbling 2022-10-18 08:31:44 +02:00
Gerd Möllmann
77543a203a Revert "Dpn't assume symbol-name of keywords starts with colon"
This reverts commit bb6b5db2b7.
2022-10-18 08:31:19 +02:00
Gerd Möllmann
6a8c172927 Add cö-symbol-name 2022-10-18 08:28:28 +02:00
Gerd Möllmann
d374cb202a Revert "Use make-package instead of make-vector"
This reverts commit 072e89afa1.
2022-10-18 08:28:13 +02:00
Gerd Möllmann
e1a730849e Fix printing uninterned symbols 2022-10-18 07:59:29 +02:00
Gerd Möllmann
c025885c33 symbol-name returning ':' for keywords
* src/data.c (Fsymbol_name): Return a name starting with ':' for
keywords.
2022-10-18 07:58:45 +02:00
Gerd Möllmann
bbb2609103 Recognize vectors as obarrays
* lisp/obarray.el (obarray-make): Ignore parameter.
(obarray-size): Ignore parameter.
(obarrayp): Accept vectors.
2022-10-17 15:24:35 +02:00
Gerd Möllmann
2518bc249c Fix printing symbols 2022-10-17 15:24:21 +02:00
Gerd Möllmann
2030adac1c Fake obarrays 2022-10-17 12:49:47 +02:00
Gerd Möllmann
0976c09890 Fix printing of confusing symbol names 2022-10-17 11:29:56 +02:00
Gerd Möllmann
85c0eb1682 Merge remote-tracking branch 'origin/master' into pkg 2022-10-17 10:12:35 +02:00
Gerd Möllmann
963de7cafe More scribbling 2022-10-17 10:12:07 +02:00
Gerd Möllmann
df1e4c1e51 Allow intern with ":xyz" again 2022-10-17 10:05:50 +02:00
Gerd Möllmann
8561667124 Handle packages in completion
* lisp/minibuffer.el (completion-table-with-context): Add packagep
case.
* src/minibuf.c (Ftry_completion, Fall_completions),
Ftest_completion): Take into account that predicate functions used
with packages are the same that were used for obarrays.
2022-10-17 06:46:16 +02:00
Gerd Möllmann
aaf12c12b6 Some scribbling 2022-10-16 14:13:54 +02:00
Gerd Möllmann
4c1bbd4fd7 intern-soft with ':' trick
* src/lread.c (Fintern): Move everything to pkg.c
* src/pkg.c (pkg_emacs_intern): Handle ':' in symbol names.
(pkg_emacs_intern_soft): Ditto.
2022-10-16 14:10:13 +02:00
Gerd Möllmann
a5f6912c6d Mapatoms differently
Also, assume that in some cases, (intern ":xy") means that old code
wants to intern a keyword.
2022-10-16 09:25:01 +02:00
Gerd Möllmann
bdca01dd38 Workaround for something Stefan missed
See comment there for an explanation.

* src/alloc.c (xmake_pure_vector): Former make_pure_vector.
(init_vectors): Use it to allocate zero_vecgtor.
2022-10-16 08:01:58 +02:00
Stefan Monnier
ea65e35cf3 src/alloc.c: Remove all uses of pure_alloc
First step of removal of the purespace: stop using it.
The more delicate parts are the handling of 0-length strings and
vectors which we used to allocate in purespace but now need to be
allocated elsewhere, but the existing code makes us work harder to
allocate them in the normal way.

* src/alloc.c: Remove all uses of `pure_alloc`.
(init_strings): Alloc empty strings in the normal heap.
(init_vectors): Allocate the zero_vector in the normal heap.
(make_pure_string, make_pure_c_string, pure_cons): Rewrite to create
normal heap objects.
(find_string_data_in_pure, make_pure_float, make_pure_bignum)
(make_pure_vector, purecopy_hash_table): Delete functions.
(purecopy): Return without purecopying.
2022-10-16 07:12:49 +02:00
Gerd Möllmann
2edc30628a Use build_pure_c_string
* src/pkg.c (init_pkg_once): Use build_pure_c_string instead of
build_string.
2022-10-15 15:44:05 +02:00
Gerd Möllmann
aa00af4e17 Consider shorthands out of scope
* lisp/loadup.el ("emacs-lisp/shorthands"): Comment out.
2022-10-15 15:10:36 +02:00
Gerd Möllmann
f6b80ef5a5 Blabla
* src/lread.c (Fintern): Remove comment.
* src/pkg.c (pkg_emacs_intern_soft): Don't assume *package* if
a vector was passed in for a package.  Assert instead elsewhere.
2022-10-15 14:16:27 +02:00
Gerd Möllmann
bb6b5db2b7 Dpn't assume symbol-name of keywords starts with colon
* lisp/emacs-lisp/cl-seq.el (cl--parsing-keywords):
Don't substring the keyword symbol name.
2022-10-15 14:14:57 +02:00
Gerd Möllmann
072e89afa1 Use make-package instead of make-vector
* lisp/cedet/semantic/lex.el (semantic-lex-make-type-table):
Don't use obarray functionality.
2022-10-15 14:13:56 +02:00
Gerd Möllmann
a3f99fde48 Remove Lisp_Symbol::next pointer
* src/lisp.h (struct Lisp_Symbol): Remvoe next field.
(next_free_symbol, set_next_free_symbol): New.
(set_symbol_next): Remove.
* src/alloc.c (init_symbol): symbol_free_list done differently.
* src/pdumper.c (dump_symbol): Don't dump Lisp_Symbol::next.
2022-10-15 13:03:58 +02:00
Gerd Möllmann
513f5a0b90 Remove obarrays
* lisp/emacs-lisp/eldoc.el (eldoc-message-commands): Make a package
instead of an obarray-vector.
* src/doc.c (Fsnarf_documentation): Don't use oblookup.
* src/eval.c (Fsignal): Debuggin helper code.
* src/font.c (font_intern_prop):  Don't use oblookup.
* src/lisp.h (intern_c_string): Delete inline function, use the one
in fread.c.
* src/lread.c: Remove everything realted to obarray, except Vobarray,
which is now set to Vemacs_package.
* src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion):
Accept packages.
* src/pkg.c: Adapted to other changes.
2022-10-15 13:03:31 +02:00
Gerd Möllmann
2821ca31ae Use packages instead of obarrays in obarray.el 2022-10-14 16:21:03 +02:00
Gerd Möllmann
62c7059adc Initialize package system earlier 2022-10-14 15:46:22 +02:00
Gerd Möllmann
85bd8cfcdb Mapping over symbols in a package, mapatoms 2022-10-14 13:15:24 +02:00
Gerd Möllmann
d7c793cbbf Don't register packages in make-package 2022-10-14 12:57:45 +02:00
Gerd Möllmann
0e5323c908 Remove Lisp_Symbol::interned 2022-10-14 10:51:50 +02:00
Gerd Möllmann
8615f5b048 Can now pdumg withput warnings from cl-defstruct 2022-10-14 10:42:18 +02:00
Gerd Möllmann
e2b79c2c5a Revert the escaping of symbol names in lisp files 2022-10-13 13:38:18 +02:00
Gerd Möllmann
7ecfc3ca69 Can now pdump 2022-10-13 13:17:29 +02:00
Gerd Möllmann
adf7b760f2 More symbol reading 2022-10-12 15:45:56 +02:00
Gerd Möllmann
b3cdb8a3d3 Intern keywords differently
Instead of something like (intern (format ":%s" ...)) do
(intern (format "%s" :keyword).  Likewise in C.
2022-10-12 14:09:33 +02:00
Gerd Möllmann
3e29407122 And more fixes 2022-10-11 13:58:32 +02:00
Gerd Möllmann
2ed1ac6639 Fixing stuff 2022-10-11 11:49:47 +02:00
Gerd Möllmann
b5c199b118 Check for keywords differently 2022-10-10 14:13:36 +02:00
Gerd Möllmann
47a2e75c1c Read symbols differently 2022-10-10 14:05:14 +02:00
Gerd Möllmann
02e1214f23 More stuff in pkg.c 2022-10-10 14:03:18 +02:00
Gerd Möllmann
06cfa629a5 Print symbols differently 2022-10-10 14:02:26 +02:00
Gerd Möllmann
a19917468c Don't fix symbols here 2022-10-10 14:01:19 +02:00
Gerd Möllmann
f45b266d0e Don't use symbols that look package-qualified 2022-10-10 13:58:31 +02:00
Gerd Möllmann
1d02e7a48b Add xprint command 2022-10-10 13:52:26 +02:00
Gerd Möllmann
54a08db92b Basic functionality for packages
Lisp packages exist and can be dumped and loaded.  Two standard
packages "emacs" and "keyword".  Some package functions and variables
of CLHS.

Symbols have a package slot.  Built-in symbols before loaodup get
packages emacs or keyword.

Dumping and loading.

Some tests.

* src/pkg.c: New file for Lisp packages.
* src/Makefile.in (base_obj): Add pkg.c.
* test/src/pkg-tests.el: New file.
* src/lisp.h: Add Lisp_Package.
* etc/emacs_lldb.py: Add Lisp_Package.
* src/data.c (Ftype_of): Handle packages.
(syms_of_data): Add Qpackage.
* src/emacs.c (main): Initialize pkg.c, fix built-in symbols.
* src/fns.c (check_hash_table, get_key_arg): Make externally visible.
* src/pdumper.c (dump_vectorlike): Handle packages.
* src/print.c: Print packages, print symbols with packages.
2022-10-08 15:39:42 +02:00
3391 changed files with 37433 additions and 174359 deletions

View file

@ -21,9 +21,6 @@
(electric-quote-comment . nil)
(electric-quote-string . nil)
(mode . bug-reference-prog)))
(c-ts-mode . ((c-ts-mode-indent-style . gnu)
(indent-tabs-mode . t)
(mode . bug-reference-prog)))
(log-edit-mode . ((log-edit-font-lock-gnu-style . t)
(log-edit-setup-add-author . t)
(vc-git-log-edit-summary-target-len . 50)))

2
.gitattributes vendored
View file

@ -1,6 +1,6 @@
# Attributes of Emacs files in the Git repository.
# Copyright 2015-2023 Free Software Foundation, Inc.
# Copyright 2015-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

2
.gitignore vendored
View file

@ -1,6 +1,6 @@
# Files that Git should ignore in the Emacs source directory.
# Copyright 2009-2023 Free Software Foundation, Inc.
# Copyright 2009-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,4 +1,4 @@
# Copyright (C) 2021-2023 Free Software Foundation, Inc.
# Copyright (C) 2021-2022 Free Software Foundation, Inc.
#
# This file is part of GNU Emacs.
#

View file

@ -1,6 +1,3 @@
Copyright (C) 2006-2023 Free Software Foundation, Inc.
See the end of the file for license conditions.
* How developers contribute to GNU Emacs
Here is how software developers can contribute to Emacs. (Non-developers: see
@ -18,7 +15,7 @@ To configure Git for Emacs development, you can run the following:
The following shell commands then build and run Emacs from scratch:
git clone https://git.savannah.gnu.org/git/emacs.git
git clone git://git.sv.gnu.org/emacs.git
cd emacs
./autogen.sh
./configure
@ -110,7 +107,7 @@ admin/notes/bug-triage.
Any change that matters to end-users should have an entry in etc/NEWS.
Try to start each NEWS entry with a sentence that summarizes the entry
and takes just one line -- this will allow reading NEWS in Outline
and takes just one line -- this will allow to read NEWS in Outline
mode after hiding the body of each entry.
Doc-strings should be updated together with the code.
@ -123,7 +120,7 @@ Think about whether your change requires updating the manuals. If you
know it does not, mark the NEWS entry with "---". If you know
that *all* the necessary documentation updates have been made as part
of your changes or those by others, mark the entry with "+++".
Otherwise, do not mark it.
Otherwise do not mark it.
If your change requires updating the manuals to document new
functions/commands/variables/faces, then use the proper Texinfo
@ -321,7 +318,7 @@ them right the first time, so here are guidelines for formatting them:
** Committing your changes.
When you commit changes, Git invokes several scripts that test the
commit for validity, and may abort the commit if some of the tests
commit for validity, and may abort the commit of some of the tests
fail. These scripts live in the '.git/hooks/' subdirectory of the
top-level directory of the repository, and they perform the following
tests:
@ -400,7 +397,7 @@ the commit to master, by starting the commit message with "Backport:".
The gitmerge function excludes these commits from the merge to the master.
Some changes should not be merged to master at all, for whatever
reason. These should be marked by including something like "Do not
reasons. These should be marked by including something like "Do not
merge to master" or anything that matches gitmerge-skip-regexp (see
admin/gitmerge.el) in the commit message.
@ -449,8 +446,8 @@ files intended for use only with Emacs version 24.5 and later.
*** Useful files in the admin/ directory
See all the files in 'admin/notes/*'. In particular, see
'admin/notes/newfile' and 'admin/notes/repo'.
See all the files in admin/notes/* . In particular, see
admin/notes/newfile, see admin/notes/repo.
The file admin/MAINTAINERS records the areas of interest of frequent
Emacs contributors. If you are making changes in one of the files

View file

@ -4302,7 +4302,7 @@
(install-arch-indep): Don't install-etc for self-contained ns builds.
* configure.in (GCC_TEST_OPTIONS, NON_GCC_TEST_OPTIONS) <darwin>:
No longer unconditionally add /sw directories. (Bug#2280)
No longer unconditonally add /sw directories. (Bug#2280)
* Makefile.in (install-arch-dep): Depend on install-arch-indep.
(install-arch-indep): Depend on install-leim.
@ -14700,7 +14700,7 @@
;; coding: utf-8
;; End:
Copyright (C) 1993-1999, 2001-2023 Free Software Foundation, Inc.
Copyright (C) 1993-1999, 2001-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

View file

@ -111,7 +111,7 @@
2017-03-21 Noam Postavsky <npostavs@gmail.com>
Narrow scope of modification hook re-enabling in org-src fontification
Narrow scope of modification hook renabling in org-src fontification
Modification hooks should be enabled while modifying text in the
org-src temp buffer, but in 2017-01-29 "Call modification hooks in
@ -11843,7 +11843,7 @@
2016-01-05 Alan Mackenzie <acm@muc.de>
Make C++ buffers writable when writing their initial text properties.
Make C++ buffers writeable when writing their initial text properties.
This is a correction to yesterday's CC Mode patch.
@ -35787,7 +35787,7 @@ See ChangeLog.1 for earlier changes.
;; coding: utf-8
;; End:
Copyright (C) 2015-2023 Free Software Foundation, Inc.
Copyright (C) 2015-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

View file

@ -1,431 +1,3 @@
2022-02-18 Stefan Kangas <stefankangas@gmail.com>
* Version 28.3 released.
2023-02-17 Stefan Kangas <stefankangas@gmail.com>
Update HISTORY for Emacs 28.3
2023-02-17 Stefan Kangas <stefankangas@gmail.com>
Bump Emacs version to 28.3
* README:
* configure.ac:
* msdos/sed2v2.inp:
* nt/README.W32: Bump Emacs version to 28.3.
2023-02-17 Stefan Kangas <stefankangas@gmail.com>
Update NEWS for Emacs 28.3
* etc/NEWS: Update for Emacs 28.3.
2023-02-17 Stefan Kangas <stefankangas@gmail.com>
Update ChangeLog and AUTHORS for Emacs 28.3
* ChangeLog.3:
* etc/AUTHORS: Update for Emacs 28.3.
2023-02-17 Xi Lu <lx@shellcodes.org>
Fix etags local command injection vulnerability
* lib-src/etags.c: (escape_shell_arg_string): New function.
(process_file_name): Use it to quote file names passed to the
shell. (Bug#59817)
(cherry picked from commit 01a4035c869b91c153af9a9132c87adb7669ea1c)
2023-02-17 Xi Lu <lx@shellcodes.org>
Fixed ctags local command execute vulnerability
* lib-src/etags.c:
(clean_matched_file_tag): New function
(do_move_file): New function
(readline_internal):
Add `leave_cr` parameter, if true, include the \r character
* test/manual/etags/CTAGS.good_crlf: New file
* test/manual/etags/CTAGS.good_update: New file
* test/manual/etags/crlf: New file
* test/manual/etags/Makefile: Add `ctags -u` test cases
(cherry picked from commit d48bb4874bc6cd3e69c7a15fc3c91cc141025c51)
2023-02-17 Xi Lu <lx@shellcodes.org>
Fix ruby-mode.el local command injection vulnerability (bug#60268)
* lisp/progmodes/ruby-mode.el
(ruby-find-library-file): Fix local command injection vulnerability.
(cherry picked from commit 9a3b08061feea14d6f37685ca1ab8801758bfd1c)
2023-02-17 Xi Lu <lx@shellcodes.org>
Fix htmlfontify.el command injection vulnerability.
* lisp/htmlfontify.el (hfy-text-p): Fix command injection
vulnerability. (Bug#60295)
(cherry picked from commit 1b4dc4691c1f87fc970fbe568b43869a15ad0d4c)
2022-12-19 Eli Zaretskii <eliz@gnu.org>
Fix storing email into nnmail by Gnus
Backporting suggested by Florian Weimer, since this is
a denial-of-service issue.
* lisp/gnus/nnml.el (nnml--encode-headers): Wrap
'rfc2047-encode-string' calls with 'ignore-errors', to avoid
disrupting email workflows due to possibly-invalid headers.
Reported by Florian Weimer <fweimer@redhat.com>.
(cherry picked from commit 23f7c9c2a92e4619b7c4d2286d4249f812cd695d)
2022-11-14 Robert Pluim <rpluim@gmail.com>
Explain how to bind keys to non-ASCII sequences
* doc/emacs/custom.texi (Init Rebinding): Explain how to use `kbd'
when binding keys to non-ASCII sequences.
2022-11-12 Eli Zaretskii <eliz@gnu.org>
Document that 'transient-mark-mode' is off in batch mode
* doc/emacs/mark.texi (Mark, Disabled Transient Mark): Document,
belatedly, that 'transient-mark-mode' is turned on by default only
in interactive sessions. (Bug#59201)
2022-10-14 Eli Zaretskii <eliz@gnu.org>
Document how to control where the *.eln files are written
* doc/lispref/compile.texi (Native Compilation): Document the
trick of pointing $HOME to a non-existent directory.
(Native-Compilation Variables): Document the role of
'native-comp-eln-load-path' in determining where *.eln files are
written.
2022-10-14 Robert Pluim <rpluim@gmail.com>
Add cross-reference to alternative syntaxes for Unicode
These alternative syntaxes allow you to specify Unicode codepoints
using only ASCII, which helps avoid decoding issues.
* doc/emacs/custom.texi (Init Non-ASCII): Add cross reference to
"General Escape Syntax" in the Emacs Lisp Reference Manual.
2022-10-07 Lars Ingebrigtsen <larsi@gnus.org>
Update name of hs-mouse-toggle-hiding in Emacs manual
* doc/emacs/programs.texi (Hideshow): Update the name of
hs-mouse-toggle-hiding (bug#58331).
2022-10-06 Stefan Kangas <stefankangas@gmail.com>
Fix typo in `(emacs) Lisp Doc'
* doc/emacs/programs.texi (Lisp Doc): Fix reference to
'eldoc-echo-area-display-truncation-message'. (Bug#58324)
2022-10-06 Stefan Kangas <stefankangas@gmail.com>
Fix references to 'default-indent-new-line'
* doc/emacs/programs.texi (Comment Commands)
(Multi-Line Comments): Fix references to
'default-indent-new-line'. (Bug#58325)
2022-10-04 Andreas Schwab <schwab@linux-m68k.org>
* src/emacs.c (load_pdump): Propery handle case when executable
wasn't found.
2022-10-04 Eli Zaretskii <eliz@gnu.org>
Avoid assertion violations in STRING_CHAR
* src/xdisp.c (handle_composition_prop):
* src/editfns.c (styled_format): Don't call 'STRING_CHAR' on
unibyte strings. This avoids assertion violation in
'string_char_and_length'.
(cherry picked from commit d52d6e1e106117eb4bba81a65e256e2e793037b6)
2022-10-03 Stefan Kangas <stefankangas@gmail.com>
Fix documentation of 'TAB' in cc-mode
* doc/emacs/programs.texi (C Indent): Fix documentation of 'TAB'
in cc-mode. (Bug#58258)
2022-10-03 Stefan Kangas <stefankangas@gmail.com>
Fix 'org-export-dispatch' command name in manual
* doc/emacs/text.texi (Org Authoring): Fix 'org-export-dispatch'
command name. (Bug#58260)
2022-10-02 Andreas Schwab <schwab@linux-m68k.org>
* src/emacs.c (load_pdump): Fix use of xpalloc.
2022-10-02 Eli Zaretskii <eliz@gnu.org>
Avoid assertion violation in 'xpalloc'
* src/emacs.c (load_pdump): Ensure the 3rd argument of xpalloc is
always positive. (Bug#58232)
2022-09-30 Michael Albinus <michael.albinus@gmx.de>
Fix connection property incompatibility in Tramp
* lisp/net/tramp.el (tramp-get-remote-tmpdir): Remove obsolete
connection property "tmpdir". (Bug#57800)
2022-09-29 Lars Ingebrigtsen <larsi@gnus.org>
Update some Gnus documentation in the Emacs manual
* doc/emacs/misc.texi (Gnus Group Buffer, Gnus Summary Buffer):
Update documentation (bug#58145).
2022-09-28 Eli Zaretskii <eliz@gnu.org>
Clarify image file search
* doc/lispref/display.texi (Defining Images, Image Descriptors):
* lisp/image.el (create-image): Clarify that non-absolute image
files are searched along 'image-load-path'. (Bug#52931)
2022-09-28 Stefan Kangas <stefankangas@gmail.com>
.mailcap: Some additional fixes.
2022-09-28 Eli Zaretskii <eliz@gnu.org>
Avoid assertion violations in 'pop_it'
* src/xdisp.c (pop_it): Avoid assertion violations when handling
lists or vectors of display properties. (Bug#58122)
2022-09-28 Stefan Kangas <stefankangas@gmail.com>
Add .mailmap for proper git log output
This file is used to fix a few misspelled names in various git
listings (e.g., "git log"). This can be used to fix incorrect
attribution, poor display, or names showing up more than once.
It also allows updating an old email addresses to a new one.
See "man git-shortlog" for more information on the format.
* .mailmap: New file.
2022-09-27 Stefan Kangas <stefankangas@gmail.com>
* doc/emacs/ack.texi (Acknowledgments): Update maintainers.
2022-09-24 Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/progmodes/hideshow.el (hs-toggle-hiding): Fix `interactive` form
This fixes the first part of bug#52092, which is a regression
introduced by commit d0e9113de97.
2022-09-23 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Fix shaping with bitmap-only fonts on HarfBuzz 5.2.0 (Bug#57976)
* src/ftcrfont.c (ftcrhbfont_begin_hb_font): Undo last change for
HarfBuzz 5.2.0.
2022-09-20 Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/text-modes/tex-mode.el (tex-mode): Fix AUCTeX regression
As discussed in
https://lists.gnu.org/r/auctex/2022-08/msg00004.html
AUCTeX installs its own advice to redefine `tex-mode`, and that
advice used to take precedence before commit 6075a7c5ae3fa456cd.
2022-09-20 Robert Pluim <rpluim@gmail.com>
Add vc-annotate-switches to manual
* doc/emacs/maintaining.texi (Old Revisions): Add description of
`vc-annotate-switches' and `vc-BACKEND-annotate-switches'.
2022-09-20 Robert Pluim <rpluim@gmail.com>
Remove mention of non-existent `annotate-switches'
* lisp/vc/vc.el (vc-annotate-switches): Remove mention of
`annotate-switches'. As far as I can tell this has never existed in
Emacs.
2022-09-20 Robert Pluim <rpluim@gmail.com>
Mention that src/macuvs.h sometimes needs committing
* admin/notes/unicode: src/macuvs.h is generated, but needs to be
committed sometimes.
2022-09-19 Gerd Möllmann <gerd@gnu.org>
MacOS ld warning from native compilation (bug#57849)
* lisp/emacs-lisp/comp.el (native-comp-driver-options): Add "-Wl,-w"
on Darwin systems.
* etc/NEWS: Describe change.
2022-09-18 Michael Albinus <michael.albinus@gmx.de>
Fix Tramp error with eshell integration
* lisp/net/tramp-integration.el (tramp-eshell-directory-change):
Respect local `default-directory'. (Bug#57556)
2022-09-17 Michael Albinus <michael.albinus@gmx.de>
Sync with Tramp 2.5.3.2. Don't merge with master
* doc/misc/tramp.texi (Android shell setup): Rework.
(Frequently Asked Questions): Improve recommendations for speeding up.
* doc/misc/trampver.texi:
* lisp/net/trampver.el: Change version to "2.5.4-pre".
* lisp/net/tramp-adb.el (tramp-methods): Use "%d".
(tramp-adb-handle-directory-files-and-attributes): Fix "." and
".." in listing.
(tramp-adb-handle-file-attributes)
(tramp-adb-handle-directory-files-and-attributes)
(tramp-adb-handle-file-name-all-completions): Pipe "ls" output
through "cat", in order to avoid quoting special characters.
(tramp-adb-maybe-open-connection): Compute args from `tramp-login-args'.
* lisp/net/tramp-compat.el (tramp-compat-replace-regexp-in-region):
New defalias.
* lisp/net/tramp-gvfs.el (tramp-gvfs-do-copy-or-rename-file):
Adapt check for proper remote command.
* lisp/net/tramp.el (tramp-methods): Adapt docstring.
(tramp-handle-make-process): Check for adb device if indicated.
(tramp-get-remote-tmpdir): Cache result in temporary connection
property.
* test/lisp/net/tramp-tests.el (tramp-test17-insert-directory)
(tramp-test22-file-times, tramp--test-utf8): Adapt tests.
(tramp--test-shell-file-name): Do not depend on `tramp--test-adb-p'.
(tramp-test46-unload): Ignore autoload functions in
`tramp-file-name' structure tests, since `tramp-file-name-handler'
is also autoloaded in Emacs 29.
2022-09-17 Stefan Kangas <stefankangas@gmail.com>
Simplify regexp in make-news-html-file
* admin/admin.el (make-news-html-file): Simplify regexp.
Suggested by Mattias Engdegård <mattiase@acm.org>.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
* admin/admin.el (make-news-html-file): Set id on correct tag.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
Add version headlines to HTML NEWS export
This allows linking to, e.g. "NEWS.28.html#28.1" to go directly to
those release notes.
* admin/admin.el (admin--org-export-headers-format)
(make-news-html-file): Add XX.Y version headlines with an HTML anchor.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
Improve HTML export of NEWS file
* admin/admin.el (admin--org-export-headers-format)
(admin--org-html-postamble): New variables.
(admin--require-external-package): New function.
(make-news-html-file): Improve HTML export.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
Delete "etc/NEWS*.html" from .gitignore
We actually do want to see it when preparing a release, so that we
don't include it in a tarball by mistake.
* .gitignore: Don't ignore "etc/NEWS*.html".
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
Recommend NonGNU ELPA over MELPA
* doc/misc/org.org (Using CDLaTeX to enter math, Footnotes): Recommend
NonGNU ELPA over MELPA.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
Minor doc fixes in picture.el
* lisp/textmodes/picture.el: Improve Commentary.
(picture-forward-column, picture-backward-column)
(picture-move-down, picture-move-up, picture-movement-nw)
(picture-movement-ne, picture-movement-sw, picture-movement-se)
(picture-set-motion, picture-clear-line, picture-newline)
(picture-tab, picture-yank-rectangle)
(picture-yank-rectangle-from-register, picture-insert-rectangle)
(picture-draw-rectangle): Minor doc fixes.
2022-09-16 Stefan Kangas <stefankangas@gmail.com>
* lisp/textmodes/page-ext.el: Improve Commentary.
2022-09-14 Stefan Kangas <stefankangas@gmail.com>
Automate exporting etc/NEWS to HTML
* admin/admin.el (make-news-html-file): New function.
* .gitignore: Ignore generated "etc/NEWS*.html" file.
2022-09-14 Eli Zaretskii <eliz@gnu.org>
* Makefile.in (uninstall): Remove the *.eln files. (Bug#57771)
2022-09-12 Stefan Kangas <stefankangas@gmail.com>
Update HISTORY for Emacs 28.2
* etc/HISTORY: Update for the Emacs 28.2 release.
2022-09-07 Stefan Kangas <stefankangas@gmail.com>
Bump Emacs version to 28.2
* README:
* configure.ac:
* msdos/sed2v2.inp:
* nt/README.W32: Bump Emacs version to 28.2.
2022-09-07 Stefan Kangas <stefankangas@gmail.com>
Update ChangeLog and AUTHORS for Emacs 28.2
* ChangeLog.3:
* etc/AUTHORS:
* etc/NEWS: Update for Emacs 28.2.
2022-09-06 Stefan Kangas <stefankangas@gmail.com>
* doc/misc/idlwave.texi (Troubleshooting): Don't say "Emacsen".
@ -11161,7 +10733,7 @@
Bump lisp/progmodes/project.el version to 0.7.1
Among other things exposes the new project-buffers generic function to
Amont other things exposes the new project-buffers generic function to
ELPA users.
* lisp/progmodes/project.el (Version): Bump to 0.7.1
@ -25646,7 +25218,7 @@
2021-05-12 Richard Stallman <rms@gnu.org>
Little improvements in rmail.el. Recognize encrypted override headers.
Little improvements in rmail.el. Recognize encryped override headers.
* lisp/mail/rmail.el (rmail-simplified-subject): Delete `[External] :'.
(rmail-reply): In encrypted message, search for other header fields
@ -27761,7 +27333,7 @@
2021-04-24 Glenn Morris <rgm@gnu.org>
Simplify top-level Makefile since admin is always included
Simlify top-level Makefile since admin is always included
* Makefile.in (clean_dirs, distclean_dirs, maintainer_clean_dirs):
Add admin directories.
@ -28096,7 +27668,7 @@
* lisp/international/mule-cmds.el (ucs-names):
* lisp/progmodes/ebrowse.el (ebrowse-read):
* test/src/coding-tests.el (benchmark-decoder): Avoid lowering
gc-cons-threshold.
gc-cons-treshold.
2021-04-22 Stefan Kangas <stefan@marxist.se>
@ -46997,7 +46569,7 @@
Fix syntax of symbol and punctuation characters
* lisp/international/characters.el: Adjust syntax of punctuation
and symbol characters to follow that of Unicode properties.
and symbol charcaters to follow that of Unicode properties.
(Bug#44974)
2021-01-02 Andrea Corallo <akrl@sdf.org>
@ -63885,9 +63457,9 @@
2020-09-30 Lars Ingebrigtsen <larsi@gnus.org>
Fix isearch-group-* colors on low-color displays
Fix isearch-group-* colors on low-colour displays
* lisp/isearch.el (isearch-group-1): On low-color displays, just
* lisp/isearch.el (isearch-group-1): On low-colour displays, just
use the normal isearch color (bug#43702).
(isearch-group-2 etc): Ditto.
@ -124256,7 +123828,7 @@
* doc/lispref/text.texi (Special Properties): For the hook property
modification-hooks, state that inhibit-modification-hooks is NOT bound to
non-nil when calling its functions. For the hooks insert-in-front-hooks and
non-nil when calling its functions. For the hooks insert-in-fron-hooks and
insert-behind-hooks, state that that variable does get bound to non-nil.
2019-06-24 Hong Xu <hong@topbug.net>
@ -156973,7 +156545,7 @@
Obsolete Flymake's flymake-diagnostic-types-alist
That variable was an association between symbols and properties,
effectively duplicating symbol's property lists. It is simpler to just
effecively duplicating symbol's property lists. It is simpler to just
put properties on symbols. Backward compatibility to the old variable
has been kept.
@ -191121,7 +190693,7 @@
Support multi-lingual detection of SEE ALSO man sections
* lisp/man.el (Man-see-also-regexp): Add support for SEE ALSO
section detection in several languages: French, German, Spanish,
section detection in several langages: French, German, Spanish,
Portuguese, Italian, Polish, Turkish, Japanese, Chinese. (Bug#28142)
2017-08-26 Paul Eggert <eggert@cs.ucla.edu>
@ -205169,7 +204741,7 @@
2017-03-21 Noam Postavsky <npostavs@gmail.com>
Narrow scope of modification hook re-enabling in org-src fontification
Narrow scope of modification hook renabling in org-src fontification
Modification hooks should be enabled while modifying text in the
org-src temp buffer, but in 2017-01-29 "Call modification hooks in
@ -237348,14 +236920,14 @@
This file records repository revisions from
commit 9d56a21e6a696ad19ac65c4b405aeca44785884a (exclusive) to
commit f7bd5ac55211ad0ae2e473f0dff46df1e60f99bf (inclusive).
commit ddabb03a0176beb4b7fc8d4f2267d459fd2ebded (inclusive).
See ChangeLog.2 for earlier changes.
;; Local Variables:
;; coding: utf-8
;; End:
Copyright (C) 2015-2023 Free Software Foundation, Inc.
Copyright (C) 2015-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

114348
ChangeLog.4

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
# Build Emacs from a fresh tarball or version-control checkout.
# Copyright (C) 2011-2023 Free Software Foundation, Inc.
# Copyright (C) 2011-2022 Free Software Foundation, Inc.
#
# This file is part of GNU Emacs.
#

View file

@ -1,5 +1,5 @@
GNU Emacs Installation Guide
Copyright (C) 1992, 1994, 1996-1997, 2000-2023 Free Software Foundation,
Copyright (C) 1992, 1994, 1996-1997, 2000-2022 Free Software Foundation,
Inc.
See the end of the file for license conditions.

View file

@ -4,7 +4,7 @@ The Emacs repository is hosted on Savannah. The following Git command
will clone the repository to the 'emacs' subdirectory of the current
directory on your local machine:
git clone https://git.savannah.gnu.org/git/emacs.git
git clone git://git.sv.gnu.org/emacs.git
To build the repository code, simply run 'make' in the 'emacs'
directory. This should work if your files are freshly checked out
@ -98,7 +98,7 @@ never platform-specific.
Copyright (C) 2002-2023 Free Software Foundation, Inc.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
### @configure_input@
# Copyright (C) 1992-2023 Free Software Foundation, Inc.
# Copyright (C) 1992-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
@ -417,9 +417,9 @@ advice-on-failure:
sanity-check:
@[ -f .no-advice-on-failure ] && exit 0; true
@v=`src/emacs${EXEEXT} --batch --eval \
@v=$$(src/emacs${EXEEXT} --batch --eval \
'(progn (defun f (n) (if (= 0 n) 1 (* n (f (- n 1))))) (princ (f 10)))' \
2> /dev/null`; \
2> /dev/null); \
[ "X$$v" = "X3628800" ] && exit 0; \
echo >&2 '***'; \
echo >&2 '*** '"\"make ${make-target}\" succeeded, but Emacs is not functional."; \
@ -841,7 +841,7 @@ install-etc:
rm -f $${tmp}
tmp=etc/emacsclient.tmpdesktop; rm -f $${tmp}; \
client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
sed -e "/^Exec=/ s|emacsclient|${bindir}/$${client_name}|" \
sed -e "/^Exec=emacsclient/ s|emacsclient|${bindir}/$${client_name}|" \
-e "/^Icon=emacs/ s/emacs/${EMACS_NAME}/" \
$(USE_STARTUP_NOTIFICATION_SED_CMD) \
${srcdir}/etc/emacsclient.desktop > $${tmp}; \
@ -855,7 +855,7 @@ install-etc:
rm -f $${tmp}
tmp=etc/emacsclient-mail.tmpdesktop; rm -f $${tmp}; \
client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
sed -e "/^Exec=/ s|emacsclient|${bindir}/$${client_name}|" \
sed -e "/^Exec=emacsclient/ s|emacsclient|${bindir}/$${client_name}|" \
-e "/^Icon=emacs/ s/emacs/${EMACS_NAME}/" \
${srcdir}/etc/emacsclient-mail.desktop > $${tmp}; \
${INSTALL_DATA} $${tmp} "$(DESTDIR)${desktopdir}/$${client_name}-mail.desktop"; \
@ -1030,9 +1030,6 @@ $(foreach dir,$(distclean_dirs),$(eval $(call submake_template,$(dir),distclean)
distclean: $(distclean_dirs:=_distclean) clean-gsettings-schemas
${top_distclean}
ifeq ($(HAVE_NATIVE_COMP),yes)
rm -rf native-lisp
endif
### 'bootstrap-clean'
### Delete everything that can be reconstructed by 'make' and that
@ -1287,7 +1284,7 @@ PREFERRED_BRANCH = emacs-28
preferred-branch-is-current:
git branch | grep -q '^\* $(PREFERRED_BRANCH)$$'
unchanged-history-files:
x=`git diff-files --name-only $(CHANGELOG_N) $(emacslog)` && \
x=$$(git diff-files --name-only $(CHANGELOG_N) $(emacslog)) && \
test -z "$$x"
# Regular expression that matches the newest commit covered by a ChangeLog.

2
README
View file

@ -1,4 +1,4 @@
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.

View file

@ -2577,7 +2577,7 @@
;; coding: utf-8
;; End:
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

View file

@ -294,7 +294,7 @@ Po Lu
Tramp
Maintainer: Michael Albinus
Repository: https://git.savannah.gnu.org/git/tramp.git
Repository: git://git.savannah.gnu.org/tramp.git
Mailing List: tramp-devel@gnu.org
Bug Reports: M-x tramp-bug
Notes: For backward compatibility requirements, see
@ -316,7 +316,7 @@ Modus themes
Org Mode
Home Page: https://orgmode.org/
Maintainer: Org Mode developers
Repository: https://git.savannah.gnu.org/git/emacs/org-mode.git
Repository: git://git.sv.gnu.org/emacs/org-mode.git
Mailing list: emacs-orgmode@gnu.org
Bug Reports: M-x org-submit-bug-report
Notes: Org Mode is maintained as a separate project that is

View file

@ -1,4 +1,4 @@
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.

View file

@ -1,6 +1,6 @@
;;; admin.el --- utilities for Emacs administration -*- lexical-binding: t; -*-
;; Copyright (C) 2001-2023 Free Software Foundation, Inc.
;; Copyright (C) 2001-2022 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
/* Allocate X colors. Used for testing with dense colormaps.
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
;;; authors.el --- utility for maintaining Emacs's AUTHORS file -*- lexical-binding: t; -*-
;; Copyright (C) 2000-2023 Free Software Foundation, Inc.
;; Copyright (C) 2000-2022 Free Software Foundation, Inc.
;; Author: Gerd Moellmann <gerd@gnu.org>
;; Maintainer: emacs-devel@gnu.org
@ -182,7 +182,7 @@ files.")
("Philip Kaludercic" "Philip K\\." "Philip K")
("Philipp Stephani" "Philipp .*phst@google")
("Piotr Zieliński" "Piotr Zielinski")
("Po Lu" "Po Lu Via" "Your Name") ; looks like a mistake
("Po Lu" "Po Lu Via") ; looks like a mistake
("Przemysław Wojnowski" "Przemyslaw Wojnowski")
("R. Bernstein" "rb@dustyfeet.com")
("Rainer Schöpf" "Rainer Schoepf")

View file

@ -1,7 +1,7 @@
#!/bin/bash
### automerge - automatically merge the Emacs release branch to master
## Copyright (C) 2018-2023 Free Software Foundation, Inc.
## Copyright (C) 2018-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: Stefan Kangas <stefankangas@gmail.com>

View file

@ -1,7 +1,7 @@
#! /usr/bin/perl
# Build Emacs in several different configurations.
# Copyright (C) 2001-2023 Free Software Foundation, Inc.
# Copyright (C) 2001-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
### @configure_input@
# Copyright (C) 2015-2023 Free Software Foundation, Inc.
# Copyright (C) 2015-2022 Free Software Foundation, Inc.
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
# National Institute of Advanced Industrial Science and Technology (AIST)
@ -181,7 +181,7 @@ ${charsetdir}/GB180304.map: ${charsetdir}/GB180302.map ${gb180304}
${AM_V_GEN}$(AWK) -f ${gb180304} < $< > $@
${charsetdir}/JISX0201.map: ${GLIBC_CHARMAPS}/JIS_X0201.gz ${mapconv} ${compact}
${AM_V_GEN}(${run_mapconv} $< '/^<.*[ ]\/x[0-9]/' GLIBC-1 ${compact} && \
${AM_V_GEN}(${mapconv} $< '/^<.*[ ]\/x[0-9]/' GLIBC-1 ${compact} && \
echo "# Generated by hand" && \
echo "0xA1-0xDF 0xFF61" ) > $@

View file

@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (C) 2015-2023 Free Software Foundation, Inc.
# Copyright (C) 2015-2022 Free Software Foundation, Inc.
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
# National Institute of Advanced Industrial Science and Technology (AIST)
@ -38,8 +38,7 @@
## So that eg [A-F] as used by KANJI-DATABASE branch below works as expected.
## Otherwise with LANG=en_US.utf8, CNS-6.map was generated with a
## bogus entry. By experiment, LC_COLLATE=C was not enough.
LC_ALL=C
export LC_ALL
export LC_ALL=C
BASE=`expr "$1" : '.*/\(.*\)' '|' "$1"` # basename
FILE="admin/charsets/mapfiles/$BASE"

View file

@ -1,4 +1,4 @@
Copyright (C) 2009-2023 Free Software Foundation, Inc.
Copyright (C) 2009-2022 Free Software Foundation, Inc.
Copyright (C) 2009, 2010, 2011
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009

View file

@ -1,7 +1,7 @@
#!/bin/bash
### check-man-pages - check man pages for errors
## Copyright (C) 2022-2023 Free Software Foundation, Inc.
## Copyright (C) 2022 Free Software Foundation, Inc.
## Author: Stefan Kangas <stefankangas@gmail.com>

208
admin/cl-packages.org Normal file
View file

@ -0,0 +1,208 @@
# -*- mode: org; eval: (auto-fill-mode 1); org-indent-mode: 1; -*-
#+STARTUP: show3levels
* Common Lisp packages for Emacs
This is an experimental implementation of CL packages for Emacs.
The question of the experiment is if it is possible to add CL packages
to Emacs with reasonable effort and reasonable compatibility.
Note that this branch is only known to build and run under macOS. I
don't have access to other systems, so it might not compile or work on
other systems. Patches welcome.
Please see a book like Common Lisp the Language (CLtL2) for a
description of the CL package systen. The book is freely available
from CMU.
** Status
This builds and runs with unchanged Magit, Lsp-mode, and other
packages for me, so it seems to be pretty backwards-compatible. I
can't gurantee anything, of course. If you find a problem, please let
me know.
** User-visible functionality
There are three pre-defined packages.
The keyword package, named "keyword" or "" contains keywords.
The Emacs package, with name "emacs" contains all other symbols. All
code is currently loaded in this package, for compatibility. All
symbols in the package are currently exported.
The "emacs-user" package is intended for user-code, for example in
*scratch*, and uses the Emacs package, so that everything in Emacs can
be used.
These variables are defined:
"*package*" holds the current package like in CL. It's buffer-local,
and you can't set it to a non-package value, to prevent havoc.
"*emacs-package*", "*keyword-package*", "*emacs-user-package*" hold
the package objects. This is mainly for easier debugging and testing.
The variables may go at some point. Or not.
"*package-registry* is a hash-table of registered packages. The
variable may go at some point. Or not.
Various functions related to packages are defined. Depending on the
time when you read this, this may be in some state of incompleteness,
and it probably has bugs. Reports or fixes welcome.
** Implementation notes
*** Where is it?
The C part is in src/pkg.c. I chose that name because package.c
resulted in conflicts in the tests (with package.el).
The Lisp part is in lisp/emacs-lisp/pkg.el. I've done as much of this
in Lisp because that's much easier and faster. If packages are used
in files loaded in loadup, changes might be necessary to make this
possible. I consider this out of scope, ATM.
*** No pure space support
The branch contains a patch by Stefan Monnier that makes it no longer
use pure space. I didn't want to deal with pure space. Note that a
small fix in init_vectors is needed for making Stefan's patch work.
There is nothing preventing the use of pure space though, in
principle.
*** Shorthands
Are currently not supported.
*** Lisp_Package
There is a new Lisp data type Lisp_Package defined in lisp.h.
*** Lisp_Symbol
Struct Lisp_Symbol has lost its interned flag and its next pointer.
Both were an implementation detail of obarrays, which are gone.
All symbols now have a package. Uninterned symbols have a nil
package.
Keywords have the keyword package. Note that keyword symbol names do
not contain the colon. The function symbol-name still returns a
string with a leading colon. I found this was necessary to achieve
backwards-compatibility. At least at this point. The function
cl-symbol-name returns the real name of a keyword, without the colon.
Other symbols have the Emacs package.
*** Obarrays
Obarrays have been removed. Backwards-compatibility is achieved by
the following
- The variable 'obarray' still exists. Its value is now the Emacs
package.
- intern, intern-soft, unintern, mapatoms still accept vectors (former
obarrays). When called with a vector, they secretly create and use
packages. This is done because legacy code uses make-vector instead
of obarray-make to create obarrays.
*** Reader
The variable 'package-prefixes' determines if the reader will
interpret colons in a symbol name as part of a package name or not.
Default is nil.
*** Printer
The printer prints package prefixes if necessary, as in CL.
*** Completions
The completion functions accept packages as collections.
** Problems and how they are approached (currently)
*** Keywords
In CL, keywords are symbols in the keyword package. The leading colon
of a keyword is not part of its symbol name, but a package prefix.
The keyword package has a nickname that is an empty string.
In Emacs, keywords are just symbols whose names start with a colon,
and that is expected in a ton of places both implicity and explicitly
and in various forms.
Current approach:
- Internally, keyword names don't contain the colon, which is TRT.
- symbol-name returns a name with colon for keywords.
- cl-symbol-name returns the symbol name as-is.
- intern and intern-soft when called with a name starting with a colon
interpret that as wanting a keyword.
That's not at all pretty, but in an experiment with symbol-name
behaving like in CL showed serious problems that I couldn't solve so
far without modifying the code.
But see under Ideas and Todos.
*** Fake package qualification
Existing code contains symbols like GUI:xyz which look like GUI is a
package qualification. That's the reason for the variable
package-prefixes which means to interpret the : as part of the symbol
name.
** Ideas / Todo
*** Completions
It might be useful to complete over all symbols in all packages.
I haven't added that.
*** Existing package extensions
There are some language extensions available in CL implementations
that might be nice to have
- Hierarchical packages
- Package locks
- Local nicknames
None of these are implemented.
*** Changing symbol names
A trap that I always fall into, constantly, in Emacs, is to use CL
functions without the cl- prefix. It would be nice to have something
that makes these symbols available without the cl-.
Just ideas:
- (shadow-alias multiple-value-bind cl-multiple-value-bind) or maybe
with regexs. Or something.
- (import sym as another-sym)
*** Package-prefixes in functions
I'm wondering if it would be an idea to record the value of
package-prefixes at the time and in the buffer where functions are
compiled or eval'd.
We could then
- Bbind package-prefixes around the execution of the function to that
value.
- Return a name with leading colon from symbol-value if
package-prefixes is nil, which means the function was compiled or
eval'd in a "traditional" setting. It would return the keyword name
without the leading colon if package-prefixes is t.
- Make intern treat colons differently depending on the value of
package-prefixes. There are some places like transient.el which
intern names with a leading colon which are a pain in the neck.
- Maybe calls to read could also behave differently.
For subrs (native-compiled and C code), there is plenty of room for 1
bit. For byte-compiled functions, see make-bytecode + make-closure.
This should be doable from that perspective. One probably just has to
try it out.
*** Modeline
A mode-line indicator showing the current package and package-prefixes
would be helpful. Can be done with (:eval ...) in global-mode-string
now. Or maybe in a header-line.
*** Tests
Should be much improved.
*** Documentation
Doesn't exist :-).
*** Other
- Add (declare (ignore ...)) and (declare (ignorable ...) goddam :-).

View file

@ -1,6 +1,6 @@
;;; cus-test.el --- tests for custom types and load problems -*- lexical-binding: t; -*-
;; Copyright (C) 1998, 2000, 2002-2023 Free Software Foundation, Inc.
;; Copyright (C) 1998, 2000, 2002-2022 Free Software Foundation, Inc.
;; Author: Markus Rost <rost@math.uni-bielefeld.de>
;; Created: 13 Sep 1998

View file

@ -1,6 +1,6 @@
#!/bin/bash
# Copyright (C) 2001-2023 Free Software Foundation, Inc.
# Copyright (C) 2001-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,7 +1,7 @@
#!/bin/bash
### emacs-shell-lib - shared code for Emacs shell scripts
## Copyright (C) 2022-2023 Free Software Foundation, Inc.
## Copyright (C) 2022 Free Software Foundation, Inc.
## Author: Stefan Kangas <stefankangas@gmail.com>

View file

@ -1,6 +1,6 @@
#!/bin/bash
# Copyright (C) 2022-2023 Free Software Foundation, Inc.
# Copyright (C) 2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
;;; find-gc.el --- detect functions that call the garbage collector -*- lexical-binding: t; -*-
;; Copyright (C) 1992, 2001-2023 Free Software Foundation, Inc.
;; Copyright (C) 1992, 2001-2022 Free Software Foundation, Inc.
;; Maintainer: emacs-devel@gnu.org

View file

@ -4,7 +4,7 @@
### the result of merging external trees into the Emacs repository, as
### well as certain commits on which Emacs fails to build, are skipped.
## Copyright (C) 2022-2023 Free Software Foundation, Inc.
## Copyright (C) 2022 Free Software Foundation, Inc.
## This file is part of GNU Emacs.
@ -82,7 +82,7 @@ done
# SKIP-BRANCH 58cc931e92ece70c3e64131ee12a799d65409100
## The list below is the exhaustive list of all commits between Dec 1
## 2016 and Feb 28 2023 on which building Emacs with the default
## 2016 and Nov 30 2022 on which building Emacs with the default
## options, on a GNU/Linux computer and with GCC, fails. It is
## possible (though unlikely) that building Emacs with non-default
## options, with other compilers, or on other platforms, would succeed
@ -1637,86 +1637,3 @@ $REAL_GIT bisect skip $(cat $0 | grep '^# SKIP-SINGLE ' | sed 's/^# SKIP-SINGLE
# SKIP-SINGLE 4552b01d8c8052f607dca2fcddcf7b2e270f1db6
# SKIP-SINGLE b6568c1389128d47538b646d940427949ddf58d0
# SKIP-SINGLE 6d5b34d9de7b2f1b346d9aff123ad20c942166dc
# SKIP-SINGLE d9d90666f545dc25be63c1b16c030ce1aa96510e
# SKIP-SINGLE e645bcc26d468ab6b8e16b6160c203c5db70ec6b
# SKIP-SINGLE 0aea1cf8190aa804a0d11a67b4a3cb4b715ae82d
# SKIP-SINGLE 7e6d1d1c47196bf1bb5254f5c9014e25bdaf9833
# SKIP-SINGLE 784e509bded0fe41dd9908022a92c54ac8c21a2c
# SKIP-SINGLE bc4cbbcc57a56a23c64576c8c23ecf6afb1c747b
# SKIP-SINGLE 523261b454058d0b28df2c3de1eab55fe378aa69
# SKIP-SINGLE 29d23b7fa00ed8263baa060d487b526d51fa6986
# SKIP-SINGLE 9371d488be62a37788b499a7e44b1f5db158e212
# SKIP-SINGLE 60418e6f09c67924e3e05eb4948e109d8f7c4073
# SKIP-SINGLE 9153cf8158489d387a6a0d9d0ede9a2528c35f0a
# SKIP-SINGLE d11e34ce76aac8680337f247419657e042e4cf34
# SKIP-SINGLE 2541bec21bf3cf090071e434dac170d52394594e
# SKIP-SINGLE 007e66bccb2cb8382158e5e24727fd1b4478cd69
# SKIP-SINGLE 753b7a1cff6b8ce2367a94d27b615ac31f1067ba
# SKIP-SINGLE 7c63b632e4e2241a28f08015cc981a72e18d7867
# SKIP-SINGLE 91ae9f3d12885373d38c3e8d693f7dc210f9d471
# SKIP-SINGLE 314cbef84944145e2160736ce32812403ed99cd9
# SKIP-SINGLE 1a88a28ace24c8b4fb1e4780948b50dd37ada539
# SKIP-SINGLE 98327e371938033f7ccefd1c5226cd102cb29ad1
# SKIP-SINGLE 9d814bea4600ac28dcdbf9caf386467551d7d9be
# SKIP-SINGLE 73769dc2b872441eb0b8565e1090e97fc0b5d521
# SKIP-SINGLE 283043621756fd004906ecdd5ba829a47cb3fc57
# SKIP-SINGLE 05ece1eb8b7ce28d366d02df89449d453be8d37e
# SKIP-SINGLE 248c13dcfe1b9618811a6fe67e967b25b1a8f139
# SKIP-SINGLE 38c35bf0f6a938001dfecbe439addf8fb62897c6
# SKIP-SINGLE 9065d745151e1995b80a1f4d5a04e2af111ad928
# SKIP-SINGLE e78e69b33189c653d1588b810283969ac3cca137
# SKIP-SINGLE 909091d7578b7225601b202fb9257dedae879e9a
# SKIP-SINGLE 706ed85285515e7047e16608815c1d02d4907b07
# SKIP-SINGLE 7013b0179cbe5cce19e114d7673770d1425d3005
# SKIP-SINGLE 2de25accaf31aef643557ec476041c770fc7ac15
# SKIP-SINGLE 2b1fdbffcb595bcd72fa9aa3db674c6985042bcb
# SKIP-SINGLE 1480865e641b06d570f5ab56011f8e3e5481da7d
# SKIP-SINGLE 8c13e8497821881b5197a1717e9e53b9991859d0
# SKIP-SINGLE a6db8464e150c49724c71c5969b97f205ee2dec5
# SKIP-SINGLE cfbfd393b450d4eb7ac0b7922b44208688553c9e
# SKIP-SINGLE 382e018856a884a96a94ad551dbc1d7b0317b2e5
# SKIP-SINGLE 8360e12f0ea3a3ccf0305adab3c7ea7e38af36c1
# SKIP-SINGLE 56e8607dc99b90c43f82001cbf073e58a4698298
# SKIP-SINGLE 956889d8ff1c79db45ca9b1711f406961e71c272
# SKIP-SINGLE e2e937300f5a68ce1e2a349a583859a29394ac5f
# SKIP-SINGLE 176830fe2bb1c80ee128e515f6223cddc8b0a2ca
# SKIP-SINGLE 3f069bd796b0024033640051b5f74ba9834985f8
# SKIP-SINGLE 435ba92ccc4c46914c261de57f71ac6d92c20178
# SKIP-SINGLE ad6d8f7df180a9563d3f064f29c6366f114b8de0
# SKIP-SINGLE 8d7ad65665833ae99b7e7119dae37afa438968a4
# SKIP-SINGLE 10032f424ccf611783f5b92742e91e70595587c4
# SKIP-SINGLE 4b1714571c8c6cf7ae2ee2602c66b7c903c45a4a
# SKIP-SINGLE f27a330b99eebbe7f4690163358b4cacbd4e17a1
# SKIP-SINGLE b73539832d9c4e802925cb8f261a13473da383b3
# SKIP-SINGLE f50cb7d7c4b37cd8e4bb1ffa5d3f9273c7e19e10
# SKIP-SINGLE 96015c9c8cc1720e8ee7cd9cea4de48126dd9122
# SKIP-SINGLE 2bd0b9475384adfb4dd2cc794bbe1d8621546717
# SKIP-SINGLE d9a2673ee95cf7172a622dc0229ddf72aec8e8c1
# SKIP-SINGLE 0116e27b26cb4a98f2de8dca12d8e9d90d222992
# SKIP-SINGLE 96601cd90ba1b8a650d0e41dad2a58cb9e270f1b
# SKIP-SINGLE 99e40959f4036debe099f144ed2664a38e23563d
# SKIP-SINGLE 207a0d9408cb97b9ae78469e2487e3075ade03f8
# SKIP-SINGLE 64fee21d5f85db465198970a4d636cb17d500f26
# SKIP-SINGLE 48bd17923a98f49a30bdce2f3a52e03fe45d63f0
# SKIP-SINGLE 9058601308db4892fbc3e599b83fe4326fef9886
# SKIP-SINGLE a3003492ace0571e5179500b42bbe44cb9763dbb
# SKIP-SINGLE 197f994384cb37ae4ae7a771815bbe565d4ae242
# SKIP-SINGLE 1970726e26a979243925fabe32686ba2ee757c6b
# SKIP-SINGLE 1de6ebf2878485a0ef6b778df7d6a14d5b22a01c
# SKIP-SINGLE 013ab7e2a83afa7fb577c356ae686439a2906f34
# SKIP-SINGLE 1c3ca3bb649b7e812a84b4a559463462d4357080
# SKIP-SINGLE 48ed4228a75907ae1bb7a2d4314ffb3277c75e3a
# SKIP-SINGLE b9025c507a3a7dae4de19b18cafaa09b18183832
# SKIP-SINGLE 8d8464bd5a98598e7a6fe63370545c7f07574926
# SKIP-SINGLE 11c4177430230ef41cb700c48afecf475cf39893
# SKIP-SINGLE cf3c89423fabc2c5a7891a5b5465fa995e461218
# SKIP-SINGLE 8d5d7509b0a2c248084fa349b0b188d4de4af804
# SKIP-SINGLE b6e2799aa1c3887c2995e115e6ff2f69d59f0e44
# SKIP-SINGLE 1795839babcf8572a79aaee3c76ca5b357937a59
# SKIP-SINGLE abfd00e5c02ec0aed8bbac1eca0d0db1874f020a
# SKIP-SINGLE 8aef401b4f66a64ddfa9390590fb2cae1f96d522
# SKIP-SINGLE d5bf26f488b7968feed9f43e612a90da2aab15a8
# SKIP-SINGLE 5d0912f1445e33f1ccf23a84f0dc6d08c4ee2b60
# SKIP-SINGLE 95692f6754c3a8f55a90df2d6f7ce62be55cdcfc
# SKIP-SINGLE a3edacd3f547195740304139cb68aaa94d7b18ee
# SKIP-SINGLE ae4ff4f25fbf704446f8f38d8e818f223b79042b

View file

@ -1,6 +1,6 @@
;;; gitmerge.el --- help merge one Emacs branch into another -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2022 Free Software Foundation, Inc.
;; Authors: David Engster <deng@randomsample.de>
;; Stefan Monnier <monnier@iro.umontreal.ca>

View file

@ -1,6 +1,6 @@
### @configure_input@
## Copyright (C) 2013-2023 Free Software Foundation, Inc.
## Copyright (C) 2013-2022 Free Software Foundation, Inc.
## This file is part of GNU Emacs.

View file

@ -1,5 +1,5 @@
;;; c.by -- LL grammar for C/C++ language specification
;; Copyright (C) 1999-2023 Free Software Foundation, Inc.
;; Copyright (C) 1999-2022 Free Software Foundation, Inc.
;;
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; David Ponce <david@dponce.com>

View file

@ -1,6 +1,6 @@
;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars
;;
;; Copyright (C) 2002-2023 Free Software Foundation, Inc.
;; Copyright (C) 2002-2022 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002

View file

@ -1,6 +1,6 @@
;;; java-tags.wy -- Semantic LALR grammar for Java
;; Copyright (C) 2002-2023 Free Software Foundation, Inc.
;; Copyright (C) 2002-2022 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002

View file

@ -1,6 +1,6 @@
;;; javascript-jv.wy -- LALR grammar for Javascript
;; Copyright (C) 2005-2023 Free Software Foundation, Inc.
;; Copyright (C) 2005-2022 Free Software Foundation, Inc.
;; Copyright (C) 1998-2011 Ecma International.
;; Author: Joakim Verona

View file

@ -1,6 +1,6 @@
;;; make.by -- BY notation for Makefiles.
;; Copyright (C) 1999-2023 Free Software Foundation, Inc.
;; Copyright (C) 1999-2022 Free Software Foundation, Inc.
;;
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; David Ponce <david@dponce.com>

View file

@ -1,6 +1,6 @@
;;; python.wy -- LALR grammar for Python
;; Copyright (C) 2002-2023 Free Software Foundation, Inc.
;; Copyright (C) 2002-2022 Free Software Foundation, Inc.
;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
;; 2009, 2010 Python Software Foundation; All Rights Reserved

View file

@ -1,6 +1,6 @@
;;; scheme.by -- Scheme BNF language specification
;; Copyright (C) 2001-2023 Free Software Foundation, Inc.
;; Copyright (C) 2001-2022 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
;;; srecode-template.wy --- Semantic Recoder Template parser
;; Copyright (C) 2005-2023 Free Software Foundation, Inc.
;; Copyright (C) 2005-2022 Free Software Foundation, Inc.
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; Keywords: syntax

View file

@ -1,6 +1,6 @@
;;; last-chance.el --- dangling deterrence -*- lexical-binding: t; -*-
;; Copyright (C) 2016-2023 Free Software Foundation, Inc.
;; Copyright (C) 2016-2022 Free Software Foundation, Inc.
;; Author: Thien-Thi Nguyen <ttn@gnu.org>
;; Maintainer: emacs-devel@gnu.org

View file

@ -2,7 +2,7 @@
# Build Emacs with various options for profiling, debugging,
# with and without warnings enabled etc.
# Copyright (C) 2001-2023 Free Software Foundation, Inc.
# Copyright (C) 2001-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,7 +1,7 @@
#!/bin/bash
### make-manuals - create the Emacs manuals to upload to the gnu.org website
## Copyright 2018-2023 Free Software Foundation, Inc.
## Copyright 2018-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org

View file

@ -68,25 +68,16 @@ General steps (for each step, check for possible errors):
PREFERRED_BRANCH = emacs-NN
where NN is the version on the release branch from which you are
producing the tarball. If NN is incorrect (which it usually is
when starting a pretest of a new major release), update
Makefile.in and re-run 'configure' to update Makefile.
producing the tarball. If NN is incorrect, update Makefile.in and
re-run 'configure' to update Makefile.
For the first pretest of a new major release, consider starting a
new top-level ChangeLog.N file if the last versioned ChangeLog.N
file is too large. A good point to start a new ChangeLog.N file
is when the last one gets larger than 1.5 MiB. If so, start a new
one by bumping N, and also update the line in top-level
Makefile.in which says
If the versioned ChangeLog.N file is too large, start a new one
by bumping N, and also update the line in top-level Makefile.in
which says
CHANGELOG_HISTORY_INDEX_MAX = N
by incrementing the value of N by 1; then regenerate Makefile.
After bumping N, you need to actually create and commit
ChangeLog.N with the updated N, otherwise "M-x authors" below will
fail. The easiest way of creating the new ChangeLog.N is to
rename the file ChangeLog (without the .N suffix) left over from
the last major release (it is usually unversioned) and commit it.
Now:
@ -108,12 +99,11 @@ General steps (for each step, check for possible errors):
the relevant entry. If a file was deleted or renamed, consider
adding an appropriate entry to variables authors-ignored-files,
authors-valid-file-names, or authors-renamed-files-alist in
authors.el. If some authors are "ignored", consider adding
entries to the author-aliases variable.
authors.el.
If necessary, repeat 'C-u M-x authors' after making those changes.
Save the "*Authors*" buffer as etc/AUTHORS.
Check the diff looks reasonable. Maybe add more entries to
Check the diff looks reasonable. Maybe add entries to
authors-ambiguous-files or authors-aliases, and repeat.
Commit any fixes to authors.el.
@ -160,11 +150,10 @@ General steps (for each step, check for possible errors):
4. autoreconf -i -I m4 --force
make bootstrap
The below script checks for any mistakes in the source text of
manual pages. Fix any errors and re-run the script to verify.
./admin/check-man-pages
The above script checks for any mistakes in the source text of
manual pages. Fix any errors and re-run the script to verify.
Then do this:
make -C etc/refcards
@ -179,13 +168,7 @@ General steps (for each step, check for possible errors):
messages from TeX, but those seem to be harmless, as the result
looks just fine.)
5. Copy lisp/loaddefs.el to lisp/ldefs-boot.el. After copying, edit
ldefs-boot.el to add
;; no-byte-compile: t
to its file-local variables section, otherwise make-dist will
complain.
5. Copy lisp/loaddefs.el to lisp/ldefs-boot.el.
Commit ChangeLog.N, etc/AUTHORS, lisp/ldefs-boot.el, and the files
changed by M-x set-version. Note that the set-version changes

View file

@ -4,7 +4,7 @@
#
# admin/merge-gnulib
# Copyright 2012-2023 Free Software Foundation, Inc.
# Copyright 2012-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
@ -23,10 +23,10 @@
# written by Paul Eggert
GNULIB_URL=https://git.savannah.gnu.org/git/gnulib.git
GNULIB_URL=git://git.savannah.gnu.org/gnulib.git
GNULIB_MODULES='
alignasof alloca-opt binary-io byteswap c-ctype c-strcase
alloca-opt binary-io byteswap c-ctype c-strcase
canonicalize-lgpl
careadlinkat close-stream copy-file-range
count-leading-zeros count-one-bits count-trailing-zeros
@ -44,9 +44,9 @@ GNULIB_MODULES='
nanosleep nproc nstrftime
pathmax pipe2 pselect pthread_sigmask
qcopy-acl readlink readlinkat regex
sig2str sigdescr_np socklen stat-time std-gnu11 stdbool stddef stdio
sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stdbool stddef stdio
stpcpy strnlen strtoimax symlink sys_stat sys_time
tempname time-h time_r time_rz timegm timer-time timespec-add timespec-sub
tempname time time_r time_rz timegm timer-time timespec-add timespec-sub
update-copyright unlocked-io utimensat
vla warnings
'

View file

@ -4,7 +4,7 @@
#
# admin/merge-pkg-config
# Copyright 2014-2023 Free Software Foundation, Inc.
# Copyright 2014-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,4 +1,4 @@
Copyright (C) 2007-2023 Free Software Foundation, Inc.
Copyright (C) 2007-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.

View file

@ -3,7 +3,7 @@ NOTES ON THE EMACS PACKAGE ARCHIVE
The GNU Emacs package archive, at elpa.gnu.org, is managed using a Git
repository named "elpa", hosted on Savannah. To check it out:
git clone https://git.savannah.gnu.org/git/emacs/elpa
git clone git://git.sv.gnu.org/emacs/elpa
cd elpa
make setup

View file

@ -1,6 +1,6 @@
-*- mode: outline; coding: utf-8 -*-
Copyright (C) 2019-2023 Free Software Foundation, Inc.
Copyright (C) 2019-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
NOTES FOR EMACS CONTINUOUS BUILD ON EMBA
@ -83,46 +83,6 @@ Lisp packages, Makefiles, scripts, and other software could determine
whether they run on emba by checking for the environment variable
EMACS_EMBA_CI.
* Running Emba tests locally
As usual in GitLab, the tests run in containers, which could be
applied also locally. Unfortunately, the Emba container registry,
emba.gnu.org:5050, is not accessible publicly. Instead, the container
images must be build locally. Change the current directory to a
recent Emacs branch, and apply the command
docker build --target emacs-inotify --tag emacs-inotify \
-f test/infra/Dockerfile.emba .
This creates the Debian-based image emacs-inotify, based on the
instructions in the file Dockerfile.emba. This image is good for the
majority of tests. However, there are also other image build
instructions like emacs-filenotify-gio, emacs-eglot, emacs-gnustep and
emacs-native-comp-speed{0,1,2}. Use the appropriate one.
The image contains a directory "/checkout", which is a copy of your
local Emacs git repository. Emacs has been built in this directory
via "make bootstrap". In order to use the image, start a container
like
docker run --interactive --env EMACS_EMBA_CI=1 --name emacs-inotify \
emacs-inotify /bin/sh -i
In this container, change the current directory to "/checkout". Now
you can apply all commands known for Emacs, like
cd /checkout
make -C test files-tests.log
While this container runs, you can also access its filesystem from
your local Emacs via Tramp. For example, in order to see the result
of the above test run, open the log file in your local Emacs with
C-x C-f /docker:emacs-inotify:/checkout/test/lisp/files-tests.log
Note: On local Red Hat-based systems, use "podman" instead of "docker"
in the shell commands and Tramp file names.
This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
-*- mode: outline; coding: utf-8 -*-
Copyright (C) 2013-2023 Free Software Foundation, Inc.
Copyright (C) 2013-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
NOTES FOR EMACS CONTINUOUS BUILD ON HYDRA

View file

@ -1,6 +1,6 @@
-*- coding: utf-8; mode: text; -*-
Copyright (C) 2007-2023 Free Software Foundation, Inc.
Copyright (C) 2007-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
From README.multi-tty in the multi-tty branch.

View file

@ -0,0 +1,17 @@
To build the language definition for a particular language, run
./build.sh <language>
eg,
./build.sh html
The dynamic module will be in /dist directory
To build all modules at once, run
./batch.sh
This gives you C, JSON, Go, HTML, Javascript, CSS, Python, Typescript
(tsx), C# (csharp), C++ (cpp), Rust. More can be added to batch.sh
unless it's directory structure is not standard.

View file

@ -8,10 +8,8 @@ languages=(
'css'
'c-sharp'
'dockerfile'
'elixir'
'go'
'go-mod'
'heex'
'html'
'javascript'
'json'

View file

@ -3,17 +3,12 @@
lang=$1
topdir="$PWD"
case $(uname) in
"Darwin")
soext="dylib"
;;
*"MINGW"*)
soext="dll"
;;
*)
soext="so"
;;
esac
if [ $(uname) == "Darwin" ]
then
soext="dylib"
else
soext="so"
fi
echo "Building ${lang}"
@ -31,17 +26,11 @@ case "${lang}" in
"cmake")
org="uyha"
;;
"elixir")
org="elixir-lang"
;;
"go-mod")
# The parser is called "gomod".
lang="gomod"
org="camdencheek"
;;
"heex")
org="phoenixframework"
;;
"typescript")
sourcedir="tree-sitter-typescript/typescript/src"
grammardir="tree-sitter-typescript/typescript"

View file

@ -0,0 +1,206 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Accessing Node (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Accessing Node (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Accessing Node (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Pattern-Matching.html" rel="next" title="Pattern Matching">
<link href="Retrieving-Node.html" rel="prev" title="Retrieving Node">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Accessing-Node">
<div class="header">
<p>
Next: <a href="Pattern-Matching.html" accesskey="n" rel="next">Pattern Matching Tree-sitter Nodes</a>, Previous: <a href="Retrieving-Node.html" accesskey="p" rel="prev">Retrieving Node</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Accessing-Node-Information"></span><h3 class="section">37.4 Accessing Node Information</h3>
<p>Before going further, make sure you have read the basic conventions
about tree-sitter nodes in the previous node.
</p>
<span id="Basic-information"></span><h3 class="heading">Basic information</h3>
<p>Every node is associated with a parser, and that parser is associated
with a buffer. The following functions let you retrieve them.
</p>
<dl class="def">
<dt id="index-treesit_002dnode_002dparser"><span class="category">Function: </span><span><strong>treesit-node-parser</strong> <em>node</em><a href='#index-treesit_002dnode_002dparser' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns <var>node</var>&rsquo;s associated parser.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dbuffer"><span class="category">Function: </span><span><strong>treesit-node-buffer</strong> <em>node</em><a href='#index-treesit_002dnode_002dbuffer' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns <var>node</var>&rsquo;s parser&rsquo;s associated buffer.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dlanguage"><span class="category">Function: </span><span><strong>treesit-node-language</strong> <em>node</em><a href='#index-treesit_002dnode_002dlanguage' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns <var>node</var>&rsquo;s parser&rsquo;s associated language.
</p></dd></dl>
<p>Each node represents a piece of text in the buffer. Functions below
finds relevant information about that text.
</p>
<dl class="def">
<dt id="index-treesit_002dnode_002dstart"><span class="category">Function: </span><span><strong>treesit-node-start</strong> <em>node</em><a href='#index-treesit_002dnode_002dstart' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return the start position of <var>node</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dend"><span class="category">Function: </span><span><strong>treesit-node-end</strong> <em>node</em><a href='#index-treesit_002dnode_002dend' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Return the end position of <var>node</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dtext"><span class="category">Function: </span><span><strong>treesit-node-text</strong> <em>node &amp;optional object</em><a href='#index-treesit_002dnode_002dtext' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Returns the buffer text that <var>node</var> represents. (If <var>node</var> is
retrieved from parsing a string, it will be text from that string.)
</p></dd></dl>
<p>Here are some basic checks on tree-sitter nodes.
</p>
<dl class="def">
<dt id="index-treesit_002dnode_002dp"><span class="category">Function: </span><span><strong>treesit-node-p</strong> <em>object</em><a href='#index-treesit_002dnode_002dp' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Checks if <var>object</var> is a tree-sitter syntax node.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002deq"><span class="category">Function: </span><span><strong>treesit-node-eq</strong> <em>node1 node2</em><a href='#index-treesit_002dnode_002deq' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Checks if <var>node1</var> and <var>node2</var> are the same node in a syntax
tree.
</p></dd></dl>
<span id="Property-information"></span><h3 class="heading">Property information</h3>
<p>In general, nodes in a concrete syntax tree fall into two categories:
<em>named nodes</em> and <em>anonymous nodes</em>. Whether a node is named
or anonymous is determined by the language definition
(see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p>
<span id="index-tree_002dsitter-missing-node"></span>
<p>Apart from being named/anonymous, a node can have other properties. A
node can be &ldquo;missing&rdquo;: missing nodes are inserted by the parser in
order to recover from certain kinds of syntax errors, i.e., something
should probably be there according to the grammar, but not there.
</p>
<span id="index-tree_002dsitter-extra-node"></span>
<p>A node can be &ldquo;extra&rdquo;: extra nodes represent things like comments,
which can appear anywhere in the text.
</p>
<span id="index-tree_002dsitter-node-that-has-changes"></span>
<p>A node &ldquo;has changes&rdquo; if the buffer changed since when the node is
retrieved, i.e., outdated.
</p>
<span id="index-tree_002dsitter-node-that-has-error"></span>
<p>A node &ldquo;has error&rdquo; if the text it spans contains a syntax error. It
can be the node itself has an error, or one of its
children/grandchildren... has an error.
</p>
<dl class="def">
<dt id="index-treesit_002dnode_002dcheck"><span class="category">Function: </span><span><strong>treesit-node-check</strong> <em>node property</em><a href='#index-treesit_002dnode_002dcheck' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function checks if <var>node</var> has <var>property</var>. <var>property</var>
can be <code>'named</code>, <code>'missing</code>, <code>'extra</code>,
<code>'has-changes</code>, or <code>'has-error</code>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dtype"><span class="category">Function: </span><span><strong>treesit-node-type</strong> <em>node</em><a href='#index-treesit_002dnode_002dtype' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Named nodes have &ldquo;types&rdquo; (see <a href="Language-Definitions.html#tree_002dsitter-node-type">node type</a>).
For example, a named node can be a <code>string_literal</code> node, where
<code>string_literal</code> is its type.
</p>
<p>This function returns <var>node</var>&rsquo;s type as a string.
</p></dd></dl>
<span id="Information-as-a-child-or-parent"></span><h3 class="heading">Information as a child or parent</h3>
<dl class="def">
<dt id="index-treesit_002dnode_002dindex"><span class="category">Function: </span><span><strong>treesit-node-index</strong> <em>node &amp;optional named</em><a href='#index-treesit_002dnode_002dindex' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the index of <var>node</var> as a child node of its
parent. If <var>named</var> is non-nil, it only count named nodes
(see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dfield_002dname"><span class="category">Function: </span><span><strong>treesit-node-field-name</strong> <em>node</em><a href='#index-treesit_002dnode_002dfield_002dname' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>A child of a parent node could have a field name (see <a href="Language-Definitions.html#tree_002dsitter-node-field-name">field name</a>). This function returns the field name
of <var>node</var> as a child of its parent.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dfield_002dname_002dfor_002dchild"><span class="category">Function: </span><span><strong>treesit-node-field-name-for-child</strong> <em>node n</em><a href='#index-treesit_002dnode_002dfield_002dname_002dfor_002dchild' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the field name of the <var>n</var>&rsquo;th child of
<var>node</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dchild_002dcount"><span class="category">Function: </span><span><strong>treesit-child-count</strong> <em>node &amp;optional named</em><a href='#index-treesit_002dchild_002dcount' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the number of children of <var>node</var>. If
<var>named</var> is non-nil, it only counts named child (see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>, Previous: <a href="Retrieving-Node.html">Retrieving Node</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,402 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Language Definitions (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Language Definitions (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Language Definitions (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Using-Parser.html" rel="next" title="Using Parser">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Language-Definitions">
<div class="header">
<p>
Next: <a href="Using-Parser.html" accesskey="n" rel="next">Using Tree-sitter Parser</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Tree_002dsitter-Language-Definitions"></span><h3 class="section">37.1 Tree-sitter Language Definitions</h3>
<span id="index-language-definitions_002c-for-tree_002dsitter"></span>
<span id="Loading-a-language-definition"></span><h3 class="heading">Loading a language definition</h3>
<span id="index-loading-language-definition-for-tree_002dsitter"></span>
<span id="index-language-argument_002c-for-tree_002dsitter"></span>
<p>Tree-sitter relies on language definitions to parse text in that
language. In Emacs, a language definition is represented by a symbol.
For example, the C language definition is represented as the symbol
<code>c</code>, and <code>c</code> can be passed to tree-sitter functions as the
<var>language</var> argument.
</p>
<span id="index-treesit_002dextra_002dload_002dpath"></span>
<span id="index-treesit_002dload_002dlanguage_002derror"></span>
<span id="index-treesit_002dload_002dsuffixes"></span>
<p>Tree-sitter language definitions are distributed as dynamic libraries.
In order to use a language definition in Emacs, you need to make sure
that the dynamic library is installed on the system. Emacs looks for
language definitions in several places, in the following order:
</p>
<ul>
<li> first, in the list of directories specified by the variable
<code>treesit-extra-load-path</code>;
</li><li> then, in the <samp>tree-sitter</samp> subdirectory of the directory
specified by <code>user-emacs-directory</code> (see <a href="Init-File.html">The Init File</a>);
</li><li> and finally, in the system&rsquo;s default locations for dynamic libraries.
</li></ul>
<p>In each of these directories, Emacs looks for a file with file-name
extensions specified by the variable <code>treesit-load-suffixes</code>.
</p>
<p>If Emacs cannot find the library or has problems loading it, Emacs
signals the <code>treesit-load-language-error</code> error. The data of
that signal could be one of the following:
</p>
<dl compact="compact">
<dt><span><code>(not-found <var>error-msg</var> &hellip;)</code></span></dt>
<dd><p>This means that Emacs could not find the language definition library.
</p></dd>
<dt><span><code>(symbol-error <var>error-msg</var>)</code></span></dt>
<dd><p>This means that Emacs could not find in the library the expected function
that every language definition library should export.
</p></dd>
<dt><span><code>(version-mismatch <var>error-msg</var>)</code></span></dt>
<dd><p>This means that the version of language definition library is incompatible
with that of the tree-sitter library.
</p></dd>
</dl>
<p>In all of these cases, <var>error-msg</var> might provide additional
details about the failure.
</p>
<dl class="def">
<dt id="index-treesit_002dlanguage_002davailable_002dp"><span class="category">Function: </span><span><strong>treesit-language-available-p</strong> <em>language &amp;optional detail</em><a href='#index-treesit_002dlanguage_002davailable_002dp' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns non-<code>nil</code> if the language definitions for
<var>language</var> exist and can be loaded.
</p>
<p>If <var>detail</var> is non-<code>nil</code>, return <code>(t . nil)</code> when
<var>language</var> is available, and <code>(nil . <var>data</var>)</code> when it&rsquo;s
unavailable. <var>data</var> is the signal data of
<code>treesit-load-language-error</code>.
</p></dd></dl>
<span id="index-treesit_002dload_002dname_002doverride_002dlist"></span>
<p>By convention, the file name of the dynamic library for <var>language</var> is
<samp>libtree-sitter-<var>language</var>.<var>ext</var></samp>, where <var>ext</var> is the
system-specific extension for dynamic libraries. Also by convention,
the function provided by that library is named
<code>tree_sitter_<var>language</var></code>. If a language definition library
doesn&rsquo;t follow this convention, you should add an entry
</p>
<div class="example">
<pre class="example">(<var>language</var> <var>library-base-name</var> <var>function-name</var>)
</pre></div>
<p>to the list in the variable <code>treesit-load-name-override-list</code>, where
<var>library-base-name</var> is the basename of the dynamic library&rsquo;s file name,
(usually, <samp>libtree-sitter-<var>language</var></samp>), and
<var>function-name</var> is the function provided by the library
(usually, <code>tree_sitter_<var>language</var></code>). For example,
</p>
<div class="example">
<pre class="example">(cool-lang &quot;libtree-sitter-coool&quot; &quot;tree_sitter_cooool&quot;)
</pre></div>
<p>for a language that considers itself too &ldquo;cool&rdquo; to abide by
conventions.
</p>
<span id="index-language_002ddefinition-version_002c-compatibility"></span>
<dl class="def">
<dt id="index-treesit_002dlanguage_002dversion"><span class="category">Function: </span><span><strong>treesit-language-version</strong> <em>&amp;optional min-compatible</em><a href='#index-treesit_002dlanguage_002dversion' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the version of the language-definition
Application Binary Interface (<acronym>ABI</acronym>) supported by the
tree-sitter library. By default, it returns the latest ABI version
supported by the library, but if <var>min-compatible</var> is
non-<code>nil</code>, it returns the oldest ABI version which the library
still can support. Language definition libraries must be built for
ABI versions between the oldest and the latest versions supported by
the tree-sitter library, otherwise the library will be unable to load
them.
</p></dd></dl>
<span id="Concrete-syntax-tree"></span><h3 class="heading">Concrete syntax tree</h3>
<span id="index-syntax-tree_002c-concrete"></span>
<p>A syntax tree is what a parser generates. In a syntax tree, each node
represents a piece of text, and is connected to each other by a
parent-child relationship. For example, if the source text is
</p>
<div class="example">
<pre class="example">1 + 2
</pre></div>
<p>its syntax tree could be
</p>
<div class="example">
<pre class="example"> +--------------+
| root &quot;1 + 2&quot; |
+--------------+
|
+--------------------------------+
| expression &quot;1 + 2&quot; |
+--------------------------------+
| | |
+------------+ +--------------+ +------------+
| number &quot;1&quot; | | operator &quot;+&quot; | | number &quot;2&quot; |
+------------+ +--------------+ +------------+
</pre></div>
<p>We can also represent it as an s-expression:
</p>
<div class="example">
<pre class="example">(root (expression (number) (operator) (number)))
</pre></div>
<span id="Node-types"></span><h4 class="subheading">Node types</h4>
<span id="index-node-types_002c-in-a-syntax-tree"></span>
<span id="index-type-of-node_002c-tree_002dsitter"></span>
<span id="tree_002dsitter-node-type"></span><span id="index-named-node_002c-tree_002dsitter"></span>
<span id="tree_002dsitter-named-node"></span><span id="index-anonymous-node_002c-tree_002dsitter"></span>
<p>Names like <code>root</code>, <code>expression</code>, <code>number</code>, and
<code>operator</code> specify the <em>type</em> of the nodes. However, not all
nodes in a syntax tree have a type. Nodes that don&rsquo;t have a type are
known as <em>anonymous nodes</em>, and nodes with a type are <em>named
nodes</em>. Anonymous nodes are tokens with fixed spellings, including
punctuation characters like bracket &lsquo;<samp>]</samp>&rsquo;, and keywords like
<code>return</code>.
</p>
<span id="Field-names"></span><h4 class="subheading">Field names</h4>
<span id="index-field-name_002c-tree_002dsitter"></span>
<span id="index-tree_002dsitter-node-field-name"></span>
<span id="tree_002dsitter-node-field-name"></span><p>To make the syntax tree easier to analyze, many language definitions
assign <em>field names</em> to child nodes. For example, a
<code>function_definition</code> node could have a <code>declarator</code> and a
<code>body</code>:
</p>
<div class="example">
<pre class="example">(function_definition
declarator: (declaration)
body: (compound_statement))
</pre></div>
<span id="Exploring-the-syntax-tree"></span><h3 class="heading">Exploring the syntax tree</h3>
<span id="index-explore-tree_002dsitter-syntax-tree"></span>
<span id="index-inspection-of-tree_002dsitter-parse-tree-nodes"></span>
<p>To aid in understanding the syntax of a language and in debugging of
Lisp program that use the syntax tree, Emacs provides an &ldquo;explore&rdquo;
mode, which displays the syntax tree of the source in the current
buffer in real time. Emacs also comes with an &ldquo;inspect mode&rdquo;, which
displays information of the nodes at point in the mode-line.
</p>
<dl class="def">
<dt id="index-treesit_002dexplore_002dmode"><span class="category">Command: </span><span><strong>treesit-explore-mode</strong><a href='#index-treesit_002dexplore_002dmode' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This mode pops up a window displaying the syntax tree of the source in
the current buffer. Selecting text in the source buffer highlights
the corresponding nodes in the syntax tree display. Clicking
on nodes in the syntax tree highlights the corresponding text in the
source buffer.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dinspect_002dmode"><span class="category">Command: </span><span><strong>treesit-inspect-mode</strong><a href='#index-treesit_002dinspect_002dmode' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This minor mode displays on the mode-line the node that <em>starts</em>
at point. For example, the mode-line can display
</p>
<div class="example">
<pre class="example"><var>parent</var> <var>field</var>: (<var>node</var> (<var>child</var> (&hellip;)))
</pre></div>
<p>where <var>node</var>, <var>child</var>, etc., are nodes which begin at point.
<var>parent</var> is the parent of <var>node</var>. <var>node</var> is displayed in
a bold typeface. <var>field-name</var>s are field names of <var>node</var> and
of <var>child</var>, etc.
</p>
<p>If no node starts at point, i.e., point is in the middle of a node,
then the mode line displays the earliest node that spans point, and
its immediate parent.
</p>
<p>This minor mode doesn&rsquo;t create parsers on its own. It uses the first
parser in <code>(treesit-parser-list)</code> (see <a href="Using-Parser.html">Using Tree-sitter Parser</a>).
</p></dd></dl>
<span id="Reading-the-grammar-definition"></span><h3 class="heading">Reading the grammar definition</h3>
<span id="index-reading-grammar-definition_002c-tree_002dsitter"></span>
<p>Authors of language definitions define the <em>grammar</em> of a
programming language, which determines how a parser constructs a
concrete syntax tree out of the program text. In order to use the
syntax tree effectively, you need to consult the <em>grammar file</em>.
</p>
<p>The grammar file is usually <samp>grammar.js</samp> in a language
definition&rsquo;s project repository. The link to a language definition&rsquo;s
home page can be found on
<a href="https://tree-sitter.github.io/tree-sitter">tree-sitter&rsquo;s
homepage</a>.
</p>
<p>The grammar definition is written in JavaScript. For example, the
rule matching a <code>function_definition</code> node looks like
</p>
<div class="example">
<pre class="example">function_definition: $ =&gt; seq(
$.declaration_specifiers,
field('declarator', $.declaration),
field('body', $.compound_statement)
)
</pre></div>
<p>The rules are represented by functions that take a single argument
<var>$</var>, representing the whole grammar. The function itself is
constructed by other functions: the <code>seq</code> function puts together
a sequence of children; the <code>field</code> function annotates a child
with a field name. If we write the above definition in the so-called
<em>Backus-Naur Form</em> (<acronym>BNF</acronym>) syntax, it would look like
</p>
<div class="example">
<pre class="example">function_definition :=
&lt;declaration_specifiers&gt; &lt;declaration&gt; &lt;compound_statement&gt;
</pre></div>
<p>and the node returned by the parser would look like
</p>
<div class="example">
<pre class="example">(function_definition
(declaration_specifier)
declarator: (declaration)
body: (compound_statement))
</pre></div>
<p>Below is a list of functions that one can see in a grammar definition.
Each function takes other rules as arguments and returns a new rule.
</p>
<dl compact="compact">
<dt><span><code>seq(<var>rule1</var>, <var>rule2</var>, &hellip;)</code></span></dt>
<dd><p>matches each rule one after another.
</p></dd>
<dt><span><code>choice(<var>rule1</var>, <var>rule2</var>, &hellip;)</code></span></dt>
<dd><p>matches one of the rules in its arguments.
</p></dd>
<dt><span><code>repeat(<var>rule</var>)</code></span></dt>
<dd><p>matches <var>rule</var> for <em>zero or more</em> times.
This is like the &lsquo;<samp>*</samp>&rsquo; operator in regular expressions.
</p></dd>
<dt><span><code>repeat1(<var>rule</var>)</code></span></dt>
<dd><p>matches <var>rule</var> for <em>one or more</em> times.
This is like the &lsquo;<samp>+</samp>&rsquo; operator in regular expressions.
</p></dd>
<dt><span><code>optional(<var>rule</var>)</code></span></dt>
<dd><p>matches <var>rule</var> for <em>zero or one</em> time.
This is like the &lsquo;<samp>?</samp>&rsquo; operator in regular expressions.
</p></dd>
<dt><span><code>field(<var>name</var>, <var>rule</var>)</code></span></dt>
<dd><p>assigns field name <var>name</var> to the child node matched by <var>rule</var>.
</p></dd>
<dt><span><code>alias(<var>rule</var>, <var>alias</var>)</code></span></dt>
<dd><p>makes nodes matched by <var>rule</var> appear as <var>alias</var> in the syntax
tree generated by the parser. For example,
</p>
<div class="example">
<pre class="example">alias(preprocessor_call_exp, call_expression)
</pre></div>
<p>makes any node matched by <code>preprocessor_call_exp</code> appear as
<code>call_expression</code>.
</p></dd>
</dl>
<p>Below are grammar functions of lesser importance for reading a
language definition.
</p>
<dl compact="compact">
<dt><span><code>token(<var>rule</var>)</code></span></dt>
<dd><p>marks <var>rule</var> to produce a single leaf node. That is, instead of
generating a parent node with individual child nodes under it,
everything is combined into a single leaf node. See <a href="Retrieving-Nodes.html">Retrieving Nodes</a>.
</p></dd>
<dt><span><code>token.immediate(<var>rule</var>)</code></span></dt>
<dd><p>Normally, grammar rules ignore preceding whitespace; this
changes <var>rule</var> to match only when there is no preceding
whitespaces.
</p></dd>
<dt><span><code>prec(<var>n</var>, <var>rule</var>)</code></span></dt>
<dd><p>gives <var>rule</var> the level-<var>n</var> precedence.
</p></dd>
<dt><span><code>prec.left([<var>n</var>,] <var>rule</var>)</code></span></dt>
<dd><p>marks <var>rule</var> as left-associative, optionally with level <var>n</var>.
</p></dd>
<dt><span><code>prec.right([<var>n</var>,] <var>rule</var>)</code></span></dt>
<dd><p>marks <var>rule</var> as right-associative, optionally with level <var>n</var>.
</p></dd>
<dt><span><code>prec.dynamic(<var>n</var>, <var>rule</var>)</code></span></dt>
<dd><p>this is like <code>prec</code>, but the precedence is applied at runtime
instead.
</p></dd>
</dl>
<p>The documentation of the tree-sitter project has
<a href="https://tree-sitter.github.io/tree-sitter/creating-parsers">more
about writing a grammar</a>. Read especially &ldquo;The Grammar DSL&rdquo;
section.
</p>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Using-Parser.html">Using Tree-sitter Parser</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,328 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Multiple Languages (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Multiple Languages (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Multiple Languages (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Tree_002dsitter-major-modes.html" rel="next" title="Tree-sitter major modes">
<link href="Pattern-Matching.html" rel="prev" title="Pattern Matching">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Multiple-Languages">
<div class="header">
<p>
Next: <a href="Tree_002dsitter-major-modes.html" accesskey="n" rel="next">Developing major modes with tree-sitter</a>, Previous: <a href="Pattern-Matching.html" accesskey="p" rel="prev">Pattern Matching Tree-sitter Nodes</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Parsing-Text-in-Multiple-Languages"></span><h3 class="section">37.6 Parsing Text in Multiple Languages</h3>
<span id="index-multiple-languages_002c-parsing-with-tree_002dsitter"></span>
<span id="index-parsing-multiple-languages-with-tree_002dsitter"></span>
<p>Sometimes, the source of a programming language could contain snippets
of other languages; <acronym>HTML</acronym> + <acronym>CSS</acronym> + JavaScript is one
example. In that case, text segments written in different languages
need to be assigned different parsers. Traditionally, this is
achieved by using narrowing. While tree-sitter works with narrowing
(see <a href="Using-Parser.html#tree_002dsitter-narrowing">narrowing</a>), the recommended way is
instead to set regions of buffer text (i.e., ranges) in which a parser
will operate. This section describes functions for setting and
getting ranges for a parser.
</p>
<p>Lisp programs should call <code>treesit-update-ranges</code> to make sure
the ranges for each parser are correct before using parsers in a
buffer, and call <code>treesit-language-at</code> to figure out the language
responsible for the text at some position. These two functions don&rsquo;t
work by themselves, they need major modes to set
<code>treesit-range-settings</code> and
<code>treesit-language-at-point-function</code>, which do the actual work.
These functions and variables are explained in more detail towards the
end of the section.
</p>
<span id="Getting-and-setting-ranges"></span><h3 class="heading">Getting and setting ranges</h3>
<dl class="def">
<dt id="index-treesit_002dparser_002dset_002dincluded_002dranges"><span class="category">Function: </span><span><strong>treesit-parser-set-included-ranges</strong> <em>parser ranges</em><a href='#index-treesit_002dparser_002dset_002dincluded_002dranges' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function sets up <var>parser</var> to operate on <var>ranges</var>. The
<var>parser</var> will only read the text of the specified ranges. Each
range in <var>ranges</var> is a list of the form <code>(<var>beg</var>&nbsp;.&nbsp;<var>end</var>)</code><!-- /@w -->.
</p>
<p>The ranges in <var>ranges</var> must come in order and must not overlap.
That is, in pseudo code:
</p>
<div class="example">
<pre class="example">(cl-loop for idx from 1 to (1- (length ranges))
for prev = (nth (1- idx) ranges)
for next = (nth idx ranges)
should (&lt;= (car prev) (cdr prev)
(car next) (cdr next)))
</pre></div>
<span id="index-treesit_002drange_002dinvalid"></span>
<p>If <var>ranges</var> violates this constraint, or something else went
wrong, this function signals the <code>treesit-range-invalid</code> error.
The signal data contains a specific error message and the ranges we
are trying to set.
</p>
<p>This function can also be used for disabling ranges. If <var>ranges</var>
is <code>nil</code>, the parser is set to parse the whole buffer.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">(treesit-parser-set-included-ranges
parser '((1 . 9) (16 . 24) (24 . 25)))
</pre></div>
</dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002dincluded_002dranges"><span class="category">Function: </span><span><strong>treesit-parser-included-ranges</strong> <em>parser</em><a href='#index-treesit_002dparser_002dincluded_002dranges' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the ranges set for <var>parser</var>. The return
value is the same as the <var>ranges</var> argument of
<code>treesit-parser-included-ranges</code>: a list of cons cells of the form
<code>(<var>beg</var>&nbsp;.&nbsp;<var>end</var>)</code><!-- /@w -->. If <var>parser</var> doesn&rsquo;t have any
ranges, the return value is <code>nil</code>.
</p>
<div class="example">
<pre class="example">(treesit-parser-included-ranges parser)
&rArr; ((1 . 9) (16 . 24) (24 . 25))
</pre></div>
</dd></dl>
<dl class="def">
<dt id="index-treesit_002dquery_002drange"><span class="category">Function: </span><span><strong>treesit-query-range</strong> <em>source query &amp;optional beg end</em><a href='#index-treesit_002dquery_002drange' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function matches <var>source</var> with <var>query</var> and returns the
ranges of captured nodes. The return value is a list of cons cells of
the form <code>(<var>beg</var>&nbsp;.&nbsp;<var>end</var>)</code><!-- /@w -->, where <var>beg</var> and
<var>end</var> specify the beginning and the end of a region of text.
</p>
<p>For convenience, <var>source</var> can be a language symbol, a parser, or a
node. If it&rsquo;s a language symbol, this function matches in the root
node of the first parser using that language; if a parser, this
function matches in the root node of that parser; if a node, this
function matches in that node.
</p>
<p>The argument <var>query</var> is the query used to capture nodes
(see <a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>). The capture names don&rsquo;t matter. The
arguments <var>beg</var> and <var>end</var>, if both non-<code>nil</code>, limit the
range in which this function queries.
</p>
<p>Like other query functions, this function raises the
<code>treesit-query-error</code> error if <var>query</var> is malformed.
</p></dd></dl>
<span id="Supporting-multiple-languages-in-Lisp-programs"></span><h3 class="heading">Supporting multiple languages in Lisp programs</h3>
<p>It should suffice for general Lisp programs to call the following two
functions in order to support program sources that mixes multiple
languages.
</p>
<dl class="def">
<dt id="index-treesit_002dupdate_002dranges"><span class="category">Function: </span><span><strong>treesit-update-ranges</strong> <em>&amp;optional beg end</em><a href='#index-treesit_002dupdate_002dranges' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function updates ranges for parsers in the buffer. It makes sure
the parsers&rsquo; ranges are set correctly between <var>beg</var> and <var>end</var>,
according to <code>treesit-range-settings</code>. If omitted, <var>beg</var>
defaults to the beginning of the buffer, and <var>end</var> defaults to the
end of the buffer.
</p>
<p>For example, fontification functions use this function before querying
for nodes in a region.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dlanguage_002dat"><span class="category">Function: </span><span><strong>treesit-language-at</strong> <em>pos</em><a href='#index-treesit_002dlanguage_002dat' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the language of the text at buffer position
<var>pos</var>. Under the hood it calls
<code>treesit-language-at-point-function</code> and returns its return
value. If <code>treesit-language-at-point-function</code> is <code>nil</code>,
this function returns the language of the first parser in the returned
value of <code>treesit-parser-list</code>. If there is no parser in the
buffer, it returns <code>nil</code>.
</p></dd></dl>
<span id="Supporting-multiple-languages-in-major-modes"></span><h3 class="heading">Supporting multiple languages in major modes</h3>
<span id="index-host-language_002c-tree_002dsitter"></span>
<span id="index-tree_002dsitter-host-and-embedded-languages"></span>
<span id="index-embedded-language_002c-tree_002dsitter"></span>
<p>Normally, in a set of languages that can be mixed together, there is a
<em>host language</em> and one or more <em>embedded languages</em>. A Lisp
program usually first parses the whole document with the host
language&rsquo;s parser, retrieves some information, sets ranges for the
embedded languages with that information, and then parses the embedded
languages.
</p>
<p>Take a buffer containing <acronym>HTML</acronym>, <acronym>CSS</acronym> and JavaScript
as an example. A Lisp program will first parse the whole buffer with
an <acronym>HTML</acronym> parser, then query the parser for
<code>style_element</code> and <code>script_element</code> nodes, which
correspond to <acronym>CSS</acronym> and JavaScript text, respectively. Then
it sets the range of the <acronym>CSS</acronym> and JavaScript parser to the
ranges in which their corresponding nodes span.
</p>
<p>Given a simple <acronym>HTML</acronym> document:
</p>
<div class="example">
<pre class="example">&lt;html&gt;
&lt;script&gt;1 + 2&lt;/script&gt;
&lt;style&gt;body { color: &quot;blue&quot;; }&lt;/style&gt;
&lt;/html&gt;
</pre></div>
<p>a Lisp program will first parse with a <acronym>HTML</acronym> parser, then set
ranges for <acronym>CSS</acronym> and JavaScript parsers:
</p>
<div class="example">
<pre class="example">;; Create parsers.
(setq html (treesit-get-parser-create 'html))
(setq css (treesit-get-parser-create 'css))
(setq js (treesit-get-parser-create 'javascript))
</pre><pre class="example">
</pre><pre class="example">;; Set CSS ranges.
(setq css-range
(treesit-query-range
'html
&quot;(style_element (raw_text) @capture)&quot;))
(treesit-parser-set-included-ranges css css-range)
</pre><pre class="example">
</pre><pre class="example">;; Set JavaScript ranges.
(setq js-range
(treesit-query-range
'html
&quot;(script_element (raw_text) @capture)&quot;))
(treesit-parser-set-included-ranges js js-range)
</pre></div>
<p>Emacs automates this process in <code>treesit-update-ranges</code>. A
multi-language major mode should set <code>treesit-range-settings</code> so
that <code>treesit-update-ranges</code> knows how to perform this process
automatically. Major modes should use the helper function
<code>treesit-range-rules</code> to generate a value that can be assigned to
<code>treesit-range-settings</code>. The settings in the following example
directly translate into operations shown above.
</p>
<div class="example">
<pre class="example">(setq-local treesit-range-settings
(treesit-range-rules
:embed 'javascript
:host 'html
'((script_element (raw_text) @capture))
</pre><pre class="example">
</pre><pre class="example"> :embed 'css
:host 'html
'((style_element (raw_text) @capture))))
</pre></div>
<dl class="def">
<dt id="index-treesit_002drange_002drules"><span class="category">Function: </span><span><strong>treesit-range-rules</strong> <em>&amp;rest query-specs</em><a href='#index-treesit_002drange_002drules' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function is used to set <var>treesit-range-settings</var>. It
takes care of compiling queries and other post-processing, and outputs
a value that <var>treesit-range-settings</var> can have.
</p>
<p>It takes a series of <var>query-spec</var>s, where each <var>query-spec</var> is
a <var>query</var> preceded by zero or more <var>keyword</var>/<var>value</var>
pairs. Each <var>query</var> is a tree-sitter query in either the
string, s-expression or compiled form, or a function.
</p>
<p>If <var>query</var> is a tree-sitter query, it should be preceded by two
<var>:keyword</var>/<var>value</var> pairs, where the <code>:embed</code> keyword
specifies the embedded language, and the <code>:host</code> keyword
specified the host language.
</p>
<p><code>treesit-update-ranges</code> uses <var>query</var> to figure out how to set
the ranges for parsers for the embedded language. It queries
<var>query</var> in a host language parser, computes the ranges in which
the captured nodes span, and applies these ranges to embedded
language parsers.
</p>
<p>If <var>query</var> is a function, it doesn&rsquo;t need any <var>:keyword</var> and
<var>value</var> pair. It should be a function that takes 2 arguments,
<var>start</var> and <var>end</var>, and sets the ranges for parsers in the
current buffer in the region between <var>start</var> and <var>end</var>. It is
fine for this function to set ranges in a larger region that
encompasses the region between <var>start</var> and <var>end</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002drange_002dsettings"><span class="category">Variable: </span><span><strong>treesit-range-settings</strong><a href='#index-treesit_002drange_002dsettings' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This variable helps <code>treesit-update-ranges</code> in updating the
ranges for parsers in the buffer. It is a list of <var>setting</var>s
where the exact format of a <var>setting</var> is considered internal. You
should use <code>treesit-range-rules</code> to generate a value that this
variable can have.
</p>
</dd></dl>
<dl class="def">
<dt id="index-treesit_002dlanguage_002dat_002dpoint_002dfunction"><span class="category">Variable: </span><span><strong>treesit-language-at-point-function</strong><a href='#index-treesit_002dlanguage_002dat_002dpoint_002dfunction' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This variable&rsquo;s value should be a function that takes a single
argument, <var>pos</var>, which is a buffer position, and returns the
language of the buffer text at <var>pos</var>. This variable is used by
<code>treesit-language-at</code>.
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Tree_002dsitter-major-modes.html">Developing major modes with tree-sitter</a>, Previous: <a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,248 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Parser-based Font Lock (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Parser-based Font Lock (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Parser-based Font Lock (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Font-Lock-Mode.html" rel="up" title="Font Lock Mode">
<link href="Multiline-Font-Lock.html" rel="prev" title="Multiline Font Lock">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="subsection" id="Parser_002dbased-Font-Lock">
<div class="header">
<p>
Previous: <a href="Multiline-Font-Lock.html" accesskey="p" rel="prev">Multiline Font Lock Constructs</a>, Up: <a href="Font-Lock-Mode.html" accesskey="u" rel="up">Font Lock Mode</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Parser_002dbased-Font-Lock-1"></span><h4 class="subsection">24.6.10 Parser-based Font Lock</h4>
<span id="index-parser_002dbased-font_002dlock"></span>
<p>Besides simple syntactic font lock and regexp-based font lock, Emacs
also provides complete syntactic font lock with the help of a parser.
Currently, Emacs uses the tree-sitter library (see <a href="Parsing-Program-Source.html">Parsing Program Source</a>) for this purpose.
</p>
<p>Parser-based font lock and other font lock mechanisms are not mutually
exclusive. By default, if enabled, parser-based font lock runs first,
replacing syntactic font lock, then the regexp-based font lock.
</p>
<p>Although parser-based font lock doesn&rsquo;t share the same customization
variables with regexp-based font lock, it uses similar customization
schemes. The tree-sitter counterpart of <var>font-lock-keywords</var> is
<var>treesit-font-lock-settings</var>.
</p>
<span id="index-tree_002dsitter-fontifications_002c-overview"></span>
<span id="index-fontifications-with-tree_002dsitter_002c-overview"></span>
<p>In general, tree-sitter fontification works as follows:
</p>
<ul>
<li> A Lisp program (usually, part of a major mode) provides a <em>query</em>
consisting of <em>patterns</em>, each pattern associated with a
<em>capture name</em>.
</li><li> The tree-sitter library finds the nodes in the parse tree
that match these patterns, tags the nodes with the corresponding
capture names, and returns them to the Lisp program.
</li><li> The Lisp program uses the returned nodes to highlight the portions of
buffer text corresponding to each node as appropriate, using the
tagged capture names of the nodes to determine the correct
fontification. For example, a node tagged <code>font-lock-keyword</code>
would be highlighted in <code>font-lock-keyword</code> face.
</li></ul>
<p>For more information about queries, patterns, and capture names, see
<a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>.
</p>
<p>To setup tree-sitter fontification, a major mode should first set
<code>treesit-font-lock-settings</code> with the output of
<code>treesit-font-lock-rules</code>, then call
<code>treesit-major-mode-setup</code>.
</p>
<dl class="def">
<dt id="index-treesit_002dfont_002dlock_002drules"><span class="category">Function: </span><span><strong>treesit-font-lock-rules</strong> <em>&amp;rest query-specs</em><a href='#index-treesit_002dfont_002dlock_002drules' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function is used to set <var>treesit-font-lock-settings</var>. It
takes care of compiling queries and other post-processing, and outputs
a value that <var>treesit-font-lock-settings</var> accepts. Here&rsquo;s an
example:
</p>
<div class="example">
<pre class="example">(treesit-font-lock-rules
:language 'javascript
:feature 'constant
:override t
'((true) @font-lock-constant-face
(false) @font-lock-constant-face)
:language 'html
:feature 'script
&quot;(script_element) @font-lock-builtin-face&quot;)
</pre></div>
<p>This function takes a series of <var>query-spec</var>s, where each
<var>query-spec</var> is a <var>query</var> preceded by one or more
<var>:keyword</var>/<var>value</var> pairs. Each <var>query</var> is a
tree-sitter query in either the string, s-expression or compiled form.
</p>
<p>For each <var>query</var>, the <var>:keyword</var>/<var>value</var> pairs that
precede it add meta information to it. The <code>:lang</code> keyword
declares <var>query</var>&rsquo;s language. The <code>:feature</code> keyword sets the
feature name of <var>query</var>. Users can control which features are
enabled with <code>font-lock-maximum-decoration</code> and
<code>treesit-font-lock-feature-list</code> (described below). These two
keywords are mandatory.
</p>
<p>Other keywords are optional:
</p>
<table>
<thead><tr><th width="15%">Keyword</th><th width="15%">Value</th><th width="60%">Description</th></tr></thead>
<tr><td width="15%"><code>:override</code></td><td width="15%">nil</td><td width="60%">If the region already has a face, discard the new face</td></tr>
<tr><td width="15%"></td><td width="15%">t</td><td width="60%">Always apply the new face</td></tr>
<tr><td width="15%"></td><td width="15%"><code>append</code></td><td width="60%">Append the new face to existing ones</td></tr>
<tr><td width="15%"></td><td width="15%"><code>prepend</code></td><td width="60%">Prepend the new face to existing ones</td></tr>
<tr><td width="15%"></td><td width="15%"><code>keep</code></td><td width="60%">Fill-in regions without an existing face</td></tr>
</table>
<p>Lisp programs mark patterns in <var>query</var> with capture names (names
that starts with <code>@</code>), and tree-sitter will return matched nodes
tagged with those same capture names. For the purpose of
fontification, capture names in <var>query</var> should be face names like
<code>font-lock-keyword-face</code>. The captured node will be fontified
with that face.
</p>
<span id="index-treesit_002dfontify_002dwith_002doverride"></span>
<p>Capture names can also be function names, in which case the function
is called with 4 arguments: <var>node</var> and <var>override</var>, <var>start</var>
and <var>end</var>, where <var>node</var> is the node itself, <var>override</var> is
the override property of the rule which captured this node, and
<var>start</var> and <var>end</var> limits the region in which this function
should fontify. (If this function wants to respect the <var>override</var>
argument, it can use <code>treesit-fontify-with-override</code>.)
</p>
<p>Beyond the 4 arguments presented, this function should accept more
arguments as optional arguments for future extensibility.
</p>
<p>If a capture name is both a face and a function, the face takes
priority. If a capture name is neither a face nor a function, it is
ignored.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dfont_002dlock_002dfeature_002dlist"><span class="category">Variable: </span><span><strong>treesit-font-lock-feature-list</strong><a href='#index-treesit_002dfont_002dlock_002dfeature_002dlist' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This is a list of lists of feature symbols. Each element of the list
is a list that represents a decoration level.
<code>font-lock-maximum-decoration</code> controls which levels are
activated.
</p>
<p>Each element of the list is a list of the form <code>(<var>feature</var>&nbsp;&hellip;)</code><!-- /@w -->, where each <var>feature</var> corresponds to the
<code>:feature</code> value of a query defined in
<code>treesit-font-lock-rules</code>. Removing a feature symbol from this
list disables the corresponding query during font-lock.
</p>
<p>Common feature names, for many programming languages, include
<code>definition</code>, <code>type</code>, <code>assignment</code>, <code>builtin</code>,
<code>constant</code>, <code>keyword</code>, <code>string-interpolation</code>,
<code>comment</code>, <code>doc</code>, <code>string</code>, <code>operator</code>,
<code>preprocessor</code>, <code>escape-sequence</code>, and <code>key</code>. Major
modes are free to subdivide or extend these common features.
</p>
<p>Some of these features warrant some explanation: <code>definition</code>
highlights whatever is being defined, e.g., the function name in a
function definition, the struct name in a struct definition, the
variable name in a variable definition; <code>assignment</code> highlights
the whatever is being assigned to, e.g., the variable or field in an
assignment statement; <code>key</code> highlights keys in key-value pairs,
e.g., keys in a JSON object, or a Python dictionary; <code>doc</code>
highlights docstrings or doc-comments.
</p>
<p>For example, the value of this variable could be:
</p><div class="example">
<pre class="example">((comment string doc) ; level 1
(function-name keyword type builtin constant) ; level 2
(variable-name string-interpolation key)) ; level 3
</pre></div>
<p>Major modes should set this variable before calling
<code>treesit-major-mode-setup</code>.
</p>
<span id="index-treesit_002dfont_002dlock_002drecompute_002dfeatures"></span>
<p>For this variable to take effect, a Lisp program should call
<code>treesit-font-lock-recompute-features</code> (which resets
<code>treesit-font-lock-settings</code> accordingly), or
<code>treesit-major-mode-setup</code> (which calls
<code>treesit-font-lock-recompute-features</code>).
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dfont_002dlock_002dsettings"><span class="category">Variable: </span><span><strong>treesit-font-lock-settings</strong><a href='#index-treesit_002dfont_002dlock_002dsettings' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>A list of settings for tree-sitter based font lock. The exact format
of each setting is considered internal. One should always use
<code>treesit-font-lock-rules</code> to set this variable.
</p>
</dd></dl>
<p>Multi-language major modes should provide range functions in
<code>treesit-range-functions</code>, and Emacs will set the ranges
accordingly before fontifing a region (see <a href="Multiple-Languages.html">Parsing Text in Multiple Languages</a>).
</p>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="Multiline-Font-Lock.html">Multiline Font Lock Constructs</a>, Up: <a href="Font-Lock-Mode.html">Font Lock Mode</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,281 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Parser-based Indentation (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Parser-based Indentation (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Parser-based Indentation (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Auto_002dIndentation.html" rel="up" title="Auto-Indentation">
<link href="SMIE.html" rel="prev" title="SMIE">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="subsection" id="Parser_002dbased-Indentation">
<div class="header">
<p>
Previous: <a href="SMIE.html" accesskey="p" rel="prev">Simple Minded Indentation Engine</a>, Up: <a href="Auto_002dIndentation.html" accesskey="u" rel="up">Automatic Indentation of code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Parser_002dbased-Indentation-1"></span><h4 class="subsection">24.7.2 Parser-based Indentation</h4>
<span id="index-parser_002dbased-indentation"></span>
<p>When built with the tree-sitter library (see <a href="Parsing-Program-Source.html">Parsing Program Source</a>), Emacs is capable of parsing the program source and producing
a syntax tree. This syntax tree can be used for guiding the program
source indentation commands. For maximum flexibility, it is possible
to write a custom indentation function that queries the syntax tree
and indents accordingly for each language, but that is a lot of work.
It is more convenient to use the simple indentation engine described
below: then the major mode needs only to write some indentation rules
and the engine takes care of the rest.
</p>
<p>To enable the parser-based indentation engine, either set
<var>treesit-simple-indent-rules</var> and call
<code>treesit-major-mode-setup</code>, or equivalently, set the value of
<code>indent-line-function</code> to <code>treesit-indent</code>.
</p>
<dl class="def">
<dt id="index-treesit_002dindent_002dfunction"><span class="category">Variable: </span><span><strong>treesit-indent-function</strong><a href='#index-treesit_002dindent_002dfunction' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This variable stores the actual function called by
<code>treesit-indent</code>. By default, its value is
<code>treesit-simple-indent</code>. In the future we might add other,
more complex indentation engines.
</p></dd></dl>
<span id="Writing-indentation-rules"></span><h3 class="heading">Writing indentation rules</h3>
<span id="index-indentation-rules_002c-for-parser_002dbased-indentation"></span>
<dl class="def">
<dt id="index-treesit_002dsimple_002dindent_002drules"><span class="category">Variable: </span><span><strong>treesit-simple-indent-rules</strong><a href='#index-treesit_002dsimple_002dindent_002drules' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This local variable stores indentation rules for every language. It is
a list of the form: <code>(<var>language</var>&nbsp;.&nbsp;<var>rules</var>)</code><!-- /@w -->, where
<var>language</var> is a language symbol, and <var>rules</var> is a list of the
form <code>(<var>matcher</var>&nbsp;<var>anchor</var>&nbsp;<var>offset</var>)</code><!-- /@w -->.
</p>
<p>First, Emacs passes the smallest tree-sitter node at the beginning of
the current line to <var>matcher</var>; if it returns non-<code>nil</code>, this
rule is applicable. Then Emacs passes the node to <var>anchor</var>, which
returns a buffer position. Emacs takes the column number of that
position, adds <var>offset</var> to it, and the result is the indentation
column for the current line. <var>offset</var> can be an integer or a
variable whose value is an integer.
</p>
<p>The <var>matcher</var> and <var>anchor</var> are functions, and Emacs provides
convenient defaults for them.
</p>
<p>Each <var>matcher</var> or <var>anchor</var> is a function that takes three
arguments: <var>node</var>, <var>parent</var>, and <var>bol</var>. The argument
<var>bol</var> is the buffer position whose indentation is required: the
position of the first non-whitespace character after the beginning of
the line. The argument <var>node</var> is the largest (highest-in-tree)
node that starts at that position; and <var>parent</var> is the parent of
<var>node</var>. However, when that position is in a whitespace or inside
a multi-line string, no node can start at that position, so
<var>node</var> is <code>nil</code>. In that case, <var>parent</var> would be the
smallest node that spans that position.
</p>
<p>Emacs finds <var>bol</var>, <var>node</var> and <var>parent</var> and
passes them to each <var>matcher</var> and <var>anchor</var>. <var>matcher</var>
should return non-<code>nil</code> if the rule is applicable, and
<var>anchor</var> should return a buffer position.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dsimple_002dindent_002dpresets"><span class="category">Variable: </span><span><strong>treesit-simple-indent-presets</strong><a href='#index-treesit_002dsimple_002dindent_002dpresets' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This is a list of defaults for <var>matcher</var>s and <var>anchor</var>s in
<code>treesit-simple-indent-rules</code>. Each of them represents a function
that takes 3 arguments: <var>node</var>, <var>parent</var> and <var>bol</var>. The
available default functions are:
</p>
<dl compact="compact">
<dt id='index-no_002dnode'><span><code>no-node</code><a href='#index-no_002dnode' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function that is called with 3 arguments:
<var>node</var>, <var>parent</var>, and <var>bol</var>, and returns non-<code>nil</code>,
indicating a match, if <var>node</var> is <code>nil</code>, i.e., there is no
node that starts at <var>bol</var>. This is the case when <var>bol</var> is on
an empty line or inside a multi-line string, etc.
</p>
</dd>
<dt id='index-parent_002dis'><span><code>parent-is</code><a href='#index-parent_002dis' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function of one argument, <var>type</var>; it returns a
function that is called with 3 arguments: <var>node</var>, <var>parent</var>,
and <var>bol</var>, and returns non-<code>nil</code> (i.e., a match) if
<var>parent</var>&rsquo;s type matches regexp <var>type</var>.
</p>
</dd>
<dt id='index-node_002dis'><span><code>node-is</code><a href='#index-node_002dis' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function of one argument, <var>type</var>; it returns a
function that is called with 3 arguments: <var>node</var>, <var>parent</var>,
and <var>bol</var>, and returns non-<code>nil</code> if <var>node</var>&rsquo;s type matches
regexp <var>type</var>.
</p>
</dd>
<dt id='index-query'><span><code>query</code><a href='#index-query' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function of one argument, <var>query</var>; it returns a
function that is called with 3 arguments: <var>node</var>, <var>parent</var>,
and <var>bol</var>, and returns non-<code>nil</code> if querying <var>parent</var>
with <var>query</var> captures <var>node</var> (see <a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>).
</p>
</dd>
<dt id='index-match'><span><code>match</code><a href='#index-match' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function of 5 arguments: <var>node-type</var>,
<var>parent-type</var>, <var>node-field</var>, <var>node-index-min</var>, and
<var>node-index-max</var>). It returns a function that is called with 3
arguments: <var>node</var>, <var>parent</var>, and <var>bol</var>, and returns
non-<code>nil</code> if <var>node</var>&rsquo;s type matches regexp <var>node-type</var>,
<var>parent</var>&rsquo;s type matches regexp <var>parent-type</var>, <var>node</var>&rsquo;s
field name in <var>parent</var> matches regexp <var>node-field</var>, and
<var>node</var>&rsquo;s index among its siblings is between <var>node-index-min</var>
and <var>node-index-max</var>. If the value of an argument is <code>nil</code>,
this matcher doesn&rsquo;t check that argument. For example, to match the
first child where parent is <code>argument_list</code>, use
</p>
<div class="example">
<pre class="example">(match nil &quot;argument_list&quot; nil nil 0 0)
</pre></div>
</dd>
<dt id='index-comment_002dend'><span><code>comment-end</code><a href='#index-comment_002dend' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This matcher is a function that is called with 3 arguments:
<var>node</var>, <var>parent</var>, and <var>bol</var>, and returns non-<code>nil</code> if
point is before a comment ending token. Comment ending tokens are
defined by regular expression <code>treesit-comment-end</code>
(see <a href="Tree_002dsitter-major-modes.html">treesit-comment-end</a>).
</p>
</dd>
<dt id='index-first_002dsibling'><span><code>first-sibling</code><a href='#index-first_002dsibling' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the start of the first child
of <var>parent</var>.
</p>
</dd>
<dt id='index-parent'><span><code>parent</code><a href='#index-parent' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the start of <var>parent</var>.
</p>
</dd>
<dt id='index-parent_002dbol'><span><code>parent-bol</code><a href='#index-parent_002dbol' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the first non-space character
on the line of <var>parent</var>.
</p>
</dd>
<dt id='index-prev_002dsibling'><span><code>prev-sibling</code><a href='#index-prev_002dsibling' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the start of the previous
sibling of <var>node</var>.
</p>
</dd>
<dt id='index-no_002dindent'><span><code>no-indent</code><a href='#index-no_002dindent' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the start of <var>node</var>.
</p>
</dd>
<dt id='index-prev_002dline'><span><code>prev-line</code><a href='#index-prev_002dline' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the first non-whitespace
character on the previous line.
</p>
</dd>
<dt id='index-point_002dmin'><span><code>point-min</code><a href='#index-point_002dmin' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the beginning of the buffer.
This is useful as the beginning of the buffer is always at column 0.
</p>
</dd>
<dt id='index-comment_002dstart'><span><code>comment-start</code><a href='#index-comment_002dstart' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the position right after the
comment-start token. Comment-start tokens are defined by regular
expression <code>treesit-comment-start</code> (see <a href="Tree_002dsitter-major-modes.html">treesit-comment-start</a>). This function assumes <var>parent</var> is
the comment node.
</p>
</dd>
<dt id='index-coment_002dstart_002dskip'><span><code>coment-start-skip</code><a href='#index-coment_002dstart_002dskip' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This anchor is a function that is called with 3 arguments: <var>node</var>,
<var>parent</var>, and <var>bol</var>, and returns the position after the
comment-start token and any whitespace characters following that
token. Comment-start tokens are defined by regular expression
<code>treesit-comment-start</code>. This function assumes <var>parent</var> is
the comment node.
</p></dd>
</dl>
</dd></dl>
<span id="Indentation-utilities"></span><h3 class="heading">Indentation utilities</h3>
<span id="index-utility-functions-for-parser_002dbased-indentation"></span>
<p>Here are some utility functions that can help writing parser-based
indentation rules.
</p>
<dl class="def">
<dt id="index-treesit_002dcheck_002dindent"><span class="category">Function: </span><span><strong>treesit-check-indent</strong> <em>mode</em><a href='#index-treesit_002dcheck_002dindent' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function checks the current buffer&rsquo;s indentation against major
mode <var>mode</var>. It indents the current buffer according to
<var>mode</var> and compares the results with the current indentation.
Then it pops up a buffer showing the differences. Correct
indentation (target) is shown in green color, current indentation is
shown in red color. </p></dd></dl>
<p>It is also helpful to use <code>treesit-inspect-mode</code> (see <a href="Language-Definitions.html">Tree-sitter Language Definitions</a>) when writing indentation rules.
</p>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="SMIE.html">Simple Minded Indentation Engine</a>, Up: <a href="Auto_002dIndentation.html">Automatic Indentation of code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,126 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Parsing Program Source (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Parsing Program Source (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Parsing Program Source (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html" rel="up" title="Top">
<link href="Abbrevs.html" rel="next" title="Abbrevs">
<link href="Syntax-Tables.html" rel="prev" title="Syntax Tables">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="chapter" id="Parsing-Program-Source">
<div class="header">
<p>
Next: <a href="Abbrevs.html" accesskey="n" rel="next">Abbrevs and Abbrev Expansion</a>, Previous: <a href="Syntax-Tables.html" accesskey="p" rel="prev">Syntax Tables</a>, Up: <a href="index.html" accesskey="u" rel="up">Emacs Lisp</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Parsing-Program-Source-1"></span><h2 class="chapter">37 Parsing Program Source</h2>
<span id="index-syntax-tree_002c-from-parsing-program-source"></span>
<p>Emacs provides various ways to parse program source text and produce a
<em>syntax tree</em>. In a syntax tree, text is no longer considered a
one-dimensional stream of characters, but a structured tree of nodes,
where each node representing a piece of text. Thus, a syntax tree can
enable interesting features like precise fontification, indentation,
navigation, structured editing, etc.
</p>
<p>Emacs has a simple facility for parsing balanced expressions
(see <a href="Parsing-Expressions.html">Parsing Expressions</a>). There is also the SMIE library for
generic navigation and indentation (see <a href="SMIE.html">Simple Minded Indentation Engine</a>).
</p>
<p>In addition to those, Emacs also provides integration with
<a href="https://tree-sitter.github.io/tree-sitter">the tree-sitter
library</a>) if support for it was compiled in. The tree-sitter library
implements an incremental parser and has support from a wide range of
programming languages.
</p>
<dl class="def">
<dt id="index-treesit_002davailable_002dp"><span class="category">Function: </span><span><strong>treesit-available-p</strong><a href='#index-treesit_002davailable_002dp' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns non-<code>nil</code> if tree-sitter features are
available for the current Emacs session.
</p></dd></dl>
<p>To be able to parse the program source using the tree-sitter library
and access the syntax tree of the program, a Lisp program needs to
load a language definition library, and create a parser for that
language and the current buffer. After that, the Lisp program can
query the parser about specific nodes of the syntax tree. Then, it
can access various kinds of information about each node, and search
for nodes using a powerful pattern-matching syntax. This chapter
explains how to do all this, and also how a Lisp program can work with
source files that mix multiple programming languages.
</p>
<ul class="section-toc">
<li><a href="Language-Definitions.html" accesskey="1">Tree-sitter Language Definitions</a></li>
<li><a href="Using-Parser.html" accesskey="2">Using Tree-sitter Parser</a></li>
<li><a href="Retrieving-Nodes.html" accesskey="3">Retrieving Nodes</a></li>
<li><a href="Accessing-Node-Information.html" accesskey="4">Accessing Node Information</a></li>
<li><a href="Pattern-Matching.html" accesskey="5">Pattern Matching Tree-sitter Nodes</a></li>
<li><a href="Multiple-Languages.html" accesskey="6">Parsing Text in Multiple Languages</a></li>
<li><a href="Tree_002dsitter-major-modes.html" accesskey="7">Developing major modes with tree-sitter</a></li>
<li><a href="Tree_002dsitter-C-API.html" accesskey="8">Tree-sitter C API Correspondence</a></li>
</ul>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Abbrevs.html">Abbrevs and Abbrev Expansion</a>, Previous: <a href="Syntax-Tables.html">Syntax Tables</a>, Up: <a href="index.html">Emacs Lisp</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,451 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Pattern Matching (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Pattern Matching (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Pattern Matching (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Multiple-Languages.html" rel="next" title="Multiple Languages">
<link href="Accessing-Node-Information.html" rel="prev" title="Accessing Node Information">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Pattern-Matching">
<div class="header">
<p>
Next: <a href="Multiple-Languages.html" accesskey="n" rel="next">Parsing Text in Multiple Languages</a>, Previous: <a href="Accessing-Node-Information.html" accesskey="p" rel="prev">Accessing Node Information</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Pattern-Matching-Tree_002dsitter-Nodes"></span><h3 class="section">37.5 Pattern Matching Tree-sitter Nodes</h3>
<span id="index-pattern-matching-with-tree_002dsitter-nodes"></span>
<span id="index-capturing_002c-tree_002dsitter-node"></span>
<p>Tree-sitter lets Lisp programs match patterns using a small
declarative language. This pattern matching consists of two steps:
first tree-sitter matches a <em>pattern</em> against nodes in the syntax
tree, then it <em>captures</em> specific nodes that matched the pattern
and returns the captured nodes.
</p>
<p>We describe first how to write the most basic query pattern and how to
capture nodes in a pattern, then the pattern-matching function, and
finally the more advanced pattern syntax.
</p>
<span id="Basic-query-syntax"></span><h3 class="heading">Basic query syntax</h3>
<span id="index-tree_002dsitter-query-pattern-syntax"></span>
<span id="index-pattern-syntax_002c-tree_002dsitter-query"></span>
<span id="index-query_002c-tree_002dsitter"></span>
<p>A <em>query</em> consists of multiple <em>patterns</em>. Each pattern is an
s-expression that matches a certain node in the syntax node. A
pattern has the form <code>(<var>type</var>&nbsp;(<var>child</var>&hellip;))</code><!-- /@w -->
</p>
<p>For example, a pattern that matches a <code>binary_expression</code> node that
contains <code>number_literal</code> child nodes would look like
</p>
<div class="example">
<pre class="example">(binary_expression (number_literal))
</pre></div>
<p>To <em>capture</em> a node using the query pattern above, append
<code>@<var>capture-name</var></code> after the node pattern you want to
capture. For example,
</p>
<div class="example">
<pre class="example">(binary_expression (number_literal) @number-in-exp)
</pre></div>
<p>captures <code>number_literal</code> nodes that are inside a
<code>binary_expression</code> node with the capture name
<code>number-in-exp</code>.
</p>
<p>We can capture the <code>binary_expression</code> node as well, with, for
example, the capture name <code>biexp</code>:
</p>
<div class="example">
<pre class="example">(binary_expression
(number_literal) @number-in-exp) @biexp
</pre></div>
<span id="Query-function"></span><h3 class="heading">Query function</h3>
<span id="index-query-functions_002c-tree_002dsitter"></span>
<p>Now we can introduce the <em>query functions</em>.
</p>
<dl class="def">
<dt id="index-treesit_002dquery_002dcapture"><span class="category">Function: </span><span><strong>treesit-query-capture</strong> <em>node query &amp;optional beg end node-only</em><a href='#index-treesit_002dquery_002dcapture' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function matches patterns in <var>query</var> within <var>node</var>.
The argument <var>query</var> can be either a string, a s-expression, or a
compiled query object. For now, we focus on the string syntax;
s-expression syntax and compiled query are described at the end of the
section.
</p>
<p>The argument <var>node</var> can also be a parser or a language symbol. A
parser means using its root node, a language symbol means find or
create a parser for that language in the current buffer, and use the
root node.
</p>
<p>The function returns all the captured nodes in a list of the form
<code>(<var><span class="nolinebreak">capture_name</span></var>&nbsp;.&nbsp;<var>node</var>)</code><!-- /@w -->. If <var>node-only</var> is
non-<code>nil</code>, it returns the list of nodes instead. By default the
entire text of <var>node</var> is searched, but if <var>beg</var> and <var>end</var>
are both non-<code>nil</code>, they specify the region of buffer text where
this function should match nodes. Any matching node whose span
overlaps with the region between <var>beg</var> and <var>end</var> are captured,
it doesn&rsquo;t have to be completely in the region.
</p>
<span id="index-treesit_002dquery_002derror"></span>
<span id="index-treesit_002dquery_002dvalidate"></span>
<p>This function raises the <code>treesit-query-error</code> error if
<var>query</var> is malformed. The signal data contains a description of
the specific error. You can use <code>treesit-query-validate</code> to
validate and debug the query.
</p></dd></dl>
<p>For example, suppose <var>node</var>&rsquo;s text is <code>1 + 2</code>, and
<var>query</var> is
</p>
<div class="example">
<pre class="example">(setq query
&quot;(binary_expression
(number_literal) @number-in-exp) @biexp&quot;)
</pre></div>
<p>Matching that query would return
</p>
<div class="example">
<pre class="example">(treesit-query-capture node query)
&rArr; ((biexp . <var>&lt;node for &quot;1 + 2&quot;&gt;</var>)
(number-in-exp . <var>&lt;node for &quot;1&quot;&gt;</var>)
(number-in-exp . <var>&lt;node for &quot;2&quot;&gt;</var>))
</pre></div>
<p>As mentioned earlier, <var>query</var> could contain multiple patterns.
For example, it could have two top-level patterns:
</p>
<div class="example">
<pre class="example">(setq query
&quot;(binary_expression) @biexp
(number_literal) @number @biexp&quot;)
</pre></div>
<dl class="def">
<dt id="index-treesit_002dquery_002dstring"><span class="category">Function: </span><span><strong>treesit-query-string</strong> <em>string query language</em><a href='#index-treesit_002dquery_002dstring' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function parses <var>string</var> with <var>language</var>, matches its
root node with <var>query</var>, and returns the result.
</p></dd></dl>
<span id="More-query-syntax"></span><h3 class="heading">More query syntax</h3>
<p>Besides node type and capture, tree-sitter&rsquo;s pattern syntax can
express anonymous node, field name, wildcard, quantification,
grouping, alternation, anchor, and predicate.
</p>
<span id="Anonymous-node"></span><h4 class="subheading">Anonymous node</h4>
<p>An anonymous node is written verbatim, surrounded by quotes. A
pattern matching (and capturing) keyword <code>return</code> would be
</p>
<div class="example">
<pre class="example">&quot;return&quot; @keyword
</pre></div>
<span id="Wild-card"></span><h4 class="subheading">Wild card</h4>
<p>In a pattern, &lsquo;<samp>(_)</samp>&rsquo; matches any named node, and &lsquo;<samp>_</samp>&rsquo; matches
any named and anonymous node. For example, to capture any named child
of a <code>binary_expression</code> node, the pattern would be
</p>
<div class="example">
<pre class="example">(binary_expression (_) @in_biexp)
</pre></div>
<span id="Field-name"></span><h4 class="subheading">Field name</h4>
<p>It is possible to capture child nodes that have specific field names.
In the pattern below, <code>declarator</code> and <code>body</code> are field
names, indicated by the colon following them.
</p>
<div class="example">
<pre class="example">(function_definition
declarator: (_) @func-declarator
body: (_) @func-body)
</pre></div>
<p>It is also possible to capture a node that doesn&rsquo;t have a certain
field, say, a <code>function_definition</code> without a <code>body</code> field.
</p>
<div class="example">
<pre class="example">(function_definition !body) @func-no-body
</pre></div>
<span id="Quantify-node"></span><h4 class="subheading">Quantify node</h4>
<span id="index-quantify-node_002c-tree_002dsitter"></span>
<p>Tree-sitter recognizes quantification operators &lsquo;<samp>*</samp>&rsquo;, &lsquo;<samp>+</samp>&rsquo; and
&lsquo;<samp>?</samp>&rsquo;. Their meanings are the same as in regular expressions:
&lsquo;<samp>*</samp>&rsquo; matches the preceding pattern zero or more times, &lsquo;<samp>+</samp>&rsquo;
matches one or more times, and &lsquo;<samp>?</samp>&rsquo; matches zero or one time.
</p>
<p>For example, the following pattern matches <code>type_declaration</code>
nodes that has <em>zero or more</em> <code>long</code> keyword.
</p>
<div class="example">
<pre class="example">(type_declaration &quot;long&quot;*) @long-type
</pre></div>
<p>The following pattern matches a type declaration that has zero or one
<code>long</code> keyword:
</p>
<div class="example">
<pre class="example">(type_declaration &quot;long&quot;?) @long-type
</pre></div>
<span id="Grouping"></span><h4 class="subheading">Grouping</h4>
<p>Similar to groups in regular expression, we can bundle patterns into
groups and apply quantification operators to them. For example, to
express a comma separated list of identifiers, one could write
</p>
<div class="example">
<pre class="example">(identifier) (&quot;,&quot; (identifier))*
</pre></div>
<span id="Alternation"></span><h4 class="subheading">Alternation</h4>
<p>Again, similar to regular expressions, we can express &ldquo;match anyone
from this group of patterns&rdquo; in a pattern. The syntax is a list of
patterns enclosed in square brackets. For example, to capture some
keywords in C, the pattern would be
</p>
<div class="example">
<pre class="example">[
&quot;return&quot;
&quot;break&quot;
&quot;if&quot;
&quot;else&quot;
] @keyword
</pre></div>
<span id="Anchor"></span><h4 class="subheading">Anchor</h4>
<p>The anchor operator &lsquo;<samp>.</samp>&rsquo; can be used to enforce juxtaposition,
i.e., to enforce two things to be directly next to each other. The
two &ldquo;things&rdquo; can be two nodes, or a child and the end of its parent.
For example, to capture the first child, the last child, or two
adjacent children:
</p>
<div class="example">
<pre class="example">;; Anchor the child with the end of its parent.
(compound_expression (_) @last-child .)
</pre><pre class="example">
</pre><pre class="example">;; Anchor the child with the beginning of its parent.
(compound_expression . (_) @first-child)
</pre><pre class="example">
</pre><pre class="example">;; Anchor two adjacent children.
(compound_expression
(_) @prev-child
.
(_) @next-child)
</pre></div>
<p>Note that the enforcement of juxtaposition ignores any anonymous
nodes.
</p>
<span id="Predicate"></span><h4 class="subheading">Predicate</h4>
<p>It is possible to add predicate constraints to a pattern. For
example, with the following pattern:
</p>
<div class="example">
<pre class="example">(
(array . (_) @first (_) @last .)
(#equal @first @last)
)
</pre></div>
<p>tree-sitter only matches arrays where the first element equals to
the last element. To attach a predicate to a pattern, we need to
group them together. A predicate always starts with a &lsquo;<samp>#</samp>&rsquo;.
Currently there are two predicates, <code>#equal</code> and <code>#match</code>.
</p>
<dl class="def">
<dt id="index-equal-1"><span class="category">Predicate: </span><span><strong>equal</strong> <em>arg1 arg2</em><a href='#index-equal-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Matches if <var>arg1</var> equals to <var>arg2</var>. Arguments can be either
strings or capture names. Capture names represent the text that the
captured node spans in the buffer.
</p></dd></dl>
<dl class="def">
<dt id="index-match-1"><span class="category">Predicate: </span><span><strong>match</strong> <em>regexp capture-name</em><a href='#index-match-1' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Matches if the text that <var>capture-name</var>&rsquo;s node spans in the buffer
matches regular expression <var>regexp</var>. Matching is case-sensitive.
</p></dd></dl>
<p>Note that a predicate can only refer to capture names that appear in
the same pattern. Indeed, it makes little sense to refer to capture
names in other patterns.
</p>
<span id="S_002dexpression-patterns"></span><h3 class="heading">S-expression patterns</h3>
<span id="index-tree_002dsitter-patterns-as-sexps"></span>
<span id="index-patterns_002c-tree_002dsitter_002c-in-sexp-form"></span>
<p>Besides strings, Emacs provides a s-expression based syntax for
tree-sitter patterns. It largely resembles the string-based syntax.
For example, the following query
</p>
<div class="example">
<pre class="example">(treesit-query-capture
node &quot;(addition_expression
left: (_) @left
\&quot;+\&quot; @plus-sign
right: (_) @right) @addition
[\&quot;return\&quot; \&quot;break\&quot;] @keyword&quot;)
</pre></div>
<p>is equivalent to
</p>
<div class="example">
<pre class="example">(treesit-query-capture
node '((addition_expression
left: (_) @left
&quot;+&quot; @plus-sign
right: (_) @right) @addition
[&quot;return&quot; &quot;break&quot;] @keyword))
</pre></div>
<p>Most patterns can be written directly as strange but nevertheless
valid s-expressions. Only a few of them needs modification:
</p>
<ul>
<li> Anchor &lsquo;<samp>.</samp>&rsquo; is written as <code>:anchor</code>.
</li><li> &lsquo;<samp>?</samp>&rsquo; is written as &lsquo;<samp>:?</samp>&rsquo;.
</li><li> &lsquo;<samp>*</samp>&rsquo; is written as &lsquo;<samp>:*</samp>&rsquo;.
</li><li> &lsquo;<samp>+</samp>&rsquo; is written as &lsquo;<samp>:+</samp>&rsquo;.
</li><li> <code>#equal</code> is written as <code>:equal</code>. In general, predicates
change their &lsquo;<samp>#</samp>&rsquo; to &lsquo;<samp>:</samp>&rsquo;.
</li></ul>
<p>For example,
</p>
<div class="example">
<pre class="example">&quot;(
(compound_expression . (_) @first (_)* @rest)
(#match \&quot;love\&quot; @first)
)&quot;
</pre></div>
<p>is written in s-expression as
</p>
<div class="example">
<pre class="example">'((
(compound_expression :anchor (_) @first (_) :* @rest)
(:match &quot;love&quot; @first)
))
</pre></div>
<span id="Compiling-queries"></span><h3 class="heading">Compiling queries</h3>
<span id="index-compiling-tree_002dsitter-queries"></span>
<span id="index-queries_002c-compiling"></span>
<p>If a query is intended to be used repeatedly, especially in tight
loops, it is important to compile that query, because a compiled query
is much faster than an uncompiled one. A compiled query can be used
anywhere a query is accepted.
</p>
<dl class="def">
<dt id="index-treesit_002dquery_002dcompile"><span class="category">Function: </span><span><strong>treesit-query-compile</strong> <em>language query</em><a href='#index-treesit_002dquery_002dcompile' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function compiles <var>query</var> for <var>language</var> into a compiled
query object and returns it.
</p>
<p>This function raises the <code>treesit-query-error</code> error if
<var>query</var> is malformed. The signal data contains a description of
the specific error. You can use <code>treesit-query-validate</code> to
validate and debug the query.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dquery_002dlanguage"><span class="category">Function: </span><span><strong>treesit-query-language</strong> <em>query</em><a href='#index-treesit_002dquery_002dlanguage' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function return the language of <var>query</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dquery_002dexpand"><span class="category">Function: </span><span><strong>treesit-query-expand</strong> <em>query</em><a href='#index-treesit_002dquery_002dexpand' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function converts the s-expression <var>query</var> into the string
format.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dpattern_002dexpand"><span class="category">Function: </span><span><strong>treesit-pattern-expand</strong> <em>pattern</em><a href='#index-treesit_002dpattern_002dexpand' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function converts the s-expression <var>pattern</var> into the string
format.
</p></dd></dl>
<p>For more details, read the tree-sitter project&rsquo;s documentation about
pattern-matching, which can be found at
<a href="https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries">https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries</a>.
</p>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Multiple-Languages.html">Parsing Text in Multiple Languages</a>, Previous: <a href="Accessing-Node-Information.html">Accessing Node Information</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,421 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Retrieving Node (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Retrieving Node (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Retrieving Node (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Accessing-Node-Information.html" rel="next" title="Accessing Node Information">
<link href="Using-Parser.html" rel="prev" title="Using Parser">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Retrieving-Node">
<div class="header">
<p>
Next: <a href="Accessing-Node-Information.html" accesskey="n" rel="next">Accessing Node Information</a>, Previous: <a href="Using-Parser.html" accesskey="p" rel="prev">Using Tree-sitter Parser</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Retrieving-Node-1"></span><h3 class="section">37.3 Retrieving Node</h3>
<span id="index-retrieve-node_002c-tree_002dsitter"></span>
<span id="index-tree_002dsitter_002c-find-node"></span>
<span id="index-get-node_002c-tree_002dsitter"></span>
<span id="index-terminology_002c-for-tree_002dsitter-functions"></span>
<p>Here&rsquo;s some terminology and conventions we use when documenting
tree-sitter functions.
</p>
<p>We talk about a node being &ldquo;smaller&rdquo; or &ldquo;larger&rdquo;, and &ldquo;lower&rdquo; or
&ldquo;higher&rdquo;. A smaller and lower node is lower in the syntax tree and
therefore spans a smaller portion of buffer text; a larger and higher
node is higher up in the syntax tree, it contains many smaller nodes
as its children, and therefore spans a larger portion of text.
</p>
<p>When a function cannot find a node, it returns <code>nil</code>. For
convenience, all functions that take a node as argument and return
a node, also accept the node argument of <code>nil</code> and in that case
just return <code>nil</code>.
</p>
<span id="index-treesit_002dnode_002doutdated"></span>
<p>Nodes are not automatically updated when the associated buffer is
modified, and there is no way to update a node once it is retrieved.
Using an outdated node signals the <code>treesit-node-outdated</code> error.
</p>
<span id="Retrieving-node-from-syntax-tree"></span><h3 class="heading">Retrieving node from syntax tree</h3>
<span id="index-retrieving-tree_002dsitter-nodes"></span>
<span id="index-syntax-tree_002c-retrieving-nodes"></span>
<dl class="def">
<dt id="index-treesit_002dnode_002dat"><span class="category">Function: </span><span><strong>treesit-node-at</strong> <em>pos &amp;optional parser-or-lang named</em><a href='#index-treesit_002dnode_002dat' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the <em>smallest</em> node that starts at or after
the buffer position <var>pos</var>. In other words, the start of the node
is greater or equal to <var>pos</var>.
</p>
<p>When <var>parser-or-lang</var> is <code>nil</code> or omitted, this function uses
the first parser in <code>(treesit-parser-list)</code> of the current
buffer. If <var>parser-or-lang</var> is a parser object, it uses that
parser; if <var>parser-or-lang</var> is a language, it finds the first
parser using that language in <code>(treesit-parser-list)</code>, and uses
that.
</p>
<p>If <var>named</var> is non-<code>nil</code>, this function looks for a named node
only (see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p>
<p>When <var>pos</var> is after all the text in the buffer, technically there
is no node after <var>pos</var>. But for convenience, this function will
return the last leaf node in the parse tree. If <var>strict</var> is
non-<code>nil</code>, this function will strictly comply to the semantics and
return <var>nil</var>.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">;; Find the node at point in a C parser's syntax tree.
(treesit-node-at (point) 'c)
&rArr; #&lt;treesit-node (primitive_type) in 23-27&gt;
</pre></div>
</dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002don"><span class="category">Function: </span><span><strong>treesit-node-on</strong> <em>beg end &amp;optional parser-or-lang named</em><a href='#index-treesit_002dnode_002don' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the <em>smallest</em> node that covers the region
of buffer text between <var>beg</var> and <var>end</var>. In other words, the
start of the node is before or at <var>beg</var>, and the end of the node
is at or after <var>end</var>.
</p>
<p><em>Beware:</em> calling this function on an empty line that is not
inside any top-level construct (function definition, etc.) most
probably will give you the root node, because the root node is the
smallest node that covers that empty line. Most of the time, you want
to use <code>treesit-node-at</code>, described above, instead.
</p>
<p>When <var>parser-or-lang</var> is <code>nil</code>, this function uses the first
parser in <code>(treesit-parser-list)</code> of the current buffer. If
<var>parser-or-lang</var> is a parser object, it uses that parser; if
<var>parser-or-lang</var> is a language, it finds the first parser using
that language in <code>(treesit-parser-list)</code>, and uses that.
</p>
<p>If <var>named</var> is non-<code>nil</code>, this function looks for a named node
only (see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002droot_002dnode"><span class="category">Function: </span><span><strong>treesit-parser-root-node</strong> <em>parser</em><a href='#index-treesit_002dparser_002droot_002dnode' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the root node of the syntax tree generated by
<var>parser</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dbuffer_002droot_002dnode"><span class="category">Function: </span><span><strong>treesit-buffer-root-node</strong> <em>&amp;optional language</em><a href='#index-treesit_002dbuffer_002droot_002dnode' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the first parser that uses <var>language</var> in
<code>(treesit-parser-list)</code> of the current buffer, and returns the
root node generated by that parser. If it cannot find an appropriate
parser, it returns <code>nil</code>.
</p></dd></dl>
<p>Given a node, a Lisp program can retrieve other nodes starting from
it, or query for information about this node.
</p>
<span id="Retrieving-node-from-other-nodes"></span><h3 class="heading">Retrieving node from other nodes</h3>
<span id="index-syntax-tree-nodes_002c-retrieving-from-other-nodes"></span>
<span id="By-kinship"></span><h4 class="subheading">By kinship</h4>
<span id="index-kinship_002c-syntax-tree-nodes"></span>
<span id="index-nodes_002c-by-kinship"></span>
<span id="index-syntax-tree-nodes_002c-by-kinship"></span>
<dl class="def">
<dt id="index-treesit_002dnode_002dparent"><span class="category">Function: </span><span><strong>treesit-node-parent</strong> <em>node</em><a href='#index-treesit_002dnode_002dparent' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the immediate parent of <var>node</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dchild"><span class="category">Function: </span><span><strong>treesit-node-child</strong> <em>node n &amp;optional named</em><a href='#index-treesit_002dnode_002dchild' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the <var>n</var>&rsquo;th child of <var>node</var>. If
<var>named</var> is non-<code>nil</code>, it counts only named nodes
(see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p>
<p>For example, in a node that represents a string <code>&quot;text&quot;</code>, there
are three children nodes: the opening quote <code>&quot;</code>, the string text
<code>text</code>, and the closing quote <code>&quot;</code>. Among these nodes, the
first child is the opening quote <code>&quot;</code>, and the first named child
is the string text.
</p>
<p>This function returns <code>nil</code> if there is no <var>n</var>&rsquo;th child.
<var>n</var> could be negative, e.g., <code>-1</code> represents the last child.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dchildren"><span class="category">Function: </span><span><strong>treesit-node-children</strong> <em>node &amp;optional named</em><a href='#index-treesit_002dnode_002dchildren' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns all of <var>node</var>&rsquo;s children as a list. If
<var>named</var> is non-<code>nil</code>, it retrieves only named nodes.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnext_002dsibling"><span class="category">Function: </span><span><strong>treesit-next-sibling</strong> <em>node &amp;optional named</em><a href='#index-treesit_002dnext_002dsibling' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the next sibling of <var>node</var>. If <var>named</var> is
non-<code>nil</code>, it finds the next named sibling.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dprev_002dsibling"><span class="category">Function: </span><span><strong>treesit-prev-sibling</strong> <em>node &amp;optional named</em><a href='#index-treesit_002dprev_002dsibling' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the previous sibling of <var>node</var>. If
<var>named</var> is non-<code>nil</code>, it finds the previous named sibling.
</p></dd></dl>
<span id="By-field-name"></span><h4 class="subheading">By field name</h4>
<span id="index-nodes_002c-by-field-name"></span>
<span id="index-syntax-tree-nodes_002c-by-field-name"></span>
<p>To make the syntax tree easier to analyze, many language definitions
assign <em>field names</em> to child nodes (see <a href="Language-Definitions.html#tree_002dsitter-node-field-name">field name</a>). For example, a <code>function_definition</code> node
could have a <code>declarator</code> node and a <code>body</code> node.
</p>
<dl class="def">
<dt id="index-treesit_002dchild_002dby_002dfield_002dname"><span class="category">Function: </span><span><strong>treesit-child-by-field-name</strong> <em>node field-name</em><a href='#index-treesit_002dchild_002dby_002dfield_002dname' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the child of <var>node</var> whose field name is
<var>field-name</var>, a string.
</p>
<div class="example">
<pre class="example">;; Get the child that has &quot;body&quot; as its field name.
(treesit-child-by-field-name node &quot;body&quot;)
&rArr; #&lt;treesit-node (compound_statement) in 45-89&gt;
</pre></div>
</dd></dl>
<span id="By-position"></span><h4 class="subheading">By position</h4>
<span id="index-nodes_002c-by-position"></span>
<span id="index-syntax-tree-nodes_002c-by-position"></span>
<dl class="def">
<dt id="index-treesit_002dfirst_002dchild_002dfor_002dpos"><span class="category">Function: </span><span><strong>treesit-first-child-for-pos</strong> <em>node pos &amp;optional named</em><a href='#index-treesit_002dfirst_002dchild_002dfor_002dpos' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the first child of <var>node</var> that extends beyond
buffer position <var>pos</var>. &ldquo;Extends beyond&rdquo; means the end of the
child node is greater or equal to <var>pos</var>. This function only looks
for immediate children of <var>node</var>, and doesn&rsquo;t look in its
grandchildren. If <var>named</var> is non-<code>nil</code>, it looks for the
first named child (see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>).
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002ddescendant_002dfor_002drange"><span class="category">Function: </span><span><strong>treesit-node-descendant-for-range</strong> <em>node beg end &amp;optional named</em><a href='#index-treesit_002dnode_002ddescendant_002dfor_002drange' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds the <em>smallest</em> descendant node of <var>node</var>
that spans the region of text between positions <var>beg</var> and
<var>end</var>. It is similar to <code>treesit-node-at</code>. If <var>named</var>
is non-<code>nil</code>, it looks for smallest named child.
</p></dd></dl>
<span id="Searching-for-node"></span><h3 class="heading">Searching for node</h3>
<dl class="def">
<dt id="index-treesit_002dsearch_002dsubtree"><span class="category">Function: </span><span><strong>treesit-search-subtree</strong> <em>node predicate &amp;optional backward all limit</em><a href='#index-treesit_002dsearch_002dsubtree' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function traverses the subtree of <var>node</var> (including
<var>node</var> itself), looking for a node for which <var>predicate</var>
returns non-<code>nil</code>. <var>predicate</var> is a regexp that is matched
against each node&rsquo;s type, or a predicate function that takes a node
and returns non-<code>nil</code> if the node matches. The function returns
the first node that matches, or <code>nil</code> if none does.
</p>
<p>By default, this function only traverses named nodes, but if <var>all</var>
is non-<code>nil</code>, it traverses all the nodes. If <var>backward</var> is
non-<code>nil</code>, it traverses backwards (i.e., it visits the last child first
when traversing down the tree). If <var>limit</var> is non-<code>nil</code>, it
must be a number that limits the tree traversal to that many levels
down the tree.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dsearch_002dforward"><span class="category">Function: </span><span><strong>treesit-search-forward</strong> <em>start predicate &amp;optional backward all</em><a href='#index-treesit_002dsearch_002dforward' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Like <code>treesit-search-subtree</code>, this function also traverses the
parse tree and matches each node with <var>predicate</var> (except for
<var>start</var>), where <var>predicate</var> can be a regexp or a function.
For a tree like the below where <var>start</var> is marked S, this function
traverses as numbered from 1 to 12:
</p>
<div class="example">
<pre class="example"> 12
|
S--------3----------11
| | |
o--o-+--o 1--+--2 6--+-----10
| | | |
o o +-+-+ +--+--+
| | | | |
4 5 7 8 9
</pre></div>
<p>Note that this function doesn&rsquo;t traverse the subtree of <var>start</var>,
and it always traverse leaf nodes first, then upwards.
</p>
<p>Like <code>treesit-search-subtree</code>, this function only searches for
named nodes by default, but if <var>all</var> is non-<code>nil</code>, it
searches for all nodes. If <var>backward</var> is non-<code>nil</code>, it
searches backwards.
</p>
<p>While <code>treesit-search-subtree</code> traverses the subtree of a node,
this function starts with node <var>start</var> and traverses every node
that comes after it in the buffer position order, i.e., nodes with
start positions greater than the end position of <var>start</var>.
</p>
<p>In the tree shown above, <code>treesit-search-subtree</code> traverses node
S (<var>start</var>) and nodes marked with <code>o</code>, where this function
traverses the nodes marked with numbers. This function is useful for
answering questions like &ldquo;what is the first node after <var>start</var> in
the buffer that satisfies some condition?&rdquo;
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dsearch_002dforward_002dgoto"><span class="category">Function: </span><span><strong>treesit-search-forward-goto</strong> <em>node predicate &amp;optional start backward all</em><a href='#index-treesit_002dsearch_002dforward_002dgoto' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function moves point to the start or end of the next node after
<var>node</var> in the buffer that matches <var>predicate</var>. If <var>start</var>
is non-<code>nil</code>, stop at the beginning rather than the end of a node.
</p>
<p>This function guarantees that the matched node it returns makes
progress in terms of buffer position: the start/end position of the
returned node is always greater than that of <var>node</var>.
</p>
<p>Arguments <var>predicate</var>, <var>backward</var> and <var>all</var> are the same
as in <code>treesit-search-forward</code>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dinduce_002dsparse_002dtree"><span class="category">Function: </span><span><strong>treesit-induce-sparse-tree</strong> <em>root predicate &amp;optional process-fn limit</em><a href='#index-treesit_002dinduce_002dsparse_002dtree' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function creates a sparse tree from <var>root</var>&rsquo;s subtree.
</p>
<p>It takes the subtree under <var>root</var>, and combs it so only the nodes
that match <var>predicate</var> are left. Like previous functions, the
<var>predicate</var> can be a regexp string that matches against each
node&rsquo;s type, or a function that takes a node and return non-<code>nil</code>
if it matches.
</p>
<p>For example, for a subtree on the left that consist of both numbers
and letters, if <var>predicate</var> is &ldquo;letter only&rdquo;, the returned tree
is the one on the right.
</p>
<div class="example">
<pre class="example"> a a a
| | |
+---+---+ +---+---+ +---+---+
| | | | | | | | |
b 1 2 b | | b c d
| | =&gt; | | =&gt; |
c +--+ c + e
| | | | |
+--+ d 4 +--+ d
| | |
e 5 e
</pre></div>
<p>If <var>process-fn</var> is non-<code>nil</code>, instead of returning the matched
nodes, this function passes each node to <var>process-fn</var> and uses the
returned value instead. If non-<code>nil</code>, <var>limit</var> is the number of
levels to go down from <var>root</var>.
</p>
<p>Each node in the returned tree looks like
<code>(<var><span class="nolinebreak">tree-sitter-node</span></var>&nbsp;.&nbsp;(<var>child</var>&nbsp;&hellip;))</code><!-- /@w -->. The
<var>tree-sitter-node</var> of the root of this tree will be nil if
<var>root</var> doesn&rsquo;t match <var>predicate</var>. If no node matches
<var>predicate</var>, the function returns <code>nil</code>.
</p></dd></dl>
<span id="More-convenience-functions"></span><h3 class="heading">More convenience functions</h3>
<dl class="def">
<dt id="index-treesit_002dfilter_002dchild"><span class="category">Function: </span><span><strong>treesit-filter-child</strong> <em>node predicate &amp;optional named</em><a href='#index-treesit_002dfilter_002dchild' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function finds immediate children of <var>node</var> that satisfy
<var>predicate</var>.
</p>
<p>The <var>predicate</var> function takes a node as the argument and should
return non-<code>nil</code> to indicate that the node should be kept. If
<var>named</var> is non-<code>nil</code>, this function only examines the named
nodes.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparent_002duntil"><span class="category">Function: </span><span><strong>treesit-parent-until</strong> <em>node predicate</em><a href='#index-treesit_002dparent_002duntil' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function repeatedly finds the parents of <var>node</var>, and returns
the parent that satisfies <var>predicate</var>, a function that takes a
node as the argument. If no parent satisfies <var>predicate</var>, this
function returns <code>nil</code>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparent_002dwhile"><span class="category">Function: </span><span><strong>treesit-parent-while</strong> <em>node predicate</em><a href='#index-treesit_002dparent_002dwhile' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function repeatedly finds the parent of <var>node</var>, and keeps
doing so as long as the nodes satisfy <var>predicate</var>, a function that
takes a node as the argument. That is, this function returns the
farthest parent that still satisfies <var>predicate</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dnode_002dtop_002dlevel"><span class="category">Function: </span><span><strong>treesit-node-top-level</strong> <em>node &amp;optional type</em><a href='#index-treesit_002dnode_002dtop_002dlevel' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the highest parent of <var>node</var> that has the
same type as <var>node</var>. If no such parent exists, it returns
<code>nil</code>. Therefore this function is also useful for testing
whether <var>node</var> is top-level.
</p>
<p>If <var>type</var> is non-<code>nil</code>, this function matches each parent&rsquo;s
type with <var>type</var> as a regexp, rather than using <var>node</var>&rsquo;s type.
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Accessing-Node-Information.html">Accessing Node Information</a>, Previous: <a href="Using-Parser.html">Using Tree-sitter Parser</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,212 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Tree-sitter C API (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Tree-sitter C API (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Tree-sitter C API (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Tree_002dsitter-major-modes.html" rel="prev" title="Tree-sitter major modes">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Tree_002dsitter-C-API">
<div class="header">
<p>
Previous: <a href="Tree_002dsitter-major-modes.html" accesskey="p" rel="prev">Developing major modes with tree-sitter</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Tree_002dsitter-C-API-Correspondence"></span><h3 class="section">37.8 Tree-sitter C API Correspondence</h3>
<p>Emacs&rsquo; tree-sitter integration doesn&rsquo;t expose every feature
provided by tree-sitter&rsquo;s C API. Missing features include:
</p>
<ul>
<li> Creating a tree cursor and navigating the syntax tree with it.
</li><li> Setting timeout and cancellation flag for a parser.
</li><li> Setting the logger for a parser.
</li><li> Printing a <acronym>DOT</acronym> graph of the syntax tree to a file.
</li><li> Copying and modifying a syntax tree. (Emacs doesn&rsquo;t expose a tree
object.)
</li><li> Using (row, column) coordinates as position.
</li><li> Updating a node with changes. (In Emacs, retrieve a new node instead
of updating the existing one.)
</li><li> Querying statics of a language definition.
</li></ul>
<p>In addition, Emacs makes some changes to the C API to make the API more
convenient and idiomatic:
</p>
<ul>
<li> Instead of using byte positions, the Emacs Lisp API uses character
positions.
</li><li> Null nodes are converted to nil.
</li></ul>
<p>Below is the correspondence between all C API functions and their
ELisp counterparts. Sometimes one ELisp function corresponds to
multiple C functions, and many C functions don&rsquo;t have an ELisp
counterpart.
</p>
<div class="example">
<pre class="example">ts_parser_new treesit-parser-create
ts_parser_delete
ts_parser_set_language
ts_parser_language treesit-parser-language
ts_parser_set_included_ranges treesit-parser-set-included-ranges
ts_parser_included_ranges treesit-parser-included-ranges
ts_parser_parse
ts_parser_parse_string treesit-parse-string
ts_parser_parse_string_encoding
ts_parser_reset
ts_parser_set_timeout_micros
ts_parser_timeout_micros
ts_parser_set_cancellation_flag
ts_parser_cancellation_flag
ts_parser_set_logger
ts_parser_logger
ts_parser_print_dot_graphs
ts_tree_copy
ts_tree_delete
ts_tree_root_node
ts_tree_language
ts_tree_edit
ts_tree_get_changed_ranges
ts_tree_print_dot_graph
ts_node_type treesit-node-type
ts_node_symbol
ts_node_start_byte treesit-node-start
ts_node_start_point
ts_node_end_byte treesit-node-end
ts_node_end_point
ts_node_string treesit-node-string
ts_node_is_null
ts_node_is_named treesit-node-check
ts_node_is_missing treesit-node-check
ts_node_is_extra treesit-node-check
ts_node_has_changes
ts_node_has_error treesit-node-check
ts_node_parent treesit-node-parent
ts_node_child treesit-node-child
ts_node_field_name_for_child treesit-node-field-name-for-child
ts_node_child_count treesit-node-child-count
ts_node_named_child treesit-node-child
ts_node_named_child_count treesit-node-child-count
ts_node_child_by_field_name treesit-node-by-field-name
ts_node_child_by_field_id
ts_node_next_sibling treesit-next-sibling
ts_node_prev_sibling treesit-prev-sibling
ts_node_next_named_sibling treesit-next-sibling
ts_node_prev_named_sibling treesit-prev-sibling
ts_node_first_child_for_byte treesit-first-child-for-pos
ts_node_first_named_child_for_byte treesit-first-child-for-pos
ts_node_descendant_for_byte_range treesit-descendant-for-range
ts_node_descendant_for_point_range
ts_node_named_descendant_for_byte_range treesit-descendant-for-range
ts_node_named_descendant_for_point_range
ts_node_edit
ts_node_eq treesit-node-eq
ts_tree_cursor_new
ts_tree_cursor_delete
ts_tree_cursor_reset
ts_tree_cursor_current_node
ts_tree_cursor_current_field_name
ts_tree_cursor_current_field_id
ts_tree_cursor_goto_parent
ts_tree_cursor_goto_next_sibling
ts_tree_cursor_goto_first_child
ts_tree_cursor_goto_first_child_for_byte
ts_tree_cursor_goto_first_child_for_point
ts_tree_cursor_copy
ts_query_new
ts_query_delete
ts_query_pattern_count
ts_query_capture_count
ts_query_string_count
ts_query_start_byte_for_pattern
ts_query_predicates_for_pattern
ts_query_step_is_definite
ts_query_capture_name_for_id
ts_query_string_value_for_id
ts_query_disable_capture
ts_query_disable_pattern
ts_query_cursor_new
ts_query_cursor_delete
ts_query_cursor_exec treesit-query-capture
ts_query_cursor_did_exceed_match_limit
ts_query_cursor_match_limit
ts_query_cursor_set_match_limit
ts_query_cursor_set_byte_range
ts_query_cursor_set_point_range
ts_query_cursor_next_match
ts_query_cursor_remove_match
ts_query_cursor_next_capture
ts_language_symbol_count
ts_language_symbol_name
ts_language_symbol_for_name
ts_language_field_count
ts_language_field_name_for_id
ts_language_field_id_for_name
ts_language_symbol_type
ts_language_version
</pre></div>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="Tree_002dsitter-major-modes.html">Developing major modes with tree-sitter</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,231 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This is the GNU Emacs Lisp Reference Manual
corresponding to Emacs version 29.0.50.
Copyright © 1990-1996, 1998-2022 Free Software Foundation,
Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License," with the
Front-Cover Texts being "A GNU Manual," and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the
section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom." -->
<title>Using Parser (GNU Emacs Lisp Reference Manual)</title>
<meta name="description" content="Using Parser (GNU Emacs Lisp Reference Manual)">
<meta name="keywords" content="Using Parser (GNU Emacs Lisp Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Index.html" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source">
<link href="Retrieving-Nodes.html" rel="next" title="Retrieving Nodes">
<link href="Language-Definitions.html" rel="prev" title="Language Definitions">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="./manual.css">
</head>
<body lang="en">
<div class="section" id="Using-Parser">
<div class="header">
<p>
Next: <a href="Retrieving-Nodes.html" accesskey="n" rel="next">Retrieving Nodes</a>, Previous: <a href="Language-Definitions.html" accesskey="p" rel="prev">Tree-sitter Language Definitions</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Using-Tree_002dsitter-Parser"></span><h3 class="section">37.2 Using Tree-sitter Parser</h3>
<span id="index-tree_002dsitter-parser_002c-using"></span>
<p>This section describes how to create and configure a tree-sitter
parser. In Emacs, each tree-sitter parser is associated with a
buffer. As the user edits the buffer, the associated parser and
syntax tree are automatically kept up-to-date.
</p>
<dl class="def">
<dt id="index-treesit_002dmax_002dbuffer_002dsize"><span class="category">Variable: </span><span><strong>treesit-max-buffer-size</strong><a href='#index-treesit_002dmax_002dbuffer_002dsize' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This variable contains the maximum size of buffers in which
tree-sitter can be activated. Major modes should check this value
when deciding whether to enable tree-sitter features.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dcan_002denable_002dp"><span class="category">Function: </span><span><strong>treesit-can-enable-p</strong><a href='#index-treesit_002dcan_002denable_002dp' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function checks whether the current buffer is suitable for
activating tree-sitter features. It basically checks
<code>treesit-available-p</code> and <code>treesit-max-buffer-size</code>.
</p></dd></dl>
<span id="index-creating-tree_002dsitter-parsers"></span>
<span id="index-tree_002dsitter-parser_002c-creating"></span>
<dl class="def">
<dt id="index-treesit_002dparser_002dcreate"><span class="category">Function: </span><span><strong>treesit-parser-create</strong> <em>language &amp;optional buffer no-reuse</em><a href='#index-treesit_002dparser_002dcreate' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>Create a parser for the specified <var>buffer</var> and <var>language</var>
(see <a href="Language-Definitions.html">Tree-sitter Language Definitions</a>). If <var>buffer</var> is omitted or
<code>nil</code>, it stands for the current buffer.
</p>
<p>By default, this function reuses a parser if one already exists for
<var>language</var> in <var>buffer</var>, but if <var>no-reuse</var> is
non-<code>nil</code>, this function always creates a new parser.
</p></dd></dl>
<p>Given a parser, we can query information about it.
</p>
<dl class="def">
<dt id="index-treesit_002dparser_002dbuffer"><span class="category">Function: </span><span><strong>treesit-parser-buffer</strong> <em>parser</em><a href='#index-treesit_002dparser_002dbuffer' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the buffer associated with <var>parser</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002dlanguage"><span class="category">Function: </span><span><strong>treesit-parser-language</strong> <em>parser</em><a href='#index-treesit_002dparser_002dlanguage' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the language used by <var>parser</var>.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002dp"><span class="category">Function: </span><span><strong>treesit-parser-p</strong> <em>object</em><a href='#index-treesit_002dparser_002dp' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function checks if <var>object</var> is a tree-sitter parser, and
returns non-<code>nil</code> if it is, and <code>nil</code> otherwise.
</p></dd></dl>
<p>There is no need to explicitly parse a buffer, because parsing is done
automatically and lazily. A parser only parses when a Lisp program
queries for a node in its syntax tree. Therefore, when a parser is
first created, it doesn&rsquo;t parse the buffer; it waits until the Lisp
program queries for a node for the first time. Similarly, when some
change is made in the buffer, a parser doesn&rsquo;t re-parse immediately.
</p>
<span id="index-treesit_002dbuffer_002dtoo_002dlarge"></span>
<p>When a parser does parse, it checks for the size of the buffer.
Tree-sitter can only handle buffer no larger than about 4GB. If the
size exceeds that, Emacs signals the <code>treesit-buffer-too-large</code>
error with signal data being the buffer size.
</p>
<p>Once a parser is created, Emacs automatically adds it to the
internal parser list. Every time a change is made to the buffer,
Emacs updates parsers in this list so they can update their syntax
tree incrementally.
</p>
<dl class="def">
<dt id="index-treesit_002dparser_002dlist"><span class="category">Function: </span><span><strong>treesit-parser-list</strong> <em>&amp;optional buffer</em><a href='#index-treesit_002dparser_002dlist' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the parser list of <var>buffer</var>. If
<var>buffer</var> is <code>nil</code> or omitted, it defaults to the current
buffer.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002ddelete"><span class="category">Function: </span><span><strong>treesit-parser-delete</strong> <em>parser</em><a href='#index-treesit_002dparser_002ddelete' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function deletes <var>parser</var>.
</p></dd></dl>
<span id="index-tree_002dsitter-narrowing"></span>
<span id="tree_002dsitter-narrowing"></span><p>Normally, a parser &ldquo;sees&rdquo; the whole buffer, but when the buffer is
narrowed (see <a href="Narrowing.html">Narrowing</a>), the parser will only see the accessible
portion of the buffer. As far as the parser can tell, the hidden
region was deleted. When the buffer is later widened, the parser
thinks text is inserted at the beginning and at the end. Although
parsers respect narrowing, modes should not use narrowing as a means
to handle a multi-language buffer; instead, set the ranges in which the
parser should operate. See <a href="Multiple-Languages.html">Parsing Text in Multiple Languages</a>.
</p>
<p>Because a parser parses lazily, when the user or a Lisp program
narrows the buffer, the parser is not affected immediately; as long as
the mode doesn&rsquo;t query for a node while the buffer is narrowed, the
parser is oblivious of the narrowing.
</p>
<span id="index-tree_002dsitter-parse-string"></span>
<span id="index-parse-string_002c-tree_002dsitter"></span>
<p>Besides creating a parser for a buffer, a Lisp program can also parse a
string. Unlike a buffer, parsing a string is a one-off operation, and
there is no way to update the result.
</p>
<dl class="def">
<dt id="index-treesit_002dparse_002dstring"><span class="category">Function: </span><span><strong>treesit-parse-string</strong> <em>string language</em><a href='#index-treesit_002dparse_002dstring' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function parses <var>string</var> using <var>language</var>, and returns
the root node of the generated syntax tree.
</p></dd></dl>
<span id="Be-notified-by-changes-to-the-parse-tree"></span><h3 class="heading">Be notified by changes to the parse tree</h3>
<span id="index-update-callback_002c-for-tree_002dsitter-parse_002dtree"></span>
<span id="index-after_002dchange-notifier_002c-for-tree_002dsitter-parse_002dtree"></span>
<span id="index-tree_002dsitter-parse_002dtree_002c-update-and-after_002dchange-callback"></span>
<span id="index-notifiers_002c-tree_002dsitter"></span>
<p>A Lisp program might want to be notified of text affected by
incremental parsing. For example, inserting a comment-closing token
converts text before that token into a comment. Even
though the text is not directly edited, it is deemed to be &ldquo;changed&rdquo;
nevertheless.
</p>
<p>Emacs lets a Lisp program to register callback functions
(a.k.a. <em>notifiers</em>) for this kind of changes. A notifier
function takes two arguments: <var>ranges</var> and <var>parser</var>.
<var>ranges</var> is a list of cons cells of the form <code>(<var>start</var>&nbsp;.&nbsp;<var>end</var>)</code><!-- /@w -->, where <var>start</var> and <var>end</var> mark the start and the
end positions of a range. <var>parser</var> is the parser issuing the
notification.
</p>
<p>Every time a parser reparses a buffer, it compares the old and new
parse-tree, computes the ranges in which nodes have changed, and
passes the ranges to notifier functions.
</p>
<dl class="def">
<dt id="index-treesit_002dparser_002dadd_002dnotifier"><span class="category">Function: </span><span><strong>treesit-parser-add-notifier</strong> <em>parser function</em><a href='#index-treesit_002dparser_002dadd_002dnotifier' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function adds <var>function</var> to <var>parser</var>&rsquo;s list of
after-change notifier functions. <var>function</var> must be a function
symbol, not a lambda function (see <a href="Anonymous-Functions.html">Anonymous Functions</a>).
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002dremove_002dnotifier"><span class="category">Function: </span><span><strong>treesit-parser-remove-notifier</strong> <em>parser function</em><a href='#index-treesit_002dparser_002dremove_002dnotifier' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function removes <var>function</var> from the list of <var>parser</var>&rsquo;s
after-change notifier functions. <var>function</var> must be a function
symbol, rather than a lambda function.
</p></dd></dl>
<dl class="def">
<dt id="index-treesit_002dparser_002dnotifiers"><span class="category">Function: </span><span><strong>treesit-parser-notifiers</strong> <em>parser</em><a href='#index-treesit_002dparser_002dnotifiers' class='copiable-anchor'> &para;</a></span></dt>
<dd><p>This function returns the list of <var>parser</var>&rsquo;s notifier functions.
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Retrieving-Nodes.html">Retrieving Nodes</a>, Previous: <a href="Language-Definitions.html">Tree-sitter Language Definitions</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>

View file

@ -0,0 +1,23 @@
#!/bin/bash
MANUAL_DIR="../../../../doc/lispref"
THIS_DIR=$(pwd)
echo "Build manual"
cd "${MANUAL_DIR}"
make elisp.html HTML_OPTS="--html --css-ref=./manual.css"
cd "${THIS_DIR}"
echo "Copy manual"
cp -f "${MANUAL_DIR}/elisp.html/Parsing-Program-Source.html" .
cp -f "${MANUAL_DIR}/elisp.html/Language-Definitions.html" .
cp -f "${MANUAL_DIR}/elisp.html/Using-Parser.html" .
cp -f "${MANUAL_DIR}/elisp.html/Retrieving-Node.html" .
cp -f "${MANUAL_DIR}/elisp.html/Accessing-Node.html" .
cp -f "${MANUAL_DIR}/elisp.html/Pattern-Matching.html" .
cp -f "${MANUAL_DIR}/elisp.html/Multiple-Languages.html" .
cp -f "${MANUAL_DIR}/elisp.html/Tree_002dsitter-C-API.html" .
cp -f "${MANUAL_DIR}/elisp.html/Parser_002dbased-Font-Lock.html" .
cp -f "${MANUAL_DIR}/elisp.html/Parser_002dbased-Indentation.html" .

View file

@ -0,0 +1,374 @@
/* Style-sheet to use for Emacs manuals */
/* Copyright (C) 2013-2014 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
*/
/* style.css begins here */
/* This stylesheet is used by manuals and a few older resources. */
/* reset.css begins here */
/*
Software License Agreement (BSD License)
Copyright (c) 2006, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and
binary forms, with or without modification, arepermitted
provided that the following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
html {
color: #000;
background: #FFF;
}
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4,
h5, h6, pre, code, form, fieldset, legend, input,
button, textarea, p, blockquote, th, td {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset, img {
border: 0;
}
address, caption, cite, code, dfn, em, strong,
th, var, optgroup {
font-style: inherit;
font-weight: inherit;
}
del, ins {
text-decoration: none;
}
li {
list-style:none;
}
caption, th {
text-align: left;
}
h1, h2, h3, h4, h5, h6 {
font-size: 100%;
font-weight: normal;
}
q:before, q:after {
content:'';
}
abbr, acronym {
border: 0;
font-variant: normal;
}
sup {
vertical-align: baseline;
}
sub {
vertical-align: baseline;
}
legend {
color: #000;
}
input, button, textarea, select, optgroup, option {
font-family: inherit;
font-size: inherit;
font-style: inherit;
font-weight: inherit;
}
input, button, textarea, select {
*font-size: 100%;
}
/* reset.css ends here */
/*** PAGE LAYOUT ***/
html, body {
font-size: 1em;
text-align: left;
text-decoration: none;
}
html { background-color: #e7e7e7; }
body {
max-width: 74.92em;
margin: 0 auto;
padding: .5em 1em 1em 1em;
background-color: white;
border: .1em solid #c0c0c0;
}
/*** BASIC ELEMENTS ***/
/* Size and positioning */
p, pre, li, dt, dd, table, code, address { line-height: 1.3em; }
h1 { font-size: 2em; margin: 1em 0 }
h2 { font-size: 1.50em; margin: 1.0em 0 0.87em 0; }
h3 { font-size: 1.30em; margin: 1.0em 0 0.87em 0; }
h4 { font-size: 1.13em; margin: 1.0em 0 0.88em 0; }
h5 { font-size: 1.00em; margin: 1.0em 0 1.00em 0; }
p, pre { margin: 1em 0; }
pre { overflow: auto; padding-bottom: .3em; }
ul, ol, blockquote { margin-left: 1.5%; margin-right: 1.5%; }
hr { margin: 1em 0; }
/* Lists of underlined links are difficult to read. The top margin
gives a little more spacing between entries. */
ul li { margin: .5em 1em; }
ol li { margin: 1em; }
ol ul li { margin: .5em 1em; }
ul li p, ul ul li { margin-top: .3em; margin-bottom: .3em; }
ul ul, ol ul { margin-top: 0; margin-bottom: 0; }
/* Separate description lists from preceding text */
dl { margin: 1em 0 0 0; }
/* separate the "term" from subsequent "description" */
dt { margin: .5em 0; }
/* separate the "description" from subsequent list item
when the final <dd> child is an anonymous box */
dd { margin: .5em 3% 1em 3%; }
/* separate anonymous box (used to be the first element in <dd>)
from subsequent <p> */
dd p { margin: .5em 0; }
table {
display: block; overflow: auto;
margin-top: 1.5em; margin-bottom: 1.5em;
}
th { padding: .3em .5em; text-align: center; }
td { padding: .2em .5em; }
address { margin-bottom: 1em; }
caption { margin-bottom: .5em; text-align: center; }
sup { vertical-align: super; }
sub { vertical-align: sub; }
/* Style */
h1, h2, h3, h4, h5, h6, strong, dt, th { font-weight: bold; }
/* The default color (black) is too dark for large text in
bold font. */
h1, h2, h3, h4 { color: #333; }
h5, h6, dt { color: #222; }
a[href] { color: #005090; }
a[href]:visited { color: #100070; }
a[href]:active, a[href]:hover {
color: #100070;
text-decoration: none;
}
h1 a[href]:visited, h2 a[href]:visited, h3 a[href]:visited,
h4 a[href]:visited { color: #005090; }
h1 a[href]:hover, h2 a[href]:hover, h3 a[href]:hover,
h4 a[href]:hover { color: #100070; }
ol { list-style: decimal outside;}
ul { list-style: square outside; }
ul ul, ol ul { list-style: circle; }
li { list-style: inherit; }
hr { background-color: #ede6d5; }
table { border: 0; }
abbr,acronym {
border-bottom:1px dotted #000;
text-decoration: none;
cursor:help;
}
del { text-decoration: line-through; }
em { font-style: italic; }
small { font-size: .9em; }
img { max-width: 100%}
/*** SIMPLE CLASSES ***/
.center, .c { text-align: center; }
.nocenter{ text-align: left; }
.underline { text-decoration: underline; }
.nounderline { text-decoration: none; }
.no-bullet { list-style: none; }
.inline-list li { display: inline }
.netscape4, .no-display { display: none; }
/*** MANUAL PAGES ***/
/* This makes the very long tables of contents in Gnulib and other
manuals easier to read. */
.contents ul, .shortcontents ul { font-weight: bold; }
.contents ul ul, .shortcontents ul ul { font-weight: normal; }
.contents ul { list-style: none; }
/* For colored navigation bars (Emacs manual): make the bar extend
across the whole width of the page and give it a decent height. */
.header, .node { margin: 0 -1em; padding: 0 1em; }
.header p, .node p { line-height: 2em; }
/* For navigation links */
.node a, .header a { display: inline-block; line-height: 2em; }
.node a:hover, .header a:hover { background: #f2efe4; }
/* Inserts */
table.cartouche td { padding: 1.5em; }
div.display, div.lisp, div.smalldisplay,
div.smallexample, div.smalllisp { margin-left: 3%; }
div.example { padding: .8em 1.2em .4em; }
pre.example { padding: .8em 1.2em; }
div.example, pre.example {
margin: 1em 0 1em 3% ;
-webkit-border-radius: .3em;
-moz-border-radius: .3em;
border-radius: .3em;
border: 1px solid #d4cbb6;
background-color: #f2efe4;
}
div.example > pre.example {
padding: 0 0 .4em;
margin: 0;
border: none;
}
pre.menu-comment { padding-top: 1.3em; margin: 0; }
/*** FOR WIDE SCREENS ***/
@media (min-width: 40em) {
body { padding: .5em 3em 1em 3em; }
div.header, div.node { margin: 0 -3em; padding: 0 3em; }
}
/* style.css ends here */
/* makeinfo convert @deffn and similar functions to something inside
<blockquote>. style.css uses italic for blockquote. This looks poor
in the Emacs manuals, which make extensive use of @defun (etc).
In particular, references to function arguments appear as <var>
inside <blockquote>. Since <var> is also italic, it makes it
impossible to distinguish variables. We could change <var> to
e.g. bold-italic, or normal, or a different color, but that does
not look as good IMO. So we just override blockquote to be non-italic.
*/
blockquote { font-style: normal; }
var { font-style: italic; }
div.header {
background-color: #DDDDFF;
padding-top: 0.2em;
}
/*** Customization ***/
body {
font-family: Charter, serif;
font-size: 14pt;
line-height: 1.4;
background-color: #fefefc;
color: #202010;
}
pre.menu-comment {
font-family: Charter, serif;
font-size: 14pt;
}
body > *, body > div.display, body > div.lisp, body > div.smalldisplay,
body > div.example, body > div.smallexample, body > div.smalllisp {
width: 700px;
margin-left: auto;
margin-right: auto;
}
div.header {
width: 100%;
min-height: 3em;
font-size: 13pt;
}
/* Documentation block for functions and variables. Make then
narrower*/
dd {
margin: .5em 6% 1em 6%
}
code, pre, kbd, samp, tt {
font-size: 12pt;
font-family: monospace;
}
/* In each node we have index table to all sub-nodes. Make more space
for the first column, which is the name to each sub-node. */
table.menu tbody tr td:nth-child(1) {
white-space: nowrap;
}
div.header p {
text-align: center;
margin: 0.5em auto 0.5em auto;
}

View file

@ -17,7 +17,6 @@ TOC:
- More features?
- Common tasks (code snippets)
- Manual
- Appendix 1
* Building Emacs with tree-sitter
@ -43,9 +42,11 @@ You can use this script that I put together here:
https://github.com/casouri/tree-sitter-module
You can also find them under this directory in /build-modules.
This script automatically pulls and builds language definitions for C,
C++, Rust, JSON, Go, HTML, JavaScript, CSS, Python, Typescript,
C#, etc. Better yet, I pre-built these language definitions for
C++, Rust, JSON, Go, HTML, Javascript, CSS, Python, Typescript,
and C#. Better yet, I pre-built these language definitions for
GNU/Linux and macOS, they can be downloaded here:
https://github.com/casouri/tree-sitter-module/releases/tag/v2.1
@ -67,10 +68,6 @@ organization has all the "official" language definitions:
https://github.com/tree-sitter
Alternatively, you can use treesit-install-language-grammar command
and follow its instructions. If everything goes right, it should
automatically download and compile the language grammar for you.
* Setting up for adding major mode features
Start Emacs and load tree-sitter with
@ -81,10 +78,6 @@ Now check if Emacs is built with tree-sitter library
(treesit-available-p)
Make sure Emacs can find the language grammar you want to use
(treesit-language-available-p 'lang)
* Tree-sitter major modes
Tree-sitter modes should be separate major modes, so other modes
@ -96,15 +89,12 @@ modes.
If the tree-sitter variant and the "native" variant could share some
setup, you can create a "base mode", which only contains the common
setup. For example, python.el defines python-base-mode (shared),
python-mode (native), and python-ts-mode (tree-sitter).
setup. For example, there is python-base-mode (shared), python-mode
(native), and python-ts-mode (tree-sitter).
In the tree-sitter mode, check if we can use tree-sitter with
treesit-ready-p, it will error out if tree-sitter is not ready.
In Emacs 30 we'll introduce some mechanism to more gracefully inherit
modes and fallback to other modes.
* Naming convention
Use tree-sitter for text (documentation, comment), use treesit for
@ -190,17 +180,18 @@ mark the offending part in red.
To enable tree-sitter font-lock, set treesit-font-lock-settings and
treesit-font-lock-feature-list buffer-locally and call
treesit-major-mode-setup. For example, see
python--treesit-settings in python.el. Below is a snippet of it.
python--treesit-settings in python.el. Below I paste a snippet of
it.
Just like the current font-lock, if the to-be-fontified region already
has a face (ie, an earlier match fontified part/all of the region),
the new face is discarded rather than applied. If you want later
matches always override earlier matches, use the :override keyword.
Note that like the current font-lock, if the to-be-fontified region
already has a face (ie, an earlier match fontified part/all of the
region), the new face is discarded rather than applied. If you want
later matches always override earlier matches, use the :override
keyword.
Each rule should have a :feature, like function-name,
string-interpolation, builtin, etc. Users can then enable/disable each
feature individually. See Appendix 1 at the bottom for a set of common
features names.
feature individually.
#+begin_src elisp
(defvar python--treesit-settings
@ -247,7 +238,7 @@ Concretely, something like this:
...
(cond
;; Tree-sitter.
((treesit-ready-p 'python)
((treesit-ready-p 'python-mode 'python)
(treesit-parser-create 'python)
(setq-local treesit-font-lock-settings python--treesit-settings)
(setq-local treesit-font-lock-feature-list
@ -256,7 +247,8 @@ Concretely, something like this:
(string-interpolation decorator)))
(treesit-major-mode-setup))
(t
;; No tree-sitter, do nothing or fallback to another mode.
;; No tree-sitter
(setq-local font-lock-defaults ...)
...)))
#+end_src
@ -279,7 +271,7 @@ Matchers and anchors are functions that takes (NODE PARENT BOL &rest
_). Matches return nil/non-nil for no match/match, and anchors return
the anchor point. Below are some convenient builtin matchers and anchors.
For MATCHER we have
For MATHCER we have
(parent-is TYPE) => matches if PARENTs type matches TYPE as regexp
(node-is TYPE) => matches NODEs type
@ -297,7 +289,6 @@ For ANCHOR we have
first-sibling => start of the first sibling
parent => start of parent
parent-bol => BOL of the line parent is on.
standalone-parent => Like parent-bol but handles more edge cases
prev-sibling => start of previous sibling
no-indent => current position (dont indent)
prev-line => start of previous line
@ -338,8 +329,7 @@ tells you which rule is applied in the echo area.
...))))
#+end_src
To setup indentation for your major mode, set
treesit-simple-indent-rules to your rules, and call
Then you set treesit-simple-indent-rules to your rules, and call
treesit-major-mode-setup:
#+begin_src elisp
@ -349,14 +339,36 @@ To setup indentation for your major mode, set
* Imenu
Set treesit-simple-imenu-settings and call
treesit-major-mode-setup.
Not much to say except for utilizing treesit-induce-sparse-tree (and
explicitly pass a LIMIT argument: most of the time you don't need more
than 10). See js--treesit-imenu-1 in js.el for an example.
Once you have the index builder, set imenu-create-index-function to
it.
* Navigation
Set treesit-defun-type-regexp and call
treesit-major-mode-setup. You can additionally set
treesit-defun-name-function.
Mainly beginning-of-defun-function and end-of-defun-function.
You can find the end of a defun with something like
(treesit-search-forward-goto "function_definition" 'end)
where "function_definition" matches the node type of a function
definition node, and end means we want to go to the end of that node.
Tree-sitter has default implementations for
beginning-of-defun-function and end-of-defun-function. So for
ordinary languages, it is enough to set treesit-defun-type-regexp
to something that matches all the defun struct types in the language,
and call treesit-major-mode-setup. For example,
#+begin_src emacs-lisp
(setq-local treesit-defun-type-regexp (rx bol
(or "function" "class")
"_definition"
eol))
(treesit-major-mode-setup)
#+end_src>
* Which-func
@ -364,7 +376,36 @@ If you have an imenu implementation, set which-func-functions to
nil, and which-func will automatically use imenus data.
If you want an independent implementation for which-func, you can
find the current function by treesit-defun-at-point.
find the current function by going up the tree and looking for the
function_definition node. See the function below for an example.
Since Python allows nested function definitions, that function keeps
going until it reaches the root node, and records all the function
names along the way.
#+begin_src elisp
(defun python-info-treesit-current-defun (&optional include-type)
"Identical to `python-info-current-defun' but use tree-sitter.
For INCLUDE-TYPE see `python-info-current-defun'."
(let ((node (treesit-node-at (point)))
(name-list ())
(type nil))
(cl-loop while node
if (pcase (treesit-node-type node)
("function_definition"
(setq type 'def))
("class_definition"
(setq type 'class))
(_ nil))
do (push (treesit-node-text
(treesit-node-child-by-field-name node "name")
t)
name-list)
do (setq node (treesit-node-parent node))
finally return (concat (if include-type
(format "%s " type)
"")
(string-join name-list ".")))))
#+end_src
* More features?
@ -408,51 +449,7 @@ section is Parsing Program Source. Typing
C-h i d m elisp RET g Parsing Program Source RET
will bring you to that section. You dont need to read through every
sentence, just read the text paragraphs and glance over function
names.
* Appendix 1
Below is a set of common features used by built-in major mode.
Basic tokens:
delimiter ,.; (delimit things)
operator == != || (produces a value)
bracket []{}()
misc-punctuation (other punctuation that you want to highlight)
constant true, false, null
number
keyword
comment (includes doc-comments)
string (includes chars and docstrings)
string-interpolation f"text {variable}"
escape-sequence "\n\t\\"
function every function identifier
variable every variable identifier
type every type identifier
property a.b <--- highlight b
key { a: b, c: d } <--- highlight a, c
error highlight parse error
Abstract features:
assignment: the LHS of an assignment (thing being assigned to), eg:
a = b <--- highlight a
a.b = c <--- highlight b
a[1] = d <--- highlight a
definition: the thing being defined, eg:
int a(int b) { <--- highlight a
return 0
}
int a; <-- highlight a
struct a { <--- highlight a
int b; <--- highlight b
}
will bring you to that section. You can also read the HTML version
under /html-manual in this directory. I find the HTML version easier
to read. You dont need to read through every sentence, just read the
text paragraphs and glance over function names.

View file

@ -1,50 +0,0 @@
NOTES ON TREESIT_RECORD_CHANGE
It is vital that Emacs informs tree-sitter of every change made to the
buffer, lest tree-sitter's parse tree would be corrupted/out of sync.
All buffer changes in Emacs are made through functions in insdel.c
(and casefiddle.c), I augmented functions in those files with calls to
treesit_record_change. Below is a manifest of all the relevant
functions in insdel.c as of Emacs 29:
Function Calls
----------------------------------------------------------------------
copy_text (*1)
insert insert_1_both
insert_and_inherit insert_1_both
insert_char insert
insert_string insert
insert_before_markers insert_1_both
insert_before_markers_and_inherit insert_1_both
insert_1_both treesit_record_change
insert_from_string insert_from_string_1
insert_from_string_before_markers insert_from_string_1
insert_from_string_1 treesit_record_change
insert_from_gap_1 treesit_record_change
insert_from_gap insert_from_gap_1
insert_from_buffer treesit_record_change
insert_from_buffer_1 (used by insert_from_buffer) (*2)
replace_range treesit_record_change
replace_range_2 (caller needs to call treesit_r_c)
del_range del_range_1
del_range_1 del_range_2
del_range_byte del_range_2
del_range_both del_range_2
del_range_2 treesit_record_change
(*1) This functions is used only to copy from string to string when
used outside of insdel.c, and when used inside insdel.c, the caller
calls treesit_record_change.
(*2) This function is a static function, and insert_from_buffer is its
only caller. So it should be fine to call treesit_record_change in
insert_from_buffer but not insert_from_buffer_1. I also left a
reminder comment.
As for casefiddle.c, do_casify_unibyte_region and
do_casify_multibyte_region modifies buffer, but they are static
functions and are called by casify_region, which calls
treesit_record_change. Other higher-level functions calls
casify_region to do the work.

View file

@ -1,6 +1,6 @@
-*-mode: text; coding: utf-8;-*-
Copyright (C) 2002-2023 Free Software Foundation, Inc.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
Importing a new Unicode Standard version into Emacs

View file

@ -1,6 +1,6 @@
-*- outline -*-
Copyright (C) 2013-2023 Free Software Foundation, Inc.
Copyright (C) 2013-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
NOTES FOR EMACS WWW PAGES

View file

@ -10,10 +10,9 @@ results for plausibility, then commit them.
A few known problems with the build-aux/update-copyright script:
. it doesn't update config.bat, msdos/depfiles.bat,
nt/configure.bat, etc/tutorials/TUTORIAL.cn,
etc/tutorials/TUTORIAL.el_GR, and etc/tutorials/TUTORIAL.he
because the "Copyright" statement begins in these files
after a prefix that is more than 5 characters long
nt/configure.bat, etc/tutorials/TUTORIAL.cn, and
etc/tutorials/TUTORIAL.he because the "Copyright" statement begins
in these files after a prefix that is more than 5 characters long
. it doesn't update etc/tutorials/TUTORIAL.nl and
etc/tutorials/TUTORIAL.ro for some reason
. it doesn't update the second Copyright notice, the one that gets

View file

@ -1,4 +1,4 @@
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
Emacs for Windows

View file

@ -1,4 +1,4 @@
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
See the end of the file for license conditions.
Precompiled Distributions of

View file

@ -1,6 +1,6 @@
#!/usr/bin/python3
## Copyright (C) 2017-2023 Free Software Foundation, Inc.
## Copyright (C) 2017-2022 Free Software Foundation, Inc.
## This file is part of GNU Emacs.

View file

@ -1,6 +1,6 @@
#!/bin/bash
## Copyright (C) 2017-2023 Free Software Foundation, Inc.
## Copyright (C) 2017-2022 Free Software Foundation, Inc.
## This file is part of GNU Emacs.

View file

@ -1,7 +1,7 @@
#!/bin/sh
### quick-install-emacs --- do a halfway-decent job of installing emacs quickly
## Copyright (C) 2001-2023 Free Software Foundation, Inc.
## Copyright (C) 2001-2022 Free Software Foundation, Inc.
## Author: Miles Bader <miles@gnu.org>

View file

@ -1,6 +1,6 @@
### @configure_input@
# Copyright (C) 2012-2023 Free Software Foundation, Inc.
# Copyright (C) 2012-2022 Free Software Foundation, Inc.
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
# National Institute of Advanced Industrial Science and Technology (AIST)

View file

@ -1,6 +1,6 @@
#!/usr/bin/awk -f
## Copyright (C) 2015-2023 Free Software Foundation, Inc.
## Copyright (C) 2015-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org

View file

@ -1,6 +1,6 @@
#!/usr/bin/awk -f
## Copyright (C) 2020, 2022-2023 Free Software Foundation, Inc.
## Copyright (C) 2020, 2022 Free Software Foundation, Inc.
## Author: Robert Pluim <rpluim@gmail.com>

View file

@ -1,6 +1,6 @@
;;; unidata-gen.el --- Create files containing character property data -*- lexical-binding:t -*-
;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
;; Copyright (C) 2008-2022 Free Software Foundation, Inc.
;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
;; National Institute of Advanced Industrial Science and Technology (AIST)

View file

@ -1,6 +1,6 @@
;;; uvs.el --- utility for UVS (format 14) cmap subtables in OpenType fonts -*- lexical-binding:t -*-
;; Copyright (C) 2014-2023 Free Software Foundation, Inc.
;; Copyright (C) 2014-2022 Free Software Foundation, Inc.
;; Author: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>

View file

@ -7,7 +7,7 @@
# By default, this script uses the local-time calendar year.
# Set the UPDATE_COPYRIGHT_YEAR environment variable to override the default.
# Copyright 2013-2023 Free Software Foundation, Inc.
# Copyright 2013-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
### update_autogen - update some auto-generated files in the Emacs tree
## Copyright (C) 2011-2023 Free Software Foundation, Inc.
## Copyright (C) 2011-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: Stefan Kangas <stefankangas@gmail.com>

View file

@ -2,7 +2,7 @@
### upload-manuals - upload the Emacs manuals to the gnu.org website
## Copyright 2018-2023 Free Software Foundation, Inc.
## Copyright 2018-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org

View file

@ -1,7 +1,7 @@
#!/bin/sh
### autogen.sh - tool to help build Emacs from a repository checkout
## Copyright (C) 2011-2023 Free Software Foundation, Inc.
## Copyright (C) 2011-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org
@ -340,8 +340,7 @@ git_config diff.texinfo.xfuncname \
tailored_hooks=
sample_hooks=
for hook in commit-msg pre-commit prepare-commit-msg post-commit \
pre-push commit-msg-files.awk; do
for hook in commit-msg pre-commit prepare-commit-msg; do
cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 ||
tailored_hooks="$tailored_hooks $hook"
done

View file

@ -1,10 +1,10 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright 1992-2023 Free Software Foundation, Inc.
# Copyright 1992-2022 Free Software Foundation, Inc.
# shellcheck disable=SC2006,SC2268 # see below for rationale
timestamp='2023-01-01'
timestamp='2022-09-17'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@ -60,7 +60,7 @@ version="\
GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright 1992-2023 Free Software Foundation, Inc.
Copyright 1992-2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."

View file

@ -1,10 +1,10 @@
#! /bin/sh
# Configuration validation subroutine script.
# Copyright 1992-2023 Free Software Foundation, Inc.
# Copyright 1992-2022 Free Software Foundation, Inc.
# shellcheck disable=SC2006,SC2268 # see below for rationale
timestamp='2023-01-21'
timestamp='2022-09-17'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@ -76,7 +76,7 @@ Report bugs and patches to <config-patches@gnu.org>."
version="\
GNU config.sub ($timestamp)
Copyright 1992-2023 Free Software Foundation, Inc.
Copyright 1992-2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -1075,7 +1075,7 @@ case $cpu-$vendor in
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
cpu=i586
;;
pentiumpro-* | p6-* | 6x86-* | athlon-* | athlon_*-*)
pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
cpu=i686
;;
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)

View file

@ -1,7 +1,7 @@
#!/bin/sh
# Check the format of GNU Emacs change log entries.
# Copyright 2014-2023 Free Software Foundation, Inc.
# Copyright 2014-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,128 +0,0 @@
# Check the file list of GNU Emacs change log entries for each commit SHA.
# Copyright 2023 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
# GNU Emacs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
### Commentary:
# This script accepts a list of (unabbreviated) Git commit SHAs, and
# will then iterate over them to check that any files mentioned in the
# commit message are actually present in the commit's diff. If not,
# it will print out the incorrect file names and return 1.
# You can also pass "-v reason=pre-push", which will add more-verbose
# output, indicating the abbreviated commit SHA and first line of the
# commit message for any improper commits.
### Code:
function get_commit_changes(commit_sha, changes, cmd, i, j, len, \
bits, filename) {
# Collect all the files touched in the specified commit.
cmd = ("git show --name-status --first-parent --format= " commit_sha)
while ((cmd | getline) > 0) {
for (i = 2; i <= NF; i++) {
len = split($i, bits, "/")
for (j = 1; j <= len; j++) {
if (j == 1)
filename = bits[j]
else
filename = filename "/" bits[j]
changes[filename] = 1
}
}
}
close(cmd)
}
function check_commit_msg_files(commit_sha, verbose, changes, good, \
cmd, msg, filenames_str, filenames, i) {
get_commit_changes(commit_sha, changes)
good = 1
cmd = ("git log -1 --format=%B " commit_sha)
while ((cmd | getline) > 0) {
if (verbose && ! msg)
msg = $0
# Find file entries in the commit message. We look at any line
# starting with "*" (possibly prefixed by "; ") followed by a ":",
# possibly on a different line. If we encounter a blank line
# without seeing a ":", then we don't treat that as a file entry.
# Accumulate the contents of a (possible) file entry.
if (/^[ \t]*$/)
filenames_str = ""
else if (/^(; )?\*[ \t]+[[:alnum:]]/)
filenames_str = $0
else if (filenames_str)
filenames_str = (filenames_str $0)
# We have a file entry; analyze it.
if (filenames_str && /:/) {
# Delete the leading "*" and any trailing information.
sub(/^(; )?\*[ \t]+/, "", filenames_str)
sub(/[ \t]*[[(<:].*$/, "", filenames_str)
# There might be multiple files listed in this entry, separated
# by spaces (and possibly a comma). Iterate over each of them.
split(filenames_str, filenames, ",[ \t]+")
for (i in filenames) {
# Remove trailing slashes from any directory entries.
sub(/\/$/, "", filenames[i])
if (length(filenames[i]) && ! (filenames[i] in changes)) {
if (good) {
# Print a header describing the error.
if (verbose)
printf("In commit %s \"%s\"...\n", substr(commit_sha, 1, 10), msg)
printf("Files listed in commit message, but not in diff:\n")
}
printf(" %s\n", filenames[i])
good = 0
}
}
filenames_str = ""
}
}
close(cmd)
return good
}
BEGIN {
if (reason == "pre-push")
verbose = 1
}
/^[a-z0-9]{40}$/ {
if (! check_commit_msg_files($0, verbose)) {
status = 1
}
}
END {
if (status != 0) {
if (reason == "pre-push")
error_msg = "Push aborted"
else
error_msg = "Bad commit message"
printf("%s; please see the file 'CONTRIBUTE'\n", error_msg)
}
exit status
}

View file

@ -1,47 +0,0 @@
#!/bin/sh
# Check the file list of GNU Emacs change log entries after committing.
# Copyright 2023 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
# GNU Emacs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
### Commentary:
# This hook runs after a commit is finalized and checks that the files
# mentioned in the commit message match the diff. We perform this in
# the post-commit phase so that we can be sure we properly detect all
# the files in the diff (this is difficult during the commit-msg hook,
# since there's no cross-platform way to detect when a commit is being
# amended).
# However, since this is a post-commit hook, it's too late to error
# out and abort the commit: it's already done! As a result, this hook
# is purely advisory, and instead we error out when trying to push
# (see "pre-push" in this directory).
### Code:
HOOKS_DIR=`dirname "$0"`
# Prefer gawk if available, as it handles NUL bytes properly.
if type gawk >/dev/null 2>&1; then
awk="gawk"
else
awk="awk"
fi
git rev-parse HEAD | $awk -v reason=post-commit \
-f "$HOOKS_DIR"/commit-msg-files.awk

View file

@ -1,7 +1,7 @@
#!/bin/sh
# Check file names in git commits for GNU Emacs.
# Copyright 2014-2023 Free Software Foundation, Inc.
# Copyright 2014-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -1,88 +0,0 @@
#!/bin/sh
# Check the file list of GNU Emacs change log entries before pushing.
# Copyright 2023 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
# GNU Emacs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
### Commentary:
# This hook runs before pushing a series of commits and checks that
# the files mentioned in each commit message match the diffs. This
# helps ensure that the resulting change logs are correct, which
# should prevent errors when generating etc/AUTHORS.
# These checks also happen in the "post-commit" hook (which see), but
# that hook can't abort a commit; it just advises the committer to fix
# the commit so that this hook runs without errors.
### Code:
HOOKS_DIR=`dirname "$0"`
# Prefer gawk if available, as it handles NUL bytes properly.
if type gawk >/dev/null 2>&1; then
awk="gawk"
else
awk="awk"
fi
# Standard input receives lines of the form:
# <local ref> SP <local sha> SP <remote ref> SP <remote sha> LF
$awk -v origin_name="$1" '
# If the local SHA is all zeroes, ignore it.
$2 ~ /^0{40}$/ {
next
}
# Check any lines with a valid local SHA and whose remote ref is
# master or an emacs-NN release branch. (We want to avoid checking
# feature or scratch branches here.)
$2 ~ /^[a-z0-9]{40}$/ && $3 ~ /^refs\/heads\/(master|emacs-[0-9]+)$/ {
newref = $2
# If the remote SHA is all zeroes, this is a new object to be
# pushed (likely a branch)...
if ($4 ~ /^0{40}$/) {
back = 0
# ... Go backwards until we find a SHA on an origin branch.
# Stop trying after 1000 commits, just in case...
for (back = 0; back < 1000; back++) {
cmd = ("git branch -r -l '\''" origin_name "/*'\''" \
" --contains " newref "~" back)
rv = (cmd | getline)
close(cmd)
if (rv > 0)
break;
}
cmd = ("git rev-parse " newref "~" back)
cmd | getline oldref
if (!(oldref ~ /^[a-z0-9]{40}$/)) {
# The SHA is misformatted! Skip this line.
next
}
close(cmd)
} else if ($4 ~ /^[a-z0-9]{40}$/) {
oldref = $4
} else {
# The SHA is misformatted! Skip this line.
next
}
# Print every SHA after oldref, up to (and including) newref.
system("git rev-list --first-parent --reverse " oldref ".." newref)
}
' | $awk -v reason=pre-push -f "$HOOKS_DIR"/commit-msg-files.awk

View file

@ -1,7 +1,7 @@
#!/bin/sh
# Check the format of GNU Emacs change log entries.
# Copyright 2019-2023 Free Software Foundation, Inc.
# Copyright 2019-2022 Free Software Foundation, Inc.
# This file is part of GNU Emacs.

View file

@ -3,7 +3,7 @@
# Convert git log output to ChangeLog format.
# Copyright (C) 2008-2023 Free Software Foundation, Inc.
# Copyright (C) 2008-2022 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View file

@ -2,7 +2,7 @@
# Convert git log output to ChangeLog format for GNU Emacs.
# Copyright (C) 2014-2023 Free Software Foundation, Inc.
# Copyright (C) 2014-2022 Free Software Foundation, Inc.
# Author: Paul Eggert

View file

@ -2,7 +2,7 @@
### make-info-dir - create info/dir, for systems without install-info
## Copyright (C) 2013-2023 Free Software Foundation, Inc.
## Copyright (C) 2013-2022 Free Software Foundation, Inc.
## Author: Glenn Morris <rgm@gnu.org>
## Maintainer: emacs-devel@gnu.org

View file

@ -8,7 +8,7 @@ VERSION='2018-03-07 03:47'; # UTC
# If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually.
# Copyright (C) 2002-2023 Free Software Foundation, Inc.
# Copyright (C) 2002-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

Some files were not shown because too many files have changed in this diff Show more