Sharing how to do this using the NppExec plugin and Ruby.
Solution:
Approach: Get an external scripting language (in this case Ruby) to return the formatted timestamp and for NppExec to receive it and insert it into the cursor location in the current file shown in Notepad++.
First configure the console :
npe_console v+ // set console to receive output in $(OUTPUT) variable
npe_console d+ // set current working directory to same as current file
Then in NppExec > Execute menu command, enter the following snippet:
// Diary snippet (Generates timestamp YYYY-MM-DD--DAY--HH:MM for NPP++)
npp_console disable // turn off output displaying to console
// this ruby one-liner does the work
ruby -r Date -e "dt=DateTime.now; dname = Date::ABBR_DAYNAMES[dt.wday]; puts dt.strftime(\"%Y-%m-%d--#{dname}--%H:%M\");"
sel_settext $(OUTPUT) // put result at cursor in current file
npp_console enable // restore output displaying to console
npp_console 0 // hide the console window
This uses the Ruby engine to generate the timestamp and inserts it where the cursor is in the current file in Notepad++. The result (with about a 500ms delay) is the timestamp:
2012-08-20--Mon--20:16
Note: While this certainly does the job, if anyone has a solution that doesn't rely on anything external (in this case Ruby), that would be better.
Edit: "Productionising" the solution... (robustness and convenience)
By following the steps below, the above solution can be productionised...
A hurdle is that closing Notepad++ loses the console configuration, so this has to be setup on every re-start.
So we set up the console configuration as a script that is run automatically every time Notepad++ starts.
Then associate a keyboard shortcut (hotkey) to the diary script for convenience.
Step 1: Enter the diary code into an NppExec Excute... dialog: Plugins > NppExec > Execute...
, giving it a name (you'll use that name later)
Step 2: Enter the setup_console configuration code similarly:
Steps 3, 4, 5: In Plugins > NppExec > Advanced Options
, set setup_console to run at startup (3), create a Menu item for the diary code (4), and put the Menu item into the Macro
menu (5):
Step 6: Set a keyboard hotkey (shortcut) to the diary script: Settings > Shortcut Mapper... > Plugins
, and scroll down till you find the diary script name you used...
Result: Looking under the Macros
menu command, you'll see your new Timestamp command with keyboard shortcut.
Done!
What are the dashes between DD & DAY and DAY & HH? – Louis – 2012-08-20T10:10:20.737
The double dashes -- are to visually set-off the date from the day from the time. Seems more pleasing aesthetically than
2012-08-19-Sun-20:30
. (Would like the timestamp to be a single unit of characters, hence don't want spaces...) Have edited the question accordingly. – Assad Ebrahim – 2012-08-20T15:57:48.6471Having done heavy coding work over the years using Notepad++ due to its out-of-the-box powerful featureset, you have no idea how many times I've wanted to be able to plug into it with a scripting language from within the GUI. Thanks for posting this! – Ben Richards – 2012-09-06T20:09:53.747