1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-04 02:51:31 -08:00

Merge from origin/emacs-29

861556c133 Fix minibuffer-completion tests
c0578edc8f ; * doc/misc/eglot.texi (Troubleshooting Eglot): Fix typo...
c6bbf9cc27 Add c-ts-mode tests
a760364f5f Fix c-ts-mode--fill-paragraph
2a2b1d09ac Fix minor issues with 'pp' and related commands
dfb38fb2ee ; Improve documentation of tree-sitter node comparison
e8a89a18b6 ; Fix non-tree-sitter builds
f27a330b99 ; Fix typo in ert-with-temp-file
956889d8ff Equal now recognizes tree-sitter nodes (bug#60659)
8f446c2d39 Fix c-ts-mode comment indentation (bug#60270)
083badc9c1 * lisp/subr.el (while-let): Use if-let, not if-let* (bug#...
9ecebcdded * lisp/simple.el (next-completion): Handle first completi...
cfd2b3504a Fix encoding with 'utf-8-auto'
53b47df822 Report cursor correctly on PGTK when there is a margin

# Conflicts:
#	etc/NEWS
This commit is contained in:
Stefan Monnier 2023-01-14 09:10:45 -05:00
commit 4f0459aaf7
18 changed files with 167 additions and 45 deletions

View file

@ -929,9 +929,13 @@ Here are some predicates on tree-sitter nodes:
Checks if @var{object} is a tree-sitter syntax node.
@end defun
@cindex compare tree-sitter syntax nodes
@cindex tree-sitter nodes, comparing
@defun treesit-node-eq node1 node2
Checks if @var{node1} and @var{node2} are the same node in a syntax
tree.
Checks if @var{node1} and @var{node2} refer to the same node in a
tree-sitter syntax tree. This function uses the same equivalence
metric as @code{equal}. You can also compare nodes using @code{equal}
(@pxref{Equality Predicates}).
@end defun
@heading Property information

View file

@ -1104,7 +1104,7 @@ troubleshoot Eglot problems. It also provides guidelines for
reporting Eglot bugs in a way that facilitates their resolution.
When you encounter problems with Eglot, try first using the commands
@kbd{M-x eglot-events-server} and @kbd{M-x eglot-stderr-buffer}. They
@kbd{M-x eglot-events-buffer} and @kbd{M-x eglot-stderr-buffer}. They
pop up special buffers that can be used to inspect the communications
between the Eglot and language server. In many cases, this will
indicate the problems or at least provide a hint.

View file

@ -4321,15 +4321,21 @@ whose matches are to be replaced. If these variables are nil (which
is the default), 'query-replace' and 'query-replace-regexp' take the
default value from the previous FROM-TO pair.
---
** New user option 'pp-use-max-width'.
If non-nil, 'pp' will attempt to limit the line length when formatting
long lists and vectors.
** Lisp pretty-printer ('pp')
---
** New function 'pp-emacs-lisp-code'.
*** New function 'pp-emacs-lisp-code'.
'pp' formats general Lisp sexps. This function does much the same,
but applies formatting rules appropriate for Emacs Lisp code.
but applies formatting rules appropriate for Emacs Lisp code. Note
that this could currently be quite slow, and is thus appropriate only
for relatively small code fragments.
---
*** New user option 'pp-use-max-width'.
If non-nil, 'pp' and all 'pp-*' commands that format the results, will
attempt to limit the line length when formatting long lists and
vectors. This uses 'pp-emacs-lisp-code', and thus could be slow for
large lists.
+++
** New function 'file-has-changed-p'.

View file

@ -496,7 +496,7 @@ See also `ert-with-temp-directory'."
(progn ,@body)
(ignore-errors
,@(when buffer
(list `(with-current-buffer buf
(list `(with-current-buffer ,buffer
(set-buffer-modified-p nil))
`(kill-buffer ,buffer))))
(ignore-errors

View file

@ -47,7 +47,9 @@ Otherwise this should be a number."
(defcustom pp-use-max-width nil
"If non-nil, `pp'-related functions will try to fold lines.
The target width is given by the `pp-max-width' variable."
The target width is given by the `pp-max-width' variable.
Note that this could slow down `pp' considerably when formatting
large lists."
:type 'boolean
:version "29.1")
@ -162,14 +164,15 @@ Also add the value to the front of the list in the variable `values'."
(message "Evaluating...")
(let ((result (eval expression lexical-binding)))
(values--store-value result)
(pp-display-expression result "*Pp Eval Output*")))
(pp-display-expression result "*Pp Eval Output*" pp-use-max-width)))
;;;###autoload
(defun pp-macroexpand-expression (expression)
"Macroexpand EXPRESSION and pretty-print its value."
(interactive
(list (read--expression "Macroexpand: ")))
(pp-display-expression (macroexpand-1 expression) "*Pp Macroexpand Output*"))
(pp-display-expression (macroexpand-1 expression) "*Pp Macroexpand Output*"
pp-use-max-width))
(defun pp-last-sexp ()
"Read sexp before point. Ignore leading comment characters."
@ -219,7 +222,8 @@ Ignores leading comment characters."
;;;###autoload
(defun pp-emacs-lisp-code (sexp)
"Insert SEXP into the current buffer, formatted as Emacs Lisp code.
Use the `pp-max-width' variable to control the desired line length."
Use the `pp-max-width' variable to control the desired line length.
Note that this could be slow for large SEXPs."
(require 'edebug)
(let ((obuf (current-buffer)))
(with-temp-buffer

View file

@ -863,7 +863,8 @@ This attribute is meaningful only when `:coding-type' is `utf-16' or
VALUE must be `big' or `little' specifying big-endian and
little-endian respectively. The default value is `big'.
This attribute is meaningful only when `:coding-type' is `utf-16'.
Changing this attribute is only meaningful when `:coding-type'
is `utf-16'.
`:ccl-decoder' (required if :coding-type is `ccl')

View file

@ -122,11 +122,13 @@ MODE is either `c' or `cpp'."
((node-is "else") parent-bol 0)
((node-is "case") parent-bol 0)
((node-is "preproc_arg") no-indent)
;; `c-ts-mode--looking-at-star' has to come before
;; `c-ts-mode--comment-2nd-line-matcher'.
((and (parent-is "comment") c-ts-mode--looking-at-star)
c-ts-mode--comment-start-after-first-star -1)
(c-ts-mode--comment-2nd-line-matcher
c-ts-mode--comment-2nd-line-anchor
1)
((and (parent-is "comment") c-ts-mode--looking-at-star)
c-ts-mode--comment-start-after-first-star -1)
((parent-is "comment") prev-adaptive-prefix 0)
(c-ts-mode--top-level-label-matcher point-min 1)
((node-is "labeled_statement") parent-bol 0)
@ -724,7 +726,10 @@ ARG is passed to `fill-paragraph'."
;; Let `fill-paragraph' do its thing.
(goto-char orig-point)
(narrow-to-region start end)
(funcall #'fill-paragraph arg)
;; We don't want to fill the region between START and
;; START-MARKER, otherwise the filling function might delete
;; some spaces there.
(fill-region start-marker end arg)
;; Unmask.
(when start-marker
(goto-char start-marker)

View file

@ -9774,6 +9774,14 @@ Also see the `completion-auto-wrap' variable."
(let ((tabcommand (member (this-command-keys) '("\t" [backtab])))
pos)
(catch 'bound
(when (and (bobp)
(> n 0)
(get-text-property (point) 'mouse-face)
(not (get-text-property (point) 'first-completion)))
(let ((inhibit-read-only t))
(add-text-properties (point) (1+ (point)) '(first-completion t)))
(setq n (1- n)))
(while (> n 0)
(setq pos (point))
;; If in a completion, move to the end of it.

View file

@ -2567,7 +2567,7 @@ The variable list SPEC is the same as in `if-let'."
(let ((done (gensym "done")))
`(catch ',done
(while t
(if-let* ,spec
(if-let ,spec
(progn
,@body)
(throw ',done nil))))))

View file

@ -1431,7 +1431,7 @@ encode_coding_utf_8 (struct coding_system *coding)
ptrdiff_t produced_chars = 0;
int c;
if (CODING_UTF_8_BOM (coding) == utf_with_bom)
if (CODING_UTF_8_BOM (coding) != utf_without_bom)
{
ASSURE_DESTINATION (3);
EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3);

View file

@ -38,6 +38,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "puresize.h"
#include "gnutls.h"
#ifdef HAVE_TREE_SITTER
#include "treesit.h"
#endif
enum equal_kind { EQUAL_NO_QUIT, EQUAL_PLAIN, EQUAL_INCLUDING_PROPERTIES };
static bool internal_equal (Lisp_Object, Lisp_Object,
enum equal_kind, int, Lisp_Object);
@ -2828,6 +2832,11 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
bool_vector_bytes (size)));
}
#ifdef HAVE_TREE_SITTER
if (TS_NODEP (o1))
return treesit_node_eq (o1, o2);
#endif
/* Aside from them, only true vectors, char-tables, compiled
functions, and fonts (font-spec, font-entity, font-object)
are sensible to compare, so eliminate the others now. */

View file

@ -2959,7 +2959,8 @@ pgtk_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x,
if (w == XWINDOW (f->selected_window))
{
int frame_x = (WINDOW_TO_FRAME_PIXEL_X (w, x)
+ WINDOW_LEFT_FRINGE_WIDTH (w));
+ WINDOW_LEFT_FRINGE_WIDTH (w)
+ WINDOW_LEFT_MARGIN_WIDTH (w));
int frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, y);
pgtk_im_set_cursor_location (f, frame_x, frame_y,
w->phys_cursor_width,

View file

@ -2154,11 +2154,24 @@ If NODE is nil, return nil. */)
return make_treesit_node (XTS_NODE (node)->parser, child);
}
/* Return true if NODE1 and NODE2 are the same node. Assumes they are
TS_NODE type. */
bool treesit_node_eq (Lisp_Object node1, Lisp_Object node2)
{
treesit_initialize ();
TSNode treesit_node_1 = XTS_NODE (node1)->node;
TSNode treesit_node_2 = XTS_NODE (node2)->node;
return ts_node_eq (treesit_node_1, treesit_node_2);
}
DEFUN ("treesit-node-eq",
Ftreesit_node_eq,
Streesit_node_eq, 2, 2, 0,
doc: /* Return non-nil if NODE1 and NODE2 are the same node.
If any one of NODE1 and NODE2 is nil, return nil. */)
doc: /* Return non-nil if NODE1 and NODE2 refer to the same node.
If any one of NODE1 and NODE2 is nil, return nil.
This function uses the same equivalence metric as `equal', and returns
non-nil if NODE1 and NODE2 refer to the same node in a syntax tree
produced by tree-sitter. */)
(Lisp_Object node1, Lisp_Object node2)
{
if (NILP (node1) || NILP (node2))
@ -2166,12 +2179,7 @@ If any one of NODE1 and NODE2 is nil, return nil. */)
CHECK_TS_NODE (node1);
CHECK_TS_NODE (node2);
treesit_initialize ();
TSNode treesit_node_1 = XTS_NODE (node1)->node;
TSNode treesit_node_2 = XTS_NODE (node2)->node;
bool same_node = ts_node_eq (treesit_node_1, treesit_node_2);
bool same_node = treesit_node_eq (node1, node2);
return same_node ? Qt : Qnil;
}

View file

@ -191,6 +191,7 @@ extern bool treesit_node_uptodate_p (Lisp_Object);
extern void treesit_delete_parser (struct Lisp_TS_Parser *);
extern void treesit_delete_query (struct Lisp_TS_Query *);
extern bool treesit_named_node_p (TSNode);
extern bool treesit_node_eq (Lisp_Object, Lisp_Object);
#endif /* HAVE_TREE_SITTER */

View file

@ -421,7 +421,7 @@
(switch-to-completions)
;; Fixed in bug#55430
(should (equal "aa" (get-text-property (point) 'completion--string)))
(next-completion 2)
(next-completion 3)
(should (equal "ac" (get-text-property (point) 'completion--string)))
(previous-completion 2)
(should (equal "aa" (get-text-property (point) 'completion--string)))

View file

@ -0,0 +1,44 @@
Code:
(lambda ()
(c-ts-mode)
(indent-region (point-min) (point-max)))
Name: Basic
=-=
int
main (void)
{
return 0;
}
=-=-=
Name: Hanging Braces (GNU Style)
=-=
int
main (void)
{
if (true)
{
}
}
=-=-=
Name: Multiline Parameter List (bug#60398)
=-=
int f2(int x,
int y) {
return x + y;
};
=-=-=
Name: Multiline Block Comments (bug#60270)
=-=
/**
* @some_func:
* @arg1:
*/
=-=-=

View file

@ -0,0 +1,31 @@
;;; c-ts-mode-tests.el --- Tests for Tree-sitter-based C mode -*- lexical-binding: t; -*-
;; Copyright (C) 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/>.
;;; Code:
(require 'ert)
(require 'ert-x)
(require 'treesit)
(ert-deftest c-ts-mode-test-indentation ()
(skip-unless (treesit-ready-p 'c))
(ert-test-erts-file (ert-resource-file "indent.erts")))
(provide 'c-ts-mode-tests)
;;; c-ts-mode-tests.el ends here

View file

@ -148,7 +148,7 @@
(defun coding-tests (content-type write-coding read-coding detected-coding
&optional translator)
(prefer-coding-system 'utf-8-auto)
(with-coding-priority '(utf-8-auto)
(let ((filename (coding-tests-filename content-type write-coding)))
(with-temp-buffer
(let ((coding-system-for-read read-coding)
@ -162,7 +162,7 @@
nil
(list buffer-file-coding-system
(string-to-list (buffer-string))
(string-to-list contents)))))))
(string-to-list contents))))))))
(ert-deftest ert-test-coding-ascii ()
(unwind-protect