Add the current mode to the API #43

Closed
opened 2011-03-17 02:17:41 +01:00 by marijnh · 13 comments
marijnh commented 2011-03-17 02:17:41 +01:00 (Migrated from gitlab.com)

It'd be nice if a CodeMirror object had an API method / property containing the current mode. Or does it and I'm missing it?

It'd be nice if a CodeMirror object had an API method / property containing the current mode. Or does it and I'm missing it?
marijnh commented 2011-03-17 08:00:14 +01:00 (Migrated from gitlab.com)

I think getOption("mode") will do what you want.

I think getOption("mode") will do what you want.
marijnh commented 2011-03-17 08:22:23 +01:00 (Migrated from gitlab.com)

Unfortunately not.

>> editor.getOption("mode")
"rb"

That's the mode I set, but not the mode in use as shown by the warning I see:

No mode rb found, falling back to plain text.
Unfortunately not. ``` >> editor.getOption("mode") "rb" ``` That's the mode I set, but not the mode in use as shown by the warning I see: ``` No mode rb found, falling back to plain text. ```
marijnh commented 2011-03-17 08:25:52 +01:00 (Migrated from gitlab.com)

Right, when trying to use a mode that wasn't loaded, it'll fall back to the null mode. Why do you need to detect this? Wouldn't it suffice to just ensure you only use modes that are loaded?

I am planning to add something that'll list loaded modes. That might help here.

Right, when trying to use a mode that wasn't loaded, it'll fall back to the null mode. Why do you need to detect this? Wouldn't it suffice to just ensure you only use modes that are loaded? I am planning to add something that'll list loaded modes. That might help here.
marijnh commented 2011-03-17 08:31:33 +01:00 (Migrated from gitlab.com)

Why not load all the modes and let CodeMirror figure out which mode to use?

That's how it works right now if you load all modes and pass an extension, with a few special cases.

The only problem is there's no way to figure out which mode CodeMirror picked.

Why not load all the modes and let CodeMirror figure out which mode to use? That's how it works right now if you load all modes and pass an extension, with a few special cases. The only problem is there's no way to figure out which mode CodeMirror picked.
marijnh commented 2011-03-17 08:34:02 +01:00 (Migrated from gitlab.com)

Mode names are not extensions. If you want something 'clever' like this, use MIME types. Again, why do you need to find out which mode was picked?

Mode names are not extensions. If you want something 'clever' like this, use MIME types. Again, why do you need to find out which mode was picked?
marijnh commented 2011-03-17 08:35:49 +01:00 (Migrated from gitlab.com)

You're already calling console.warn in the exact case I'm asking about. Why not set a flag or variable?

You're already calling `console.warn` in the exact case I'm asking about. Why not set a flag or variable?
marijnh commented 2011-03-17 08:37:19 +01:00 (Migrated from gitlab.com)

Yeah, I can, but I'm trying to figure out your use case. I try to be a bit conservative in adding API functions, to keep things tidy.

Yeah, I can, but I'm trying to figure out your use case. I try to be a bit conservative in adding API functions, to keep things tidy.
marijnh commented 2011-03-17 08:39:12 +01:00 (Migrated from gitlab.com)

I guess I'm a bit confused.

When you ask CodeMirror to use a mode, and it cannot find that mode, it falls back to the plain text mode.

However there is absolutely no way in JavaScript to know if CodeMirror found the mode you asked for.

I guess I'm a bit confused. When you ask CodeMirror to use a mode, and it cannot find that mode, it falls back to the plain text mode. However there is absolutely no way in JavaScript to know if CodeMirror found the mode you asked for.
marijnh commented 2011-03-17 09:29:53 +01:00 (Migrated from gitlab.com)

Because you're not expected to ask for any old random mode. You have control over the modes you load, so you should know whether the mode you're trying to use is present.

Because you're not expected to ask for any old random mode. You have control over the modes you load, so you should know whether the mode you're trying to use is present.
marijnh commented 2011-03-17 09:35:52 +01:00 (Migrated from gitlab.com)

So not only does CodeMirror let me give it a String mode name with no way to verify I was correct, it also stores a dictionary of modes internally as well as the current mode internally but refuses to surface this data to plugin developers.

So not only does CodeMirror let me give it a String mode name with no way to verify I was correct, it also stores a dictionary of modes internally as well as the current mode internally but refuses to surface this data to plugin developers.
marijnh commented 2011-03-17 09:38:19 +01:00 (Migrated from gitlab.com)

Firstly, I talked about adding a way to list the loaded modes, and in fact have already added that (see the the current HEAD commit).

Secondly, if your tone is going to be like this, forget about it—go bother the maintainer of some other project.

Firstly, I talked about adding a way to list the loaded modes, and in fact have already added that (see the the current HEAD commit). Secondly, if your tone is going to be like this, forget about it—go bother the maintainer of some other project.
marijnh commented 2011-03-17 09:46:05 +01:00 (Migrated from gitlab.com)

All I want is for the mode variable you use internally to be available to plugins so I can use your sweet library on my project. And you're telling me I'm doing it wrong (even though your library does it this way) and to fuck off?

Okay, I will (and I've closed this issue), but I still vote that CodeMirror2 should let you know whether the mode you want is available or not :) Especially when writing plugins.

All I want is for the `mode` variable you use internally to be available to plugins so I can use your sweet library on my project. And you're telling me I'm doing it wrong (even though your library does it this way) and to fuck off? Okay, I will (and I've closed this issue), but I still vote that CodeMirror2 should let you know whether the mode you want is available or not :) Especially when writing plugins.
marijnh commented 2011-03-17 14:49:54 +01:00 (Migrated from gitlab.com)

@_marijnh_: I still think it would be useful to be able to get this option. It may be possible to figure it out, but it could be a lot more convenient.
@_defunkt_: Listing a use case is a must for feature additions like this. He wouldn't have told you to fuck off if you would have just provided reasons why this feature should exist instead of being so stubborn. You may have thought it was implicit, but reasons why it is superior to the provided methods (given they are valid) would surely be enough to convince the maintainer to comply.

`@_marijnh_`: I still think it would be useful to be able to get this option. It may be possible to figure it out, but it could be a lot more convenient. ` @_defunkt_`: Listing a use case is a must for feature additions like this. He wouldn't have told you to fuck off if you would have just provided reasons why this feature should exist instead of being so stubborn. You may have thought it was implicit, but reasons why it is superior to the provided methods (given they are valid) would surely be enough to convince the maintainer to comply.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/codemirror5#43
No description provided.