aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-04-15 13:05:04 -0400
committerEli Zaretskii2023-04-15 13:05:04 -0400
commitbc61a1afdd6c3ba8a605ed46ae97b1e36b40f951 (patch)
tree2a1b5d52bdd74fe0a3d2098d526d862f0737c485
parenta85279f390523f0872a5462219941e440feb7393 (diff)
parentb7023da6627f911c087961d9d476b3eafabb7ae7 (diff)
downloademacs-bc61a1afdd6c3ba8a605ed46ae97b1e36b40f951.tar.gz
emacs-bc61a1afdd6c3ba8a605ed46ae97b1e36b40f951.zip
Merge from origin/emacs-29
b7023da6627 Make image-map bindings available on image links d9e96c029bb * CONTRIBUTE: Fix a typo 3f71a2a0cf6 ; * lisp/progmodes/c-ts-mode.el (treesit-node-next-siblin... adf9c956c28 Add to Eglot support for additional language-servers. b3603b84bd9 Partial support for DEFUN in c-ts-mode (bug#62825) # Conflicts: # lisp/progmodes/c-ts-mode.el
-rw-r--r--CONTRIBUTE2
-rw-r--r--lisp/net/eww.el2
-rw-r--r--lisp/net/shr.el2
-rw-r--r--lisp/progmodes/c-ts-mode.el127
-rw-r--r--lisp/progmodes/eglot.el6
5 files changed, 109 insertions, 30 deletions
diff --git a/CONTRIBUTE b/CONTRIBUTE
index f56ba1df630..464b800adfb 100644
--- a/CONTRIBUTE
+++ b/CONTRIBUTE
@@ -321,7 +321,7 @@ them right the first time, so here are guidelines for formatting them:
321** Committing your changes. 321** Committing your changes.
322 322
323When you commit changes, Git invokes several scripts that test the 323When you commit changes, Git invokes several scripts that test the
324commit for validity, and may abort the commit of some of the tests 324commit for validity, and may abort the commit if some of the tests
325fail. These scripts live in the '.git/hooks/' subdirectory of the 325fail. These scripts live in the '.git/hooks/' subdirectory of the
326top-level directory of the repository, and they perform the following 326top-level directory of the repository, and they perform the following
327tests: 327tests:
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 11be20b68db..99450356b7c 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -326,7 +326,7 @@ parameter, and should return the (possibly) transformed URL."
326 "<mouse-2>" #'eww-follow-link) 326 "<mouse-2>" #'eww-follow-link)
327 327
328(defvar-keymap eww-image-link-keymap 328(defvar-keymap eww-image-link-keymap
329 :parent shr-map 329 :parent shr-image-map
330 "RET" #'eww-follow-link) 330 "RET" #'eww-follow-link)
331 331
332(defun eww-suggested-uris nil 332(defun eww-suggested-uris nil
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 9c2ae98d77e..4e44dfbef03 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -276,7 +276,7 @@ and other things:
276 276
277(defvar-keymap shr-map 277(defvar-keymap shr-map
278 "a" #'shr-show-alt-text 278 "a" #'shr-show-alt-text
279 "i" #'shr-browse-image 279 "M-i" #'shr-browse-image
280 "z" #'shr-zoom-image 280 "z" #'shr-zoom-image
281 "TAB" #'shr-next-link 281 "TAB" #'shr-next-link
282 "C-M-i" #'shr-previous-link 282 "C-M-i" #'shr-previous-link
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 5a38d714e5a..e93a0fec707 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -79,6 +79,7 @@
79(declare-function treesit-node-type "treesit.c") 79(declare-function treesit-node-type "treesit.c")
80(declare-function treesit-node-prev-sibling "treesit.c") 80(declare-function treesit-node-prev-sibling "treesit.c")
81(declare-function treesit-node-first-child-for-pos "treesit.c") 81(declare-function treesit-node-first-child-for-pos "treesit.c")
82(declare-function treesit-node-next-sibling "treesit.c")
82 83
83;;; Custom variables 84;;; Custom variables
84 85
@@ -192,6 +193,10 @@ To set the default indent style globally, use
192 (c-ts-mode--get-indent-style 193 (c-ts-mode--get-indent-style
193 (if (derived-mode-p 'c-ts-mode) 'c 'cpp)))))) 194 (if (derived-mode-p 'c-ts-mode) 'c 'cpp))))))
194 195
196(defvar c-ts-mode-emacs-devel nil
197 "If the value is t, enable Emacs source-specific features.
198This needs to be set before enabling `c-ts-mode'.")
199
195;;; Syntax table 200;;; Syntax table
196 201
197(defvar c-ts-mode--syntax-table 202(defvar c-ts-mode--syntax-table
@@ -802,7 +807,14 @@ Return nil if NODE is not a defun node or doesn't have a name."
802 ((or "struct_specifier" "enum_specifier" 807 ((or "struct_specifier" "enum_specifier"
803 "union_specifier" "class_specifier" 808 "union_specifier" "class_specifier"
804 "namespace_definition") 809 "namespace_definition")
805 (treesit-node-child-by-field-name node "name"))) 810 (treesit-node-child-by-field-name node "name"))
811 ;; DEFUNs in Emacs source.
812 ("expression_statement"
813 (let* ((call-exp-1 (treesit-node-child node 0))
814 (call-exp-2 (treesit-node-child call-exp-1 0))
815 (arg-list (treesit-node-child call-exp-2 1))
816 (name (treesit-node-child arg-list 1 t)))
817 name)))
806 t)) 818 t))
807 819
808;;; Defun navigation 820;;; Defun navigation
@@ -810,28 +822,29 @@ Return nil if NODE is not a defun node or doesn't have a name."
810(defun c-ts-mode--defun-valid-p (node) 822(defun c-ts-mode--defun-valid-p (node)
811 "Return non-nil if NODE is a valid defun node. 823 "Return non-nil if NODE is a valid defun node.
812Ie, NODE is not nested." 824Ie, NODE is not nested."
813 (not (or (and (member (treesit-node-type node) 825 (or (c-ts-mode--emacs-defun-p node)
814 '("struct_specifier" 826 (not (or (and (member (treesit-node-type node)
815 "enum_specifier" 827 '("struct_specifier"
816 "union_specifier"
817 "declaration"))
818 ;; If NODE's type is one of the above, make sure it is
819 ;; top-level.
820 (treesit-node-top-level
821 node (rx (or "function_definition"
822 "type_definition"
823 "struct_specifier"
824 "enum_specifier" 828 "enum_specifier"
825 "union_specifier" 829 "union_specifier"
826 "declaration")))) 830 "declaration"))
831 ;; If NODE's type is one of the above, make sure it is
832 ;; top-level.
833 (treesit-node-top-level
834 node (rx (or "function_definition"
835 "type_definition"
836 "struct_specifier"
837 "enum_specifier"
838 "union_specifier"
839 "declaration"))))
827 840
828 (and (equal (treesit-node-type node) "declaration") 841 (and (equal (treesit-node-type node) "declaration")
829 ;; If NODE is a declaration, make sure it is not a 842 ;; If NODE is a declaration, make sure it is not a
830 ;; function declaration. 843 ;; function declaration.
831 (equal (treesit-node-type 844 (equal (treesit-node-type
832 (treesit-node-child-by-field-name 845 (treesit-node-child-by-field-name
833 node "declarator")) 846 node "declarator"))
834 "function_declarator"))))) 847 "function_declarator"))))))
835 848
836(defun c-ts-mode--defun-for-class-in-imenu-p (node) 849(defun c-ts-mode--defun-for-class-in-imenu-p (node)
837 "Check if NODE is a valid entry for the Class subindex. 850 "Check if NODE is a valid entry for the Class subindex.
@@ -871,17 +884,73 @@ the semicolon. This function skips the semicolon."
871 (setq parent (treesit-node-parent smallest-node))))) 884 (setq parent (treesit-node-parent smallest-node)))))
872 (list node parent bol))) 885 (list node parent bol)))
873 886
887(defun c-ts-mode--emacs-defun-p (node)
888 "Return non-nil if NODE is a DEFUN in Emacs source files."
889 (and (equal (treesit-node-type node) "expression_statement")
890 (equal (treesit-node-text
891 (treesit-node-child-by-field-name
892 (treesit-node-child
893 (treesit-node-child node 0) 0)
894 "function")
895 t)
896 "DEFUN")))
897
898(defun c-ts-mode--emacs-defun-at-point (&optional range)
899 "Return the current defun node.
900
901This function recognizes DEFUNs in Emacs source files.
902
903Note that for the case of a DEFUN, it is made of two separate
904nodes, one for the declaration and one for the body, this
905function returns the declaration node.
906
907If RANGE is non-nil, return (BEG . END) where BEG end END
908encloses the whole defun. This solves the problem of only
909returning the declaration part for DEFUN."
910 (or (when-let ((node (treesit-defun-at-point)))
911 (if range
912 (cons (treesit-node-start node)
913 (treesit-node-end node))
914 node))
915 (and c-ts-mode-emacs-devel
916 (let ((candidate-1 ; For when point is in the DEFUN statement.
917 (treesit-node-prev-sibling
918 (treesit-node-top-level
919 (treesit-node-at (point))
920 "compound_statement")))
921 (candidate-2 ; For when point is in the body.
922 (treesit-node-top-level
923 (treesit-node-at (point))
924 "expression_statement")))
925 (when-let
926 ((node (or (and (c-ts-mode--emacs-defun-p candidate-1)
927 candidate-1)
928 (and (c-ts-mode--emacs-defun-p candidate-2)
929 candidate-2))))
930 (if range
931 (cons (treesit-node-start node)
932 (treesit-node-end
933 (treesit-node-next-sibling node)))
934 node))))))
935
874(defun c-ts-mode-indent-defun () 936(defun c-ts-mode-indent-defun ()
875 "Indent the current top-level declaration syntactically. 937 "Indent the current top-level declaration syntactically.
876 938
877`treesit-defun-type-regexp' defines what constructs to indent." 939`treesit-defun-type-regexp' defines what constructs to indent."
878 (interactive "*") 940 (interactive "*")
879 (when-let ((orig-point (point-marker)) 941 (when-let ((orig-point (point-marker))
880 (node (treesit-defun-at-point))) 942 (range (c-ts-mode--emacs-defun-at-point t)))
881 (indent-region (treesit-node-start node) 943 (indent-region (car range) (cdr range))
882 (treesit-node-end node))
883 (goto-char orig-point))) 944 (goto-char orig-point)))
884 945
946(defun c-ts-mode--emacs-current-defun-name ()
947 "Return the name of the current defun.
948This is used for `add-log-current-defun-function'. This
949recognizes DEFUN in Emacs sources, in addition to normal function
950definitions."
951 (or (treesit-add-log-current-defun)
952 (c-ts-mode--defun-name (c-ts-mode--emacs-defun-at-point))))
953
885;;; Modes 954;;; Modes
886 955
887(defvar-keymap c-ts-base-mode-map 956(defvar-keymap c-ts-base-mode-map
@@ -1025,7 +1094,11 @@ in your configuration."
1025 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c)) 1094 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c))
1026 ;; Navigation. 1095 ;; Navigation.
1027 (setq-local treesit-defun-tactic 'top-level) 1096 (setq-local treesit-defun-tactic 'top-level)
1028 (treesit-major-mode-setup))) 1097 (treesit-major-mode-setup)
1098
1099 (when c-ts-mode-emacs-devel
1100 (setq-local add-log-current-defun-function
1101 #'c-ts-mode--emacs-current-defun-name))))
1029 1102
1030;;;###autoload 1103;;;###autoload
1031(define-derived-mode c++-ts-mode c-ts-base-mode "C++" 1104(define-derived-mode c++-ts-mode c-ts-base-mode "C++"
@@ -1067,8 +1140,10 @@ recommended to enable `electric-pair-mode' with this mode."
1067 1140
1068 ;; Font-lock. 1141 ;; Font-lock.
1069 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp)) 1142 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp))
1070 1143 (treesit-major-mode-setup)
1071 (treesit-major-mode-setup))) 1144 (when c-ts-mode-emacs-devel
1145 (setq-local add-log-current-defun-function
1146 #'c-ts-mode--emacs-current-defun-name))))
1072 1147
1073(easy-menu-define c-ts-mode-menu (list c-ts-mode-map c++-ts-mode-map) 1148(easy-menu-define c-ts-mode-menu (list c-ts-mode-map c++-ts-mode-map)
1074 "Menu for `c-ts-mode' and `c++-ts-mode'." 1149 "Menu for `c-ts-mode' and `c++-ts-mode'."
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index c4f773c8426..24f2fda5ae5 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -250,7 +250,11 @@ chosen (interactively or automatically)."
250 ("csharp-ls")))) 250 ("csharp-ls"))))
251 (purescript-mode . ("purescript-language-server" "--stdio")) 251 (purescript-mode . ("purescript-language-server" "--stdio"))
252 ((perl-mode cperl-mode) . ("perl" "-MPerl::LanguageServer" "-e" "Perl::LanguageServer::run")) 252 ((perl-mode cperl-mode) . ("perl" "-MPerl::LanguageServer" "-e" "Perl::LanguageServer::run"))
253 (markdown-mode . ("marksman" "server"))) 253 (markdown-mode
254 . ,(eglot-alternatives
255 '(("marksman" "server")
256 ("vscode-markdown-language-server" "--stdio"))))
257 (graphviz-dot-mode . ("dot-language-server" "--stdio")))
254 "How the command `eglot' guesses the server to start. 258 "How the command `eglot' guesses the server to start.
255An association list of (MAJOR-MODE . CONTACT) pairs. MAJOR-MODE 259An association list of (MAJOR-MODE . CONTACT) pairs. MAJOR-MODE
256identifies the buffers that are to be managed by a specific 260identifies the buffers that are to be managed by a specific