From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#59468: 29.0.50; c-ts-mode cannot fontify after macros are encountered Date: Tue, 22 Nov 2022 12:11:17 -0800 Message-ID: References: <87k03n4v0r.fsf@yahoo.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5878"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59468@debbugs.gnu.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 22 21:12:19 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oxZcx-0001O3-7O for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Nov 2022 21:12:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxZch-0001o7-Tx; Tue, 22 Nov 2022 15:12:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxZcg-0001nn-Eo for bug-gnu-emacs@gnu.org; Tue, 22 Nov 2022 15:12:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxZcg-0005YJ-6K for bug-gnu-emacs@gnu.org; Tue, 22 Nov 2022 15:12:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oxZcf-00017G-Uc for bug-gnu-emacs@gnu.org; Tue, 22 Nov 2022 15:12:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87k03n4v0r.fsf@yahoo.com> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Nov 2022 20:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59468 X-GNU-PR-Package: emacs Original-Received: via spool by 59468-submit@debbugs.gnu.org id=B59468.16691478884248 (code B ref 59468); Tue, 22 Nov 2022 20:12:01 +0000 Original-Received: (at 59468) by debbugs.gnu.org; 22 Nov 2022 20:11:28 +0000 Original-Received: from localhost ([127.0.0.1]:52605 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oxZc7-00016R-Am for submit@debbugs.gnu.org; Tue, 22 Nov 2022 15:11:27 -0500 Original-Received: from mail-pg1-f181.google.com ([209.85.215.181]:44706) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oxZc5-00016D-5n for 59468@debbugs.gnu.org; Tue, 22 Nov 2022 15:11:25 -0500 Original-Received: by mail-pg1-f181.google.com with SMTP id q1so14964759pgl.11 for <59468@debbugs.gnu.org>; Tue, 22 Nov 2022 12:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=6YJTpzz8DtGYoeGniJ76Pva3bRvvhebLhEnrJou1+vQ=; b=bSehFa92FraTBYhXG82FD0s3UqoMd2k5Go84iMUCuj/+SXk4sUCwgXA5swRg9qODHa Y6ykxcdtpvaYmaGeupD9myFHdwJwghuDYrA8seGckSFFW0gkhl+3CqTtkLIQVPsxDLDQ 8sjpgIiuHc2Nftm4qrrNiSzHxpZsSVh1ieJEZIJAraZXIsUMgAVbUT6O4oSdk4DEfcHA rvA0fQcaia2xWrAf7RNyvT5i1kK/C/uFBdWpqXQuPl0j+jjFtNfna31SDBnlwaCRsGFo YREZRCxGGtO6cHJQ3DZOHEmTe3XU78jppQfrum5niv5rCdaw8CIOIEYQ13sSNUOEWCAh Q0QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6YJTpzz8DtGYoeGniJ76Pva3bRvvhebLhEnrJou1+vQ=; b=UCGc72lO81LQcRLarQV431R/V/2+xSa0jHIhViDmVqwyMHT7Ahhv1vfCi5i8LILzwg H7fYs+UYhtk2Bi3lF4VELMpwcbNkG1VE2E4XV3rZi/sUwxTMmLcg2hCC87a6czTpB8am +qNQp2eFPKmYb6YTB1L+eTC6v/R8qOn0wYhl/4F0ZXwfzX56Yhtm1aVUCZQErxeFjBW9 OAbK9pfv+K4XEDGzLMDamZUFwfFRxcR1i+jROemateAciFVFX9AHqVuNRfeOZhMWZOJL UZWDGuBECxEqo7yBtrbmnLuWKVs2tgDVyimAJZ8/2x2/MYMlDkgSg8tZeQ5/ueMi5Mq5 2YXQ== X-Gm-Message-State: ANoB5pm+iRcnoKVE3H1f8Hhl1zFWH4mBm4cvm6e5uyc1x1QKMYmVr5K9 UitES2xbZ0ietm3ypQV/68U= X-Google-Smtp-Source: AA0mqf7GzdkQqhtWRiXu1HxK09T7KftSZ3tTyXOacvvFQI3NPHpBh0aHujcHAeVunnq1gFZf1Cd3+w== X-Received: by 2002:a05:6a00:16c6:b0:573:65d4:a104 with SMTP id l6-20020a056a0016c600b0057365d4a104mr16465136pfc.85.1669147878963; Tue, 22 Nov 2022 12:11:18 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id c10-20020a630d0a000000b0047702d44861sm9490494pgl.18.2022.11.22.12.11.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Nov 2022 12:11:18 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:248673 Archived-At: Po Lu writes: > Insert the following code in a buffer, and enable c-ts-mode. > > #define CheckExtension(name) \ > if (!name) \ > { \ > if (display) \ > eglTerminate (display); \ > fprintf (stderr, "Missing: egl%s\n", #name + 1); \ > return False; \ > } > > #define CheckExtensionGl(name) \ > if (!name) \ > { \ > /* If the context remains current, then nothing \ > will get released upon eglTerminate. */ \ > eglMakeCurrent (display, EGL_NO_SURFACE, \ > EGL_NO_SURFACE, EGL_NO_CONTEXT); \ > eglTerminate (display); \ > fprintf (stderr, "Missing: gl%s\n", #name + 1); \ > return False; \ > } > > #define LoadProc(name, ext, extname) \ > if (HaveEglExtension (extname)) \ > I##name \ > =3D (void *) eglGetProcAddress ("egl" #name ext) > > #define LoadProcGl(name, ext, extname) \ > if (HaveGlExtension (extname)) \ > I##name \ > =3D (void *) eglGetProcAddress ("gl" #name ext) > > #define CheckGlExtension(name) \ > if (!HaveGlExtension (name)) \ > { \ > fprintf (stderr, "Missing %s\n", name); \ > \ > eglMakeCurrent (display, EGL_NO_SURFACE, \ > EGL_NO_SURFACE, \ > EGL_NO_CONTEXT); \ > eglTerminate (display); \ > return False; \ > } > > There will be no fontification of types or string constants inside the > macro bodies. CC Mode works fine. > > Now, insert the following code below the macro definition: > > static Visual * > FindVisual (VisualID visual, int *depth) > { > XVisualInfo vinfo, *visuals; > Visual *value; > int nvisuals; > const char *override; > } > > visual, depth, visuals, value and override are not fontified as > identifiers. Line feed characters below the macros are also fontfied = as > "errors". > > Within the following code: > > static BufferActivityRecord * > FindBufferActivityRecord (PictureBuffer *buffer, PictureTarget = *target) > { > BufferActivityRecord *record; > > /* Look through the global activity list for a record matching > the given values. */ > record =3D all_activity.global_next; > while (record !=3D &all_activity) > { > if (record->buffer =3D=3D buffer > && record->target =3D=3D target) > return record; > > record =3D record->global_next; > } > > return NULL; > } > > "record" is fontified as an identifier, but not within the condition = in > the while loop. > > Within the following code: > > static void > compare_single_row_8bpc4 (unsigned char *data, unsigned char *xdata, > size_t size, > struct image_difference_statistics = *statistics) > { > unsigned char channel_a, channel_b; > int diff; > size_t i; > > for (i =3D 0; i < size; ++i) > { > channel_a =3D data[i]; > channel_b =3D xdata[i]; > > diff =3D (int) channel_b - (int) channel_a; > statistics->min_diff =3D MIN (statistics->min_diff, > diff); > statistics->max_diff =3D MAX (statistics->max_diff, > diff); > } > } > > the "i" in "size_t i" is fontified as an identifier the first time, = but > not in future appearances in the function. > > Within src/xterm.c, every appearance of ATOM_REFS_INIT is fontified in > the error face. Also, inside `xm_setup_dnd_targets', > > xm_targets_table_header header; > xm_targets_table_rec **recs UNINIT; > xm_byte_order byteorder; > > "recs" is fontified in the error face. > > recs =3D xmalloc (sizeof *recs); > recs[0] =3D xmalloc (FLEXSIZEOF (struct = xm_targets_table_rec, > targets, ntargets * 4)); > > recs[0]->n_targets =3D ntargets; > > "struct" is fontified in the error face. Within > x_sync_note_frame_times: > > #ifdef FRAME_DEBUG > uint_fast64_t last_frame_ms =3D output->last_frame_time / 1000; > fprintf (stderr, > "Drawing the last frame took: %"PRIuFAST64" ms = (%"PRIuFAST64")\n", > last_frame_ms, time); > #endif > > "PRIuFAST64" is fontified in the error face. Within > x_dnd_begin_drag_and_drop: > > if (x_dnd_movement_frame > /* FIXME: how come this can end up with movement frames > from other displays on GTK builds? */ > && (FRAME_X_DISPLAY (x_dnd_movement_frame) > =3D=3D FRAME_X_DISPLAY (f)) > /* If both those variables are false, then F is no > longer protected from deletion by Lisp code. This > can only happen during the final iteration of the DND > event loop. */ > && (x_dnd_in_progress || x_dnd_waiting_for_finish)) > { > XSETFRAME (frame_object, x_dnd_movement_frame); > > is fontified incorrectly: the "if" is not fontified at all, and the = last > three lines show up in the error faces. > > In addition: > > Lisp_Object > x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, > Lisp_Object return_frame, Atom = *ask_action_list, > const char **ask_action_names, size_t = n_ask_actions, > bool allow_current_frame, Atom *target_atoms, > int ntargets, Lisp_Object = selection_target_list, > bool follow_tooltip) > > "Lisp_Object" and "x_dnd_begin_drag_and_drop" are not fontified at = all. > > Here: > > /* Select for input extension events used by scroll bars. This will > result in the corresponding core events not being generated for > SCROLL_BAR. */ > > MAYBE_UNUSED static void > xi_select_scroll_bar_events (struct x_display_info *dpyinfo, > Window scroll_bar) > > "void" is fontified in the error face. > > Here, in handle_one_xevent: > > #ifdef HAVE_XINPUT2 > if (event->type !=3D GenericEvent) > #endif > any =3D x_any_window_to_frame (dpyinfo, event->xany.window); > #ifdef HAVE_XINPUT2 > else > any =3D NULL; > #endif > > the "else" is fontified as a type. > > static int > handle_one_xevent (struct x_display_info *dpyinfo, > #ifndef HAVE_XINPUT2 > const XEvent *event, > #else > XEvent *event, > #endif > int *finish, struct input_event *hold_quit) > > the "const XEvent *" is fontified in the error face. > > Here: > > case GraphicsExpose: /* This occurs when an XCopyArea's > source area was obscured or not > available. */ > f =3D x_window_to_frame (dpyinfo, = event->xgraphicsexpose.drawable); > if (f) > { > expose_frame (f, event->xgraphicsexpose.x, > event->xgraphicsexpose.y, > event->xgraphicsexpose.width, > event->xgraphicsexpose.height); > #ifndef USE_TOOLKIT_SCROLL_BARS > x_scroll_bar_handle_exposure (f, (XEvent *) event); > #endif > #ifdef USE_GTK > x_clear_under_internal_border (f); > #endif > #ifdef HAVE_XDBE > show_back_buffer (f); > #endif > } > #ifdef USE_X_TOOLKIT > else > goto OTHER; > #endif /* USE_X_TOOLKIT */ > break; > > "goto OTHER" is fontified in the error face, and "else" as a type. > > Here: > > #ifdef HAVE_XINPUT2 > if (event->xkey.time =3D=3D pending_keystroke_time) > { > source =3D xi_device_from_id (dpyinfo, > = dpyinfo->pending_keystroke_source); > > if (source) > inev.ie.device =3D source->name; > } > #endif > > "inev" is fontified in the error face. > > Here: > > #ifdef USE_GTK > /* See comment in EnterNotify above */ > else if (dpyinfo->last_mouse_glyph_frame) > x_note_mouse_movement (dpyinfo->last_mouse_glyph_frame, > &event->xmotion, Qnil); > #endif > > "else" and "dpyinfo" are fontified as types. > > #ifdef USE_MOTIF > Widget widget; > > widget =3D XtWindowToWidget (dpyinfo->display, > event->xbutton.window); > > if (widget && XmIsCascadeButton (widget) > && XtIsSensitive (widget)) > { > #endif > if (!f->output_data.x->saved_menu_event) > f->output_data.x->saved_menu_event =3D xmalloc (sizeof = *event); > *f->output_data.x->saved_menu_event =3D *event; > inev.ie.kind =3D MENU_BAR_ACTIVATE_EVENT; > XSETFRAME (inev.ie.frame_or_window, f); > *finish =3D X_EVENT_DROP; > #ifdef USE_MOTIF > } > #endif > > here, the last closing brace is fontified in the error face. > > Here: > > static void NO_INLINE > x_error_quitter (Display *display, XErrorEvent *event) > { > char buf[256], buf1[400 + INT_STRLEN_BOUND (int) > + INT_STRLEN_BOUND (unsigned long)]; > > "NO_INLINE" and "unsigned long" are fontified in the error face. > > CC mode fontifies all of the examples above fine, and they are not = even > pre-standard C. Would someone please fix c-ts-mode to fontify them > correctly as well? > Thanks for these reports! Buuuuut as we=E2=80=99ve seen, tree-sitter = really doesn=E2=80=99t handle macros that well. I=E2=80=99ll see what I can do = when I find the time, but there really isn=E2=80=99t any good solutions to this (right = now, that I can think of). I=E2=80=99m not even sure the author of tree-sitter-c = would accept changes that try to parse macros: he has made it clear that the purpose of tree-sitter-c is to support post-processed C and leave macros and preprocessor to error-recovery. Yuan