Editor:capitalize-case?


#1

Emacs has {upcase, downcase, capitalize}-{word, region}, but I only found editor:lower-case and editor:upper-case in Atom. I think something like editor:capitalize-case is useful, too. I use {capitalize}-{word, region} in Emacs every day.


#2

Actually, I was thinking of writing a package to do title casing. It wouldn’t be too hard to do the others while I’m at it.


#3

Don’t forget …

BumpyCaps
camelBack
CamelCaps
CapWords
compoundNames
Embedded Caps
HumpBack
InterCaps
mixedCase
nerdCaps
headlessCamelCase
Smalltalk case
WikiWord
WikiCase
wimpyCaps
All caps
Capitalization
Letter case
Sentence case
Small caps
snake case
StudlyCaps
Unicase

From …


#4

You can put this in your init.js file. This will capitalize the current word under the cursor(s)

atom.commands.add('atom-text-editor', 'init:capitalize-word', () => {
  const editor = atom.workspace.getActiveTextEditor();
  if (!editor) {
    return;
  }
  editor.getCursors().forEach(cursor => {
    const range = cursor.getCurrentWordBufferRange();
    const text = editor.getTextInBufferRange(range);
    const capitalized = text.charAt(0).toUpperCase() + text.slice(1);
    editor.setTextInBufferRange(range, capitalized);
  });
});

#5

@mads-hartmann
looks good, but gives me an Failed to load: Invalid or unexpected token
can’t find the invalid token though.
(could you also extend your snippet, that it not only capitalizes the current word, but toggles the word’s capitalization?)


#6

That’s funky. You can see my full init file here which works :slight_smile: I’ll have a look at toggling the capitalisation and get back to you


#7

Hello.

Caution: The code given by @mads-hartmann is Javascript meant for init.js.
Perhaps your Atom setup uses init.coffee.
Pasted the Javascript code into init.coffee, you will give a problem.

Cheers.
- Dan Padric


#8

switched to https://atom.io/packages/inc