[Request] Snippet Editor - Check temp file for external changes and update in Snippet Script box
I was looking at https://github.com/lintalist/lintalist/blob/fc1bea39d539baf2eb7c3f2c195e514b9b4c6bdf/include/Editor.ahk#L837-L869
To stop losing work by accident, could the __tmplintalistedit temp file be checked for changes to be copied when Modified Date is different?
The snippet Script box could periodically sync with the file until it's deleted.
Something like this maybe?
[!NOTE]
I have my temp file named as .ahk rather than .txt
check_date(){
global TmpDir
FileGetTime, current_modified , %TmpDir%\__tmplintalistedit.ahk, M
if (prev_modified = current_modified)
return
prev_modified := current_modified
FileRead, NewText, %TmpDir%\__tmplintalistedit.ahk
return
}
I had been looking into it because the tmp file gets deleted at line 853 since changing tabs in VScode will change the Window Title that's being monitored.
I realise it is not ideal, but it is a relatively easy solution. As is is now the snippet editor is activated again when the "window" is no longer available, not sure how to solve that if you don't use the WinExist
- Using WatchFolder() might be a good way to monitor for file changes (size, time) https://www.autohotkey.com/boards/viewtopic.php?f=6&t=8384
- Update the edit control when changes are detected
- Delete the
__tmplintalistedit.txtfile when the snippet editor closes
That leaves us with the problem how detect when the text editor is done/closed so the snippet editor is focused again.
The .txt is useful as on nearly all systems there will be an editor assigned to .txt files so run should open the set editor (even if it is just notepad)
Using WatchFolder() might be a good way to monitor for file changes
I was looking into that, but didn't want to add too much extra code since I was thinking of solutions for a possible Pull. I guess whatever is less resource intensive would work.
That leaves us with the problem how detect when the text editor is done/closed so the snippet editor is focused again
Yeah, that's been difficult with vscode since I haven't been able to tell if that file is open in a different tab. Even the process commandline doesn't show the file if the window is shared.
The .txt is useful as on nearly all systems there will be an editor assigned to .txt files so run should open the set editor (even if it is just notepad)
That's fine, I was just mentioning it because my example code had .ahk.
I had made the change for myself so I wouldn't have to keep switching the Language Mode to ahk when it's opened in an IDE. Maybe a setting for the extension could be added where the optional Editor is defined 🤔
Not all that important though.
I don't use vscode but in my editor I simply say .txt files should be treated as .ahk files re syntax highlighting ;)
I would do that, but I use vscode (well, vscodium) as my general text editor too 😅
I've tried some advanced code I found on the ahk forum to get a list of all opened files by a process. Indeed it shows for notepad and some editors that the temp file is open and of course when it is closed. But not for a portable version of vscodium for example, so I suspect that that is also not a fail safe method.
Therefore I'm thinking about adding a checkbox "Monitor editor" that when checked (default) uses the current behaviour with the timer.
When unchecked, the button which launched the editor gets a new text and you have to click that button to load the edited file manually, and then it will be deleted (or attempt made, the file could still be open but in that case I think it is user error)
That'll actually work fine. Simple 😃
You can try the attached editor.ahk (replace the one in include\ and restart.
If you want to change the extension of __tmplintalistedit.txt to __tmplintalistedit.ahk or something else, manually add an entry to session.ini under the [editor] section like so:
[editor]
EditorTempFileExtension=ahk
If SnippetEditor is not defined you may be asked to select a program as I now use Run, edit instead of just Run reason being if you do set it extension to ahk it would run the script instead of opening it.
📁 Editor.zip - updated 2
Thanks! I'm still testing, but I noticed 'Monitor Editor' doesn't seem to work when checked. Closing the file in editor doesn't cause the tmp file to be copied then deleted.
btw, it looks like you forgot to add the window focus fix from #267
I worked from and older branch so yes 267 was omitted, updated the above edit.ahk so should work better now. Thanks for testing.
To add, don't keep this tab with this title active/open because it will match the title criteria and won't load the edited file 😹
Things are better (the Editor button isn't changing when it shouldn't), but it's still unable to detect when I close the editor. It might be the way I'm launching my editor. I'll test some things out.
If you have this tab open/active it will detect it as a valid window due to the title of your request (it includes __tmplintalistedit) - edit: removed it from the title...
If you have this tab open/active it will detect it as a valid window due to the title of your request (it includes __tmplintalistedit) - edit: removed it from the title...
lmfao, I completely misunderstood your original statement. Got it. It's working just fine 🤣
The code posted was more proof of concept, it doesn't work yet with syntax highlighting enabled and the repetitive code needs to be condensed as well, so re-opening so I have it on my todo list for the next update.
Should I remove the pull request or keep it up for you to modify?
- [x] Probably close pull request #277
Closing it would be best :)
Just
You can try the attached
editor.ahk(replace the one ininclude\and restart. If you want to change the extension of__tmplintalistedit.txtto__tmplintalistedit.ahkor something else, manually add an entry tosettings.iniunder the[editor]section like so:[editor] EditorTempFileExtension=ahkIf
SnippetEditoris not defined you may be asked to select a program as I now useRun, editinstead of justRunreason being if you do set it extension to ahk it would run the script instead of opening it.📁 Editor.zip - updated 1
Should line 975 maybe be changed from
IniRead, EditorTempFileExtension, %A_ScriptDir%\session.ini, editor, EditorTempFileExtension, txt
to this? (maybe even moved)
IniRead, EditorTempFileExtension, %A_ScriptDir%\Settings.ini, editor, EditorTempFileExtension, txt
.txt was being used instead of .ahk since the value was being referenced from session.ini and ignoring the Settings.ini
I thought it best to keep the EditorTempFileExtension in session.ini as I believe it is rather an exotic setting that wouldn't be used (but was easy to add).
For settings in settings.ini I would "need" to have a include\settings\EditorTempFileExtension.ini ( I would make it hidden, but need to add the help text regardless) and update ReadIni.ahk as well.
Oh, I see. I had asked since you told me to put the change in Settings.ini
Found a tiny bug in the posted Editor.ahk.
Line 915 has ToolTip % whichcontrol which causes the word Script to stay stuck on the screen after you click Load From File
Ha ha wondered if you'd spot that.. (was for debugging)
re https://github.com/lintalist/lintalist/discussions/276 and just for testing (I'll move some code elsewhere later on):
see Update 2 editor.ahk above, to set/select another text editor in the editor:
Make an editors.ini like so in the lintalist folder:
[settings]
TextAdept=c:\Portable\TextAdept\TextAdept.exe
Pragtical=c:\Portable\pragtical\pragtical.exe
then restart lintalist, now you should see ▼ Set editor just before monitor editor checkbox which just shows a menu so you pick another editor. The Default editor is the SnippetEditor you set in ⚙ Configuration.
As I think this is rather an expert/niche option I'll keep it like this e.g. only show ▼ Set editor when there is a editors.ini
Thanks for making changes, however, I don't see Editor Update 2 anywhere...
weird I tested the download and it worked, now the comments seems to be back to update 1, it should be here (edited it again) https://github.com/lintalist/lintalist/issues/268#issuecomment-2143772783 and to be sure here as well Editor.zip - update 2
edit: on line 41 of edit.ahk there is a debug msgbox that should show the contents of the editors from the ini if it is empty something is wrong obviously (with the ini or location of the ini)
Thanks, I was able to get the changed editor file.
I haven't had any major problems yet. Just a small one; the first time you launch bundle editor (after completely closing Lintalist, not reloading), the Set Editor control gets overlapped and you have to adjust the window size to make it stay until Lintalist is started again.
I also learned to avoid putting quotes around the values in editors.ini (even if it has spaces in its path) else they get double quoted by line 932, causing it to instead open an Explorer window 😅
Thanks for testing. I think it isn't such a problem as you can indeed make the window a tad wider (it remembers the width/height +X/Y pos between sessions). There isn't really that much room to place it elsewhere (I didn't like the placement before the edit button) and it will only be shown when there is an editors.ini and I suspect it be very rarely used. I could just use ▼ but it so tiny to click with the mouse.
So I'll leave it like this for now, unless dozens of people start complaining about it :)
I fixed #288 and moved the set editor to the menu bar (obviously better).
As it is possible to cancel the edit and because I now disable the other 2 edit buttons I've added a "Reset (enable) Edit Buttons" option to the edit menu as well:
Edit menu only available when there is an
editors.ini
Nice. Having the Editor in a menu really does make sense. I can't believe it didn't even occur to me.
Added to v1.9.23, I'll close the issue but feel free to report any problems https://lintalist.github.io/#Configuration-SnippetEditor