Running a hacked editor to experiment with mixed tab/space indent?


Hi all-

I’ve been dabbling in Atom for about a week now, but to use it full time at $dayjob I need mixed tab/space indent support (yay legacy code base!). I hacked on the whitespace module over the weekend (with some success), but bulk replacing spaces with tabs at save time runs into some annoying complications (not insurmountable, but annoying).

For my next attempt I’d like to try improving TextEditor.buildIndentString to handle the issue when the user is inserting indentation (and explore the performance implications of such an approach). Since isn’t in a package, what’s the recommended workflow for hacking on the file? Can I link it in ~/.atom/packages? Or can I edit in place in the Atom install? Or do I need to actually build Atom? (Sorry, my Google-fu failed me on this front)



If you’re asking about development workflows when working on Atom (in which case this is a misleading topic title :grinning: ) … then I would direct you to this topic:

And would suggest that this topic is a duplicate of the above. We like to unify similar discussions under one topic so that people don’t have to read a bunch of different threads to get the whole story. If this is a duplicate, please continue the conversation in the above topic and I’ll close this one as duplicate. Otherwise, let me know.


Oh the irony :slight_smile: When I started my post it was about running a hacked Atom. As I wrote I became concerned the post was veering towards an X/Y problem, so I attempted to reframe it… but in the end I guess it was still about hacking the core editor. Thanks for the redirect, I’ll see what I can learn there.


Thanks for the link. We, obviously, run into this problem a lot here. I’m glad to know it has a formal name and definition :laughing: I’ll probably write up a FAQ on it.


Perl Monks also has a semi-famous page on it (I originally ran into the name on the Git mailing list).


Did your hack eventually work? I’m considering writing a package for this and I’m curious if this worked for you?


tl;dr: no, I didn’t actually get it working.

Long version: I started working on a modification to the whitespace module that only applies whitespace fixes to edited lines (I think it’s common to experience to edit a file from an outside source, e.g. an open source project, and suddenly ends up with a zillion changes due to whitespace fixes). That worked fairly well but I think I was still tweaking performance (we have several 15-20k+ line files in our repo so keeping the editor snappy is important).

Most of my testing at the time was trailing whitespace, but I started to look at it for mixed indent. Back then I convinced myself I preferred the Vim/Emacs approach of fixing indent as the user typed rather than fix-on-save, which lead to a long sojourn in the Atom core that stalled my project. Now (a year later) I’m not as convinced the indent character(s) in the buffer matter so much – I think the two key goals are the tab key indents code one level and the backspace key should remove one level of indent regardless of tab vs space (and of course it should all look right). So when the discussion came up again recently around the lunch table I proposed translating all tabs to spaces on load (using the user’s indent size preference), letting the user edit in spaces, and then fixing up user-edited lines on save (reverting all non-user-edited lines to their original state).

But I haven’t gotten around to implementing that either – a survey of my company’s developers showed more people are fans of full IDEs than simple(-er) editors (yes, I’m the type to hack my editor to the point it can do most of the IDE stuff, but many of our developers are not), so I’m not sure I’ll find time soon.

Let me know if you have any success, this is the (first?) major roadblock to me adopting Atom. Thanks!


Thanks for the info. I’ve got some indications from the atomio.slack forum which also suggest that it might be more difficult than I first thought:

I don’t think a package could actually do that, at least not without breaking all packages that depend on the APIs Atom already has in place that deal with indentation
Anything that would attempt to work with that would break APIs like, is there a reason part of the policy change wasn’t “if a file indented in the old style is touched, it is updated to the current policy”?

In regards to your idea of removing all tabs on open and only saving edited lines on save I think that should work. Howver, it would mess with various other packages that utilizes info about edited lines. For example, git packages which shows edited lines would fill the gutter while editing/reading, and this would be an issue for me since our code base is tracked by git.

I’ll investigate further and let you know if I come across anything or figure out a solution myself.

PS: I really think this should be implemented in the core of the editor. Hint Hint Atom :innocent:


Good point. I was thinking something like a smudge/clean filter (smudge to display to the user, clean before any mechanical operation) would work, but would also require core-Atom work so…

… yeah. No argument here :wink:



Good point. I was thinking something like a smudge/clean filter (smudge to display to the user, clean before any mechanical operation) would work, but would also require core-Atom work so…

Good idea! The challenge is core work as you say. I haven’t looked much at the atom source code, nor have I tried building atom from source.

Another idea: I was thinking about whether a macro that removes four spaces after pressing tabs could be a possible hack. Then you can have your editor set up with tabsize 8 and tab-policy spaces, and when you hit tab you still get four spaces as desired. However, in order for snippets and language specific auto-complete, grammar files must be rewritten to insert spaces only, and not use tab characters ("/t"). I tested it for the language-c packages via a global find-and-replace in the source code and the snippets work fine. Now I just need to find a macro-package that can tweak my tab key!