tags:

views:

148

answers:

3

Does anyone know of an editor that has the ability to enforce exact line lengths (bonus if it allows association of maximum line lengths by file name/extension)?

What I mean by exact line lengths is that the editor will always save each line padded to a maximum line length (defined by the user). For example, if a file should have a 120-character line length every line in the file will be 120-characters long, padded with blanks if needed, follow by the appropriate newline indicator. When someone edits a line the editor will prevent them from typing if the line length hits the max length.

Platform is Win XP/Vista.

A: 

I am not aware of an editor that handles this type of input, however, I can say that overall it wouldn't be that hard to actually create a system that works in this manner.

Mitchel Sellers
I agree we could create something and I'd also like to think that "overall it wouldn't be that hard," but when I do my coder-sense tingles warning me that writing a robust editor of any kind is always == !!hard.
Robert
A: 

Vim

:syn match Error /^.{,119}$/
:syn match Error /.{121,}/

This will cause any lines of length != 120 to be highlighted with a solid red background (in the default color scheme).

If you write this (without the leading colons) into $VIMRUNTIME/syntax/foo.vim, and place

:au BufRead,BufNewFile *.foo    set filetype=foo
:au Syntax foo  source $VIMRUNTIME/syntax/foo.vim

in vimrc or the usual ftdetect and synload.vim locations, then as long as syntax highlighting is enabled, these rules will will automatically apply to any *.foo file you open in Vim.

(See :h mysyntaxfile-add if you want to add to an existing syntax file, and see :h rtp for the default $VIMRUNTIME path on your platform.)

ephemient
While not exactly enforcing, at least this provides a visual cue.
Robert
A: 

The Zeus editor can't enforce this rule, but by using a two stage search and replace it would be possible to convert a file into this format in a semi-automatic fashion.

Step One: Make saure all lines are longer than 120 characters by running the following regexp search and replace to pad the strings.

 Search: (.*)\n
Replace: \1                              \n

NOTE: The replace string shown above should have 120 white space characters and not just the 30 shown.

Step Two: Trim the lines at the 120 character mark using this regexp search and replace.

 Search: ^(.{120,120})(.*)\n
Replace: /1\n

At this point all the lines in the file will be exactly 120 characters in length.

But to make sure these lengths stick, make sure the Zeus option to trim lines of white on save is disabled ;)

Also since Zeus is scriptable, it would be possible to semi-automate this process by writing a simple macro script to run these two operations.

Finally Zeus has an option to run a macro script on a trigger so the macro could be added to the save trigger to make it semi-automatic.

I am sure it would be possible to configure any scriptable editor to do something similar.

jussij