autom4te and m4sh for the impatient

autom4te is the engine beneath autoconf, but you can use it to generate your own portable shell scripts for other purposes.  For example, create this test.m4sh:

# test.m4sh
m4_errprintn([before init])
AS_INIT
m4_errprintn([before copyright])
AS_COPYRIGHT([CC0])
AS_WARN([warning])
AS_ECHO([Hello!])

# draws a box on stdout
AS_BOX([Test foo])

# Puts a box in the output as a comment
m4_text_box([testing foo])

foo=1
AS_IF([test "x$foo" = 'x1'],[
echo Foo is 1
])
m4_errprintn([at end])

Run autom4te:

$ autom4te -l M4sh -Wall -o test.sh test.m4sh 
before init
before copyright
at end

(Note that the m4_errprintn calls print while autom4te is running.)

Now you have test.sh:

$ ./test.sh
test.sh: WARNING: warning
Hello!
## -------- ##
## Test foo ##
## -------- ##
Foo is 1

Stunning, right? 😉

The number one gotcha

If you forget AS_INIT, you will get no output and no error message.  You have been warned.

Commands used in this example

  • AS_INIT: required.  At the top of the input file.
  • AS_COPYRIGHT: puts the text you give it into the output as a comment at the top of the generated script file.
  • AS_WARN: prints a warning when the generated script runs
  • AS_ECHO: prints to stdout when the generated script runs
  • m4_errprintn: prints to stderr when autom4te runs.  No effect on the generated script.
  • AS_BOX: prints the “Test foo” box in the example output, when the generated script runs
  • m4_text_box: puts into the generated script file a comment like this one:
## ----------- ##
## testing foo ##
## ----------- ##
  • AS_IF: a shell conditional, but more portable.
  • test: the clunky, old-school (but very portable) way of checking conditionals.  For maximum portability, don’t let any argument to test be the empty string (hence the xs in the test command above)

Happy hacking!

I installed Rakudo Star

It’s the reference implementation of the Raku programming language. https://rakudo.org/

The installer ran very quickly and the REPL worked out of the box. Nothing else to report yet, but I’m sure I’ll have more to say in the future.

Happy hacking!

Updated 1: Rakudo won’t build from source on Cygwin because libuv is still a bit dicey there.  However, cascent/neovim-cygwin looks like a promising step forward.

How to delete all the animations in a PowerPoint presentation using VBA

Very useful! This answer is copied from here. I tried to archive it, but archive.org wasn’t able to save it for some reason. I am posting it here so it can be archived for posterity.

answerspleasee asked on October 19, 2010
 Q:
 How to delete all the animations in a presentation
 heyehy

how do I delete all animations i have put on for the past 200 slides.

k.thanks.bye

Shyam Pillai replied on October 19, 2010
 MVP
 A:
 Hi,

You can turn off the animations by going to Setup Slide Show and under Show Options tick the Show without animation option and click OK. Now run the show and it will display without the animations.

If you really want to delete all the animations in a single sweep then you will need to run this macro.

Sub StripAllBuilds()
 Dim I As Integer: Dim J As Integer
 Dim oActivePres As Object
 Set oActivePres = ActivePresentation
 With oActivePres
 For I = 1 To .Slides.Count
 If val(Application.Version) < 10 Then
 ' Older versions of PowerPoint 97/2000
 ' In each slide set the animation property
 ' of the Shape object to FALSE
 For J = 1 To .Slides(I).Shapes.Count
 .Slides(I).Shapes(J).AnimationSettings.Animate = msoFalse
 Next J
 Else
 ' New versions support the Timeline object
 For J = .Slides(I).TimeLine.MainSequence.Count To 1 Step -1
 .Slides(I).TimeLine.MainSequence(J).Delete
 Next J
 End If
 Next I
 End With
 Set oActivePres = Nothing
End Sub

Regards, Shyam Pillai. http://skp.mvps.org
 Regards
 Shyam Pillai

http://skphub.com

 

Some bookmarklets

Edit: For the “welcome to Stack Overflow” bookmarklet, go to this jsFiddle, hit Run, and then drag the resulting link to your bookmarks bar.

A custom tea timer for https://smithtea.com/pages/know-your-tea#brewing-instructions:

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; /*https://stackoverflow.com/a/7540412/2877364*/ 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){e.click();var a=t('textarea[name="comment"]');a&&(a.value="Welcome to the site! Check out the [tour](https://stackoverflow.com/tour) and the [how-to-ask page](https://stackoverflow.com/help/how-to-ask) 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 https://jscompress.com/; non-minified is:

javascript:(function(){
 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;
 add_comment.click();
 var textbox = qsel('textarea[name="comment"]');
 if(!textbox) return;
 textbox.value =
"Welcome to the site! Check out the [tour](https://stackoverflow.com/tour) "+
"and the [how-to-ask page](https://stackoverflow.com/help/how-to-ask) 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;
 textbox.focus();
})();

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 🙂 .

Edit 2017/11/02

More discussion of this issue, in a LibreOffice context.  Apparently Word 2016 has gone back to fixed-width NBSPs.  I hope it is still fixable!  I will probably have 2016 by the end of the year and will post updates then.

 

 

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.