From 589959fb09d8a8f60179e1cceca4c3777b8c7719 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 10 Apr 2023 02:08:48 +0300 Subject: project-search: Pipe the list of files through 'file-regular-p' * lisp/progmodes/project.el (project-search): Pipe the list of files through 'file-regular-p' to skip directories (bug#62735). --- lisp/progmodes/project.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 11228226592..a18b918db62 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1216,7 +1216,10 @@ To continue searching for the next match, use the command \\[fileloop-continue]." (interactive "sSearch (regexp): ") (fileloop-initialize-search - regexp (project-files (project-current t)) 'default) + regexp + ;; XXX: See the comment in project-query-replace-regexp. + (cl-delete-if-not #'file-regular-p (project-files (project-current t))) + 'default) (fileloop-continue)) ;;;###autoload -- cgit v1.2.3 From db8f207e52fc969e0dcf30e197bcfaa4fa1d2b6e Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 10 Apr 2023 02:58:46 +0300 Subject: Fix some cases of incomplete code's indentation [c/c++-ts-mode] * lisp/progmodes/c-ts-mode.el (c-ts-base--before-indent): Try to guess when the parse tree is incomplete, and provide a better node to indent against (bug#62717). (c-ts-base-mode): Set up advice for local treesit-indent-function. --- lisp/progmodes/c-ts-mode.el | 17 +++++++++++++++++ test/lisp/progmodes/c-ts-mode-resources/indent.erts | 14 ++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'lisp') diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 981c7766375..83e89c3a335 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -859,6 +859,18 @@ the semicolon. This function skips the semicolon." (goto-char (match-end 0))) (treesit-default-defun-skipper)) +(defun c-ts-base--before-indent (args) + (pcase-let ((`(,node ,parent ,bol) args)) + (when (null node) + (let ((smallest-node (treesit-node-at (point)))) + ;; "Virtual" closer curly added by the + ;; parser's error recovery. + (when (and (equal (treesit-node-type smallest-node) "}") + (equal (treesit-node-end smallest-node) + (treesit-node-start smallest-node))) + (setq parent (treesit-node-parent smallest-node))))) + (list node parent bol))) + (defun c-ts-mode-indent-defun () "Indent the current top-level declaration syntactically. @@ -904,6 +916,11 @@ the semicolon. This function skips the semicolon." ;; function_definitions, so we need to find the top-level node. (setq-local treesit-defun-prefer-top-level t) + ;; When the code is in incomplete state, try to make a better guess + ;; about which node to indent against. + (add-function :filter-args (local 'treesit-indent-function) + #'c-ts-base--before-indent) + ;; Indent. (when (eq c-ts-mode-indent-style 'linux) (setq-local indent-tabs-mode t)) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 5cdefe2122c..221b3d809af 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -464,3 +464,17 @@ main (void) | } =-=-= + +Name: Empty Line (Block Start) + +=-= +int +main (void) +{ +| +=-= +int +main (void) +{ + | +=-=-= -- cgit v1.2.3