Wednesday, 29 July 2015

CFB profiles and Preferences

CFB profiles and Preferences

Profiles is one of my favourite features of CFB3. It allows you to keep separate preferences as schemes(profiles we call it). For example when you are developing or writing code, you want to see your comments in yellow but when you demo your application you want to keep your comments in grey so they are not catchy. You don't have to change your comment colors always but you just have to switch your profile. To be specific you can maintain different color schemes, code-assist preferences, typing preferences, task tags, outline and syntax checking preferences with different profiles. For most developers modifying these small preferences increase their productivity, so trust me these are very helpful.

Here we will talk about how to maintain different profiles and also a bit about all these preferences that you can modify and play with and will be starting with Code Assist Preferences. To find them in CFB open Window->Preferences in your menubar. A preferences dialog will open. On left panel you have to reach to "ColdFusion->Profiles->Editor->Code Assist". On clicking it, in right panel you will see all related preferences.

Code Asisst:
For most of preferences, you will be able to understand what they do by their name, like in case of Code Assist they will help you modify what you see in code assist and how you get it and some related stuff.

BTW code assist is the small popup you get regarding code when you are typing it. You can also forcefully call code assist by pressing ctrl+space. If you want to try it right now, go to some closing tag, remove part of it from end and hit ctrl+space, you will get a popup suggesting to auto complete that tag. Now quickly moving to the preferences.

  • Code Assist Dictionary version: you can select which ColdFusion server version you are running your code. You never want tags/functions in code assist which will not work for your version of ColdFusion.
  • Reload Dictionaries: In case you have modified the dictionary, you can reload them to reflect changes.
  • Cycling Code Assist Proposals: type "<cfset x = " and hit ctrl+space, you will get some suggestions for variable names, but what if you wanted to type a function here. If cycling is enabled, on hitting space 2 times, you will get functions suggestions. The funda is keep ctrl pressed and keep hitting space until you get correct suggestion.
  • Filter proposals containing text: On typing "<cfa" you will get suggestions like "<cfabort>, <cfajaximport>", all of them starting with "cfa". If this is enabled, you will also get "<cfbreak>" because it has c,f,a characters in it. Filter proposal CONTAINING text.
  • Automatically display Code Assist when typing: pretty simple, if enabled, you start typing and you will see code assist wherever necessary, otherwise you have to hit ctrl+space everytime.
  • Automatically display SQL Code Assist when typing: same as above, just that this is applicable if you are typing in sql editor.  If you do not know whats sql editor, then type this shortcut while typing, "ctrl+alt+W S"
  • Delay before showing code assist(in milliseconds): As name says, code assist popup will open after this many milliseconds.
  • Automatically insert a single proposal: Say you type "<cfoutpu" and call code assist(by hitting ctrl+space), you will get a popup with one proposal called "<cfoutput>", and then you hit enter on it to insert it. That is a overhead if it was a single proposal, you can directly insert it without getting a popup, it was anyways a single proposal. Enable this option to directly insert single proposal without getting a popup.
  • Automatically insert a closing tag: If you insert a tag from code assist when typing starting tag and this preference is enabled, then closing tag will be autoinserted.
  • Insert closing tag on a new line: enable this if you want closing tag on next line.
  • Append space after inserting selection: a space will be appended on insertion of proposal, it helps if you add a lot of attributes by code assist.
  • Automatically insert equals sign: equals sign will be appended automatically after attribute name is selected from proposal.
  • Auto insert required attributes: name itself explains, type "<cfhtt", call code assist, hit proposal cfhttp, see url attribute is added on its own, because it's a required attribute, I can't think of a scenario, when you will use cfhttp without typing url attribute.
  • Automatically quote attributes: On selecting attribute proposals, if enabled, you will automatically get quotes after equals sign. And it will not work if you have disabled auto insert equals sign.
  • Character to use when quoting attribute: If you quotes attributes values with single quotes, you have an option to do that here, auto quoting will quote with character you specify here.

Outline: You can see the outline of your file in Outline view. Shortcut: "Alt+Shift+Q O", or "WIndow->Show View->Outline" in menubar. Outline gives you brief summary of tags/functions used in your file and on clicking on a particular tag/function in outline, it will take you to your particular code where it is used. It is very helpful in very long files.

  • Show All tags: By default, you will get all tags in your outline view.
  • Show selected tags: Or you can chose which all tags to show in outline. You can add or remove the tags you want.

Syntax Checking: In case you made a typo while typing or you inserted a wrong attribute, wont it be beautiful to know right there that something is wrong with code before even running your file on server. Syntax checking helps you in that.

  • Enable syntax checking: enable or disable this feature.
  • Display syntax errors only on file save: if enabled, it will check for errors only on file save. You can enable this for better performance.

Task Tags: Task tags are very useful while coding. Suppose you are building a feature and for testing purposes you have hardcoded a path, but ideally in production server you want to manipulate it and make it safe. You can insert a "TODO" task by typing "<!--- TODO --->"(or "// TODO" in cfscript) where you have hardcoded path. Later on before moving your project to production, you can open Tasks view and check all the TODO tasks you have left pending in your code.

  • By default there are two tasks: TODO and FIXME are provided but you can add your tags too and there is no limit on that. You can also select/modify the priority of the tasks, If high priority is selected, then in Tasks view, red exclamation mark will appear in front of your task.

Typing: Some preferences which will help you while typing.
Enable Auto insertion: This is a parent preference for following six preferences. If disabled, auto insertion of matching character will not be performed. Like on typing a double quotes, another double quotes following it is automatically inserted.Or on typing {, } this will be automatically inserted.

  • Double Quotes: typing " will insert following " on its own.
  • Similarly we have Single Quotes, Round brackets, Curly Brackets, Square brackets, Pound sign.
  • Auto close tags: When to auto close the starting tag. You can disable this by  choosing never.
  • Auto-indent on carriage return: If enabled, on hitting enter, a "TAB" will be automatically inserted on new line. It helps in beautifying the code.
  • Auto adjust indentation on closing tags: If you typed closing tag with wrong indentation, if enabled, it will adjust the indentation according to the starting tag.
  • Replace whitespace with indentation character: If you are editing a legacy file, it might be possible that whitespaces are used for indentation, enabling this preference will replace those characters with indentation character wherever you edit. This indentation character can be specified in Formatter preferences.

Syntax Coloring: Syntax Coloring is one the most important feature of any editor. CFB gives you option to have different colors for different language. Like you can keep comments in yellow for ColdFusion but grey in HTML or JS. You can do chose colors for CFML, CFScript, HTML, JS, CSS. But all these colors will be applied in CFML or a CFC page. If you are editing a html file(file with extension html or htm) or JS file(file with extension js), these settings will not be applied. For that you need to refer "HTML->EDitor->Syntax Coloring" in left pane or "JavaScript->EDitor->Syntax Coloring" or "CSS->EDitor->Syntax Coloring".

  • We have two panes in these preferences. In left pane you will see tree of keys like Tag key under CFML or Attribute Name under CFML and so on. If you a select a key under a particular langauge, then on right pane you will see few preferences you can change. Like foreground color, Enable option, Bold, italic, Underline, Strikethrough options. With these you can controll each and every keys behavior in detailed manner. 

I will not discuss each and every key as their names pretty much explains them. You just need to play with them to understand it.

  • One more important feature in Syntax Coloing is importing and exporting colors. CFB2 colors are not compatible with CFB3, so importing CFB2 colors will not work. On exporting .col file will be generated with all the color information. Similarly to import colors, a compatible .col has to be provided.

Since we are done with all the preferences, I will explain the Profiles page. In profiles page you will see a drop down listing all the profiles. And Active profile will be selected. CFB comes with 4 default profiles which you will not be able to modify or delete. These are CFB1, CFEclipse, Dreamweaver and default(ColdFusion Builder's own) profiles, we call these as system profiles. So in case you have  migrated from dreamweaver to CFB, you must be used to dreamweaver's shortcuts or coloring scheme, just select dreamweaver profile, hit apply and all settings, colors, shortcuts will be applied as they are in dreamweaver. Pretty solid feature isn't it? Well that's for default profiles, but you can create your own custom profile too.
To create a custom profile, hit "Create New Profile", it will ask for a profile name and ofcourse you cannot name of system profile. On creating a new profile, all the settings in it will be copied from currently active profile. So if dreamweaver profile is active, and you created a new profile, all the dreamweaver's profile preferences will be copied in this new profile.
When you make any changes in the preference pages falling under profiles page, all these changes will be saved in your custom profile. So if your custom profile is selected, and you have changed the dictionary version, then even on restarting Builder, this setting will persist, which I think is the expected behaviour of Profiles. There is a catch in saving profile, if any system profile is selected let's say dreamweaver, and you change any preference under profiles, let's say you change dictionary version, then this settign will be saved(as expected). But earlier I said system profiles cannot be changed, so will they not be persisted? Don't worry, they will be. In this case a new profile will be created for you called "custom" and all the new changes will be saved in this custom profile. Now if you will try to change this profile, it will ask you whether you want to save this custom profile. So you can mistakenly delete or loose your preferences as it will always ask you to save or discard the changes first.
As I said, its pretty important and strong feature, play around it, you will enjoy it for sure.

No comments:

Post a Comment