Managing line width in ColdFusion - vim

If you work with ColdFusion, you've probably gotten used to either line-wrapping or horizontal scrolling. Infrequently, this isn't so bad, but when three out of four lines in an existing code base are wrapped, sometimes twice, it becomes a huge readability hindrance.
A line such as...
<cffunction name="v_multiple_item" access="public" output="false" returntype="query">
can easily be broken up HTML-like into
<cffunction name = "v_multiple_item"
access = "public"
output = "false"
returntype = "query"
>
Which is fairly easy to automate with a macro in a good editor. What I'm more concerned with is interspersed ColdFusion and HTML, like so:
<cffunction..>
<cfif..>
<cfif..>
<form..>
<div..>
<table..>
<tr..>
<td..>
<cfif..>
<select..>
<cfoutput>
<option>#stuff#</option>
</cfoutput>
It's not uncommon that I see lines of code, with 8-sp tabs, that are line-wrapped during the whitespace.
Reducing tab width hasn't been enough. The code base is too big for rewrites/frameworkification to be an option. Left-justify everything?
Is there a simple, winning strategy for reducing line widths to a manageable level without further damaging readability?

I don't want to get into a 'tabs versus spaces' issue here, but one thing you can do is adjust your tabs in the IDE. If you use tabbing, you could always make a tab be 2 or 3 spaces rather than 8 (or more). This will reduce the unnecessary whitespace, at least visually.
In Eclipse you can do this under Preferences > General > Editors > Text Editors. There's a 'Displayed Tab Width' there which you can reduce to your heart's content.
The real answer, however, is that this is just the nature of the beast. If you're going to intermix CF with HTML, and you want clarity, you'll indent your code.
Edit: Come to think of it, CFInclude just came to mind. Granted, this can also cause spaghetti code, but how things like this are often handled is with CFInclude. You can break reusable portions of CF code into cfm templates and include those. For a situation with a header, with many nested divs and pieces of CF logic intermixed, you'd be better off using a cfinclude anyway. So an index.cfm page that looked like your example might instead look more like this:
<cfinclude template="header.cfm">
<div>Some Content Here</div>
<cfinclude template="footer.cfm">
All of your wrapping is included in header.cfm or footer.cfm. You can even do includes within those templates as well, keeping things like the navigation isolated into a separate cfm page as well.
I'm not advocating that you go hogwild with includes, but it's a standard way of handling reuseable snippets of HTML/CFML in ColdFusion, and breaks things up into conceptual blocks that makes it easier to find what you're looking for.

IMO, this isn't a ColdFusion specific problem, this is related to code readability in general.
My solution? I got a 28" monitor. :)

Related

Is there any reason to reference UI element text in the strings.xml resource file rather than hard-coding in Android Studio?

It seems like it's simply more straightforward to hard-code the text values. In an event that these values should be changed it seems like it would be more logical to search for the relevant UI element in each activity's xml layout file rather than look through the entire strings.xml. Of course if you have certain UI elements across multiple activities that all share the same text then this might be an exception (like a back button for instance), but generally there doesn't seem to be much advantage to storing these in the strings.xml. Am I missing something?
I will give you two reasons;
1 - Avoid duplication: all of your strings in one place. also, you can use string value many times. when you want to change it, there is one place to do the change. that makes it easier to maintain.
2 - Multi-language support: if you want to translate your strings to another language you must have all the strings in Strings.xml
let me know if you need more clarifications.

How do I configure Kate to automatically detect spaces/tabs indentation?

I mess with software written by completely unrelated groups of people, and it all uses completely different indentation standards. I'm okay with having to set the indentation width, but there's nothing more annoying than opening up a file with tabs, making some changes, and finding that my changes used spaces for indentation instead.
All the software I write uses four-space indentation. Then I go to make a Quake 3 mod and the entire codebase uses tabs. When I make changes I have to be incredibly careful to set my indentation settings first or I'm going to have to manually rewrite the indentation before committing, every single time.
I went through the settings and couldn't find anything. The tabs-and-spaces mode literally doesn't do anything special and just sets it to tabs mode instead (after a reset). I went through google and all I found was this extremely unhelpful mailing list message. Detecting consistent indentation isn't that difficult, other text editors manage it fine, it doesn't have to be perfect, it just has to work most of the time.
If Kate has a setting for this, where is it, and if it doesn't, when is it going to get such a setting? If I can't make Kate do this I'm going to have to switch off of it. I already went through Notepad++ and Geany, but they both have serious problems with doing regexes on extremely large files (say, tens of megabytes of text) or with rendering monospace non-european text.
Unfortunately, kate does not support this right now. There is a bug report for this from 2005, but noone implemented that yet (yes, 13 years ago).
What Kate does support though are Kate modeline (also called document variables). For instance, you can write in your text document e.g.:
// kate: replace-tabs on; indent-width 4;
And then the document containing this comment will automatically use 4 spaces and use spaces to indent.
Instead of writing these kind of comments into files, you can also write this into files called .kateconfig. You can find more information about .kateconfig files and modelines in this article.

What are "Code Styles" in Intelli J IDEs?

I took a look at this, and I thought it was a color scheme or something. I followed my stems to find out that it's not.
What are "Code Styles" and what changes can they, for example, do?
Code styles dictate what happens when you auto-format your code, which includes:
The placing of braces, forcing or omitting their inclusion with a single statement
The amount of spaces indentation does
Whether or not you chop down or wrap long statements or parameters
How annotations appear in fields (on top of/next to)
Whether or not you use import * statements in Java, and what/when the cutoff is
How you close ML tags (XML, HTML, etc - either with the </full-name> or <full-name />)
...and many other pieces.
Code style varies from person to person, and shop to shop, so having IntelliJ as a way to configure this once and shared with others is ideal.

Exclude comments from search results in IntelliJ global search?

I found the grammar error "it's" as a possessive on one page of a large project. I'm trying to search for any other usages of this on pages to correct it, but I'm getting results containing hundreds of comments. I just want to filter for the important user-facing portions of the project. Is there a way to exclude comments from the results of a global search?
In more recent versions, at least in PyCharm 2018 (similar to IntelliJ), there is a filter option "Except comments," as shown here:
(Click the small filter icon to show the dropdown.)
Note: The selected filter option persists during a session, and the active filter option is not immediately apparent unless you open the dropdown. To prevent accidentally limiting subsequent searches, it may be a good idea to switch back to "Anywhere" afterward.
Another approach would be to enable the "Regular expression" (or "Regex") checkbox in the search dialog, then use some kind of negative lookaround to exclude comments.
In one case, I needed to exclude lines with single-line comments (e.g. # this is a comment) from a search, but not lines with inline comments (e.g. a=b+1 # this is an inline comment). The following did the trick, searching for something (for Python comments, starting with #):
^((?!#).)*something.*$
Please note I'm not a regex-expert, so this regex pattern can probably be improved upon greatly, but it illustrates the idea. You can play around with this on regex101. Any comments to improve the pattern are most welcome, of course.
Note sure if this approach could be extended to multiline comments though. (as in """ several lines here """).
It's difficult to suggest something without really looking at the code, but since it seems like a one-off thing, I would use global search just in comments to temporary replace "it's" with some #temporary-token#, then use global search everywhere, you should everything what's left. Then rollback temporary token for comments. Should be easy to try with VCS. Just an idea.
As you can see, with "Comments only" option, only one #token is found.

creating tags for a script language for easy browsing in vim

I use ctags+Vim for a lot of my projects and I really like the ability to easily browse through large chunks of code quickly.
I am also using Stata, a statistical package, which has a script language. Even though you can have routines in the code, its code tends to be series of commands that perform data and statistics operations. And the code files can be very long. So I always find myself in need of a way to browse it efficiently.
Since I use Vim, I can use marks. But I was wondering if I could use ctags to do this. That is, I want to create a tag marker which (1) won't cause a problem when I run the script (2) easy to introduce to ctags.
Because it is supposed to not break the script, it needs to be a comment. In Stata, comment lines start with * and flow comments can be made by /* ..... */.
It would be great, for example, have sections in the code, marked by comments:
* Section: Data
And ctags picks up "Data Manipulation" as the tag. So I can see a list of sections and jump to them easily without the needs for creating marks.
Is there anyway to do this? I'd appreciate any comments.
You need a way to generate a tags database for your Stata files. The format is simple, see :help tags-file-format. The default tags program, Exuberant Ctags can be extended with regular expressions (--langmap, --regex); that probably only yields an approximate parsing for complex languages, but it should suffice for custom section marks; maybe you could even directly extract interesting language keywords.

Resources