When I run indent with various options I want against my source, it does what I want but also messes with the placement of *s in pointer types:
-int send_pkt(tpkt_t* pkt, void* opt_data);
-void dump(tpkt_t* bp);
+int send_pkt(tpkt_t * pkt, void *opt_data);
+void dump(tpkt * bp);
I know my placement of *s next to the type not the variable is unconventional but how can I get indent to just leave them alone? Or is there another tool that will do what I want? I've looked in the man page, the info page, and visited a half a dozen pages that Google suggested and I can't find an option to do this.
I tried Artistic Style (a.k.a. AStyle) but can't seem to figure out how to make it indent in multiples of 4 but make every 8 a tab. That is:
if ( ... ) {
<4spaces>if ( ... ) {
<tab>...some code here...
<4spaces>}
}
Uncrustify
Uncrustify has several options on how to indent your files.
From the config file:
indent_with_tabs
How to use tabs when indenting code
0=spaces only
1=indent with tabs, align with spaces
2=indent and align with tabs
You can find it here.
BCPP
From the website: "bcpp indents C/C++ source programs, replacing tabs with spaces or the reverse. Unlike indent, it does (by design) not attempt to wrap long statements."
Find it here.
UniversalIndentGUI
It's a tool which supports several beautifiers / formatters. It could lead you to even more alternatives.
Find it here.
Artistic Style
You could try Artistic Style aka AStyle instead (even though it doesn't do what you need it to do, I'll leave it here in case someone else finds it useful).
Hack around and change its behavior editing the code. It's GNU after all. ;-)
As it's probably not the answer you wanted, here's another link: http://www.fnal.gov/docs/working-groups/c++wg/indenting.html.
Related
Something that drives me nuts in the developper tools of Chrome (106) and Firefox (105) is the fact that whenever some text logged to the console via console.log(text) happens to contain a hyperlink, this link is not only turned clickable (I can live with it even when I usually prefer to have just plain text) but is abbreviated, if it is a long link. So when I want to control what precise link is in some variable, I cannot just write e.g. console.log(img.src), because some of the interesting information of the link is hidden.
You can try yourself with
var href = 'https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools%5D+%5Bconsole.log%5D+%5Bfirefox-developer-tools%5D+%5Bhyperlink%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger';
console.log(href);
In both, Firefox and Chrome, the output for me contains some '...', e.g. in Firefox I obtain as output:
https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools…link%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger
thus hiding the part after "-devtools". (Chrome hides a slightly different part). The console is mostly a debugging tool. I log things because I want to see them, not hide them. I always need to either hover with the mouse and wait for the tooltip (doesn't allow me to copy fractions of the link) or to right click copy the link and paste it somewhere where I can see it completely. Or take a substring to remove the "https://" in the front. But note that the variable isn't necessarily a single hyperlink, but can be any text containing several such hyperlinks. I didn't find a way to force console.log to just print plain text all content. Did anybody meet this problem as well and find a workaround?
I made this a community wiki answer, because the main insight is not from myself but from the comments. Feel free to improve.
The console.log() function allows several arguments, which allows also a formatted output similar to printf in some languages. The possibilities of formatting can be found in the documentation of console.log() on MDN. In any case, this formatted output provides a solution at least for Chrome, as #wOxxOm pointed out in the comments:
console.log('%O', href) // works in Chrome
This is rather surprising, because %O is described at MDN as
"Outputs a JavaScript object. Clicking the object name opens more information about it in the inspector".
It seems there is no 'clicking' in Chrome when the object is a string.
There is also %s for string output, but this just gives the standard behavior of replacing links in both browsers. And for Firefox none of the above two formatting options works. There one really has to replace the protocol "https://" by something that is not recognized as link. A space behind ':' seems enough, so "https: //". It turns out, that one can also insert a formatting string "https:%c//", which can even be empty, and thus yield an output which is the complete link and can be copied as well:
console.log(href.replace(/(https?:)/, "$1%c"), ""); // works in Firefox
In particular the FF solution is cumbersome, and there might also be several links within one console-output. So it is useful to define one's own log-function (or if one prefers, redefine console.log, but note the remark at the end)
function isChrome() {...} // use your favorite Chrome detection here
function isFirefox() {...} // use your favorite Firefox detection here
function plainLog() {
const msg = arguments[0];
if (isChrome() && arguments.length == 1 && typeof msg == "string") {
return console.log("%O", msg);
}
if (isFirefox() && arguments.length == 1 && typeof msg == "string") {
const emptyStyle = ""; // serves only as a separator, such that FF doesn't recognize the link anymore
const reg = /(https?:)\/\//g;
const emptyStyles = []; // we need to insert one empty Style for every found link
const matches = msg.matchAll(reg);
for (let match of matches) {
emptyStyles.push(emptyStyle);
}
return console.log(msg.replace(reg, '$1%c//'), ...emptyStyles);
}
return console.log(...arguments);
}
For browser detection isChrome() and isFirefox() see e.g. here on SO.
One can of course extend the redefinition also to the other console functions (console.info, console.warn, etc.)
The downside of the redefinition of console.log is that usually every output of the console shows also the last entry of the call stack as a practical link to the source of the logging. But due to the redefintion, this link is now always to the same place, namely the file and line number where plainLog() is defined and calls console.log(), instead of the place where the new log command plainLog() was called. This new problem is described on SO here, but the solution (see comment) is again a bit involved and also not completely satisfying to serve as a replacement for the built-in console.log . So if links appear only rarely in the logging, it's probably better to switch to the redefined plainLog() only for these links.
Following this Blog:
https://medium.com/blogging-guide/how-to-insert-a-code-block-or-inline-code-into-a-medium-article-7b697bd12e0a
It should be simple to add inline Code with Back Tics (`).
However it does not work for me - it only displays the back tics as characters:
Is there something that I miss?
If you are using other than "Standard US English Keyboard" then medium formatting options may vary.
For instance, I am using ABC-QWERTZ layout on my mac.
For me:
To enter into inline code block:
[Single backtick + space key] worked.
To come out from inline code block:
[Single backtick key]
Start writing after pressing key.
On U.S. Keyboard:
To enter into inline code block:
[Single backtick].
To come out from inline code block:
[Single backtick key]
Note:
When you want to add inline block in the middle of sentence, add one space before pressing single backtick.
For me none of the backtick solutions worked, but at least for code blocks (not inline code between two words)
ALT + CMD + 6
did the job.
For MAC Users:
⌥ + ⌘ + 6
If you type the code rather than highlighting existing code, and start with a backtick, you enter inline code mode. To escape, another backtick doesn't work for me - I have to use right arrow.
Selecting code and pressing backtick just deletes the code and displays a backtick. Pretty useless really...
It's a quite old question, but i found a way on French keyboard to it : You need to use the # button (and not the ` button), which is fact at the same place on an English keyboard :
I have tried many different libraries, but none came.
None of them can not be specified without introducing his own style in Painter.
I need to be able to quickly and dynamically change the style tab.
In response, I showed my developments.
If someone has similar developments - write them in response.
I decided to upgrade the simplest of them: TJvTabBar of JVCL (latest revision: 13415)
Here is the result.
Before (default)
After
Style sources (All graphics imported from png files with transparency)
Easy apply any personal style to any JvTabBar
var tmp:TStrings;
begin
tmp:=TStringList.Create;
tmp.Values['TOP_background']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-TOP_background.png';
tmp.Values['TOP_active_left_side']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-TOP_active_left_side.png';
tmp.Values['TOP_active_right_side']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-TOP_active_right_side.png';
tmp.Values['TOP_active_center']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-TOP_active_center.png';
tmp.Values['BOTTOM_background']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-BOTTOM_background.png';
tmp.Values['BOTTOM_active_left_side']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-BOTTOM_active_left_side.png';
tmp.Values['BOTTOM_active_right_side']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-BOTTOM_active_right_side.png';
tmp.Values['BOTTOM_active_center']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-BOTTOM_active_center.png';
tmp.Values['CLOSEBUTTON_normal']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_normal.png';
tmp.Values['CLOSEBUTTON_selected']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_selected.png';
tmp.Values['CLOSEBUTTON_disabled']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_disabled.png';
tmp.Values['CLOSEBUTTON_closing']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_closing.png';
tmp.Values['CLOSEBUTTON_modified']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_modified.png';
tmp.Values['CLOSEBUTTON_closing_modified']:= ExtractFileDir(Application.ExeName)+'\skins\default\tabs-CLOSEBUTTON_closing_modified.png';
JvTabBar1.StyleImages:=tmp;
tmp.Values['BOTTOM_background']:= ExtractFileDir(Application.ExeName)+'\skins\default\MYMOD_tabs-BOTTOM_background.png';
JvTabBar2.StyleImages:=tmp;
Main changes
Added ability to specify their own style ( JvTabBar1.StyleImages )
Added the ability to move the close button to the right ( JvTabBar1.CloseButtonRight: = true or false )
Many fixes to the size and position of text / icons / buttons / scroll
My JvTabBar.pas mod You can download it here http://pastebin.com/JmbufHy0
And example source style + JvTabBar.pas http://www.sendspace.com/file/shhuzr
I am using Delphi and I need to prepare some documentation. One of possible solutions to that is to use Doxygen with Pas2Dox filter.
I am currently using pas2dox-0.50rc1.exe filter and Doxygen wizard 1.8.3.1. I am struggling to setup Doxygen properly to display my comments in Delphi but the thing is that I am not sure anymore what is the proper comment format in Delphi. I searched interenet but I can't find any tutorial or example on how to succesfully generate html documentation with delphi.
Is there maybe somebody who can share me some tips how to achieve that?
My current comments are as:
{*------------------------------------------------------------------------------
test
#param AGraphicsOwner ParameterDescription
#param ASettingsPath ParameterDescription
#param AEngineType ParameterDescription
#return ResultDescription
------------------------------------------------------------------------------*}
constructor TBaseEngine.Create(AGraphicsOwner: HWND;
ASettingsPath: PAnsiChar;
AEngineType: byte);
THANKS!!
I succeeded in creating a nice doxygen documentation with comments formated exactly like yours on my delphi code!
Here is how:
Replace all not-doxygen comments with // :
instead of
(* comment *) or { comment }
have
// comment
Why? According to this blog entry for the pas2dox filter it is crucial not to use (* and *) for commentaries in your delphi file. Furthermore simple one-line commentaries embraced by { and } seem to destroy the doxygen documentation as well.
Put the methods you want to see documented in doxygen into the INTERFACE section:
Only the methods "declared" in the INTERFACE section will be visible in doxygen (I have not quite figured out why, yet)
I tested it with a file that had all types of delphi comment-styles. I replaced the comment-idicators with notepad++'s replace-all function in the following order (I am completely sure there is a more elegant way to do that, but for me it was handy):
replace { with //
replace //$ with {$
replace (* with //
after that, all methods (in the INTERFACE section) appeared in doxygen and I started to comment using the doxygen style from above. I left away the ---, but I don't think this should be an issue =)
I use T4MVC and I'm happy with it and want to keep it - it keeps down run time defects. Unfortunately, it makes it harder to navigate to views and content (a.k.a. Views and Links in T4MVC) though. Even using Resharper, I can't navigate to the referenced item:
T4MVC and Resharper Navigation
Can I get a hand building a macro to do this? Never having built a VS IDE macro before, I don't have a grasp on how to get at some things, like the internal results of the "Go To Definition" process, if that's even possible.
If you aren't familiar with T4MVC, here's generally what the macro might do to help:
Given the token: Links.Content.Scripts.jQuery_js in the file MyView.cshtml, '(F12) Go To Definition'. This behaves properly.
Having arrived at the the related assignment:
public readonly string jQuery_js = "~/Content/Scripts/jQuery.js"; in a file generated by T4MVC (which is very nice, thank you David, but we really don't ever need to see), capture the string assigned and close the file.
Navigate in Solution Explorer to the PhysicalPath represented by the captured string.
This process would also work for views/layouts/master-pages/partials, etc.
If you provide a macro or link to a macro to do this, or have another solution, wonderful. Otherwise, hints on how to do step 3 simply in a VS macro would be especially appreciated and receive upvote from me. I'd post the macro back here as an answer when done.
Thanks!
Here's a Visual Studio macro to help.
What it does
Now you probably use T4MVC references in places like this:
Layout = MVC.Shared.Views.MasterSiteTheme;
ScriptManager.AddResource(Links.Content.Script.jQueryXYZ_js);
<link type="text/css" href="#Links.Content.Style.SiteTheme_css" />
return View(MVC.Account.Views.SignIn);
#Html.Partial(MVC.Common.Views.ContextNavigationTree)
#Html.ActionLink("Sign in / Register", MVC.Account.SignIn())
F12 (Go to Definition) already works for the last bullet (actions), but this hack is intended to cover the other scenarios (resources).
Macro
Imports EnvDTE
Imports System.IO
Public Module NavT4Link
Sub NavigateToLink()
DTE.ExecuteCommand("Edit.GoToDefinition")
Dim navpath As String = Path.GetFileName(DTE.ActiveDocument.FullName)
Dim isContentLink As Boolean = navpath.Equals("T4MVC.cs")
If (isContentLink Or navpath.EndsWith("Controller.generated.cs")) Then
Dim t4doc As TextDocument = DTE.ActiveDocument.Object()
navpath = CurrentLinePathConstant(t4doc)
If isContentLink Then
t4doc.Selection.MoveToPoint(t4doc.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).StartPoint)
t4doc.Selection.FindText("URLPATH")
navpath = Path.Combine(CurrentLinePathConstant(t4doc), navpath)
End If
If navpath.StartsWith("~") Then
DTE.ActiveDocument.Close(vsSaveChanges.vsSaveChangesPrompt)
Dim proj As Object = DTE.Solution.FindProjectItem(DTE.ActiveDocument.FullName).ContainingProject
navpath = Path.GetDirectoryName(proj.Fullname()) + navpath.TrimStart("~")
DTE.ItemOperations.OpenFile(navpath)
End If
End If
End Sub
Function CurrentLinePathConstant(ByVal t4doc As TextDocument) As String
t4doc.Selection.SelectLine()
Dim sa() As String = t4doc.Selection.Text().Split("""")
If sa.Length > 1 Then Return sa(sa.Length - 2) Else Return ""
End Function
End Module
Installation
In Visual Studio, press "Alt-F8" to open Macro Explorer.
Right-Click "My Macros", select "New Module...", and click "Add".
Replace all the text with the code shown here.
Save and exit the Macro Editor.
Open "Tools : Options".
In the left pane, select "Environment : Keyboard".
In the "Show commands containing" text field enter "T4".
In the "Press shortcut keys:" field press the "F12" key.
Click "Assign" and "OK".
On un-patched VS, this installation process doesn't result in a 'bindable' macro. A workaround was to (CTRL-SHIFT-R-R) to record an empty macro, and paste the code into it without renaming it. If someone knows of a more documentable approach to install a macro in VS, please comment.
Notes/Caveats
It's meant to replace the current F12 functionality, so if it isn't a T4MVC link, it will do the usual, otherwise it continues on to open the resource. It handles the majority of cases, but not T4MVC-generated empty controller methods. Those you get dumped off at the same place you did before.
For Content/Asset/Link resources, navigating to it in Solution Explorer would probably be in order, for image files for example, but I didn't see that functionality in the Visual Studio docs.