Author Topic: Help me make text formatting work like I want?  (Read 19191 times)

AlpineDude

  • Community Member
  • Posts: 5
  • Hero Points: 0
Help me make text formatting work like I want?
« on: October 12, 2006, 01:10:19 AM »
I am in the process of evaluating SlickEdit as a possible replacement for my previous programmer's editor, which was EdForWindows (http://www.getsoft.com/).

One thing that Ed does that I very much wish to continuing doing is a single key command (cntl-B, not that it matters) that rewraps a block of text starting at the cursor. That rewrap uses the cursor column as the left margin for the resulting text block and continues until a double hard return is encountered (i.e., an extra blank line).

That seems very simple and straightforward to me, but I can't seem to find a way to make SlickEdit do it.  :-/

Can anybody help me out with this?

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Help me make text formatting work like I want?
« Reply #1 on: October 12, 2006, 11:51:42 AM »
One thing that Ed does that I very much wish to continuing doing is a single key command (cntl-B, not that it matters) that rewraps a block of text starting at the cursor. That rewrap uses the cursor column as the left margin for the resulting text block and continues until a double hard return is encountered (i.e., an extra blank line).

Look at reflow-paragraph, reflow-comment, and reflow-selection.  They will do a lot of what you want.
For the exact behavior you describe-- using the  cursor position as the left margin -- I think you will have to write a macro.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Help me make text formatting work like I want?
« Reply #2 on: October 12, 2006, 08:59:00 PM »

If the reflow commands that wanderer suggested don't do what you want, can you post again with an example that shows what you're trying to do  - especially explain where the block of text starts i.e. does it start at the character the cursor is on or at the start of the line the cursor is on.  You might be able to record a macro that does what you want with a single keystroke.

Graeme

AlpineDude

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Help me make text formatting work like I want?
« Reply #3 on: October 17, 2006, 01:33:54 AM »
Thanks Wanderer and Graeme! I appreciate your interest and anything you can do to help!
I am brand new to SlickEdit, and still feeling my way around in it!

Wanderer -- Thanks for pointing those out. I looked them and figured out how to use them, and Yes those do PART of what I want, but as you said, they don't do it all. Specifically, they don't give me a dynamic left margin.

Graeme -- Here are a couple of examples:

#1 Before (cursor at 'o' in first "brown", right margin fixed short):

    The quick brown fox jumped over the lazy dog's
    back. The quick brown fox jumped over the lazy
    dog's back.


#1 After (cursor still at 'o' in first "brown"):

    The quick brown fox jumped over the lazy dog's
                back. The quick brown fox jumped
                over the lazy dog's back.


That first example shows how it works in an odd place, but this second example is more like how I would normally use it to help me manage text in work logs and such:

#2 Before (cursor at 'S' in second subheading, right margin fixed short):

1.  Major section heading in text file:
    -   Subheading under that:
        -   Subheading under that: The quick brown fox jumped over the lazy dog's back. The quick brown fox jumped over the lazy dog's back.


#2 After (cursor still at 'S' in second subheading):

1.  Major section heading in text file:
    -   Subheading under that:
        -   Subheading under that: The quick brown fox
            jumped over the lazy dog's back. The quick
            brown fox jumped over the lazy dog's back.



Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Help me make text formatting work like I want?
« Reply #4 on: October 17, 2006, 08:48:26 AM »

What is the file type / extension that you want to do this in?  Slick comment reflow is limited to C, C++, C#, Java, and Slick-C (according to the help).

On my system, it seems the hyphen/ minus character has special meaning because if I put the cursor on the 'S' in the second subheading and do reflow-comment, a "hanging indent" is created (as you want) and the text is aligned with the 'S' character.  Unfortunately macro recording doesn't seem to work through the reflow comment dialog - it doesn't remember the settings in the dialog and it generates a pile of spurious duplicate lines that call _setext that appear to be trying to remember the desired reflow options but actually don't.

I also can't get the "continue bullet list on enter" option to work, and there's no info on what constitutes a "bullet".

It looks like slick can almost do what you want, so maybe if the macro recording problem can be fixed it will work for you - depending on whether it only needs to work when the bullet character is a hyphen I guess. 

It's quite likely what you want can also be done with a macro that steps through "words" and wraps the lines when necessary, so if "slickteam" can't solve this for you, and you can't do it yourself, I'll have a go sometime.

Graeme

SlickEdit Support

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 384
  • Hero Points: 29
Re: Help me make text formatting work like I want?
« Reply #5 on: October 18, 2006, 05:29:56 PM »
Hey Folks,

Investigating this one and will let all of you know, via post, what we come up with.

AlpineDude, as mentioned, will email you as well.

Best,
SlickEdit Support

AlpineDude

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Help me make text formatting work like I want?
« Reply #6 on: October 18, 2006, 08:10:46 PM »
Graeme -- I'm wanting this feature for use in a normal text (.txt) file. I keep software history logs that way, as well as my day-to-day work logs. Plain text is just so much more compact and more easily accessible than any word processing format that I prefer it for such uses. And I've previously taken for granted the ability to format multiple levels of indented paragraphs quickly and easily. Hence my desire for this feature.

Yes, I do find that, when used in a .C file, the reflow-comment seems to work ALMOST like what I'm asking for, if one excludes the hyphen bullet character. But of course, that doesn't work in a .txt file. :-/

As for your offer to have a go at such a macro, that would be great! At this point I'm still evaluating several editors, and trying to keep up with my normal software engineering career at the same time, so anything you can do would be greatly appreciated. At this point I wouldn't know where to start.

SlickEdit Support -- Got your email. Good info, though, as you said, it doesn't offer an immediate solution. Thanks though!

SlickEdit Support

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 384
  • Hero Points: 29
Re: Help me make text formatting work like I want?
« Reply #7 on: October 18, 2006, 08:52:27 PM »
Give this one a whirl then.  (Tested in a text file.)  It's based on whatever your right margin is set to and will NOT work in source code comments--it will execute, but with undesired results.  There will be more configuration of lines, word wrap in future versions that more than likely will make this redundant.

Save this file to your slickedit\macros directory and then load it via Macro-->Load Module.  The command that runs this macro is 'reflow_hanging_indent' (no quotes) from the SlickEdit command line.  (The command line can be accessed by hitting Escape in most emulations or simply clicking on the message area in the bottom left corner of the main SlickEdit application window.)

You will want to bind this new macro command to a keystroke by using the Tools-->Options-->Key Bindings dialog and then you can easily run it with the key combination of your choice.

//  Running this command will wrap the text below the current cursor position, using the current cursor column location as the "left margin" for the lines below it.
//  You can change the right margin settings in Tools-->Options-->File Extension Setup-->Word Wrap tab.

Best,
SlickEdit Support

NOTE:  Updated copy of macro in post below.
« Last Edit: October 19, 2006, 02:39:42 PM by SlickEdit Support »

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help me make text formatting work like I want?
« Reply #8 on: October 19, 2006, 06:13:53 AM »
Hello AlpineDude,
I'm also using txt files for changelogs etc.
Maybe a good hint for you:
If you setup the txt file extension to refer to 'ini' you get certain tagging support for your changelogs if you use this e.g. as date entry '[19.10.2006]' (normal ini section formatting). This is quite helpful for projects w/ a longer history...
(I'm using a tiny 'changes' macro which handles a workspace associated changelog (it's simply located in workspace dir) and autoinserts the curr. date on top etc.)

@Slickteam: Thanks for the macro !

HS2

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help me make text formatting work like I want?
« Reply #9 on: October 19, 2006, 07:39:39 AM »
Hello AlpineDude,

you could use this (very rough check) to avoid accidentally messing up your source:
Code: [Select]
_command void reflow_hanging_indent() name_info(',')
{
   _str ext = _bufname2ext ( p_buf_name );
   if ( commentwrap_isSupportedLanguage ( ext ) )
   {
      message ("Use lang specific reflow support !");
      return;
   }
   ...

HS2

SlickEdit Support

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 384
  • Hero Points: 29
Re: Help me make text formatting work like I want?
« Reply #10 on: October 19, 2006, 02:41:45 PM »
Added new nameinfo item to reflowhang.e---> name_info(','VSARG2_REQUIRES_EDITORCTL)

Save, over-writing the current if you already have it, and reload it accordingly.

Best,
SlickEdit Support

AlpineDude

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Help me make text formatting work like I want?
« Reply #11 on: October 19, 2006, 11:55:44 PM »
Thanks for all the help folks! It is very much appreciated! :-)

The reflow_hanging_indent() macro from Support works very well except when the cursor for the affected text is on the first line of the text and is preceded by an item number or bullet character (which I almost always do). That is, it works fine in the first example text I gave the other day:
Code: [Select]
#1 Before (cursor at 'o' in first "brown", right margin fixed short):

    The quick brown fox jumped over the lazy dog's
    back. The quick brown fox jumped over the lazy
    dog's back.

#1 After (cursor still at 'o' in first "brown"):

    The quick brown fox jumped over the lazy dog's
                back. The quick brown fox jumped
                over the lazy dog's back.

but it does not work for the second example situation:
Code: [Select]
#2 Before (cursor at 'S' in second subheading, right margin fixed short):

1.  Major section heading in text file:
    -   Subheading under that:
        -   Subheading under that: The quick brown fox jumped over the lazy dog's back. The quick brown fox jumped over the lazy dog's back.

#2 After (cursor still at 'S' in second subheading):

1.  Major section heading in text file:
    -   Subheading under that:
        -   Subheading under that: The quick brown fox
            jumped over the lazy dog's back. The quick
            brown fox jumped over the lazy dog's back.

In that latter situation, with the cursor starting at the S of the second subheading, this happens:
Code: [Select]
1.  Major section heading in text file:
    -   Subheading under that:
        - Subheading under that: The quick brown fox jumped over the lazy dog's
            back. The quick brown fox jumped over the lazy dog's back.
That is, the first line of text moved back two spaces, and the subsequent lines ended up right.
It's VERY close though! :-)

Hs2 -- Thanks for your input! But if I did mess up some code with the macro, couldn't I just use the undo to undo it?
As for the .INI tip, that could be handy, and I'll keep it in mind, but I need the other capability to support years of legacy documents in a consistant format... You know how it is?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Help me make text formatting work like I want?
« Reply #12 on: October 20, 2006, 10:27:46 AM »
Hello AlpineDude,

I think it's up to you to make the macro doing the right thing for you...
The Slickteam example is surely a good basis, but I afraid they've got no time to write macros for the community ;)
Try message() / messageNwait () / say () to see what's going on (attached note.e contains some commented dbg lines).
I'm sure you will easly get it done.
And it's a good chance to get used to Slick-C programming, which will help you a lot later on.

My tiny 'note' macro would just add some text at the top of a '!<workspace name>.not' file and the chamges are undoable like almost any 'action' in Slick.
(I added a new file ext. 'not' referring to 'ini' for this.)
--top---
[20.10.2006]
-  <cursor>

your legacy text
   -   much more legacy text
...
--end---

Subseq. calls at the same day are appending more '-  ' entries to the [today date] section.
Next day a new [next day date] is added on top. Simple, isn't it ?

You could try it by loading the attached 'note.e' or copy it's content to your AlpineDude.e macro collection module or just take it as an add. example...
 
HS2

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Help me make text formatting work like I want?
« Reply #13 on: October 20, 2006, 04:27:55 PM »
@AlpineDude  I noticed that a bullet with multiple spaces problem.  This is fixable but a bit tricky to do right.  I don't want the macro to have to know what a bullet is.  Also, I'd prefer to support all justfication options.

For now, if you set your Justification to "Left" instead of "Left and respace", the macro should work fine.  Document>Justify...

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Help me make text formatting work like I want?
« Reply #14 on: October 20, 2006, 04:43:46 PM »
Here's a new version of reflowhang_indent.e.  It handles all justification options and bullets followed by multiple spaces.