How do you default to Soft Tabs while programming in Textmate? - tabs

My "Soft Tabs" setting in TextMate is not sticky. After I restart TextMate, I often have to set the option again for the same file. How can I make this setting the sticky default across all files?

For Textmate 1
After doing some research, I found that you can set TextMate 1 to default to using Soft tabs.
In the "Shell Variables" area of the Advanced preferences pane, add a new entry with the name TM_SOFT_TABS and a value of YES.
From that point on, TextMate should default to Soft tabs, though for at least one or two languages, I had to specify the number of tabs. After I did that, it seemed to stick for everything I did.

For Textmate 2
To set the options in TextMate 2 add following settings to your ~/.tm_properties file:
softWrap = true
tabSize = 4
softTabs = true
Check these links for more information:
FAQ: https://github.com/textmate/textmate/wiki/FAQ
Settings: http://wiki.macromates.com/Reference/Settings

From the documentation:
4.11 Using Spaces Instead of Tabs
TextMate can use spaces instead of tab
characters. This is done by clicking
the “Tab Size” pop-up in the status
bar and enabling Soft Tabs.
This setting will only affect the
current language and all languages
with a common root that do not have
the option set yet. The same applies
to the state of spell checking, soft
wrap and the actual tab size.
When soft tabs are enabled, TextMate
will for the most part act exactly as
if you were using hard tabs but the
document does indeed contain spaces.
Looks like Textmate sets it for the current language, but I think Textmate analyzes the files you open and adjust its settings to match the files. You can convert the tabs in your files to spaces and vice versa in the "Text" menu.

You don't need anything special. You just need to adjust your Python bundle.
Go into the 'bundle editor' and find Python. Open its caret, and scroll down and find the 'miscellaneous' preferences. It should read something like:
{ decreaseIndentPattern = '^\s*(elif|else|except|finally)\b.*:';
increaseIndentPattern = '^\s*(class|def|elif|else|except|finally|for|if|try|with|while)\b.*:\s*$';
shellVariables = (
{ name = 'TM_COMMENT_START';
value = '# ';
},
{ name = 'TM_LINE_TERMINATOR';
value = ':';
},
);
}
These are the environmental variables. What you want is the environmental variable TM_SOFT_TABS to be set to 'YES'. Simple enough, Just insert a new assignment like so:
{ name = 'TM_SOFT_TABS';
value = 'YES';
},
...and voilà! Your tabs will be soft every time you use Textmate in Python mode.
For all the different enviornmental variables you can set, check out the manual here:
http://manual.macromates.com/en/environment_variables.html

... in addition to #Ivan Sviatenko's answer
For Textmate 2, language specific softTabs default
edit ~/.tm_properties, for example:
# Default editing configuration
#
tabSize = 2
softTabs = true
softWrap = true
# Defaults for c
#
[ source.c ]
softTabs = true
tabSize = 8
# Defaults for python
#
[ source.python ]
softTabs = true
tabSize = 4

There is also a drop down menu at the bottom of TextMate, which allows you to set your Tab Size value and whether to use Soft Tabs, and it is sticky.

Create an alias icon for TextMate on the desktop.
Drag the file to be opened to the icon.
The file should now be opened in TextMate.
Set the soft tab with the status bar options.
Close TextMate.
Repeat step 2 - 5 for each file type you want the soft tab settings to be remembered.
Every time you want to open a file type with TextMate drag that file to that desktop icon.
Do not open more than one file type at the same time, the second file type opened will get its soft tab settings erased.
This is the only way I've been able to get a consistant behavior on the soft tabs settings.

I found a popular TextMate plugin called "TabMate," which has solved this issue for me. While it requires me to add a tabline to every file, TextMate adjusts my tab settings to be whatever is described in the tabline.
Also, technically gs's answer above should work but for some reason it isn't working for me and I found no other way to set SoftTabs is the default setting for ALL languages forever.
TabMate: http://konstochvanligasaker.se/tabmate/

Related

Sublime Text 3 - Hitting tab doesn't add space, instead makes text lower case

If I were to type the following:
TEST
Then hit TAB, the code would now look like this:
test
I don't know what happened, but tab is not indenting anymore and changes the text on the current line to lowercase.
Any idea how to restore the TAB function?
One possible reason for this in the general case is that you have installed a third party package that's stolen the Tab key binding in order to perform it's own action, which in this case would be turning the prior word lower case.
This will be the case if this behaviour holds true for any word that you happen to press Tab after. In that case the solution would be to find the package that's doing this and disable or reconfigure it.
In your case I think the more likely cause for this is that in the file you're currently editing the word TEST appears, and you have the following setting turned on:
// When enabled, pressing tab will insert the best matching completion.
// When disabled, tab will only trigger snippets or insert a tab.
// Shift+tab can be used to insert an explicit tab when tab_completion is
// enabled.
"tab_completion": true,
When the setting is set to true (which is the default), pressing Tab will attempt to perform a tab completion, which considers not only snippets and completions but also words in the current buffer as well.
In that case, if you were to enter the word test and press Tab at a point where the word TEST also appears in the buffer, it's considered a potential completion and will become the replacement.
If this is the problem you would see similar behaviour by just entering t and pressing Tab, which would cycle through all of the T words in the buffer as possible completions.
Assuming this is what's happening to you, one of the following should fix the problem for you:
Set tab_completion to false in your preferences; this will disable the feature entirely everywhere
Set tab_completion to false only in the settings of the specific file type that you're having the problem in; that would leave the feature enabled in the general case but stop it from occurring in the files that you don't want it to occur in.
Use Shift+Tab instead; that key sequence will do what Tab normally does and insert a tab character even if Tab would try to do a completion.
For #3 to work, make sure that you have this setting set as follows:
// By default, shift+tab will only unindent if the selection spans
// multiple lines. When pressing shift+tab at other times, it'll insert a
// tab character - this allows tabs to be inserted when tab_completion is
// enabled. Set this to true to make shift+tab always unindent, instead of
// inserting tabs.
"shift_tab_unindent": false,
The default for this value is false, in which case as the comment mentions the binding will perform a tab unless you have multiple lines selected in which case it unindents instead.

PhpStorm combine multiple Predefined Live Template functions

I have a project where my files are in "lisp-case" (hyphen delimited) and I would like to use the filename as a variable in a live template, but it must be converted to CamelCase first.
I found out that you can set the expression fileNameWithoutExtension() under "Edit Template Variables" and there is also a function called camelCase() which should be able to turn my filenames into CamelCase. But I cannot figure out how to combine those two. I tried doing camelCase(fileNameWithoutExtension()) but that does not work, unfortunately.
Is it possible to achieve this some other way?
camelCase(fileNameWithoutExtension())
It's a correct syntax.
Is it possible to achieve this some other way?
Please ensure that Skip if defined checkbox is checked for this variable.
If I try to wrap fileNameWithoutExtension() inside camelCase() and press enter to save the entry the window is closed but the change is not saved
It's an IDE bug (https://youtrack.jetbrains.com/issue/IDEA-132965 -- supposed to be fixed in current 2017.1.x version).
In any case: either press Enter before leaving the field ... or click on OK button straight away (you may then reopen this window to do further changes).
Also, when editing the field it's rendered like a select box which is kind of weird. Maybe it's a bug in this specific version. I'm on PhpStorm 10.0.4 for Mac.
Not a Mac user here .. but it is an editable drop-down box indeed (it lists all possible functions).

How to disable Auto Complete in Sublime Text (2&3)

I understand there are a few questions surrounding the auto_complete function in Sublime Text.
However, I have not been able to disable the auto_complete function in the Sublime Text settings (I've tried both Sublime Text 2&3). I just get the "Error trying to parse settings: Unexpected trailing characters in Packages/User/Preferences.sublime-settings:5:1" error when inputting the {"auto_complete": false,} command in user settings.
Would love to turn off the setting, but can't find a way to. Any help much appreciated!
Put , after font-size:17 like:
{
"font_size":17, //note a comma here after 17
"auto_complete": false,
}
This is the first result that pops up when Googling "Sublime Text disable autocomplete", and none of the answers answered my question completely, so I'd just like to add to the existing answers that if you are setting auto_complete to false and still having problems with Sublime Text auto-closing parentheses and brackets, then you also need to set auto_match_enabled to false. This should solve the problem. So as a whole, here is what I have:
{
"auto_complete": false,
"auto_complete_commit_on_tab": false,
"auto_close_tags":false,
"auto_match_enabled": false
}
There are two options:
1: In Preference --> User, Check if TernJS plugin is Installed. If Yes, Unistall it from your editor (i.e. Sublime Text Editor).
2: In Preferences --> User, check for the auto_complete and change it to false
"auto_complete": false,
Restart Your Editor(Sublime Text)
This should be the option.
{
"auto_close_tags":false
}
My solution to this problem was to change "auto_complete_commit_on_tab" from true
to false. This way you aren't turning off autocomplete altogether, but the autocompletion is ignored unless you hit the tab key.
In preferences, user settings, add:
{
"auto_complete_commit_on_tab": false
}
I came here looking for a Python-related solution, where autocompletion worked well for variable names etc. but was quite slow for methods etc.
So, to disable Python syntax autocomplete:
open the command palette with ctrl + shift + P
enter Package Control: Remove Package and select it
enter Jedi and remove the Jedi autocomplete package

Autocomplete the equal and quotes when adding class or ID

Sublime Text 2 allows me to autocomplete the class or id attribute, but it is not adding the ="" automatically when I start typing class=" ".
I want to type in <div c and at the moment the c is typed the autocomplete should show the option class="" not just class but also the equal and the quotes. The same goes for id="" and style="".
I am sure this is fairly simple to do; just installed the software today.
Thanks
First, install the Sublime package manager Package Control to allow for the easy installation, removal, upgrading, and otherwise managing third-party plugins and packages. Next, after restarting Sublime, hit CtrlShiftP (Windows/Linux) or ⌘ShiftP (OS X) to bring up the Command Palette. Type pci to get to Package Control: Install. Hit Enter, then start typing in HTMLAttributes until it shows up. Hit Enter again to install it. You'll now have a much greater selection of auto-completions, including the class, id, and style elements you were looking for. So, inside a tag start typing class and when the autocomplete appears, hit Tab. The rest of the word class will complete, along with an equals sign and a pair of double quotes. Your cursor will automatically be positioned inside the quotes, and when you're done entering the value(s) you want just hit Tab again and your cursor will jump outside the quotes, ready to close the tag or enter the next attribute.
To see what sort of completions are available to you, check out the source here or go to Preferences -> Browse Packages... to open up your system's file explorer, then enter the HTMLAttributes directory and open the HTMLAttributes.sublime-completions as a JSON file in Sublime. If a trigger contains a \t (tabstop) character, the part before it is the completion, and the part after it is what appears in the autocomplete menu on the right. In contents, $1, $2, and so on are successive places where hitting Tab will land your cursor. $0 is the exit point. Something like ${1:form_id} gives a default value, and something like "draggable=\"$1${1/(t$)|(f$)|(a$)|.*/?1:rue:?2:alse:?3:uto/i}\"$0" is an autocomplete regex, so that if you type t inside the field, it autocompletes to true, if you backspace and hit f it becomes false, and a becomes auto.
This package is really great at supplementing the standard HTML autocomplete that ships with Sublime, but unfortunately it doesn't necessarily play nicely with Emmet, formerly known as Zen Coding, as some of the completions may clash with Emmet's abbreviations. Of course, as always, YMMV.
Good luck!

How do I configure Emacs html-mode to behave like TextMate's default HTML bundle?

A friend of mine is considering switching to Emacs from TextMate. He is used to TextMate's default HTML editing mode which has 4-space tab stops and inserts tab characters (i.e. it does no auto-indenting by default). It also allows completion of open HTML tags with "Cmd-Shift->". Any ideas?
I think these settings should do the trick:
(defun my-html-mode-hook ()
(setq tab-width 4)
(setq indent-tabs-mode t)
(define-key html-mode-map (kbd "<tab>") 'my-insert-tab)
(define-key html-mode-map (kbd "C->") 'sgml-close-tag))
(defun my-insert-tab (&optional arg)
(interactive "P")
(insert-tab arg))
(add-hook 'html-mode-hook 'my-html-mode-hook)
An explanation of the settings in 'my-html-mode-hook is as follows:
set the tab width to 4
force tabs to be inserted (as opposed to spaces)
force the TAB key to insert a tab (by default it is bound to do indentation, not just insertion of tabs
'sgml-close-tag is the command that inserts a close tag for you, and this setting gets you the keybinding you want
I'm having a bit of a brain freeze and couldn't figure out the simple way to have the TAB key insert a TAB character, so I wrote my own. I don't know why a binding to 'self-insert-command didn't work (that's what normal keys are bound to).
The last line just adds the setup function to the 'html-mode-hook. The key bindings really only need to be run once (as opposed to every time html-mode is enabled), but this is a little easier to read than using 'eval-after-load. It's use is left as an exercise to the reader.
I don't know about emacs's HTML modes specifically, but I can answer about general editing:
by default, Emacs doesn't autoindent, so nothing to do here.
Emacs preserves tab characters, unless you explicitely ask them changed (check out tabify and untabify). Their width is determined by the buffer-local tab-width variable. M-x set-variable, (setq...), customize at will.
you should be able to get the behavior you want with the tab key by setting indent-line-function to tab-to-tab-stop, setting tab-stop-list to (4 8 12 16...) and indent-tabs-mode to t.
Setting indent-tabs-mode allows Emacs to insert tab characters when indenting. The tab-to-tab-stop is a form of indentation that only goes to specific positions in the line, which we set to match the expected behavior of the tab characters by setting tab-stop-list to the multiples of 4.
About completion, the only thing my muscle memory tells me is "C-c C-e", but I don't remember for sure which major mode it's supposed to go with. The closest I see in the list is sgml-close-tag, bound to C-c /
A bit of politics: don't use tab characters, especially if you use widths not equal to 8. It only results in unpredictable results