Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #20720
    LifeTimer
    Participant

    The (very useful) filtering feature of EmEditor has import/export buttons in the “Advanced Filter” dialog.
    I’ve been trying to script these operations with macros, but as soon as I perform an import/export while recording a macro, I only get the separate filter operations that I import dumped to the macro, instead of the import operation itself.

    Scripting the import (and export) operation itself (with a possibility to provide the filename to be imported/exported) would be highly useful, so my question is if this is already possible, or if it could otherwise be implemented in the macro capabilities of EmEditor?

    #20746
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    Just to be clear, do you want to record exporting the current filter as a macro?

    #20749
    LifeTimer
    Participant

    That depends on what you mean by that. :-)

    What I want is to be able to tell a macro to “import the (previously exported) filter file at the following path right now, and apply this filter”.

    In other words, I want to automate the action of going into the advanced filter dialog, pressing the “Import…” button, selecting a certain path, clicking “Open…” and then clicking the “Filter” button.

    The reason for this is that I want to be able to create “default filters” for arbitrarily many different files in my computer, in a generic way. As soon as I open any file in my computer, my macro will find the correct filter file for this specific file (based on its path), and then immediately import and execute this filter.

    The reason for not storing the entire filter inside the macro itself is that the filters need to be possible to update often and fast, and by several different users, and that creating new such default filters for new files should be as simple as exporting a filter to the corresponding path for that file, rather than recording a macro for it, and with the corresponding automation implemented in EmEditor of also the export filter operation, this will also be as simple as the press of a hotkey for my macro!

    So, my goal is the have on hot-key in EmEditor for “apply the default filter for the currently open file”, and another hot-key for “save the current filter as the default filter for the currently open file”, and for this to be possible I need to be able to automate the above mentioned functionality.

    #20751
    Yutaka Emura
    Keymaster

    Hello,

    Can you just select a previously used filter by clicking the v button (or pressing the DOWN key) on the drop-down list box in the Filter toolbar?

    #20752
    LifeTimer
    Participant

    Unfortunately, that solution would not work since I have 500+ different files that I work with regularly. :-( That method would also eliminate the above-mentioned flexibility with regularly being able to update all these different filters for the different files by just adding more filter-levels in them and then quickly being able to save the filter automatically to the right file (instead of browsing manually to the correct file among the 500+ filter export files that will be required).

    So pretty please, with sugar on top, couldn’t you possibly implement macro commands just for the following?

    import_and_apply_filter_from_file(path)

    export_current_filter_to_file(path)

    I’m quite sure it’s not just me that would find good use for this flexibility, after all? I really love the flexibility of the filter functionality in EmEditor, but this is a roadblock that I just can’t seem to get past without having this little extra functionality added to the macro actions first. :-/

    #20755
    Yutaka Emura
    Keymaster

    Thanks for the function proposals. These two function prototypes are helpful. Do you want to export filters to TSV files?

    #20757
    LifeTimer
    Participant

    Excellent, and yes, the TSV filter export/import format would be great!

    Thanks a lot for being so responsive to customer suggestions, as usual, it really makes my lifetime license of EmEditor feel like a good choice every time!

    #20780
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    It will take some time until we can release a new version, so I built a test version for you:

    Here is an example:

    sTsvFile = "E:\\Test\\filter.tsv";
    
    // export the current filter to a TSV file.
    document.ExportFilter( sTsvFile );
    
    // import the TSV file and apply the filter
    nCount = document.ImportFilter( sTsvFile );
    
    #20783
    LifeTimer
    Participant

    Thanks so much, I’ve downloaded it now and it works great! What an excellent service you provide!! :-)

    One small thing related to this that I just came to think about is the following:

    Is there any way to inspect the items of the currently applied filter from a macro? At least how many they are? The reason I’m asking this is that I just got a little nervous about mistakenly pressing the shortcut for my export filter macro instead of the import filter macro, and thus overwriting the currently exported macro with an empty filter, which would not be very fun. :-( If I could just inspect the number of items in the current filter from my export macro, I could at least implement a warning when trying to export an empty filter, that’s what I thought.

    I cannot find any separate Filter object in the macro reference, but rather just the Filter() method of the Document object, so I unfortunately cannot imagine how to accomplish this currently? Is it possible, or could you perhaps otherwise implement a quick method/property for this too (i.e. returning the number of items in the current filter)?

    Thanks so much again for your excellent support!

    #20788
    Yutaka Emura
    Keymaster

    ExportFilter shouldn’t overwrite an existing file if the filter is empty, instead it should return an error. I will fix ExportFilter on the next version. I also might consider adding more methods or properties to inspect the filter items.

    Thanks!

    #20789
    LifeTimer
    Participant

    Thanks as usual for being so responsive!

    About the methodology you mention above, of always returning an error if trying to write an empty filter, it is indeed a good safety precaution for the situation I mention, but unfortunately it might also have unintended side-effects in other situations.

    One such situation is the functionality that I mentioned above that I’m implementing, i.e. automatic “default filters” for a large bunch of files on my disk (every file will have a corresponding filter export file in a certain directory, which will be imported by a macro based on the directory and filename of the currently edited file in EmEditor). In some cases I will therefore want to empty this default filter for a certain file, and if exporting an empty filter has been made completely impossible, as you suggest above, there will be no way to reset such a default filter once it has been exported with any contents at any one point. :-(

    If the EmEditor macro capabilities include the possibility to delete arbitrary files on disk (I’m not aware if it does this though?) I could of course just make my macro delete the exported file completely as soon as I try to export an empty filter, BUT, as long as there is also no way for me to inspect if the current filter is empty from a macro (for example by the kind of method I suggest above, querying the current number of items in the filter) I cannot even do that, since the macro would in this case never be able to tell if the filter is empty or not. :-(

    So, if you choose to implement the “impossible to export empty filter” functionality (and if it is at the same time possible to somehow delete arbitrary files from disk from EmEditor macros), please do indeed consider adding at least the possibility to query the current number of items in the currently applied filter from inside macros, so that I can implement an “empty filter” special case myself for the situation of wanting to “clear” an exported filter file.

    If there is not a possibility to delete arbitrary files from within EmEditor macros though, I cannot see any other way of solving this except somehow making it possible to export empty filters after all, possibly by using some kind of special flag to the export command (for example FORCE_EMPTY_FILTER_EXPORT or similar).

    In my opinion, being able to query the number of items in the current filter from macros would make the absolutely cleanest solution though, since the macro developer can then be responsible himself for any extra security measures he might want to implement in order to avoid unintentionally writing an empty filter over an existing filter export file.

    #20795
    Yutaka Emura
    Keymaster

    Hello,

    To delete a file, you can call:

    function DeleteFile(filespec)
    {
       var fso;
       fso = new ActiveXObject("Scripting.FileSystemObject");
       fso.DeleteFile(filespec);
    }
    

    See: https://msdn.microsoft.com/en-us/library/thx0f315.aspx

    However, I will add an ability to query the filter items in macros.

    Thanks,

    #20796
    LifeTimer
    Participant

    Excellent on both accounts, thanks as usual for your responsiveness!

    #20829
    Yutaka Emura
    Keymaster

    Hello LifeTimer,

    I released v16.0.0 beta 1 today. New Filter and Filters objects were introduced while ExportFilter and ImportFilter methods are obsolete now. Please refer to http://www.emeditor.org/en/macro_filters_export.html and http://www.emeditor.org/en/macro_filters_import.html for examples of exporting and importing filters.

    Thanks!

    #20831
    LifeTimer
    Participant

    Excellent, thanks! I’ll take a look at it and get back to you if I find any problems.

    #20833
    LifeTimer
    Participant

    I’ve tested it now, and it seems to work great, thanks!

    One detail is that the entire macro crashes if you try to export an empty filter (which could be desirable in some situations), so perhaps this should be possible, or at least it should only return some error code instead of crashing the entire macro? (it’s still no show-stopper for me since I can just check the filter count and then delete the file instead, but it still might be more robust through)

    An error code might perhaps also be preferable to crashing the entire macro (which currently happens) if you try to import a filter file that does not exist?

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.