[SOLVED] How: Exclude keybinding for language grammar


#1

Hi there.

According to the Flight Manual a keybinding can be associated with a grammar (read: ‘language’).
http://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/#selectors-and-custom-packages

Please help me - how to identify the scope of a keybinding to exclude a grammar?

My objective is a solution for: (gfm = Github Version MarkDown)

'atom-text-editor:not([mini]) , not(source.gfm)':
# should exclude all non-program languages
  'alt': 'placeRuler'
  '^alt': 'hideRuler'

Thanks for your attention.
  dP


#2

Extending my question (please)…
Is it possible declare a variable inside the keymap.cson code?

allTextFiles := source.gfm & text.plain


#3

The keys in keymap.cson are CSS selectors. Here’s a good guide for using the :not() feature. It should be .source.gfm, because those are two class names.


#4

Hello. I have digged into the resource you linked to - thank you.

I have come up with the following:

"atom-text-editor:not(.mini):not([data-grammar='text plain']):not([data-grammar='source gfm'])":
  'alt': 'placeRuler'
  '^alt': 'hideRuler'

Note:

  1. Positions of the " and ' quotes.
  2. The . in .mini … (child?)
  3. The [ ] in the attribute
  4. The 'source gfm' without the .

Now…
Is there a way:
a) Combining the attribute tests as [data-grammar='text plain' | 'source gfm']
…(above does not work)
b) Combining the not() to not(.mini [data-grammar='text plain' | 'source gfm']
…(above does not work)
c) Making a constant / variable to represent 'text plain' or 'source gfm'
d) Write the scope over multiple lines…(below does not work)

"atom-text-editor:not(.mini):/
  not([data-grammar='text plain']):/ 
  not([data-grammar='source gfm'])":
    'alt': 'placeRuler'
    '^alt': 'hideRuler'

Thanks again for the chat.


#5

…variation to working code -
     Note the ~=

"atom-text-editor:not(.mini):not([data-grammar~='text']):not([data-grammar='source gfm'])":
  'alt': 'placeRuler'
  '^alt': 'hideRuler'

#6

You removed the [] from [mini], which was the thing you had right. This works for me:

"atom-text-editor:not([mini]):not([data-grammar='text plain']):not([data-grammar='source gfm'])"

#7

:slightly_smiling_face: The not(.mini) seems to work too.


#8

Ah, fair. I just checked and there it is. Not sure why it needs both a .mini class and a mini attribute.


#9

What I can tell you is that not(.data-grammar='text plain') does not work.

I assume that you can reach mini by atom-text-editor.mini which is an (?) object and a (?) child of atom-text-editor. But it is also captured as an attribute. [1]

atom-text-editor.data-grammar() is however an attribute of atom-text-editor and not a (?) child.

I am inclined to think that the functionality of [1] is unintended. The [xx] should not work.

Mr. Wilson - Do you still wear your ‘academic’ hat? Am my assumptions good or how am I wrong?
dP


#10

You’re wrong because this is how a mini editor is defined (taken from the find-and-replace feature):

The mini attribute (which the cursor is pointing at) is the thing being checked by atom-text-editor[mini] or atom-text-editor:not([mini]). I was wrong because I forgot that it also had a .mini class.


#11

:smile: { Thank you! }