When I'm writing code, I keep format it using CTRL + SHIFT + F. Everything works fine except comments, Eclipse wrapes comments and its very annoying. I just want single line comment, no matter how long it is.
For example
void SomeMethod()
{
int someValue = 155; // This value is for blah blah blah blah
}
after format
void SomeMethod()
{
int someValue = 155; // This value is
// for blah blah
// blah blah
}
Now its taking 3 lines for nothing.
I'm using Eclipse 3.7.2, anyway to fix it ?
Preferences -> Java -> Code Style -> Formatter
Choose the current active formatter profile , press edit and you will the following screen.
The Comments tab contains all the stuff about comments formatting. Set the Maximum line width for comments to a very large number.
Related
I'm using nerdcommenter alongside neovim, and every time I comment out a block of code with <leader>cc, the code isn't really spaced out:
fn main() {
//println!("Hello, world!");
}
I want to get an output of something like this:
fn main() {
// println!("Hello, world!");
}
Is there a command or configuration that I'm missing out on? (I haven't configured nerdcommenter at all in my vimrc)
See the plugin docs : use g:NERDSpaceDelims configuration option
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
Or for Neovim with Lua configuration :
vim.g.NERDSpaceDelims = 1
I am currently working on an Eclipse plugin. In order to do an action, I need to listen to the caret listener of the active tab.
public void partOpened(IWorkbenchPartReference partRef) {
AbstractTextEditor e = (AbstractTextEditor) ((IEditorReference) partRef).getEditor(false);
StyledText sText = ((StyledText) e.getAdapter(Control.class));
sText.addCaretListener(new CaretListener() {
#Override
public void caretMoved(CaretEvent event) {
IDocument d = e.getDocumentProvider().getDocument(e.getEditorInput());
...
int line = d.getLineOfOffset(event.caretOffset);
Point p = sText.getLocationAtOffset(event.caretOffset);
}
});
}
I use this code to add the CaretListener on the latest opened tab.
The variable line is correct only when no code blocks are collapsed.
In fact, the offset returned by the event is linked to the StyledText, but I'd like to get the line number of the file.
This picture shows an example of folded text. The StyledText caret offset will give me something like line 6, 7 and 8, instead of 6, 7 and 12 (like Eclipse does).
Is there a way to "transform" the StyledText offset to a "real file" offset ? I could retrieve the line as a String and find it in the file, but it sounds like a bad idea.
Thanks !
For folding editors the editor's source viewer will implement ITextViewerExtension5 which provides a widgetOffset2ModelOffset method to make this adjustment.
Get the caret position using something like:
ISourceViewer sourceViewer = e.getSourceViewer();
int caret;
if (sourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5)sourceViewer;
caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
} else {
int offset = sourceViewer.getVisibleRegion().getOffset();
caret = offset + styledText.getCaretOffset();
}
The Thunderbird Lightning extension shows the time on the left side of the Week and Day views as shown here...
I would like the time to show 2 different time zones (e.g. local time and Pacific Time) as shown here...
Is there a configuration parameter to do this? Is there another extension which can tweak this? If not, how do I hack the Thunderbird extension to do this?
For reference, Outlook has this functionality. Also, this answer shows how to hack the Lightning extension.
I didn't solve the problem for the general case. I simply caused the time to be displayed in the current time zone and the previous hour to be displayed. In my case, the current time zone is USA Mountain time and the previous hour ends up being USA Pacific time.
The file calendar-multiday-view.xml in the following jar file must be edited while Thunderbird is not running.
C:\Users\nreynold.ORADEV\AppData\Roaming\Thunderbird\Profiles\profile\extensions\{e2fda1a4-762b-4020-b5ad-a41df1933103}\chrome.jar
The method makeTimeBox() must be changed as indicated by comments:
function makeTimeBox(timestr, time2str, size) { // Add time2str parameter
var box = createXULElement("box");
box.setAttribute("orient", orient);
box.setAttribute("align", "left"); // Add
if (orient == "horizontal") {
box.setAttribute("width", size);
} else {
box.setAttribute("height", size);
}
var label = createXULElement("label");
label.setAttribute("class", "calendar-time-bar-label");
label.setAttribute("value", timestr);
label.setAttribute("style", "color: #4080C0; font-weight: bold;"); // Replace "align"
box.appendChild(label);
var label = createXULElement("label"); // Add
label.setAttribute("class", "calendar-time-bar-label"); // Add
label.setAttribute("value", time2str); // Add
box.appendChild(label); // Add
return box;
}
Add the following method after makeTimeBox().
function makeTime(hour) {
var h = hour % 12;
if (h == 0)
h = 12;
var s = hour >= 12 ? " pm" : " am";
var result = h + s;
return result;
}
Remove the following line which appears a few lines below makeTimeBox()
var formatter = Components.classes["#mozilla.org/intl/scriptabledateformat;1"].
getService(Components.interfaces.nsIScriptableDateFormat);
Change the following line...
var timeString;
... to be ...
var timeString, time2String;
About 25 lines lower, replace the following lines...
timeString = formatter.FormatTime("",
Components.interfaces.nsIScriptableDateFormat.timeFormatNoSeconds,
theHour, 0, 0);
box = makeTimeBox(timeString, durPix);
... to be ...
timeString = makeTime(theHour) + " MT";
ptHour = theHour - 1;
ptHour += 23;
ptHour %= 24;
ptHour += 1;
time2String = makeTime(ptHour) + " PT";
box = makeTimeBox(timeString, time2String, durPix);
I am not aware of any existing add-ons that do this, but I can tell you how it is done. First of all create a typical skeleton Thunderbird extension, in the Firefox world this is called a "legacy" extension in case you are searching for docs. It should contain an install.rdf and a chrome.manifest. I'm assuming you choose view-zones as the identifier in chrome.manifest.
Next you need to create a CSS file that will allow you to override the calendar-time-bar binding. Note that with this method there can only be one extension that overrides the binding. The contents will look like this:
calendar-time-bar {
-moz-binding: url(chrome://view-zones/content/bindings.xml#calendar-time-bar) !important;
}
This will override the time bar with your binding, which you will create in the bindings.xml file. It extends the builtin time bar, but adds some code after the relayout to add those extra labels. The CSS file needs to be referenced in the chrome.manifest file with a style directive and can extend chrome://calendar/skin/calendar-views.css. Then you will have to create the xml file for chrome://view-zones/content/bindings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<bindings id="calendar-multiday-view-bindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl">
<binding id="calendar-time-bar"
extends="chrome://calendar/content/calendar-multiday-view.xml#calendar-time-bar">
<implementation>
<method name="relayout">
<body><![CDATA[
this.__proto__.__proto__.relayout.call(this);
let XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
let topbox = document.getAnonymousElementByAttribute(this, "anonid", "topbox");
for (let box of topbox.childNodes) {
let timelabel = box.appendChild(document.createElementNS(XUL_NS, "label"));
timelabel.setAttribute("value", "10:00 PT");
}
]]></body>
</method>
</implementation>
</binding>
</bindings>
I've left the label static for now, but you can think of some logic that would change the "10:00 PT" to the actual time based on the other label or the same algorithm used in the actual method. You can also add classes and styling to make it look different.
That said, maybe you'd be interested in adding this feature to core Lightning instead? I think it would be a nice addition. I'm pretty sure we had a bug open for this but I can't find it at the moment, so if you are interested maybe you could file a bug and I can give you more information on how to get set up. In that case it would be a matter of changing the binding to show more than one label and adding user-visible preferences to be able to chose the timezone.
I want to get line number from Visual Studio. Is it possible ? Thanks
You can use CallerLineNumberAttribute
public void DoProcessing()
{
TraceMessage("Something happened.");
}
public void TraceMessage(string message,
[CallerLineNumber] int sourceLineNumber = 0)
{
Trace.WriteLine("message: " + message);
Trace.WriteLine("source line number: " + sourceLineNumber);
}
// Sample Output:
// message: Something happened.
// source line number: 31
If you just want to display line numbers in the IDE (as in your screenshot), follow these steps (tested in VS2012):
On the menu bar, choose Tools / Options. Expand the Text Editor node, then select either All Languages or, if you want it for just a specific language, open the node for the language you're using. Then check the Line Numbers checkbox in the Display section.
More info here on MSDN.
I'm trying to create a JAVA code formatter such that it doesn't wrap any lines. BUT for any lines in my code that I have manually wrapped I want the formatter to respect them and not format them in to one line.
For example:
public Class {
public Class(String a,
String b,
String c,
String d) {
// The constructor arguments should stay as they are
}
public void aMethod() {
// This statement should not be wrapped
get().doSomething().getAnohterMethodThatHasAReeeeeeeaalllyyLongName();
}
}
I have made the line width 9999 (the max), and I have turned off line wrapping for everything. What have I missed?
Thanks.
I opened the preference page for
"Java - Code Style - Formatter"
and activated "never join lines"
and selected "Do not wrap" in the combo box "line wrapping policy"
After this change i was able to write code, which was not wrapped.