Created
September 5, 2024 14:30
-
-
Save nfedyashev/51b994941f738b5341b4d67fefb32c88 to your computer and use it in GitHub Desktop.
Related github issue https://github.com/karthink/gptel/issues/346
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun gptel--strip-mode-suffix (mode-sym) | |
"Remove the -mode suffix from MODE-NAME. | |
MODE-NAME is typically a major-mode symbol." | |
- (let ((mode-name (thread-last | |
- (symbol-name mode-sym) | |
- (string-remove-suffix "-mode") | |
- (string-remove-suffix "-ts")))) | |
- (if (provided-mode-derived-p | |
- mode-sym 'prog-mode 'text-mode 'tex-mode) | |
- mode-name ""))) | |
+ (cond | |
+ ((eq mode-sym 'enh-ruby-mode) "ruby") | |
+ ((eq mode-sym 'js2-mode) "js") | |
+ ((eq mode-sym 'scad-mode) "openscad") | |
+ (t | |
+ (let ((mode-name (thread-last | |
+ (symbol-name mode-sym) | |
+ (string-remove-suffix "-mode") | |
+ (string-remove-suffix "-ts")))) | |
+ (if (provided-mode-derived-p | |
+ mode-sym 'prog-mode 'text-mode 'tex-mode) | |
+ mode-name ""))))) | |
+ |
And your question about a better way: unfortunately we don't have an unequivocal major-mode=>language mapping anywhere yet, but there is another source of information: major-mode-remap-alist
and (most recently) major-mode-remap-defaults
. So one could also check whether the current mode is associated as a value with some major mode as a key which fits the traditional naming scheme (when the mapped one doesn't).
But I would only bother with it after finding a real-world mode that doesn't fit the current detector. That mapping is only used for TeX/LaTeX and ts modes by default.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dgutov thank you!