CommentBox() - Turn comments into a block for easier readability

Post your working scripts, libraries and tools
LuisSalas
Posts: 6
Joined: 25 Nov 2018, 23:20

CommentBox() - Turn comments into a block for easier readability

26 Jun 2019, 21:48

Simply turn comments into blocks.

Code: Select all

; CommentBox(align)
; align - string
;   •"left" - aligns left
;   •"right" - aligns right
;   •"center" or nothing - center

; ┌───────────────────────────────────┐
; │  CommentBox(align)                │
; │  align - string                   │
; │    •"left" - aligns left          │
; │    •"right" - aligns right        │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘

; ┌───────────────────────────────────┐
; │         CommentBox(align)         │
; │          align - string           │
; │        •"left" - aligns left      │
; │       •"right" - aligns right     │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘

; ┌───────────────────────────────────┐
; │                CommentBox(align)  │
; │                   align - string  │
; │            •"left" - aligns left  │
; │          •"right" - aligns right  │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘
Edit v1.1: • Added alignment with "left", "right" and "center" or nothing!

Gist url: https gist.github.com /LuisSanchez-Dev/75ec401b13f76dbef3c490357250311c Broken Link for safety
Function:
Spoiler
Last edited by LuisSalas on 30 Jun 2019, 02:27, edited 2 times in total.
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: CommentBox() - Turn comments into a block for easier readability

26 Jun 2019, 22:52

Ha! Nice trick, thanks!

I only got it to work properly a few times though. There's some unreliability somewhere... sometimes noting happens, sometimes I get the output:

Code: Select all

topLine +----+
topLine ¦    ¦
topLine +----+
Would be great to firm it up!
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

26 Jun 2019, 23:31

Very nice, thanks for this. Works great as long as you select the whole line including the comment character and there is a space after the comment character.

An option for the text to be left justified would be great.

It does not work on comments that wrap to the next line.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
LuisSalas
Posts: 6
Joined: 25 Nov 2018, 23:20

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 07:53

potscrubber wrote:
26 Jun 2019, 22:52
Ha! Nice trick, thanks!

I only got it to work properly a few times though. There's some unreliability somewhere... sometimes noting happens, sometimes I get the output:

Code: Select all

topLine +----+
topLine ¦    ¦
topLine +----+
Would be great to firm it up!
I could recreate this when running the command on the following text:

Code: Select all

topLine 
The way it works is that the commenting character is picked as everthing before the first space in the first line, so it could be used on any programming language, for example:

Code: Select all

; Simple ahk comment
; ┌──────────────────────┐
; │  Simple ahk comment  │
; └──────────────────────┘
# Python comment
# ┌──────────────────┐
# │  Python comment  │
# └──────────────────┘
// Java, js and c++ like comments
// ┌──────────────────────────────────┐
// │  Java, js and c++ like comments  │
// └──────────────────────────────────┘
derp java daba doo
derp ┌─────────────────┐
derp │  java daba doo  │
derp └─────────────────┘
So I would recommend checking if you selected from behind the commenting character until the end of the last line.
I have tested this on VSCode and works great, for notepad I just have to add an `r every line break.
I would like to know if this funtionality replicates on your machine, and if it doesn't, give more details that could help solve the problem.
LuisSalas
Posts: 6
Joined: 25 Nov 2018, 23:20

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 08:03

DataLife wrote:
26 Jun 2019, 23:31
Very nice, thanks for this. Works great as long as you select the whole line including the comment character and there is a space after the comment character.

An option for the text to be left justified would be great.

It does not work on comments that wrap to the next line.
What would be better in your opinion, global alignment or per-line alignment?
Example of the per-line alignment:

Code: Select all

; Multiply(x,y) - Center
; <int x - first value
; <int y - second value
; >returns int
; Multiply two values together

; ┌────────────────────────────────┐
; │     Multiply(x,y) - Center     │
; │  int x - first value           │
; │  int y - second value          │
; │                   returns int  │
; │  Multiply two values together  │
; └────────────────────────────────┘
Could you post an example of the wrapped comments that you talk about? Thanks a lot for checking out!
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 13:05

Comment lines that are too long are not a limitation of CommentBox().

CommentBox() should not be expected to break up long lines.

Before
; This line is too long and wraps to the next line in Scite4Autohotkey. I have comments like this in my scripts. AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as: form fillers, auto-clicking, macros, etc.
After
; +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
; ¦ This line is too long and wraps to the next line in Scite4Autohotkey. I have comments like this in my scripts. AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as: form fillers, auto-clicking, macros, etc. ¦
; ¦ ¦
; ¦ ¦
; +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


Would it be difficult to add a parameter to tell it to "left, right or center justify" the text. Like this.

Code: Select all

; +-------------------------------------------------------------+
; ¦  This text is left justified                                ¦
; ¦  Short line                                                 ¦
; ¦  A much longer line that makes the comment box much larger  ¦
; +-------------------------------------------------------------+

; +-------------------------------------------------------------+
; ¦                               This text is right justified  ¦
; ¦                                                 Short Line  ¦
; ¦  A much longer line that makes the comment box much larger  ¦
; +-------------------------------------------------------------+

; +-------------------------------------------------------------+
; ¦                    This text is centered                    ¦
; ¦                          Short line                         ¦
; ¦  A much longer line that makes the comment box much larger  ¦
; +-------------------------------------------------------------+
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 15:27

What would be better in your opinion, global alignment or per-line alignment?
I don't like the "per line", that could get complicated. How would you know what the user wanted per line? I think it should stay global.

Although, in addition to options for left, center & right text justify there could be an option for "don't change current indention"

I will definitely use CommentBlock() just like it is or with text justify parameters as long as I am coding. This makes it so simple to have nice looking comments with very little effort.

There is no way I could figure out how your code works, otherwise I would add the text justification parameters myself.

edit 6-27-19
I just noticed the arrows <> and word center to justify the text.
That would require me to rewrite all my current comments. I prefer parameters to text justify.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 19:50

LuisSalas wrote:
27 Jun 2019, 07:53
So I would recommend checking if you selected from behind the commenting character until the end of the last line.
I have tested this on VSCode and works great, for notepad I just have to add an `r every line break.
I would like to know if this funtionality replicates on your machine, and if it doesn't, give more details that could help solve the problem.
Hi - thanks for your response.

I'm definately initiating and selecting the comments correctly.

Firstly, I found that the function script version I was using (having copied and pasted it into SciTE4AHK) had somehow come across as ANSI. So I downloaded from GitHub and now have the correct unicode characters for the box corners etc.

Code: Select all

My test comment input:

;
; test
;

Output in SciTE4AHK:

;
; test
;

Output in Notepad++:

; ┌────────┐
; │        │
; │  test  │
; │        │
; └────────┘
Now, in Notepad, for output in the application I get :
CommentBoxCapture.PNG
CommentBoxCapture.PNG (3.95 KiB) Viewed 2965 times
and when I copy and paste that code into this forum post I get:

Code: Select all

; ┌────────┐
; │        │
; │  test  │
; │        │
; │        │
; └────────┘
As to Notepad, it's obviously a linefeed thing. I don't really care about that.

What I would love is to work out the issue in SciTE4AHK. In SciTE4AHK the default encoding for new scripts is Code Page Property, and the Line End Characters are CR+LF. Are there any other factors to do with SciTE4AHK that could prevent the script working properly? My system region is English (New Zealand).

thanks!
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 23:11

This works properly in my Scite4Autohotkey, Notepad and NotePad++ for me. Notepad++ version 7.7.1 (64 bit)
Before

Code: Select all

;
; test
;
After

Code: Select all

; +--------+
; ¦        ¦
; ¦  test  ¦
; ¦        ¦
; +--------+
I am using Autohotkey Unicode 32bit.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

27 Jun 2019, 23:44

How can I get my Scite4Autohotkey to show the corners like notepad? I used notepad to save my CommentBox() script as unicode, then I tested on Scite4Autohotkey and the unicode characters are replaced by ansi characters.

Notepad

Code: Select all

; ┌────────┐
; │        │
; │  test  │
; │        │
; └────────┘
Scite4Autohotkey

Code: Select all

; +--------+
; ¦        ¦
; ¦  test  ¦
; ¦        ¦
; +--------+
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: CommentBox() - Turn comments into a block for easier readability

28 Jun 2019, 06:09

DataLife wrote:
27 Jun 2019, 23:44
How can I get my Scite4Autohotkey to show the corners like notepad? I used notepad to save my CommentBox() script as unicode, then I tested on Scite4Autohotkey and the unicode characters are replaced by ansi characters.
In Scite4Autohotkey, for the document, check the menu setting File / Encoding. Should be UTF-16 Little Endian for unicode compatibility. I say this not from any deep knowledge just experimenting on my system. I actually think the ANSI character CommentBox() version looks better, but hey....
Last edited by potscrubber on 28 Jun 2019, 08:49, edited 1 time in total.
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: CommentBox() - Turn comments into a block for easier readability

28 Jun 2019, 07:08

So I sorted out the issues I was having in SciTE4AHK by changing the Send statements to SendEvent. I always start a new script with the AHK new script default header which includes:

Code: Select all

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
But this seemed to break the functionality of copying and pasting to the clipboard, which individual SendEvent statements fixed. I don't use the clipboard much with AHK so I'm probably somewhat ignorant in this field.

Anyway, the script is now working great thanks LuisSalas and I will definately put it to use.

cheers
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

28 Jun 2019, 11:40

potscrubber wrote:
28 Jun 2019, 06:09
DataLife wrote:
27 Jun 2019, 23:44
How can I get my Scite4Autohotkey to show the corners like notepad? I used notepad to save my CommentBox() script as unicode, then I tested on Scite4Autohotkey and the unicode characters are replaced by ansi characters.
In Scite4Autohotkey, for the document, check the menu setting File / Encoding. Should be UTF-16 Little Endian for unicode compatibility. I say this not from any deep knowledge just experimenting on my system. I actually think the ANSI character CommentBox() version looks better, but hey....
That worked, thanks
Also CommentBox() will put a box around a box

Code: Select all

; ┌──────────────┐
; │  ┌────────┐  │
; │  │  test  │  │
; │  └────────┘  │
; └──────────────┘


; ┌────────┐
; │        │
; │  test  │
; │        │
; └────────┘
This is the way it looks in my Scite4Autohotkey
Attachments
CommentBox().JPG
CommentBox().JPG (2.14 KiB) Viewed 2868 times
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
LuisSalas
Posts: 6
Joined: 25 Nov 2018, 23:20

Re: CommentBox() - Turn comments into a block for easier readability

30 Jun 2019, 02:34

Thanks you @potscrubber and @DataLife for sorting that out!
I use VSCode for this so I didn't get that problem.
DataLife wrote:
27 Jun 2019, 15:27
I will definitely use CommentBlock() just like it is or with text justify parameters as long as I am coding. This makes it so simple to have nice looking comments with very little effort.

There is no way I could figure out how your code works, otherwise I would add the text justification parameters myself.
[...]
That would require me to rewrite all my current comments. I prefer parameters to text justify.
v1.1: • Added alignment with "left", "right" and "center" or nothing!

Code: Select all

; CommentBox(align)
; align - string
;   •"left" - aligns left
;   •"right" - aligns right
;   •"center" or nothing - center

; ┌───────────────────────────────────┐
; │  CommentBox(align)                │
; │  align - string                   │
; │    •"left" - aligns left          │
; │    •"right" - aligns right        │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘

; ┌───────────────────────────────────┐
; │         CommentBox(align)         │
; │          align - string           │
; │        •"left" - aligns left      │
; │       •"right" - aligns right     │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘

; ┌───────────────────────────────────┐
; │                CommentBox(align)  │
; │                   align - string  │
; │            •"left" - aligns left  │
; │          •"right" - aligns right  │
; │    •"center" or nothing - center  │
; └───────────────────────────────────┘
User avatar
DataLife
Posts: 360
Joined: 29 Sep 2013, 19:52

Re: CommentBox() - Turn comments into a block for easier readability

01 Jul 2019, 13:11

thanks text alignment works great.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
burque505
Posts: 1416
Joined: 22 Jan 2017, 19:37

Re: CommentBox() - Turn comments into a block for easier readability

10 Jul 2019, 12:20

Thank you for this, a keeper for sure.
Regards, burque505
ozzii
Posts: 380
Joined: 30 Oct 2013, 06:04

Re: CommentBox() - Turn comments into a block for easier readability

18 May 2020, 03:04

Thanks to the link from @burque505 I have discovered this script.

Any possibility (if not too complicated) to add an optionnal option for an max length of the comment?
Any line too long will be split and put on a new line from the word before the maxlengh.

Thank you in advance.

EDIT: I thought about this also. Have the possibility to make the box in a fixe width. So even when the line is shorter, it's adding spaces until the requested length.
So for example all the line will have 15 of width.

Code: Select all

; ┌───────────────────┐
; │  1111             │
; │  222222           │
; │  33333333         │
; └───────────────────┘

; ┌───────────────────┐
; │       1111        │
; │      222222       │
; │     33333333      │
; └───────────────────┘


Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 29 guests