-
-
Save nfedyashev/51b994941f738b5341b4d67fefb32c88 to your computer and use it in GitHub Desktop.
(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 ""))))) | |
+ |
nfedyashev
commented
Sep 5, 2024
Hi! Makes sense to me.
Also, not sure what was the goal of the provided-mode-derived-p
call, but if it's to limit gptel to working in certain major modes, you might want to add a user option.
@dgutov thank you!
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.