Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExplorerCreateFile: set encoding of new files content #60

Closed
ewerybody opened this issue Jan 29, 2022 · 14 comments
Closed

ExplorerCreateFile: set encoding of new files content #60

ewerybody opened this issue Jan 29, 2022 · 14 comments

Comments

@ewerybody
Copy link
Owner

@Cyberkabauter contributed an idea in a2#250:

It would be great, if I could define the fileformat of the textfile (UTF8 and so on)

Yes! Good idea! I wonder if that acually works if there is no content given yet but it all comes down to the capabilities we get from Autohotkeys FileEncoding

@Cyberklabauter
Copy link

Yes, should work with FileEncoding :).

@ewerybody ewerybody changed the title ExplorerCreateFile: set encoding of new files conten ExplorerCreateFile: set encoding of new files content Feb 5, 2022
@ewerybody
Copy link
Owner Author

Hey @Cyberklabauter its in! :)
image

@Cyberklabauter
Copy link

Cyberklabauter commented Feb 10, 2022

Awesome. Thx so much! Another of my scripts I can drop.

  • I would recommend to clearify UTF-8/16-Raw adding "(BOM)" or "(with BOM)", which is the more common term.
  • I also would like to see ANSI Latin 1 (CP1252)
  • If you want to make it really flexible, user could add their own CP number.
  • Looking at your screenshot: I would like to have an option to open the created file with my preferred editor (accepting relative paths to it) immediatly.
    -> Like: Loop -> FileExist() -> run
    Would it be possible to add?

@ewerybody
Copy link
Owner Author

Ah ok 👍 I was just grabbing the exact terms from the FileEncoding docs, added them to the ui/a2ahk.py and filled the menu like that.

I wouldn't have thought that these are needed. But here we have a request :) I wonder how I'd do the "any" codepage thing.

And just to clarify: The RAW ones are the BOM ones? I think I'll add a link to the Autohotkey docs right in the menu...

@ewerybody
Copy link
Owner Author

OK. For now I put an integer to set the encoding from that short list ..
So I'll just change it to be a string then. Just need to match the display names to the actual names from the docs to be accepted by the command. Its a little more fiddly but not too bad.

The thing with the opening ... sorry for being so picky with this but this would be out of the scope of this issue. Moved it to a new one #66 :)

@ewerybody
Copy link
Owner Author

wip: Docs link already works as well 👍
image

@Cyberklabauter
Copy link

You are fast. Wow. I think it adresses a smaller group of users. Anyways, it is quite powerfull option, to create files very quickly which matching your needs.

Thank you!

And just to clarify: The RAW ones are the BOM ones? I think I'll add a link to the Autohotkey docs right in the menu...

Sorry: This was misleading. Somehow I wrote it upside down. Of course RAW stands for WITHOUT BOM (Byte Order Mark).

  • UTF-8 RAW
  • UTF-8 (with BOM)
  • UTF-16 RAW
  • UTF-16 (with BOM)

@ewerybody
Copy link
Owner Author

Ah Ok I see. looking at the docs it looks like their order is rather:

  • UTF-8 (with BOM)
  • UTF-8 RAW
  • UTF-16 (with BOM)
  • UTF-16 RAW

🤔 But the "standard" encoding in these terms would be UTF-8 RAW is that correct?

Now .. I think I'll remove this CONST and make it a JSON in the module folder
with key:value pairs like ValidAHK-Encoding:Display Name

@ewerybody ewerybody reopened this Feb 11, 2022
@Cyberklabauter
Copy link

Yes, As I know the UTF-8 Specifications recommend UTF.8 without BOM. But this topic is quite confusing and I am not an expert on it. AHK usually adds a BOM; From the FAQ:

To read other UTF-8 files which lack a byte order mark, use FileEncoding "UTF-8-RAW", the *P65001 option with FileRead, or "UTF-8-RAW" for the third parameter of FileOpen. The -RAW suffix can be omitted, but in that case any newly created files will have a byte order mark. look at the AHK FAQ

I interpret this, that if you don't use the UTF-8-RAW option (which most scripts won't do) with FileRead or FileOpen BOM is automatically added to the string and represented in each files you will save the string to.

@Cyberklabauter
Copy link

I just had a look at my notes why I use BOM with my AHK scripts: Lexikos recommended it, so I decided to go with it:

My recommendation for AutoHotkey v1 is still UTF-8 with BOM. UTF-8 without BOM will not work without the /cp65001 command line switch, such as with portable AutoHotkey.exe or without the UTF-8 option enabled in the installer.
The top line of the FAQ does not specify with or without BOM. In all but the most recent versions of Notepad, UTF-8 with BOM is just "UTF-8", and ANSI is the default. AutoHotkey does not exclusively run on the latest Windows 10 builds. Further down the FAQ says "To save as UTF-8 in Notepad, select UTF-8 or UTF-8 with BOM from the Encoding drop-down in the Save As dialog", but either option could include a BOM, depending on the Notepad version. ([Source]https://www.autohotkey.com/boards/viewtopic.php?p=345161#p345161) )

@ewerybody
Copy link
Owner Author

ewerybody commented Feb 11, 2022

Ok. We should have some defaults anyway. I'd suggest to have sth like:

  • .ahk
    • encoding: UTF-8 (with BOM)
    • content:
      #SingleInstance, Force
      SendMode, Input
      SetWorkingDir, %A_ScriptDir%
  • .txt
    • encoding: UTF-8-RAW (without BOM)
    • no content
  • .py
    • encoding: UTF-8-RAW (without BOM)
      def main():
          pass
      
      if __name__ == '__main__':
          main()

but that's another topic again. But might be easy ;)

@Cyberklabauter
Copy link

Can't say something to python. The rest looks good or how I would chose it. May,

SendMode, Input

to keep same coding style (just because it is a template 😉)

@ewerybody
Copy link
Owner Author

Ok. I made some UX improvements and made the 2 things "create from menu list" and "create from clipboard" more or less work basically the same, made them all have all their features with porting some things to the main lib. like:

  • create file input dialog now part of the explorer lib
    • pops again if file exists
    • takes care of default file extension (and different capitalizations)
    • handles empty input
  • path_get_free_name ported to path lib
    • already provides available file name in dialog on first pop

And also:

  • ComboBoxes can be connected with alternative trigger_signal, so we can have either index OR text (was index only)
  • error msgbox when files for some reason were not created (unknown encoding or image file extension for instance)
  • combobox is now writable
  • first encodings in combo are filled from JSON file which could be extended on demand.
  • ...

@ewerybody
Copy link
Owner Author

having defaults is a new issue now :) #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants