git: showing within-line changes … within a line!

Just found this while looking for a way to show changes within a line rather than on separate +/- lines.  “git diff –word-diff” does the trick!  Thanks to A few git tips you didn’t know about by .

For an extra-clean diff, the final command I used was:

git diff –word-diff –ignore-space-at-eol –patience -b -w –ignore-blank-lines <file1> <file2>

My git installation (version 2.8.3 on cygwin) defaults to a color diff, which makes it extra-easy to read.

Filename searching in Explorer – Windows 8.1 Enterprise

Some tips for filename searches in the “Search” box in an Explorer window in Windows 8.1 Enterprise.  I just found these out by trial and error.

  • You can specify “filename:” rather than “system.filename:” to search filenames.
  • The text after “filename:” will, by default, only match at the beginning of a word within the filename.
  • “filename:*foo” will search for foo, whether at the beginning of a word within the filename or not.
  • As far as I can tell, search filenames get an implicit “*” added on the end unless you specify otherwise.
  • To search for a word in the name and also the extension, use “filename:foo AND ext” where DOS would have required “*foo*.ext”.  I tried “filename:*foo*.ext” and “filename:(foo AND ext)” without success.  Remember, the “AND” has to be uppercase!

Happy searching!

C++11 with MinGW

Using standard MinGW (cc 4.9.3), I couldn’t compile C++11 test programs without lots of errors.  The answer: use -std=gnu++11 rather than -std=c++11.  Obvious, right?…

Test program:

#include <memory>
#include <iostream>
using namespace std;
int main()
    shared_ptr<int> x(new int(42));
    cout << (*x) << endl;
    return 0;

Error messages with “c++11”:

$ g++ --std=c++11 -o test test.cpp 
In file included from c:\mingw\include\wchar.h:208:0, 
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\cwchar:44, 
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\bits\postypes.h:40,
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\iosfwd:40,
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\memory:72, from test.cpp:1: 
c:\mingw\include\sys/stat.h:173:14: error: '_dev_t' does not name a type 
struct _stat __struct_stat_defined( _off_t, time_t ); 

and many, many more (444 lines total).

By contrast:

$ g++ --std=gnu++11 -o test test.cpp
$ ./test.exe

Much better!

Exercise for the reader: try TDM-GCC and tell me in the comments whether it works with c++11.

Fixed: Word VBA crashes on “Find.Execute Replace:=wdReplaceAll”

This morning I hit a test case in which, for the first time in over a year running the same Word VBA macro, a Range.Find.Execute Replace:=wdReplaceAll hung, then crashed Word 2013 (32-bit, running on Win8.1 x64).  The Execute was running inside a custom Undo record, and was the first action taken inside that record.

Searching led me to this forum post by vbRichard suggesting that the empty Undo record was the problem.  I edited my code to change the document after opening the record, before running Execute, and Execute now runs fine!  Thanks to vbRichard, whomever you are🙂 .  I also added code to clean up the change just before closing the Undo record.

Since my use case is English, I added a zero-width joiner (“ZWJ”, ChrW(&H200D)) before the text I was processing, then deleted it at the end.  I could have used any character I was confident wouldn’t appear in the input, or wouldn’t affect the function’s main task.  The result is below (licensed CC-BY 4.0).

' Top of module:
Private Const U_ZWJ = &H200D

' Inside a function:
Dim r as Range
' ... code here to set r ...
Dim undos As UndoRecord
Set undos = Application.UndoRecord
undos.StartCustomRecord "90125"     ' or whatever record title you like
r.InsertBefore ChrW(U_ZWJ)
    ' now r includes the ZWJ.  
r.MoveStart wdCharacter, 1          ' remove the ZWJ from r
' ... code here to process r ...
r.MoveStart wdCharacter, -1         ' re-select the ZWJ
If AscW(r.Characters.first) = U_ZWJ Then   'sanity check
    r.Collapse wdCollapseStart
    r.MoveEnd wdCharacter, 1        ' select only the ZWJ
End If