February 1942: To Be Or Not To Be














To Be Or Not To Be. Ernst Lubitsch. 1942.

Oh yeah! This one! I’ve seen it several times before. And the Mel Brooks remake, of course. I’ve been attempting to avoid movies I’ve seen before in this blog series, but my research sucks!
“Heil myself.”

It’s a very funny film, of course, and as a comedy/thriller everything fits together so neatly. Masterful. But I wonder what on earth they were thinking when making this. I mean, Germany had invaded Poland in 1939, and the horrors in Poland were ongoing when they made it. So… they responded by making a very funny movie making fun of Germans.
Ah, yeah, not everybody were amused:

To Be or Not To Be, now regarded as one of the best films of Lubitsch’s, Benny’s and Lombard’s careers, was initially not well received by the public, many of whom could not understand the notion of making fun out of such a real threat as the Nazis. According to Jack Benny’s unfinished memoir, published in 1991, his own father walked out of the theater early in the film, disgusted that his son was in a Nazi uniform, and vowed not to set foot in the theater again. Benny convinced him otherwise and his father ended up loving the film, and saw it forty-six times.

(According to a wikipedia.)

Popular movies in February 1942 according to IMDB:

PosterVotesRatingMovie
199808.2To Be or Not to Be
31827.7Kings Row
9747.6Castle in the Desert
70597.3Woman of the Year
11577.1Ride ‘Em Cowboy
4297.1Mr. Wise Guy
12647.0Roxie Hart
4576.7The Great Man’s Lady
10396.5Captains of the Clouds
4636.3The Lady Is Willing

This blog post is part of the Decade series.

The Mysteries of the Selection

After writing the package to edit WordPress articles in Emacs, I started thinking about doing something about non-text X selections in Emacs.

Emacs has all the required low-level support it needs to be able to yank HTML and images into Emacs, but nobody’s mainstreamed more high-level support into Emacs. Mostly because nobody really knew what it would look like, I think. (And because most Emacsens don’t really blog that much.)

Let’s have a look at what’s available here.

Let’s mark a word in an xterm, and then let’s see what Emacs gets:

(gui-get-selection 'PRIMARY 'TARGETS)
[TIMESTAMP TARGETS MULTIPLE UTF8_STRING
COMPOUND_TEXT TEXT STRING text/plain\;charset=utf-8
text/plain]

and compare when marking a word in Firefox:

(gui-get-selection 'PRIMARY 'TARGETS)
[TIMESTAMP TARGETS MULTIPLE text/html
text/_moz_htmlcontext text/_moz_htmlinfo
UTF8_STRING COMPOUND_TEXT TEXT STRING
text/x-moz-url-priv]

See? When marking words in an xterm, you get at text/plain thing you can yank in Emacs (and that’s what normally happens), but you mark something in Firefox, you get a text/html (among other things) in addition).

The same thing is the case in Chrome, although there you have to say “Copy” first to get the text/html part, and it lands on the CLIPBOARD and not in PRIMARY.

But that should be OK, anyway. Let’s look at the output from the text/html selection from Firefox.

Er, OK, that’s… little-endian utf-16. Er, OK… So that’s a thing?

Let’s look at the selection from Chrome, then:

So that’s a UTF-8 string? With… a nul at the end?

*sigh*

Well, OK, it’s easy enough to recognise one or the other forms, as long as there’s only two. *crosses fingers*

That means that the function for yanking HTML ends up being something like:

(defun ewp-yank-html ()
  "Yank the contents of the current X text/html selection, if any."
  (interactive)
  (let ((data (loop for type in '(PRIMARY CLIPBOARD)
                    for data = (x-get-selection-internal type 'text/html)
                    when data
                    return data)))
    (if (not data)
        (message "No text/html data in the current selection")
      (set-mark (point))
      (insert
       (if (and (> (length data) 2)
                (= (aref data 0) 255)
                (= (aref data 1) 254))
           ;; Somehow the selection is UTF-16 when selecting text in
           ;; Firefox.
           (decode-coding-string data 'utf-16-le)
         ;; But some sources add a nul to the end of the data.
         (decode-coding-string
          (replace-regexp-in-string (string 0) "" data)
          'utf-8))))))

Or should it look at the TIMESTAMP from the selections and then yank the newest one? By testing, it seems to be doing the right thing when not doing that…

Yanking images into buffers works along the same line, but there’s differences between where the images originate, of course. If doing a “Copy image” from Firefox, I can yank them as any format (image/png, image/jpeg), but from Chrome doesn’t support transcoding, so you have to loop a bit to find what the format really is. Or… I could look at the output from `gui-get-selection’? Yes, that seems like a better idea.

Let me try to yank a random image from Google…

Yup, that works. So you end up with something like:

(loop for type in '(PRIMARY CLIPBOARD)
      for st = (loop for st across
                     (gui-get-selection type 'TARGETS)
                     when (equal (car (split-string
                                       (symbol-name st) "/"))
                                 "image")
                     return st)
      when st
      return (x-get-selection-internal type st))

But just yanking an image into Emacs isn’t very useful: You have to be able to do something with it. In an HTML-like mode as this Postpress editing mode makes that kinda easy: Just represent it as an <img> element… and stash the entire image in the src=”data:image/jpeg;base64,FKJDSHJF…” bit. Since I’m showing the image as the `display’ bit on top, having a few megabytes of noise in the buffer doesn’t make any difference.

I was worried that this might somehow slow Emacs down, but nope. Displaying very long lines is something that Emacs doesn’t like, but as long as it’s hidden, it doesn’t seem to make any difference.

And it autosaves nicely, too.

OK, making it that easy to insert images into blog posts perhaps isn’t a good idea, but why should all ideas be good?

Anyway, I think something like this is something that Emacs should have, and I think I’ll pursue that further when I get time to do some more real Emacs work (which probably won’t be until like February).

I was originally pondering whether to offer an interface to a detailed view of the selection/clipboard, so that you can journey into all the different selection types, but after using this stuff for a couple of days, I think I’ve reached the conclusion that the only other two yanking types that makes sense (other than plain text, which we have now) are HTML and images. At least in a WYSIWYG-ish context…

Finally! Emacs is going to catch up with 90s editors! At least on this minor point! Amazing!

My New Concert Review Blog

I went to a metal festival. In a church!

It’s been desecrated I mean des-consecrated, but it’s still a great room. Thank you, religious people, for making impractical spaces like this that can be used for fun stuff now.

The downstairs crypt is more intimate.

Anyway, as usual I thought that the traditional metal bands sounded kinda thin (Lonely Camel was very swampy, but I’m all about Skynyrd, y’all), but Domkraft were awesome in the basement, and Toner Low shook the church to its foundations as the headliner in the main space.

Isn’t that the most evil metal band name ever? It is.

January 1942: The Man Who Came To Dinner

The Man Who Came To Dinner. William Keighley. 1942.

Oh this isn’t Guess Who’s Coming To Dinner… I did think that was a much later movie… and it is!

Well, you can’t but enjoy Monty Woolley’s over-the-top performance, and Bette Davis is here, so it’s definitely got things going for it. It’s funny! It’s good, bitter fun. I was thinking at the start “er, surely it’s not going to turn out that Davis, the long-suffering secretary, is in love with that old codger?” but they go another way entirely.

Which is wonderful.

Lots of intrigue and silliness: A classic stage farce, with an incessant stream of people running in and out the doors (and up and down the stairs) to the one central room where most of the story takes place.

It’s funny and it tick tocks like a brilliant clockwork thing, but I find myself left somewhat cold throughout the middle part. And I think Lorraine is treated shabbily…

Oh! This is the film that Morrissey crabbed the lyrics for the Cemetary Gates song? “All those people, all those lives. Where are they now? Here was a woman, like myself, a woman who once lived and loved, full of they same passions, fears, jealousies, hates. And what remains of it now? Just this. Nothing more. […] I want to cry.”

Popular movies in January 1942 according to IMDB:

PosterVotesRatingMovie
sc-tt0033874.jpg52837.6The Man Who Came to Dinner
sc-tt0035360.jpg10567.1Son of Fury: The Story of Benjamin Blake
sc-tt0034919.jpg5826.9Joan of Paris
sc-tt0035114.jpg2906.9Nazi Agent
sc-tt0034736.jpg2726.9The Fleet’s In
sc-tt0033517.jpg5626.5A Date with the Falcon
sc-tt0033806.jpg2926.1Lady for a Night

This blog post is part of the Decade series.

Editing WordPress Articles in Emacs

I’ve got my blog on WordPress.com, which has some positive aspects (I don’t have to run it) and some negative (I can’t control it fully). But whether I’m running WordPress myself or not, there’s one thing that’s always true: I loathe the browser-based editor.

When composing blog articles, I’ve been using the post-by-mail interface that WordPress.com offers, and it works OK. It’s got severe limitations in what it accepts, though: No <div>s or anything more fancy than a link and an image, really, and even those can’t be combined.

But editing is the main problem: I’ve tried using the Edit with Emacs Firefox plugin, and it doesn’t work with WordPress.com, apparently. So I’ve just… not… edited much, because it’s such a pain in the ass. The “visual” editor doesn’t even have reliable scrolling.

So yesterday evening I pulled myself together and started googling “emacs wordpress”, and found org2blog, which allows you to edit your WordPress blog posts using org mode. So it’s possible!

It turns out that this all is so much easier than I had imagined: WordPress has an old xmlrpc interface that you can just call with your credentials to do all this stuff. (It also has a new interface that’s oauth2-based, i.e., it requires a web browser in the auth flow with is just ick.)

The org2blog people have kindly separated out the low-level stuff into its own library, and I wrote a new library, ewp on top of that. Because even if Org is nice and stuff, I just want to edit my WordPress articles. I want WordPress to have the articles, and don’t want to have a “shadow” set of master texts.

With the help of that library (after fixing a multi/unibyte bug in the xml-rpl.el library (that was merged fast by the nice maintainer)), I finished off the library yesterday, and it’s basic, but does what I need, I think.

It lists the posts on WordPress, allows me to edit them, and to create new posts. (And, of course, since I’m very picture-happy, I also added some stuff to upload embedded media (which was a problem with the post-by-mail interface, because WordPress’ SMTP servers had a size limit of 100MB per email which they refused to increase, even after I asked them (so unreasonable!!!ONE!)).)

Here’s a Youtube demo of me typing away at my very shiny sofa laptop:

This has all been tested very, very lightly, of course, so I’d caution er caution. I’ve tried posting and editing myself on my WordPress.com blog, but who knows what happens on other WordPress installations…

And I’m sure it’ll grow more features as time passes. Things tend that way, don’t they?