Menu

how to macro/keyboard insert DATE:20080216

2008-02-18
2012-11-13
  • - 2008-02-18

    I hope someone could give an example to help us newbies learn to customize macros and keyboard shortcuts for notepad++:

    I would like to make the key combination

    alt+1

    insert the string

    DATE::[year][month][day]

    at the cursor.

    For example, today is February 18, 2008, so it would insert

    DATE::20080218.

    (a side question:  is there a way to use python code (which I know) or lua code (which I don't) in the definitions of functions called by key strokes or macros)?

    Dave

     
    • Harry

      Harry - 2008-02-18

      You can check the InsertPlugin which has some date/time insertion options, record a macro with that (possibly combined with moving and copying text so the order is ok).
      Ive been playing with the thought of making a lua interpreter, but it didnt get very far (it was supposed to be some dynamic lexer, but lua is too slow for that ;)). You can check out simplescript for some scripting functions.

      -Harry

       
      • mapmike

        mapmike - 2008-10-15

        Wow, I'm very grateful to the people who posted in this thread! I was able to solve my problem of efficiently inserting timestamps in the format:

        yyyy-mm-dd-HH-mm

        1. I changed Windows settings through control panel -> regional settings -> ...

        2. I made a nice hotkey for the TextFX short date insertion. I picked Ctrl+F5, which is also the default.  The best I could do through regional settings gave me:

        HH-mm yyyy-mm-dd

        3. I made a macro that easily transformed that into the desired result with arrow keys, cut and paste, etc.  I made a convenient hotkey to press immediately after the other one: Ctrl+Shift+F5.

        So now I can do a rapid sequence of two hotkeys to get what I want, which I can live with until I become some kind of whiz in the distant future and make everything "perfect". :-)

        It's really sad we can't make macros for those plugins and dialog operations...

         
        • Daniel Spawn

          Daniel Spawn - 2008-10-15

          And can't the Ctrl+Shift+F5 macro also call the Ctrl+F5 function?

           
    • - 2008-02-19

      Thanks for the reply.  I got the InsertPlugin and it does have 2 date/time functions.  But the month doesn't have a leading 0 if one-digit.  I don't know how I would do conditionals.

      Is my next option to start coding C++ on these or a fresh plugin?

       
      • Nobody/Anonymous

        You could probably use a regex (CTRL+H or CTRL+R, check regular expressions option) to insert the missing 0's.

        Find field:
        DATE::(\d\d\d\d)(\d\d\d)$

        Replace field:
        DATE::\10\2

        This means a 0 will be inserted between the first (\1) and second (\2) grouped expressions of the find field. The $ is needed to exclude dates that already consist of 8 digits.

         
        • Nobody/Anonymous

          That is, if the date is on the end of the line.
          If there always is a dot behind the date, use "\." instead of "$".

           
    • Greg Bullock

      Greg Bullock - 2008-02-19

      In
      Control Panel > Regional and Language Options > Regional Options > Customize > Date
      set the Short date format to yyyyMMdd.

      Then use TextFX > TextFX Insert > Date & Time - short format.

      Regards.
      Greg

       
    • - 2008-02-19

      Thanks again for the input.

      The regional customization is neat, but it requires a date separator, so I could only get 2008.02.19 rather than 20080219 that I wanted.

      Then I tried to record it as a macro.  I started recording and did DATE:: then went to the textfx menu and chose short date.  It inserted in the file, but when I play the macro, I only get the date part.  Do macros not record menu actions, or is it something else?

      Then I noticed that ctrl+F5 does the textfx short date insert.  So I did that in the macro, but it stops at DATE::1.

      I'm learning.  More ideas?

      Dave

       
    • Greg Bullock

      Greg Bullock - 2008-02-19

      Macros record some, but not all, menu commands.  In particular, they do not record commands from the TextFX and Plugins menus, and they don't record menu commands that open dialogs, such as Find/Replace, but that's unrelated to the present problem.

      We should look into getting macros to record plugin menu commands; although, it might take a bit of work because macros are prone to redundantly record some of the individual steps that the plugins perform when the menu command is sent.  (For example, if pressing Ctrl+F5 inserts the date/time, then the macro is likely to record, and playback, both the <Ctrl-F5> keystroke as well as the insertion of the date/time text, giving you some garbled result).  Alas, I won't have time to look into this for a while.  Perhaps you or someone else can get to it before I do?

      In the meantime, I'm not sure what else to suggest right now, but if I think of something....

      Regards.
      Greg

       
    • - 2008-02-19

      OK, Thanks.

      For now I can do it in two key commands:  the DATE:: part with a macro, and ctrl-F5 to get (almost) the date format I want.

      I'm very interested in npp and hope I can participate in its development.

      Dave

       
      • Greg Bullock

        Greg Bullock - 2008-02-19

        > For now I can do it in two key commands: the DATE:: part with a macro, and ctrl-F5 to get (almost) the date format I want.

        Perhaps you can follow that sequence with a third key, playing another macro to remove the date-field separators?

        Regards.
        Greg

         
        • Greg Bullock

          Greg Bullock - 2008-02-19

          Better still, make it just two keystrokes, but in the reverse order: <Ctrl-F5> to insert the date, then a second keystroke running a single macro to (a) remove the date-field separators, and (b) insert the "DATE::" text.

          Greg

           
    • - 2008-02-20

      I'm not sure how to get a macro to remove the date-field separators?

      Also, the date includes 3:42 AM (variable length since could be 11:03 PM) at the beginning that I'd like to remove or move to the end so that the final is

      DATE::20080217

      OR

      DATE::20080217 AM 03:09

      so that it sorts in time order.

      ctrl-F5 now gives 3:42 AM 2008.02.20

       
      • Nobody/Anonymous

        Use SHIFT to select the variable length part, in combination with CTRL+CursorRight or CTRL+CursorLeft. This will select "by word" instead of "by character", which will ignore the variable length of the numbers.

         
    • Nobody/Anonymous

      Insert the date, press record, use ctrl arrows to move to the beginning of the date, type "DATE::", use ctrl-delete to remove unneeded timestamps, ctrl-arrow to move to the dots and delete to remove those too, then stop recording. Save the macro and voila :)

      -Harry

       
      • Greg Bullock

        Greg Bullock - 2008-02-21

        If you want to preserve the timestamps but put them at the end, then use Harry's instructions with a slight modification:

        Instead of "use ctrl-delete to remove unneeded timestamps", use <Ctrl-Shift-Right> to highlight the timestamp, press <Ctrl-X>, then after removing the dots, press <Ctrl-Right> <Ctrl-V>.

        Regards.
        Greg