Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable xref-js2 in js-ts-mode #850

Closed
wants to merge 0 commits into from
Closed

Conversation

archer-n
Copy link
Contributor

No description provided.

Copy link
Owner

@purcell purcell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea — I think a different formulation is needed, though (see comments), so let me have a think.

(add-hook 'js-mode-hook 'sanityinc/enable-xref-js2))
(define-key js-ts-mode-map (kbd "M-.") nil)
(add-hook 'js-mode-hook 'sanityinc/enable-xref-js2)
(add-hook 'js-ts-mode-hook 'sanityinc/enable-xref-js2))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js-mode-hook is actually run in js-ts-mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually both js-mode and js-ts-mode inherit from js-base-mode in Emacs >= 29

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, sorry, I had been tinkering with the code locally and my mind was thinking of js-base-mode.

@@ -57,7 +57,10 @@
(add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))
(with-eval-after-load 'js
(define-key js-mode-map (kbd "M-.") nil)
(add-hook 'js-mode-hook 'sanityinc/enable-xref-js2))
(define-key js-ts-mode-map (kbd "M-.") nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break in Emacs < 29 so a different formulation would be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder, I have fixed this problem, please take a look.

purcell added a commit that referenced this pull request Aug 23, 2023
@purcell
Copy link
Owner

purcell commented Aug 23, 2023

I pushed my version of this change in master, let me know if it looks okay to you.

0xMF pushed a commit to 0xMF/emacs.d that referenced this pull request Aug 25, 2023
cdadar pushed a commit to cdadar/emacs.d that referenced this pull request Sep 13, 2023
@archer-n archer-n closed this Dec 11, 2023
@archer-n
Copy link
Contributor Author

I pushed my version of this change in master, let me know if it looks okay to you.

He doesn't fix the problem, because js-ts-mode-map is copied from js-mode-map rather than inherited, so just modifying js-mode-map is invalid.

(defvar js-ts-mode-map (copy-keymap js-mode-map)
  "Keymap used in `js-ts-mode'.")

I think this could work:

(let ((base-mode (if (fboundp 'js-base-mode) 'js-base-mode 'js-mode)))
    (with-eval-after-load 'js
      (add-hook (derived-mode-hook-name base-mode) 'sanityinc/enable-xref-js2)
      (define-key js-mode-map (kbd "M-.") nil)
+    (define-key js-ts-mode-map (kbd "M-.") nil)
))

But there is another good news. In the emacs master branch, the commit Remove 'M-.' binding from js-mode and js-ts-mode has deleted this keybind.

purcell added a commit that referenced this pull request Dec 11, 2023
@purcell
Copy link
Owner

purcell commented Dec 11, 2023

Thanks. I committed a further fix here anyway.

0xMF pushed a commit to 0xMF/emacs.d that referenced this pull request Dec 12, 2023
tommas1988 pushed a commit to tommas1988/emacs.d that referenced this pull request Jan 1, 2024
tommas1988 pushed a commit to tommas1988/emacs.d that referenced this pull request Jan 1, 2024
cdadar pushed a commit to cdadar/emacs.d that referenced this pull request Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants