Automatic highlighting for files with varying file extensions (solved)

Automatic highlighting for files with varying file extensions (solved)

5

    Mar 07, 2016#1

    Hey guys,

    is there a way to activate automatically the highlighting in UltraEdit for files that don't have a file extension?

    Following situation:
    I'm using UltraEdit to edit files in our mainframe. We connect through FTP to the single members. Obviously these members are stored without any file extension on our mainframe. So, when the member gets loaded in UltraEdit, the automatic highlighting doesn't work.

    Maybe there is a way to parse the file 'to be opened' and add a file extension before the process of highlighting starts?

    The information which wordfile (and in the end which highlighting has to be taken) we have because the structure of our library contains the keyword 'cob'.

    Example: The member to be opened is named 'AB111'. The library that contains the member is named 'ABCD.EFG.COB.SOURCE'.

    Thanks for your suggestions.

    6,681583
    Grand MasterGrand Master
    6,681583

      Mar 07, 2016#2

      Readme for the Syntax Highlighting forum contains Specifying a default language for all unknown files.

      There are whether macro nor scripting commands for selecting a syntax highlighting to active file.

      When a user opens a *.uew file currently loaded into memory and applied on 1 or more opened files, modifies and saves the wordfile in same instance of UltraEdit, UltraEdit reloads the syntax highlighting definition from this modified *.uew file and applies the updated syntax highlighting on the other files opened in same instance.

      So according to your idea I wrote a small macro which modifies the last file extension in a wordfile specified in the macro with complete path and file name according to file extension of active file if the file contains a specific string.

      Here is the macro code I wrote testing this idea:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      Top
      Find MatchCase "C/C++"
      IfFound
      UltraEditReOn
      Clipboard 9
      CopyFilePath
      Open "C:\Users\UserName\AppData\Roaming\IDMComp\UltraEdit\wordfiles\c_cplusplus.uew"
      Find MatchCase RegExp " [a-z0-9_]+$"
      Replace " #>^c"
      Top
      Find MatchCase RegExp "#>*.^([a-z0-9_]+^)$"
      Replace "^1"
      CloseFile Save
      ClearClipboard
      Clipboard 0
      Top
      EndIf
      
      I put this macro into a macro file and specified at Macro - Set Macro for File Load/Save to run this macro 1 times on each file open.

      This macro searches in just opened file for the string C/C++ and if indeed found, opens the wordfile for C/C++ and replaces the last file extension in first line by the file extension of the just opened file.

      In my test case I put C/C++ into a Test.tmp file and close that file. I prepared wordfile c_cplusplus.uew for replacing last file extension by opening it once manually, append file extension XXX, saved and closed the wordfile. As I next opened the file Test.tmp containing the string C/C++, the macro opened the wordfile, replaced XXX by tmp, saved and closed the wordfile and the Test.tmp file was indeed highlighted now with language C/C++.

      The macro could also modify a file name specification in the wordfile instead of a file extension specification if the wordfile is defined to highlight files depending on file names instead of file extensions.

      Note: It is not possible to use %APPDATA% in the macro. Environment variable expansion by command Open is not supported. So the wordfile must be specified with fully qualified name for the current user on current machine. Of course the wordfiles directory can be configured to be the same for all users on all machines as I have done on my machines (makes it easier to synchronize user configurations).

      So in general this works. But honestly this is in my point of view an dirty hack for saving the manual selection of the syntax highlighting by the user via status bar (UE for Windows >= v19.00), by a click on appropriate language in View - View as (Highlighting file type) or pressing the key assigned to command ViewShowAsLanguageX for the syntax highlighting language suitable for the opened file.
      Best regards from an UC/UE/UES for Windows user from Austria

      5

        Mar 08, 2016#3

        Hi,

        thanks for the detailed answer. It works indeed. :)
        But as you already mentioned, it seems a bit dirty.

        Anyway, thanks a lot for your evaluation. Maybe in some far future there will be some native solution in UltraEdit.