Some bookmarklets

A custom tea timer for

javascript:(function(){var timestr=window.prompt("Time in sec?","120"); if(timestr===null) /*Cancel*/ return; clock.stop(); clock.reset(); var t = +parseInt(timestr,10) || 0; /**/ if(t<=0) return; clock.setTime(t); clock.start(); })();

A message I have found myself typing frequently on Stack Overflow: ūüôā

javascript:!function(){var t=document.querySelector.bind(document),o=t(".edit-post");if(o){var e=t(".js-add-link.comments-link");if(e){;var a=t('textarea[name="comment"]');a&&(a.value="Welcome to the site! Check out the [tour]( and the [how-to-ask page]( for more about asking questions that will attract quality answers. You can [edit your question]("+o.href+") to include more information.",a.scrollTop=a.scrollHeight,a.focus())}}}();

As compressed by; non-minified is:

 var qsel = document.querySelector.bind(document);
 var edit_link = qsel('.edit-post');
 if(!edit_link) return;
 var add_comment = qsel('.js-add-link.comments-link');
 if(!add_comment) return;;
 var textbox = qsel('textarea[name="comment"]');
 if(!textbox) return;
 textbox.value =
"Welcome to the site! Check out the [tour]( "+
"and the [how-to-ask page]( for "+
"more about asking questions that will attract quality answers. You can "+
"[edit your question](" + edit_link.href + ") to include more information."
 textbox.scrollTop = textbox.scrollHeight;

These are the first two I have written.  I  hope they are useful to you, or serve as helpful examples if you are writing your own bookmarklets!


NBSP in Word, part 2

This is a follow-on to my¬†previous post¬†on the subject. ¬†These are my notes as I’m working, so they don’t read very well as text ūüôā .

Another test, on a different file exhibiting the same problem:

In the UI:

  • Removed all the new-style equations (OMath objects)
  • Changed all OpenType fancy features to defaults (in the Character Properties)
  • Changed the proofing language for all text to English

In word/settings.xml:

  • Removed FELayout
  • Removed all w:compat/w:compatSetting except for [@w:name=”compatibilityMode”]
  • Left m:mathPr for now, but I may remove that another time.¬†Edit: I removed that below.

Did `find . -name \*xml | xargs grep -il asia`.  That gave me word/{document,numbering,settings,styles}.xml.

Used XML Notepad 2007 to move tags onto their own lines — just open the file, then save it.

settings.xml: it was w:themeFontLang.  Leaving that in for now.

styles.xml: It’s a bunch of <w:lang/> and <w:rFonts/> (`grep -i asia word/styles.xml |sort|uniq|less` is my friend!). ¬†Leaving them in for now.

numbering.xml: Again, just <w:rFonts/>.  Leaving them for now.

document.xml: There were two lonely <w:rFonts/> tags!  Those I left in at first.

Zipping it

I tried using 7z, both from the context menu and with `7z a -tzip -mm=Deflate -mx=0 ../draft8e.docx *` (7z command-line options reference). ¬†However, Word 2013 didn’t like either. ¬†I used Send To | Compressed Folder, and that was OK. ¬†A problem for another day.

More changes

Result?  Still no luck.  Time to strip the rFonts!

  1. Remove the rFonts referencing asia (/asia/g, in fact) from document.xml.  Result? No luck.
  2. ¬†Remove that pesky m:mathPr from settings.xml. ¬†You know, I wonder… ¬†Result? ¬†No luck.
  3. Remove w:themeFontLang from settings.  In styles, leave w:val, but remove w:eastAsia and w:bidi.  Result: success!!!!

So if you do all of the above, you’ll probably be OK ūüôā .



Word 2013 non-breaking space width: an end to the insanity!

Pre-Word 2013, a persistent annoyance was that non-breaking spaces (Chr(160)) were fixed width, even in justified text.  Word 2013 changed that.  Now, in justified text, regular spacing and non-breaking spaces are the same width.


If you’re lucky.

User¬†slasza¬†on Microsoft Answers posted this test case from Word 2013, in which everything should have been right, but the nonbreaking spaces still didn’t show up:

NBSP failure – image by slasza

I ran some test files and took a look at the Word XML, and found the culprit at last!  It is the <w:useFELayout/> tag in the <w:compat> group in word/settings.xml.  If that tag is present in a Word 2013 document, nonbreaking spaces are fixed-width.  If it is absent, nonbreaking spaces are variable-width.

More detailed instructions on how to fix this are coming soon.  But rejoice that at least now you know what the problem is!

Edit 1

I just fixed one legacy file by going on an odyssey through the UI and the XML.  I:

  1. In the UI, turned off all the fancy OpenType features
  2. Set the proofing language to US-English for all text
  3. In word/settings.xml, removed FELayout, everything under w:compat except for w:compatSetting, and I think a few other things under /w:settings.
  4. In word/*.xml, removed just about every mention of the word “asia” (case-insensitive)

And my NBSPs are finally variable-width!

vim: cleaning up mixed indents

Thanks to the wiki for this.  If you run across a file that mixes tabs and spaces (ewww!), set the tab settings the way you want (e.g., ts=4 sts=4 sw=4 et ai) and run


to convert all the tabs to the right number of spaces. ¬†This takes tab stops into account, which :%s/^I/ ¬† ¬†/g won’t.

This replaces what I used to do, which was /^I s<Tab><Esc> followed by a whole lot of n.n.n.n.n.n.n.n. … . ¬†One command is much better ūüôā . ¬†I’m not even going to try to count the keystroke savings on my current project (pym, a preprocessor written in Python).

Vim: joining lines having continuation markers

This handy file-renaming script at Perl Monks has source code with red “+” marks marking wrapped lines. I pasted it into Vim and wanted to wrap those lines back to the way they should be. After a bit of fiddling, I got:

:g/^+/execute "norm 0x" | .-1,.j!

The `g/^+/’ finds the lines beginning with a “+”. Then the `execute “norm 0x”‘ deletes the “+” (“0” moves to beginning of line; “x” deletes), “|” marks the next command, and `.-1,.j!’ joins (“j”) the current line (“.”) with the previous line (“.-1”) without whitespace (“!”) added between the lines.

I leave it to you whether I have too much time on my hands.

Solved: Windows Media Player 12 won’t recognize audio CD

Never had a problem before, but today WMP12 (on Win8.1 Enterprise) wouldn’t recognize my new copy of Music of the Spheres by Mike Oldfield (thanks to B. and N. for an early Christmas!). I could play it just fine on VLC, so I knew it wasn’t the hardware. It’s working now, thanks to this forum post and this Windows Club page.

  1. I ran the WMP troubleshooter using Start | Run with the following command line:

    msdt.exe -id WindowsMediaPlayerConfigurationDiagnostic
  2. I hit “Advanced” and selected “Run as Administrator.” (Not sure if that would have been required, but it’s what I did.) I also cleared “automatically apply fixes” because that’s the kind of person I am!
  3. I let it do the settings reset it suggested.
  4. I restarted WMP, and it recognized the disk right away.

I didn’t even have to reboot! How often does that happen?   ūüėČ