Subject: 29.1.50; cc-guess does not work with tree-sitter modes

From: Kai Ma <[email-masked]>
Date: Sat, 05 Aug 2023 01:31:16 +0800

c-guess-buffer called in a buffer whose major mode is c-ts-mode will
raise the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  looking-at(nil)
  c-guess-basic-syntax()
  c-guess-examine(1 9173 nil)
  c-guess-region-no-install(1 9173 nil)
  c-guess-region(1 9173 nil)
  c-guess-buffer(nil)
  funcall-interactively(c-guess-buffer nil)
  call-interactively(c-guess-buffer record nil)
  command-execute(c-guess-buffer record)
  execute-extended-command(nil "c-guess-buffer" "c-gues")
  funcall-interactively(execute-extended-command nil "c-guess-buffer" "c-gues")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

This problem can be easily reproduced on emacs -Q:

1. emacs -Q emacs.c
2. M-x c-ts-mode
3. M-x c-guess-buffer

FWIW, c-mode works as expected.

In GNU Emacs 29.1.50 (build 1, x86_64-apple-darwin22.6.0, NS
 appkit-2299.70 Version 13.5 (Build 22G74)) of 2023-08-03 built on
 Kais-MacBook.local
Repository revision: 7280e6aaa1978c6e26c4286db9c446fa74637fa4
Repository branch: emacs-29
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.5

Configured using:
 'configure --with-xwidgets --with-ns --with-tree-sitter -C
 'LDFLAGS=-L/usr/local/opt/llvm/lib -L/usr/local/opt/bison/lib
 -L/usr/local/opt/flex/lib' 'CPPFLAGS=-I/usr/local/opt/llvm/include
 -I/usr/local/opt/flex/include''

Configured features:
ACL DBUS GIF GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NOTIFY
KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XIM XWIDGETS ZLIB

Important settings:
  value of $LC_ALL: zh_CN.utf-8
  value of $LANG: zh_CN.utf-8
  locale-coding-system: utf-8-unix

Major mode: C/*

Minor modes in effect:
  citre-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  display-line-numbers-mode: t
  hl-todo-mode: t
  rainbow-delimiters-mode: t
  copilot-mode: t
  symbol-overlay-mode: t
  diff-hl-margin-local-mode: t
  diff-hl-margin-mode: t
  diff-hl-mode: t
  recentf-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  doom-modeline-mode: t
  winner-mode: t
  winum-mode: t
  which-key-mode: t
  global-hl-line-mode: t
  solaire-global-mode: t
  projectile-mode: t
  vertico-multiform-mode: t
  vertico-mouse-mode: t
  vertico-mode: t
  keyfreq-autosave-mode: t
  keyfreq-mode: t
  evil-leader-mode: t
  global-evil-surround-mode: t
  evil-surround-mode: t
  global-evil-collection-unimpaired-mode: t
  evil-collection-unimpaired-mode: t
  diredfl-global-mode: t
  evil-mode: t
  evil-local-mode: t
  corfu-popupinfo-mode: t
  global-corfu-mode: t
  corfu-mode: t
  marginalia-mode: t
  prescient-persist-mode: t
  global-ligature-mode: t
  ligature-mode: t
  pixel-scroll-precision-mode: t
  save-place-mode: t
  adaptive-wrap-prefix-mode: t
  server-mode: t
  electric-pair-mode: t
  global-so-long-mode: t
  delete-selection-mode: t
  global-auto-revert-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  hs-minor-mode: t

Load-path shadows:
/Users/kaima/.emacs.d/elpa/transient-20230723.1411/transient hides /Applications/Emacs.app/Contents/Resources/lisp/transient

Features:
(shadow ecomplete emacsbug evil-collection-consult consult
magit-bookmark evil-collection-bookmark bookmark cap-words superword
subword rainbow-mode cl-print cus-start citre citre-global citre-tags
citre-ctags citre-readtags citre-readtags-tables citre-backend-interface
citre-ui-peek citre-ui-jump citre-common-tag citre-common-util c-ts-mode
c-ts-common evil-collection-vundo vundo misearch multi-isearch
info-colors jka-compr evil-collection-helpful helpful cc-langs trace
evil-collection-edebug edebug info-look evil-collection-elisp-refs
elisp-refs org-capture qp org-clock flow-fill mm-archive gnus-html
url-queue help-fns radix-tree url-cache mm-url sort smiley gnus-cite
mail-extr textsec uni-scripts idna-mapping uni-confusable textsec-check
gnus-async gnus-bcklg gnus-dup gnus-ml disp-table nndraft nnmh utf-7
nnfolder align evil-collection-speedbar speedbar ezimage dframe
haskell-mode haskell-cabal haskell-utils haskell-font-lock
haskell-indentation haskell-string haskell-sort-imports haskell-lexeme
haskell-align-imports haskell-complete-module haskell-ghc-support
evil-collection-flymake flymake-proc flymake etags fileloop
haskell-customize nnnil gnus-agent gnus-srvr gnus-score score-mode
nnvirtual gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls
dig nntp gnus-cache gnus-sum shr pixel-fill kinsoku url-file gnus-topic
gnus-group gnus-undo gnus-start gnus-dbus dbus gnus-cloud nnimap nnmail
mail-source utf7 nnoo gnus-spec gnus-int gnus-range gnus-win
evil-collection-gnus gnus nnheader range org-protocol evil-org-agenda
evil-org evil-collection-org citeproc citeproc-itemgetters
citeproc-biblatex parse-time citeproc-bibtex parsebib ol-bibtex bibtex
iso8601 citeproc-cite citeproc-subbibs citeproc-sort citeproc-name
citeproc-formatters citeproc-number rst citeproc-proc citeproc-disamb
citeproc-itemdata citeproc-generic-elements citeproc-macro
citeproc-choose citeproc-date citeproc-context citeproc-prange
citeproc-style citeproc-locale citeproc-term citeproc-rt citeproc-lib
citeproc-s oc-bibtex ox-odt rng-loc rng-uri rng-parse rng-match rng-dt
rng-util rng-pttrn nxml-parse nxml-ns nxml-enc xmltok nxml-util ox-latex
ox-icalendar org-agenda ox-html table ox-ascii ox-publish ox org-element
org-persist org-id org-refile avl-tree org-tempo tempo org org-macro
org-pcomplete org-list org-footnote org-faces org-entities ob-d2 ob-dot
ob-python evil-collection-python python treesit ob-rust ob-C ob
ob-tangle org-src ob-ref ob-lob ob-table ob-exp ob-comint ccls
ccls-member-hierarchy ccls-inheritance-hierarchy ccls-call-hierarchy
ccls-tree ccls-code-lens ccls-semantic-highlight ccls-common lsp-mode
lsp-protocol evil-collection-xref xref spinner network-stream nsm
evil-collection-markdown-mode markdown-mode evil-collection-outline
noutline outline ht inline cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs ob-emacs-lisp ob-core
ob-eval org-cycle org-table ol org-fold org-fold-core org-keys oc
org-loaddefs evil-collection-calendar cal-menu calendar cal-loaddefs
org-compat org-version autoinsert org-macs all-the-icons-ibuffer
evil-collection-magit magit-submodule magit-blame magit-stash
magit-reflog magit-bisect magit-push magit-pull magit-fetch magit-clone
magit-remote magit-commit magit-sequence magit-notes magit-worktree
magit-tag magit-merge magit-branch magit-reset magit-files magit-refs
magit-status magit magit-repos magit-apply magit-wip magit-log
magit-diff smerge-mode diff git-commit evil-collection-log-edit log-edit
message sendmail yank-media puny rfc822 mml mml-sec evil-collection-epa
epa epg rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr
mailabbrev mail-utils gmm-utils mailheader add-log magit-core
magit-autorevert magit-margin magit-transient magit-process with-editor
shell pcomplete magit-mode transient magit-git magit-base which-func
evil-collection-imenu imenu ido evil-collection-magit-section
magit-section benchmark format-spec cursor-sensor crm
all-the-icons-dired dired-filter dired-hacks-utils dired-aux dired-x
vertico-directory time-date pulse hideshow display-line-numbers hl-todo
rainbow-delimiters copilot copilot-balancer editorconfig
editorconfig-core editorconfig-core-handle editorconfig-fnmatch jsonrpc
evil-collection-ert ert evil-collection-debug debug backtrace find-func
warnings symbol-overlay evil-collection-diff-hl diff-hl-margin
diff-hl-dired diff-hl vc-hg evil-collection-vc-git vc-git
evil-collection-log-view log-view pcvs-util evil-collection-vc-dir
vc-dir ewoc vc vc-dispatcher evil-collection-diff-mode diff-mode recentf
tree-widget yasnippet-snippets yasnippet doom-modeline
doom-modeline-segments let-alist doom-modeline-env doom-modeline-core
shrink-path f f-shortdoc s nerd-icons nerd-icons-faces nerd-icons-data
nerd-icons-data-mdicon nerd-icons-data-flicon nerd-icons-data-codicon
nerd-icons-data-devicon nerd-icons-data-sucicon nerd-icons-data-wicon
nerd-icons-data-faicon nerd-icons-data-powerline nerd-icons-data-octicon
nerd-icons-data-pomicon nerd-icons-data-ipsicon winner winum
evil-collection-which-key which-key hl-line solaire-mode face-remap
projectile project skeleton ibuf-macs find-dired lisp-mnt
evil-collection-grep grep evil-collection-compile compile
text-property-search evil-collection-comint comint ansi-osc ansi-color
ibuf-ext evil-collection-ibuffer ibuffer ibuffer-loaddefs
evil-collection-vertico vertico-multiform vertico-mouse vertico
hardhacker-theme keyfreq prelude-nix prelude-evil evil-leader
evil-surround evil-collection-unimpaired evil-collection-tabulated-list
evil-collection-tab-bar evil-collection-so-long evil-collection-simple
evil-collection-replace evil-collection-process-menu
evil-collection-popup evil-collection-package-menu evil-collection-info
evil-collection-indent evil-collection-image image-mode
evil-collection-dired diredfl dired dired-loaddefs exif
evil-collection-help evil-collection-eshell em-prompt esh-mode
evil-collection-elisp-mode evil-collection-eldoc evil-collection-custom
evil-collection-corfu evil-collection-buff-menu evil-collection annalist
evil evil-integration evil-maps evil-commands evil-digraphs reveal
evil-jumps evil-command-window evil-search evil-ex evil-types
evil-macros evil-repeat evil-states evil-core evil-common thingatpt rect
evil-vars prelude-irc prelude-apps prelude-mail prelude-os prelude-help
prelude-lang-zig prelude-lang-web prelude-lang-agda agda2
prelude-lang-haskell prelude-lang-js prelude-lang-ml prelude-lang-coq
prelude-lang-rust prelude-lang-python prelude-lang-cc prelude-lang-lisp
prelude-prog prelude-blog prelude-org prelude-tex prelude-git
prelude-dired prelude-chinese rime rime-predicates derived xdg posframe
popup dash prelude-ibuffer prelude-search prelude-completion kind-icon
svg-lib color svg dom xml corfu-popupinfo corfu cape marginalia
orderless prescient char-fold prelude-project prelude-ui cus-edit pp
cus-load icons wid-edit rx ligature all-the-icons all-the-icons-faces
data-material data-weathericons data-octicons data-fileicons
data-faicons data-alltheicons pixel-scroll cua-base prelude-core hydra
ring lv saveplace adaptive-wrap dabbrev server finder-inf elec-pair
diminish exec-path-from-shell eshell esh-cmd esh-ext esh-opt esh-proc
esh-io esh-arg esh-module esh-groups esh-util files-x undohist edmacro
kmacro so-long delsel autorevert filenotify prelude-benchmark
benchmark-init advice cl-extra help-mode prelude-common prelude-iload
queue generator cl prelude-package vc-use-package pcase use-package
use-package-delight use-package-diminish use-package-bind-key bind-key
easy-mmode prelude-loaddefs no-littering compat package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source eieio eieio-core password-cache json subr-x map byte-opt
url-vars cl-macs gv use-package-ensure cl-seq use-package-core
cl-loaddefs cl-lib bytecomp byte-compile info adaptive-wrap-autoloads
alert-autoloads all-the-icons-dired-autoloads
all-the-icons-ibuffer-autoloads auctex-autoloads tex-site
benchmark-init-autoloads cape-autoloads carbon-now-sh-autoloads
cargo-autoloads catppuccin-theme-autoloads ccls-autoloads
cdlatex-autoloads cider-autoloads citeproc-autoloads citre-autoloads
clojure-mode-autoloads company-coq-autoloads company-math-autoloads
company-autoloads copilot-autoloads corfu-autoloads d2-mode-autoloads
dap-mode-autoloads bui-autoloads dash-at-point-autoloads
dashboard-autoloads debbugs-autoloads deft-autoloads devdocs-autoloads
diff-hl-autoloads diminish-autoloads dired-filter-autoloads
dired-hacks-utils-autoloads diredfl-autoloads dirvish-autoloads
doom-modeline-autoloads doom-themes-autoloads dracula-theme-autoloads
dumb-jump-autoloads dune-autoloads ebib-autoloads editorconfig-autoloads
ef-themes-autoloads elfeed-autoloads embark-consult-autoloads
consult-autoloads embark-autoloads evil-collection-autoloads
annalist-autoloads evil-leader-autoloads evil-org-autoloads
evil-surround-autoloads evil-autoloads exec-path-from-shell-autoloads
expand-region-autoloads flycheck-haskell-autoloads flycheck-autoloads
forge-autoloads closql-autoloads emacsql-autoloads geiser-autoloads
ghub-autoloads gntp-autoloads go-translate-autoloads
google-translate-autoloads goto-chg-autoloads gptel-autoloads
haskell-mode-autoloads helpful-autoloads elisp-refs-autoloads
hl-todo-autoloads info-colors-autoloads js2-mode-autoloads
keyfreq-autoloads kind-icon-autoloads ligature-autoloads log4e-autoloads
lsp-docker-autoloads lsp-treemacs-autoloads lsp-ui-autoloads
lsp-mode-autoloads lua-mode-autoloads magit-autoloads
git-commit-autoloads marginalia-autoloads markdown-mode-autoloads
math-symbol-lists-autoloads merlin-autoloads minimap-autoloads
modern-cpp-font-lock-autoloads modus-themes-autoloads
multiple-cursors-autoloads nerd-icons-autoloads nix-mode-autoloads
magit-section-autoloads nix-sandbox-autoloads no-littering-autoloads
nov-autoloads esxml-autoloads kv-autoloads ob-d2-autoloads
ob-rust-autoloads one-themes-autoloads orderless-autoloads
org-appear-autoloads org-preview-html-autoloads org-xlatex-autoloads
ormolu-autoloads paredit-autoloads parsebib-autoloads parseedn-autoloads
parseclj-autoloads pdf-tools-autoloads pinyinlib-autoloads
pkg-info-autoloads epl-autoloads prescient-autoloads
proof-general-autoloads proof-site proof-autoloads queue-autoloads
quickrun-autoloads racket-mode-autoloads rainbow-delimiters-autoloads
rainbow-mode-autoloads rime-autoloads popup-autoloads ripgrep-autoloads
rotate-autoloads sesman-autoloads shrink-path-autoloads f-autoloads
sly-autoloads smartparens-autoloads solaire-mode-autoloads
speed-type-autoloads spinner-autoloads string-inflection-autoloads
svg-lib-autoloads symbol-overlay-autoloads tablist-autoloads
telega-autoloads rainbow-identifiers-autoloads theme-emacs-autoloads
transient-autoloads treemacs-all-the-icons-autoloads
all-the-icons-autoloads treemacs-persp-autoloads persp-mode-autoloads
treemacs-projectile-autoloads projectile-autoloads
treemacs-tab-bar-autoloads treemacs-autoloads cfrs-autoloads
posframe-autoloads ht-autoloads hydra-autoloads lv-autoloads
pfuture-autoloads ace-window-autoloads avy-autoloads s-autoloads
treepy-autoloads undohist-autoloads utop-autoloads tuareg-autoloads
caml-autoloads valign-autoloads vc-use-package-autoloads
vertico-autoloads visual-fill-column-autoloads vterm-toggle-autoloads
vterm-autoloads vundo-autoloads wakatime-mode-autoloads
web-mode-autoloads wgrep-autoloads which-key-autoloads winum-autoloads
dash-autoloads with-editor-autoloads compat-autoloads yaml-autoloads
yasnippet-snippets-autoloads yasnippet-autoloads zig-mode-autoloads
reformatter-autoloads rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads xwidget-internal dbusbind
kqueue cocoa ns lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 1640009 1209394)
 (symbols 48 89101 150)
 (strings 32 351297 54059)
 (string-bytes 1 10641159)
 (vectors 16 101882)
 (vector-slots 8 2989626 871662)
 (floats 8 1549 8139)
 (intervals 56 19954 7087)
 (buffers 984 43))