diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi index f47720184a3..f3824436246 100644 --- a/doc/lispref/positions.texi +++ b/doc/lispref/positions.texi @@ -852,7 +852,7 @@ matches either @code{"function_definition"} or @code{"class_definition"}. @end defvar @defvar treesit-defun-tactic -This variable determines how does Emacs treat nested defuns. If the +This variable determines how Emacs treats nested defuns. If the value is @code{top-level}, navigation functions only move across top-level defuns, if the value is @code{nested}, navigation functions recognize nested defuns. diff --git a/etc/NEWS.29 b/etc/NEWS.29 index 355ba6ba8aa..38a8798507a 100644 --- a/etc/NEWS.29 +++ b/etc/NEWS.29 @@ -68,6 +68,12 @@ Emacs modes you will use, as Emacs loads these libraries only when the corresponding mode is turned on in some buffer for the first time in an Emacs session. +Emacs provides a user command, 'treesit-install-language-grammar', +that automates the download and build process of a grammar library. +It prompts for the language, the URL of the language grammar's VCS +repository, and then uses the installed C/C++ compiler to build the +library and install it. + +++ ** Emacs can be built with built-in support for accessing SQLite databases. This uses the popular sqlite3 library, and can be disabled by using diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index c086214a11d..5c173ad24c7 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -850,7 +850,12 @@ The hash (#) is for instance methods only which are methods dot (.) is used. Double colon (::) is used between classes. The leading double colon is not added." (let* ((node (treesit-node-at (point))) - (method (treesit-parent-until node (ruby-ts--type-pred ruby-ts--method-regex))) + (method-pred + (lambda (node) + (and (<= (treesit-node-start node) (point)) + (>= (treesit-node-end node) (point)) + (string-match-p ruby-ts--method-regex (treesit-node-type node))))) + (method (treesit-parent-until node method-pred t)) (class (or method node)) (result nil) (sep "#") diff --git a/lisp/treesit.el b/lisp/treesit.el index bcdc9daeac5..e141f872c73 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -2671,7 +2671,7 @@ CC and C++ are C and C++ compilers, defaulting to \"cc\" and \"c++\", respectively.") (defun treesit--install-language-grammar-build-recipe (lang) - "Interactively build a recipe for LANG and return it. + "Interactively produce a download/build recipe for LANG and return it. See `treesit-language-source-alist' for details." (when (y-or-n-p (format "There is no recipe for %s, do you want to build it interactively?" lang)) (cl-labels ((empty-string-to-nil (string) @@ -2693,9 +2693,14 @@ See `treesit-language-source-alist' for details." (read-string "Enter the C++ compiler to use (default: auto-detect): ")))))) +;;;###autoload (defun treesit-install-language-grammar (lang) "Build and install the tree-sitter language grammar library for LANG. +Interactively, if `treesit-language-source-alist' doesn't already +have data for building the grammar for LANG, prompt for its +repository URL and the C/C++ compiler to use. + This command requires Git, a C compiler and (sometimes) a C++ compiler, and the linker to be installed and on PATH. It also requires that the recipe for LANG exists in `treesit-language-source-alist'. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 7a34357811e..7689d5f879f 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1036,6 +1036,8 @@ It is based on `log-edit-mode', and has Git-specific extensions." (let ((vc-git-patch-string patch-string)) (vc-git-checkin nil comment))) +(autoload 'vc-switches "vc") + (defun vc-git-checkin (files comment &optional _rev) (let* ((file1 (or (car files) default-directory)) (root (vc-git-root file1)) @@ -1078,7 +1080,14 @@ It is based on `log-edit-mode', and has Git-specific extensions." ;; want to commit any changes to that file, we need to ;; stash those changes before committing. (with-temp-buffer - (vc-git-command (current-buffer) t nil "diff" "--cached") + ;; If the user has switches like -D, -M etc. in their + ;; `vc-git-diff-switches', we must pass them here too, or + ;; our string matches will fail. + (if vc-git-diff-switches + (apply #'vc-git-command (current-buffer) t nil + "diff" "--cached" (vc-switches 'git 'diff)) + ;; Following code doesn't understand plain diff(1) output. + (user-error "Cannot commit patch with nil `vc-git-diff-switches'")) (goto-char (point-min)) (let ((pos (point)) file-name file-header file-diff file-beg) (while (not (eobp)) @@ -1410,8 +1419,6 @@ This prompts for a branch to merge from." :type 'boolean :version "26.1") -(autoload 'vc-switches "vc") - (defun vc-git-print-log (files buffer &optional shortlog start-revision limit) "Print commit log associated with FILES into specified BUFFER. If SHORTLOG is non-nil, use a short format based on `vc-git-root-log-format'. diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 9687231dbfa..8a75c83d2c3 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el @@ -537,9 +537,12 @@ VALUES-PLIST is a list with alternating index and value elements." | def foo | end | _ + | def bar + | end | end |end") (search-backward "_") + (delete-char 1) (should (string= (ruby-add-log-current-method)"M::C")))) (ert-deftest ruby-add-log-current-method-in-singleton-class () diff --git a/test/lisp/progmodes/ruby-ts-mode-tests.el b/test/lisp/progmodes/ruby-ts-mode-tests.el index aa1ab1e2605..b2c990f8e56 100644 --- a/test/lisp/progmodes/ruby-ts-mode-tests.el +++ b/test/lisp/progmodes/ruby-ts-mode-tests.el @@ -141,9 +141,12 @@ The whitespace before and including \"|\" on each line is removed." | def foo | end | _ + | def bar + | end | end |end") (search-backward "_") + (delete-char 1) (should (string= (ruby-ts-add-log-current-function) "M::C")))) (ert-deftest ruby-ts-add-log-current-method-in-singleton-class ()