emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 4f0459aaf7 1/6: Merge from origin/emacs-29


From: Stefan Monnier
Subject: master 4f0459aaf7 1/6: Merge from origin/emacs-29
Date: Sat, 14 Jan 2023 09:17:44 -0500 (EST)

branch: master
commit 4f0459aaf756e56db5fb943177eec6eb5bd5fc4a
Merge: 9912049173 861556c133
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Merge from origin/emacs-29
    
    861556c1339 Fix minibuffer-completion tests
    c0578edc8fc ; * doc/misc/eglot.texi (Troubleshooting Eglot): Fix typo...
    c6bbf9cc270 Add c-ts-mode tests
    a760364f5f3 Fix c-ts-mode--fill-paragraph
    2a2b1d09ac7 Fix minor issues with 'pp' and related commands
    dfb38fb2ee6 ; Improve documentation of tree-sitter node comparison
    e8a89a18b69 ; Fix non-tree-sitter builds
    f27a330b99e ; Fix typo in ert-with-temp-file
    956889d8ff1 Equal now recognizes tree-sitter nodes (bug#60659)
    8f446c2d397 Fix c-ts-mode comment indentation (bug#60270)
    083badc9c12 * lisp/subr.el (while-let): Use if-let, not if-let* (bug#...
    9ecebcdded1 * lisp/simple.el (next-completion): Handle first completi...
    cfd2b3504ab Fix encoding with 'utf-8-auto'
    53b47df8229 Report cursor correctly on PGTK when there is a margin
    
    # Conflicts:
    #       etc/NEWS
---
 doc/lispref/parsing.texi                           |  8 +++-
 doc/misc/eglot.texi                                |  2 +-
 etc/NEWS.29                                        | 18 ++++++---
 lisp/emacs-lisp/ert-x.el                           |  2 +-
 lisp/emacs-lisp/pp.el                              | 12 ++++--
 lisp/international/mule.el                         |  3 +-
 lisp/progmodes/c-ts-mode.el                        | 11 ++++--
 lisp/simple.el                                     |  8 ++++
 lisp/subr.el                                       |  2 +-
 src/coding.c                                       |  2 +-
 src/fns.c                                          |  9 +++++
 src/pgtkterm.c                                     |  3 +-
 src/treesit.c                                      | 24 ++++++++----
 src/treesit.h                                      |  1 +
 test/lisp/minibuffer-tests.el                      |  2 +-
 .../lisp/progmodes/c-ts-mode-resources/indent.erts | 44 ++++++++++++++++++++++
 test/lisp/progmodes/c-ts-mode-tests.el             | 31 +++++++++++++++
 test/src/coding-tests.el                           | 30 +++++++--------
 18 files changed, 167 insertions(+), 45 deletions(-)

diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index b55af912f9..e4a2524982 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -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
diff --git a/doc/misc/eglot.texi b/doc/misc/eglot.texi
index 253bf169cc..56151b5482 100644
--- a/doc/misc/eglot.texi
+++ b/doc/misc/eglot.texi
@@ -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.
diff --git a/etc/NEWS.29 b/etc/NEWS.29
index 16d17821b7..08c7f8a4dd 100644
--- a/etc/NEWS.29
+++ b/etc/NEWS.29
@@ -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'.
diff --git a/lisp/emacs-lisp/ert-x.el b/lisp/emacs-lisp/ert-x.el
index 83705ca5b8..98a017c8a8 100644
--- a/lisp/emacs-lisp/ert-x.el
+++ b/lisp/emacs-lisp/ert-x.el
@@ -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
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index ebda37419f..e6e3cd6c6f 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -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
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 4f6addea38..eddd7b6407 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -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')
 
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index e929fe1dd8..b2151775e9 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -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)
diff --git a/lisp/simple.el b/lisp/simple.el
index eedc5d7244..bbcb32cb04 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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.
diff --git a/lisp/subr.el b/lisp/subr.el
index 9e50b1e7f9..1762c94a43 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -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))))))
diff --git a/src/coding.c b/src/coding.c
index 4e59f2b6a1..49dcd8634f 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -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);
diff --git a/src/fns.c b/src/fns.c
index bbc9a7f962..d8bd7d318b 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -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.  */
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 5158492ca0..c00e13550b 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -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,
diff --git a/src/treesit.c b/src/treesit.c
index 55463122d1..33a7e3c852 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -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;
 }
 
diff --git a/src/treesit.h b/src/treesit.h
index 909609737d..5382bc5881 100644
--- a/src/treesit.h
+++ b/src/treesit.h
@@ -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 */
 
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index 1de8e56cbd..2ac5e0f29d 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -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)))
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts 
b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
new file mode 100644
index 0000000000..5defcbd3c8
--- /dev/null
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -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:
+ */
+=-=-=
diff --git a/test/lisp/progmodes/c-ts-mode-tests.el 
b/test/lisp/progmodes/c-ts-mode-tests.el
new file mode 100644
index 0000000000..8606faf991
--- /dev/null
+++ b/test/lisp/progmodes/c-ts-mode-tests.el
@@ -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
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index 6bd8d1ae6c..b27907027b 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -148,21 +148,21 @@
 
 (defun coding-tests (content-type write-coding read-coding detected-coding
                                   &optional translator)
-  (prefer-coding-system 'utf-8-auto)
-  (let ((filename (coding-tests-filename content-type write-coding)))
-    (with-temp-buffer
-      (let ((coding-system-for-read read-coding)
-           (contents (coding-tests-file-contents content-type))
-           (disable-ascii-optimization nil))
-       (if translator
-           (setq contents (funcall translator contents)))
-       (insert-file-contents filename)
-       (if (and (coding-system-equal buffer-file-coding-system detected-coding)
-                (string= (buffer-string) contents))
-           nil
-         (list buffer-file-coding-system
-               (string-to-list (buffer-string))
-               (string-to-list contents)))))))
+  (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)
+             (contents (coding-tests-file-contents content-type))
+             (disable-ascii-optimization nil))
+         (if translator
+             (setq contents (funcall translator contents)))
+         (insert-file-contents filename)
+         (if (and (coding-system-equal buffer-file-coding-system 
detected-coding)
+                  (string= (buffer-string) contents))
+             nil
+           (list buffer-file-coding-system
+                 (string-to-list (buffer-string))
+                 (string-to-list contents))))))))
 
 (ert-deftest ert-test-coding-ascii ()
   (unwind-protect



reply via email to

[Prev in Thread] Current Thread [Next in Thread]