Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

autoindent lines with moveLineUp/moveLineDown - #9104

Merged
maxbrunsfeld merged 2 commits into
atom:masterfrom
joseramonc:master
Nov 3, 2015
Merged

maxbrunsfeld merged 2 commits into
atom:masterfrom
joseramonc:master

Conversation

@joseramonc

Copy link
Copy Markdown
Contributor

Related to #7546, added the autoIndentSelection if should autoIndent. A demo of the change:

autoindentmoveline

@YurySolovyov

Copy link
Copy Markdown

Shouldn't there be an option in settings for that?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Shouldn't there be an option in settings for that?

It looks like it already respects the existing core.autoIndent scoped config option. It makes sense to me to use the same option as auto-indenting on newline insertion. Thoughts?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Could you add a test for this @joseramonc?

@YurySolovyov

Copy link
Copy Markdown

@maxbrunsfeld if so, it would be nice to have this metioned in setting description

@joseramonc

Copy link
Copy Markdown
Contributor Author

@maxbrunsfeld Added tests for editor.moveLineUp() and editor.moveLineDown(), hope they are right, they were passing locally

@maxbrunsfeld maxbrunsfeld self-assigned this Oct 14, 2015
@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Sorry for letting this go quiet for a while; there were some network-related CI failures. I re-ran the build.

@joseramonc

Copy link
Copy Markdown
Contributor Author

@maxbrunsfeld It seems that just one build failed, is there some guide or help to debug this locally? Tests are passing on my computer 😞

@winstliu

winstliu commented Nov 3, 2015

Copy link
Copy Markdown
Contributor

You can safely ignore the symbols-view error; that spec is super-flaky right now.

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

@joseramonc Thanks for the ping. Great work!

maxbrunsfeld pushed a commit that referenced this pull request Nov 3, 2015
autoindent lines with moveLineUp/moveLineDown
@maxbrunsfeld
maxbrunsfeld merged commit 3412251 into atom:master Nov 3, 2015
@stefanbuck

Copy link
Copy Markdown

@joseramonc Thanks for this great feature, love it 🎉

@dorian-marchal

Copy link
Copy Markdown

Thanks a lot for your contribution but this breaks a pretty common use case : https://discuss.atom.io/t/move-line-without-auto-indent/23754
Could we have an other option in settings to disable this specific behaviour ?

Original message :

I don't want my lines to auto indent when I move them.

How can I change this behaviour ?

Example :

@alexandernst

Copy link
Copy Markdown

Perhaps an option to disable auto-indent when moving lines in plain-text files?

@dorian-marchal

Copy link
Copy Markdown

Perhaps an option to disable auto-indent when moving lines in plain-text files?

Note that this is not specific to Markdown / Plain Text :

optimised

@alexandernst

Copy link
Copy Markdown

@as-cii As per the gif @dorian-marchal just posted, I'd say auto-indent shouldn't trigger when changing lines from the same "lexical" line. Or make it understand what lexical line breaks are and make it work accordingly.

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

OK, it looks like this feature seems to have undesirable consequences pretty often, even in contexts where auto-indent is desirable for text insertion.

@joseramonc I think we may need to remove this feature until Atom's auto-indentation system is good enough to avoid these problems.

@snowsunny

Copy link
Copy Markdown

Just like @dorian-marchal has demonstrated this feature wreaks havoc on indentation for code spanning multiple lines. It would be nice to have a separate setting to enable or disable auto-indent specifically for this feature. EG: "editor.indentOnLineMove", when set to false it won't automatically indent but editor.autoIndent will remain untouched/active.

@dorian-marchal I kludged it with this custom command.

atom.commands.add 'atom-text-editor', 'my:move-line-up', ->
  editor = atom.workspace.getActiveTextEditor()
  if atom.config.get('editor.autoIndent')
    atom.config.set('editor.autoIndent', false)
    editor.moveLineUp()
    atom.config.set('editor.autoIndent', true)
  else
    editor.moveLineUp()

atom.commands.add 'atom-text-editor', 'my:move-line-down', ->
  editor = atom.workspace.getActiveTextEditor()
  if atom.config.get('editor.autoIndent')
    atom.config.set('editor.autoIndent', false)
    editor.moveLineDown()
    atom.config.set('editor.autoIndent', true)
  else
    editor.moveLineDown()

and keymap

'.platform-linux atom-workspace atom-text-editor:not([mini])':
  'ctrl-shift-up': 'my:move-line-up'
  'ctrl-shift-down': 'my:move-line-down'

@dorian-marchal

Copy link
Copy Markdown

@snowsunny It works just fine, thank you 👍

@snowsunny

Copy link
Copy Markdown

@dorian-marchal I’m happy to help 👍

@jeancroy

Copy link
Copy Markdown
Contributor

Maybe make this an option ? It seems useful for people that mostly use language with clear indent scoping block (like html, JavaScript)

I also feel that re-arranging item in hanging indent is somewhat rare.

@mnquintana

Copy link
Copy Markdown
Contributor

Making this an option sounds 🆒 to me – that way we could scope it only to grammars that play nicely with this.

@geoffkembel

Copy link
Copy Markdown

Adding another vote for making this a separate option from auto-indent. For someone who moves multiple lines regularly, this is a real killer.

In the meantime, thanks to @snowsunny for the workaround.

@jeancroy

Copy link
Copy Markdown
Contributor

In what kind of scenario auto-indent works well but this does not ?
I was under the impression that this only make auto-indent flaws more apparent.

@eddiemonge

Copy link
Copy Markdown

Yes please for separating this into its own flag.

@snowsunny is that only for linux or for mac as well?

@snowsunny

Copy link
Copy Markdown

@eddiemonge Please try this keymap.

# for mac
'.platform-darwin atom-workspace atom-text-editor:not([mini])':
  'ctrl-cmd-up': 'my:move-line-up'
  'ctrl-cmd-down': 'my:move-line-down'

@phwh

phwh commented Jan 27, 2016

Copy link
Copy Markdown

Also, auto-indent while moving doesn't work well with Python code. Here is an example:

atom-indent-issue

@radiac

radiac commented Feb 29, 2016

Copy link
Copy Markdown

This can be pretty dangerous when writing python. For example, moving a line from above an if statement to underneath it makes the code conditional. If you don't notice the indentation change, it can take quite a while to figure out why your code has stopped working.

Definitely needs to be an option, and probably off by default in python - and I'd imagine any other language with significant whitespace. In the meantime, thanks @snowsunny - you are my internet hero of the day.

There is now a related issue where this is being discussed further: #10524

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.