text/list/table functions

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

text/list/table functions

18 Jan 2017, 02:19

I've made working attempts at, but am looking for the best ways to achieve:
- list comparison: items unique to list A / items unique to list B / items present in both [EDIT: see post lower down]
- table lookup: multiple values against a table/ini file [EDIT: just use an AHK array]
- table lookup: one value against a list (e.g. a spell list, do you use 26^2=676 variables to speed it up?) [EDIT: just use an AHK array][Note: for creating AHK arrays, it is faster to add keys in alphabetical order.]
- list remove duplicates: remove duplicates, maintain order [EDIT: see post lower down]
- list sort: sort list A based on list B, items in both should be in list B's order, the remaining items in list A should be in their original order [EDIT: see post lower down (list comparison)]
- list sort: start with paths/registry keys in their correct order, randomise, and restore original order [EDIT: will post code soon]
- text split: get start/end positions of nth line (see below) [EDIT: see post lower down]
- list line frequency: get frequency for each item, maintain order [EDIT: see post lower down]
- (each function would need case sensitive/case insensitive as an option)

get line: I made an attempt at this function below:
get nth/nth-to-last line of between a and b characters in length
(returning positions c and d, where the line starts after char c and ends before char d)
(note: the line could be blank, you can't use: starts with char c and ends with char d)

I'm thinking of methods including: multiple variables, arrays(?),
RegEx(?), add column - sort - remove column - sort back.
I've actually written all of these functions but they're untidy,
and am curious about any better methods, before I consider sharing.
These functions are the worst-looking/hardest-to-understand functions in my libraries.
(Something that became clear as I split my lib file into smaller files.)
I had hoped that maybe arrays might be a gamechanger, or some other method,
and wondered if anybody had any good ideas for these.

I was partly prompted by this recent question on csvs, that needs
the last non-blank line in a text file, of course you can use a parsing loop,
but what about more efficient ways:
(plus Excel can always corrupt/do weird things to the data,
because of assumptions it makes that can't be turned off)
Overwrite last row from one workbook to another - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26949

[improved version of this in a post below]

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 06 Jun 2017, 18:01, edited 15 times in total.
ryunp
Posts: 6
Joined: 14 Jan 2014, 02:01

Re: text/list/table functions

18 Jan 2017, 02:40

This massive text wall is hard to decipher. Are you looking for resources to learn the underlying data structures to accomplish these tasks? Or just looking for stack-overflow style homework answers?

The amount of specific issues is overwhelming. Can you identify just a few issues and elaborate on what you are trying to accomplish, and what's stopping you?
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

18 Jan 2017, 02:44

To be clear, I don't need anyone to write any code for me. I have functions that achieve these tasks already. I was more interested in general ideas, and what the current state of the art is. Possibly to provide some links, if there are good scripts, or point to any text function libraries. Basically I wasn't sure how to address this general problem of text functions, it doesn't seem to appear much on the forum. I thought I would at least try this approach.

In simple terms someone could go, OK for that one use arrays, for that one use RegEx etc.
ryunp
Posts: 6
Joined: 14 Jan 2014, 02:01

Re: text/list/table functions

18 Jan 2017, 03:07

I've always enjoyed JavaScript's architecture; try looking through MDN's docs on the String object. You will see a list of methods on the left sidebar. These are all the functions provided for string operations.

I also suggest looking at Array object to see how they deal with lists of elements. Their functional approach is noteworthy and incredibly powerful.

Best way to learn is study what's already been done. I've actually been rewriting most of the Array methods from JavaScript's Array object for AHK. For instance, Array.filter():

Code: [Select all] [Expand] [Download] (array_filter_ex.ahk)GeSHi © Codebox Plus



If this material is overwhelming, there is other sources I can point you to.
Last edited by ryunp on 18 Jan 2017, 03:41, edited 1 time in total.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

18 Jan 2017, 03:24

Thanks for your response, I will investigate this further.
ryunp
Posts: 6
Joined: 14 Jan 2014, 02:01

Re: text/list/table functions

18 Jan 2017, 03:40

If you end up needing JavaScript-esk Array functions, I've ported over most of them: https://github.com/ryunp/ahk-array
Last edited by ryunp on 19 Jan 2017, 05:10, edited 1 time in total.
FanaticGuru
Posts: 802
Joined: 30 Sep 2013, 22:25

Re: text/list/table functions

18 Jan 2017, 19:59

If you are looking for some functions for strings and arrays, I have found String Things useful.
https://autohotkey.com/boards/viewtopic.php?f=6&t=53

I especially like ST_printarr when debugging a script to get a visual of an arrays contents. Its recursive technique of walking through all the elements of a multi-dimensional array has been useful for me in several scripts.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

Google Search, Dictionary, Thesaurus - Quickly Get Information from Specific Web Resources

[Function] Timer - Create and Manage Timers
User avatar
tidbit
Posts: 1006
Joined: 29 Sep 2013, 17:15
Location: USA

Re: text/list/table functions

18 Jan 2017, 20:34

rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

19 Jan 2017, 02:03

Wow ahk7, the Table lib has the kind of bold ambition I'm looking for,
thanks very much.
It looks so far that I should try and publish the functions I mentioned,
once checked over, many seem to be missing from other libraries.
I'm not especially interested in list functions per se,
but when you need them, you need them, and I've tried to write them,
and they can't just work, they have to be fast, and not have any bugs!
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

19 Jan 2017, 02:06

Thanks very much FanaticGuru and tidbit, I will investigate further.

Btw tidbit your avatar is the most awesome, ... and that shade of green!
I wish there were more avatars on the new forum,
like there were on the old one.
User avatar
tidbit
Posts: 1006
Joined: 29 Sep 2013, 17:15
Location: USA

Re: text/list/table functions

19 Jan 2017, 11:23

Thanks, made it myself :)
I like owls (though, not my fav animal/bird), I also like the color teal (technically "Caribbean green" or "Sea Green 3"). the pink is because that was the color of admins/mods names on the old-old-old forum.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

19 Jan 2017, 11:48

Great story about the owl. They are wise, as they can see in the dark.
I keep a lucky Greek one euro coin with an owl on it.
Owls also remind me of Rupert and the Frog Song LOL.

I really need to become a *sort of* graphic designer, it's my one shortcoming,
I think I would love it. Yeah, maybe I need a graphics tablet and to get back to drawing AFK as well.
User avatar
tidbit
Posts: 1006
Joined: 29 Sep 2013, 17:15
Location: USA

Re: text/list/table functions

19 Jan 2017, 11:54

this is offtopic but it's your topic and you started it :D

I made this, and most of my stuff, in inkscape (svg > bitmap). Using a mouse (never owned, but always wanted, a drawing tablet). I'd get Illustrator or CorelDraw, but they are $500+. and the newest Illustrator (as with all adobe things) are locked behind the crappy subscription cloud now. I don't pirate stuff :/
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

27 Feb 2017, 18:20

I have an improved version of a function to get the position of the nth/nth-to-last of any/a specified length. I also have a simpler slower version, useful for checking that the faster function works and in case there are any bugs in the faster function. Please make any comments or notify of any errors, it is very hard to guarantee correctness.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 23 May 2017, 08:51, edited 1 time in total.
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions

27 Feb 2017, 19:36

Has anyone written a function to add indentation to lines of code?

Someone did link me to this, but I believe it's written in php not AHK:
online converter: converts your autohotkey code into pretty indented source code. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=8678
Autohotkey-code-prettify - in a web page - Github Project Hosting
http://sl5.it/SL5_preg_contentFinder/examples/AutoHotKey/converts_your_autohotkey_code_into_pretty_indented_source_code.php

Anyhow, I have written a function to add indentation to lines of code, I can't guarantee that it will work in all circumstances, however, it has worked correctly on all of my code that I tested it on.

[EDIT: 2017-03-22][This is pretty good, but it's getting the indentation wrong occasionally, in a few circumstances. I have mostly finished a more robust version.][More difficult is handling custom function names, or blocks without a preceding function name, which AHK allows, I'm working on solutions.][Basically my tests will be complete, when I can correctly indent an entire AHK script.]

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



If anyone has doubts about the value of indentation, please post below, because, apart from in a few situations, I don't think it adds much value either, it's more a tradition. It looks 'pretty' and it looks 'professional'.

Some further links I found:
Syntax-Tidy for scripts (indentation and case correction) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/2385-syntax-tidy-for-scripts-indentation-and-case-correction/
Auto-Syntax-Tidy = Somebody has it ? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=7317
Line based Parser for AHK Code v1.2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?p=43850#p43850

[EDIT:]
This is designed for working on a block of code/a subroutine, not on a whole script. Plus, use something like WinMerge to check before and after. Btw also, continuation sections, could potentially be an issue, if they contain lines that start with certain strings.

[EDIT: 2017-09-26]
New function: There are certain coding styles it doesn't (yet?) support, however, I was able to correctly indent my main written-by-me 40 or so .ahk files (i.e. scripts and function libraries).
indent code (automated code indentation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=37270
Last edited by jeeswg on 25 Sep 2017, 19:21, edited 3 times in total.
FanaticGuru
Posts: 802
Joined: 30 Sep 2013, 22:25

Re: text/list/table functions

27 Feb 2017, 21:18

There is a reason professional programmers' work looks professional, it allows them to do their job more professionally. Professional looking code is easier to understand for both the professional that wrote it and other professionals that need to understand it. A uniform formatting style is pretty much required to work as part of a professional programming team. Everyone on the team is expected to use a very similar formatting style and also coding style.

If you want the masses to accept and use your code, you are going to have to bite-the-bullet and conform to the masses, which you seem to be trying.

I hate spending the time to comment code as I find that the boring part of coding but I do try to put some extra effort in to commenting code I post. I am posting it to help people and comments are very helpful for others to understand code.

As far as I know there is no really good formatting scripts for AHK. There was Tidy Code by toralf but it is out of date to the point of not useable. I am talking code that can properly format pretty much any script. Handling functions, subroutines, hotkeys, hotstrings, comments, quotes, escaped quotes, join, etc. etc. You think you have it then run another large library or script from the forum through it and find another exception to the rule.

Because of several scripts I have written I am pretty well verse on the ins-and-outs of parsing the text of AHK files and have studied toralf's code extensively especially the RegEx. I have thought about writing a AHK formatter but once you get into it, it is quite a bit of work to handle all the formatting that AHK will accept. I might look at working on it again but the custom setup I have for SciTE4AutoHotkey now helps a lot with keeping my formatting consistent as I write it. My plan at one time was to be able to choose different formatting styles. https://en.wikipedia.org/wiki/Indent_style

Oh by the way, in almost every accepted style there should be an indent after a function definition:

Code: [Select all] [Download] (SaltInWound.ahk)GeSHi © Codebox Plus

JEE_StrIndentCode(vText)
{
vOutput := ""

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

Google Search, Dictionary, Thesaurus - Quickly Get Information from Specific Web Resources

[Function] Timer - Create and Manage Timers
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions (latest: add indentation, get nth(-to-last) line of specified length, html <> text)

04 Mar 2017, 20:30

Convert html to text / text to html via an HTMLFile object. Deal with character entities.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I would be interested in any definitive lists/methods for character entities.

Links:
[The Transform command can do text to html, but this will be removed in AHK v2]
Transform
https://autohotkey.com/docs/commands/Transform.htm
HTML, String [, Flags]

convert html special characters - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/92033-convert-html-special-characters/
UTF-8 HEX Text Conversion - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/93242-utf-8-hex-text-conversion/
User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions (latest: add indentation, get nth(-to-last) line of specified length, html to/from text)

30 May 2017, 19:42

Note: these functions have been tested but not exhaustively.

I may introduce versions of these functions that use one of 4 custom classes: case sensitive/insensitive, alphabetical/date creation order. I.e. custom types of array similar to the standard AHK arrays and the Scripting.Dictionary object.

Basic tips regarding objects:
- AHK arrays are case insensitive and alphabetical order.
- The Scripting.Dictionary object is case sensitive and date creation (date added) order.
- AHK arrays can handle string and numeric keys, e.g. it can have a numeric '1' key, and a string '1' key. The Scripting.Dictionary cannot handle numeric keys.
- One way to maintain the order of keys, is for the main array, with key K, to have an auxiliary array, with key N (number) and value K. You can then loop through the auxiliary array to retrieve the keys in order.

to create 'key 1, value 1', where value 1 is the name of a key in another array.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 3000
Joined: 19 Dec 2016, 01:58
Location: UK

Re: text/list/table functions (latest: add indentation, get nth(-to-last) line of specified length, html to/from text)

06 Jun 2017, 16:37

JEE_SortPathFindNextFile(vTextA, vTextB, vOffset) ;for use with AHK's Sort command
JEE_SortPathRegEdit(vTextA, vTextB, vOffset) ;for use with AHK's Sort command

Any comments are welcome.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Examples for getting a list of files, or a list of registry keys (via RegEdit), randomising the list, and then sorting.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “Ask For Help”

Who is online

Users browsing this forum: Odlanir and 44 guests