Emacs for Writers

Jacob Moena has a long post on using Emacs for creative writing. He begins by explaining why anyone would want to do such a thing. Of course, Emacsers already know the answer: Emacs will make you more productive, especially if you are a touch typist.

The majority of his post is a “whirlwind tour” tour of Emacs. It’s a fairly detailed tutorial on the editor’s features that a creative writer is apt to find useful. He also covers some of the packages that he uses in his own writing, including, of course, Org mode. He notes that it’s most useful to think of Emacs as an editor construction kit—although he doesn’t use those terms—and that this is its great strength: you can make Emacs adapt to your way of working instead of having to adapt your way of working to your editor.

His most important takeaway, I think, is

“The secret about Emacs is that it is driven by muscle memory, just like a musical instrument. It takes some time to get there, but once you do, you can operate it instinctively.”

If you’re an experienced Emacs user, you’ll probably find the whirlwind tour boring since it covers material you’re already familiar with. Still, he does cover some specialized commands that you may not know about so it’s worth at least skimming over it. If you’re an Emacs n00b and interested in seeing if Emacs is a good fit for your writing, Moena’s post will help you get started and tell you what to expect. There are a few typos (usually involving command shortcuts) that may be confusing so if you see something that doesn’t appear to make sense, it’s probably just a typo.

Posted in General | Tagged | Leave a comment

Easing the Use of Strong Passwords on a WiFi Router

François Marier has a cute trick to make using long and secure passwords on your WiFi router a little less painful. Setting a, say, 64 random character password isn’t too much trouble if you’re the only one using the router and you have a single device. But as soon as you have multiple devices or multiple people—guests, say—needing to use the router it becomes a nuisance. Marier’s idea is to store the password as a QR code so that it can be scanned by devices needing access.

That will work better than you think it might because both iOS and Android devices will recognize that you’re scanning a WiFi password—that information is part of what’s encoded in the QR image—and ask if you want to join the network. You don’t need a special app for your phone or tablet, you just use the camera app as usual. That’s pretty neat.

Marier uses the qrencode library to generate the QR code. His link is to the Debian package but other Linux distributions have packages for it too. The above link has the source if you want to build it yourself but there are a lot of dependencies. If you’re on a Mac you can get the binary from Homebrew.

The iPhone has a nice way of sharing WiFi passwords with other iOS devices but Marier’s method works outside Apple’s ecosystem so you may find it more useful.

UPDATE [2019-12-31 Tue 11:43]: There’s also a nice Emacs interface to qrencode if you want to expand on the idea.

Posted in General | Tagged | Leave a comment

Remote Work Will Become the New Normal

The forward march of remote work continues apace. Despite setbacks like Marissa Mayer of Yahoo! putting an end to their remote work program, researchers continue to gather evidence that remote work is a win for both employers and employees.

Over at Fast Company, Jessica Stevens argues that remote work is here to stay and will become the new norm. Of course, remote work isn’t for everyone and even those amenable will need support from their employer. Like all articles of this sort, Stevens has a list of things that the employer should do to help ensure success. Her list is:

  1. Employers should provide remote workers with the technology and infrastructure they need to do their job remotely in an efficient, low-friction way.
  2. Help the employee achieve “disciplinary excellence” by implementing systems to measure progress and provide feedback.
  3. Provide clear goals and instructions so they know what’s expected from them.

Stevens omits the item that most commenters feel is most important: Provide a robust communication environment so that remote workers know what’s going on in the company, know what other workers are doing, and don’t feel isolated. One could argue, I suppose, that that’s implicit in the three goals she lists but it seems orthogonal to me.

Remote work is becoming so ubiquitous that there’s almost no point in continuing to write about it but as I’ve said before, I’ve been fascinated by the subject for several years. When I first got interested in the subject, remote work was rare and confined to a small set of job types such as journalism. Now it seems to be everywhere and, in the tech sector at least, it’s unusual for a company not to offer some type of remote work program.

Posted in General | Tagged | Leave a comment

Query Replace with Occur

Over at (with-Emacs, Clemens Radermacher has posted a short tutorial on using occur and query-replace across several files. It’s sort of a riff on abo-abo’s post on refactoring multiple files. To a first order approximation, the idea is to use occur to locate the term of interest, put the occur buffer in edit mode, and then use query-replace or your favorite replacement tool to make the actual substitutions.

This works fine if you’re interested in a single buffer but if the text of interest is spread across several buffers, you need to use multi-occur. I can’t ever remember doing this because multi-occur is hard to use. You have to specify each buffer you’re interested in and while you can make this a little easier with multi-occur-in-matching-buffers, it isn’t ideal either.

For me, the most interesting thing about Radermacher’s post is his recommendation to use Nicolas Petton’s noccur. It’s just like occur—actually, it’s a front end to the multi-occur command—but you can ask it to operate on all files in a project or all the files marked in a dired buffer. Noccur will load the requested files into buffers and call multi-occur.

There are plenty of other ways of doing this but Radermacher’s solution works in a seamless way for project files and dired-marked files. It’s definitely worth knowing the technique. Radermacher offers some code snippets to provide a bit of context for your replacement decisions and to solve a couple of other problems. It’s a good post and definitely worth taking the time to read.

Posted in General | Tagged | Leave a comment

Org Mode 9.3.1

Batien writes that he’s released Org 9.3.1. It’s a bug fix so you should probably update if you’re having any problems with Org 9.3. I updated yesterday and haven’t had any problems. Of course, that’s a study of \(n=1\) so you may see different results.

Thanks to Bastien, Nicolas, and all the others for the hard work they do to bring us this essential package and for keeping the development robust and active.

Posted in General | Tagged , | Leave a comment

Implementing Palindrome Predicates

Joe Marshall is a long-time Lisper with an ability to come up with really elegant solutions. Indeed, the second ever Irreal post was about Marshall’s brilliant solution to a problem from SICP. Recently, he recounted a story about a recent phone screen he had in which he was asked to implement a palindrome detector. He wrote both an iterative and a recursive version. He says he gave them the iterative version so they wouldn’t think him an idiot but that he liked the recursive version better because of its simplicity and elegance.

If you think of a palindrome detector as embodying the three rules

  1. The empty string is a palindrome
  2. A string with a single character is a palindrome
  3. If the first and last characters of a string are identical and the substring between them is a palindrome, then the original string is a palindrome

the recursive algorithm writes itself.

Marshall doesn’t show his code so of course I had to try it myself. My initial effort was to bang out an Elisp implementation:

(defun palindromep (string)
(let ((len (length string)))
  (cond
   ((zerop len) t)
   ((= 1 len) t)
   ((not (char-equal (aref string 0) (aref string (1- len)))) nil)
   (t (palindromep (substring string 1 -1))))))

That’s practically a word-for-word rendition of the three rules and it worked well. But then I started thinking that Marshall said the iterative solution would be faster for most compilers. I don’t know what language he used but it almost certainly wasn’t Lisp so I wondered if the iterative version would be faster in a Lisp language. Of course I had to write an iterative version so I could compare them.

My first inclination was to write the iterative version in Elisp too but Elisp isn’t tail recursive so it would be hard to run the recursive version on large inputs. Therefore I decided to start over with Scheme. The recursive version is the same, mutatis mutandis, as the Elisp version.

(define palindrome-r?
  (lambda (string)
    (let ((len (string-length string)))
      (cond
       ((zero? len) #t)
       ((= 1 len) #t)
       ((not (char=? (string-ref string 0) (string-ref string (1- len)))) #f)
       (#t (palindrome-r? (substring string 1 (1- len))))))))

The iterative version is a little more complicated—mostly because of the do loop—but doesn’t seem nearly as elegant as the recursive version.

(define palindrome-i?
  (lambda (string)
    (do ((h 0 (1+ h))
         (t (1- (string-length string)) (1- t))
         (palindrome? #t))
        ((or (not palindrome?) (> h t))
         palindrome?)
      (set! palindrome? (char=? (string-ref string h) (string-ref string t))))))

The real test, though, is their relative speeds. In Scheme with its tail recursion, loops are generally implemented as recursion and you wouldn’t expect much difference. I ran the comparison in Guile Scheme, which has copy-on-modify string behavior so, again, the two versions seem like they should run in about the same time.

Of course, the results were nothing like that. I ran each version 1000 times on a large palindrome (100,000 x’s) with the following

(define str (make-string 100000 #\x))

(define bench
  (lambda (rcnt f)
    (do ((i rcnt (1- i)))
        ((zero? i))
      (f str))))

and here are the results

,time (bench 1000 palindrome-r?)
;; 9.204000s real time, 9.370000s run time.  2.330000s spent in GC.
,time (bench 1000 palindrome-i?)
;; 4.582000s real time, 4.660000s run time.  1.350000s spent in GC.

The recursive version runs almost exactly twice as long so Marshall was correct even in the Lisp case.

None of this is very important, of course, but it was an interesting exercise that reinforced the lesson that it’s really hard to predict run times without benchmarking.

Posted in General | Tagged , , | Leave a comment

Emacs Screencasts

Over at Meta Redux, Bozhidar Batsov, who will need no introduction to Emacs users, has a nice post on how to make a screencast from within Emacs. The result is actually an animated GIF but the results in his demo video look very good. The nice thing about his method is that it takes a screen capture only when you do something so the resulting files are smaller and there are no pauses when you’re not doing something.

The screencasts are made with the emacs-gif-screencast package that’s available on Melpa. You’ll need a couple of extra packages as well: Imagemagick and Gifsicle both of which are available on HomeBrew for MacOS users and are probably already installed on Linux—if not prebuilt binaries or source are available at the above links.

There are a few weaknesses, which Batsov discusses but nothing serious and he concludes that it’s a “pretty cool tool” so if you’re looking for any easy way to make a screencast from within Emacs you should definitely give it a look. You won’t be able to make the type of video that, say, Mike Zamansky produces but if you need a quick screencast to demo some process, emacs-gif-screencast is ideal.

Posted in General | Tagged | Leave a comment

Emacs 27 Release Branch

Eli Zaretskii writes on the Emacs Development list that he’s created the Emacs 27 release branch. Next up is the Emacs 27.1 pretest, which he hopes to release soon. He’s also set the version number of Emacs on the Master branch to 28.0.50.

Emacs 27 is finally in sight. In the meantime, we can start obsessing about Emacs 28. If you haven’t already, take a look at John Wiegley’s video on what’s coming in Emacs 27.

Posted in General | Tagged | Leave a comment

Plain Text For the Social Sciences

Regular readers know that I’m fascinated by the ways that non-technical folks make use of Emacs. Despite our prejudiced assumptions, they are often sophisticated and subtle in the ways they leverage Emacs. Recently, Eric Fraga tweeted a pointer to a long article by Kieran Healy on using plain text and Emacs for writing in the social sciences.

The article is mainly addressed to the beginning graduate school student and makes the case that if you are going to do any quantitative work in your research then you’re better off using plain text and a text editor rather than a word processor for writing your papers and books. Most Irreal readers won’t find this the slightest bit controversial and will need no convincing but social scientists are different. Their culture and training has led them to believe that writing papers is something done with Word. Their professional journals agree. With that in mind, it’s easy to see why Haley’s position can be a hard sell.

Healy is mostly concerned with workflow and although he is an Emacs user, he doesn’t insist that it’s the only good solution. He suggests several alternatives but does note that Emacs is a powerful tool that can make writing easier. He assumes that “quantitative” means “statistical” and that his readers will be using R. His workflow involves writing in Markdown and using knitr to evaluate the R code blocks and insert the results in much the same way that Org and Babel work. Org and Babel would provide a more seamless and slightly easier solution so I’m not sure why he doesn’t use them. Healy is a Full Professor at Duke so Org probably wasn’t available when he started and he’s just stuck with his “good enough” solution. The article discusses his entire tool chain with particular attention to revision control and backups so it’s about more than just what editor and markup language to use.

As I said, the article is long—a PDF version runs to 49 pages (although with generous margins)—but it’s interesting and makes many good points even if you don’t agree with all his choices of tools. I recommend reading the PDF version because it has the footnotes and is a single document rather than a series of pages.

Posted in General | Tagged | Leave a comment

John Wiegley on Emacs 27

In another of the videos from Emacs Conference 2019, John Wiegley talks about what’s coming in Emacs 27. Wiegley is still the official maintainer but Eli Zaretskii stepped up to do the heavy lifting when Wiegley’s job intervened. Wiegley says that Zaretskii is now the de facto maintainer but that he was not available to give the talk so Wiegley made the presentation.

There are several interesting changes coming. Lispers will be happy to learn that Elisp will finally be getting BIGINT support. It still doesn’t have a full numerical tower but BIGINT support is probably the most important missing piece.

On the display side, Emacs 27 is getting support for Harfbuzz, Cairo, and better ligature support. Another display-like feature is support for tabs. This is not just tabs in the browser sense—because who needs that in Emacs—but a mechanism for maintaining window configurations and switching between them.

Some other interesting enhancements are the portable dumper (a long time coming but we’re finally free of depending on glibc hacks to build our core image), initial support for the XDG directory configuration standard, so-long-mode to help deal with very long lines slowing down Emacs, and gettext integration to support internationalization of error messages and the like.

You can get more details by watching Wiegley’s talk but, unfortunately, the audio dropped out several times during his presentation. Still, every serious Emacser will want to watch the video to see what’s coming in Emacs 27.

Posted in General | Tagged | Leave a comment