Pcase and Friends

Early last year, I wrote about John Wiegley’s excellent tutorial on pcase. This tweet from Bozhidar Batsov:

reminded me of Wiegley’s post and inspired me to revisit it. It really is excellent and if you do any Elisp programming you should definitely take a look at it.

Recently, Wilfred Hughes published a great post on Pattern Matching in Emacs Lisp in which he compares pcase.el with cl.el, dash.el, and shadchen for a variety of use cases. You can follow the link to see what conclusions he arrived at.

If your work occasionally requires pattern matching of some sort, you should definitely read these two posts. The pcase family, in particular, is very powerful and allows you to write concise code for matching patterns.

Posted in General | Tagged , | 1 Comment

Introduction to Spacemacs

If you’re an Emacs n00b coming from Vim or if you just like modal editing, you should take a look at Spacemacs. Many say it combines the best aspects of Vim and Emacs. Some even claim that it heralds the end of the editor holy wars. I doubt that last claim but I do think that Spacemacs is an excellent solution for Vim users who want an Emacs environment without giving up modal editing or having to learn a new set of key sequences.

Jon Canady has a nice video that serves as an introduction to/demonstration of Spacemacs. He approaches the topic as a developer so he shows how to use Spacemacs as a development environment. Take a look at the video and see if it provides a comfortable IDE for you. The video is just short of 8 minutes so it’s easy to find time to watch it.

Posted in General | Tagged | Leave a comment

Is Cursive Virtuous?

Irreal has a large corpus on the problems with cursive handwriting (see here, here, here, here, here, here, and here) but I haven’t written about it for a while. I was going through my queue of unpublished blog ideas and came across this New Yorker article on The Lost Virtue of Cursive by Mark Oppenheimer.

Oppenheimer begins with a nostalgia-soaked story of writing his daughter longhand letters while she was at camp and how it reminded him of getting such letters from his parents when he was a child at camp. He goes on to say how he always gets a warm feeling when he reads about efforts to keep cursive in the curriculum:

When I read that Washington state is now considering Senate Bill 6469, “an act related to requiring that cursive writing be taught in common schools,” I gave a little fist pump in the air.

But then he writes, “This is sheer nonsense, of course.” Of course it is. He admits that it’s just nostalgia and snobbery. It’s fine to bring up memories of those golden feelings one got as a child upon receiving a letter from Mom or Dad but that’s no reason to inflict cursive on children who neither want nor need it.

If this subject interests you, Anne Trubek, whom I’ve mentioned before, has a book out on The History and Uncertain Future of Handwriting. I really enjoyed the articles she wrote on the subject and am looking forward to reading her book.

Posted in General | Tagged | 4 Comments

I Stand Corrected…

Last Week I wrote that I’d finally gotten mu4e working and that after I moved to elfeed, I would have everything except browsing and iMessage running under Emacs. I remarked that I didn’t expect to have iMessage or a (full-featured) browser working under Emacs anytime soon so that once I got elfeed going, I would be as Emacs-centric as I was going to get.

It turns out that I was wrong about iMessage. On a whim, I asked DuckDuckGo if there were any packages for using iMessage from within Emacs and to my surprise there is one. Chad Sahlhoff has an iMessage for Emacs package available on GitHub. It’s not available in Elpa, which is probably why I missed it at first.

The package needs Helm, which I don’t use, so I haven’t installed it yet. After a quick look at the code, it doesn’t seem like it would be difficult to use Ivy or Ido instead. Maybe I’ll take a closer look as soon as I get time.

More generally, I’m really enjoying mu4e and it really does change the way you deal with email. The tight coupling with Org mode means that every email can be dealt with at the time you read it—even if “dealing with it” means putting it on a TODO list for later action—so my INBOX is always empty when I finish an email session. No more keeping an email around even for a couple of hours. And did I mention no mouse?

I now spend almost all my time in Emacs or Safari. There’s simply no reason to use other standalone applications except for occasional special tasks. For you dedicated Emacsers, I can’t recommend this way of life enough. It just makes your day a whole lot easier and pleasanter.

Posted in General | Tagged | 12 Comments

Fire Adtech

Irreal readers who have been around for a while know of my deep and abiding hatred for adtech, a term used here to mean the technology that advertisers use to spy on and track Web users. I’ve written before that I consider legitimate advertising a fair cost for the content that it’s paying for but I really, really don’t like tracking. As a partial fix for that I use Ghostery to block tracking ads. Sadly for the advertisers, that means that almost all ads are blocked but that’s on the advertisers. I have the “do not track” bit set on my browsers but, of course, that’s almost universally ignored. Hence Ghostery.

Doc Searls over at Art+Marketing has an article up entitled Brands need to fire adtech. I can only agree. Searls explains in detail why adtech is a terrible practice, why it’s mostly fraud, how it’s a major malware vector, and, most importantly for advertisers, why it doesn’t work. The recent kerfuffle involving Google ads appearing next to what many consider “offensive content” could finally be the last straw. Many companies are refusing to place ads with YouTube and more and joining the movement.

In the meantime, the EU will make tracking illegal starting in May 2018. The fines for breaking that law are truly breathtaking. That doesn’t help those of us in the U.S. of course but users are getting better and better tools with which to fight back. Ghostery and its siblings are only the beginning. Searls says that new technology is coming that will allow advertisers to make money without resorting to the despicable practice of tracking and spying on their customers. It can’t come too soon.

Posted in General | Tagged | Leave a comment

Ivy 0.9.0

If you’re an Ivy user, you’ll be delighted to know that abo-abo has released the latest version, 0.9.0. Take a look at his blog for an overview of what’s new. If you aren’t using Ivy, you should definitely give it a try. I got turned on to it by this video from Mike Zamansky, and now I wouldn’t want to be without it.

Posted in General | Tagged | Leave a comment

A Better RETURN for Org

John Kitchin has an interesting piece of Elisp that helps when you’re writing in structured Org mode. If you’re in a bullet list, for example, you can type Meta+Return (or is it Ctrl+Return? I always get it wrong) at the end of an item to automatically begin another list item. Kitchin’s code allows you to just type return and it will do the right thing. It’s return-dwim. A double Return will end the structuring and do what a normal Return does now.

The code works for bullet lists, headings, and tables. I like it because I don’t have to stop and think which modifier key to use or, worse yet, undo the change and try the other modifier. If you do a lot of writing in Org mode, you should probably try Kitchin’s code out. It’s short and easy to paste into your init.el and if you don’t like it, you can just delete it. I’ve been using it for a couple of days and I’m still not sure if I’m going to keep it but, as I said, it’s easy to delete if I decide I don’t like it.

Posted in General | Tagged , | Leave a comment

Publishing a Book with Leanpub and Org Mode

Angelo Basile has a nice post on publishing a book with Leanpub and Org Mode. I’ve written about this before when I discussed Lakshmi Narasimhan’s workflow with Leanpub. Narasimhan used Dropbox, which some may find inconvenient so Basile employs an alternative method that uses BitBucket (or GitHub if you prefer).

I’ve never published with Leanpub so I don’t know how they are to work with but you certainly couldn’t ask for an easier publishing pipeline. If you use Basile’s method, you simply

  • Set up a new book with Leanpub (they say it takes 30 seconds)
  • Set up a repository for the book on BitBucket or GitHub
  • Add a file, Book.txt, that tells Leanpub the names (and order) of your chapters
  • Write your book adding the file or files to Book.txt
  • Use Leanpub’s publishing mechanism to preview or publish your book with a single click

Leanpub wants their input in Markdown but Juan Reyero has an Org mode to Leanpub Markdown exporter that will take your Org files and output them in Leanpub compatible Markdown (Markua). You can keep both sets of files in your repository as long as Book.txt has only the names of the Markdown files in them.

Be sure to take a look at Narasimhan’s post too because he has some Elisp to automate almost everything but the writing. If you want to self publish, it’s hard to imagine an easier way of doing so.

Posted in General | Tagged , | Leave a comment

Hacker Archetypes

Eric Raymond (ESR) has an interesting post on hacker archetypes. The list grew out of a discussion between ESR and one of his regular readers, Susan Sons. At the moment, they’ve identified 8 archetypes. You’ll want to read his post to see what they are and where you fit in but here’s an example to give you the flavor.

Algorithmicists:

  • Good at algorithms and intricate coding
  • High tolerance for complexity
  • Good mathematical intuition
  • Likes correctness proofs and thinks in terms of invariants
  • Tends to gravitate to compiler writing and crypto
  • Often has poor social skills
  • Tends to fail by excessive cleverness

That’s just the first archetype; there are 7 more and all are described in more detail than just the list of traits I gave above. ESR says that no hacker is only one of the archetypes. He describes himself as exhibiting the traits of three of them although one does dominate. That’s probably true of most of us.

Head on over to Armed and Dangerous and see which archetypes apply to you.

Posted in General | Tagged | Leave a comment

A Simple Programming Praxis Solution in Elisp

Programming Praxis has a simple problem that is meant to explore how easy your favorite programming language makes it to work with strings. The problem is to double every blank in a string. That’s pretty simple but some languages make you deal with string allocation or perhaps, in the case of languages with immutable strings, repeatedly allocate new strings.

I have two solutions for this using Elisp. The first is a sort of direct solution that doesn’t think too hard about the special functions Emacs has for dealing with strings.

(defun double-blanks (string)
  (with-temp-buffer
    (dolist (ch (string-to-list string))
      (insert ch)
      (if (eql ch ? ) (insert ? )))
    (buffer-string)))

This code deals with the fact that strings in Elisp are immutable by doing all the work in a temporary buffer as I discussed in this post. Except for the temporary buffer trick, it’s pretty much what any programmer would write. Of course, that string-to-list call is going to do a lot of consing, so for a really long string it might make sense to get the string characters by hand.

Of course, this is Emacs so there’s a prebuilt solution.

(defun double-blanks (string)
  (replace-regexp-in-string " " "  " string))

The replace-regexp-in-string function works by building up a list of matches and combining the list into a single string at the end so it also avoids the problem a immutable strings. If there are a lot of blanks, replace-regexp-in-string is going to do a lot of consing too.

If you’re dealing with large strings with lots of blanks, the best strategy is probably to combine the two approaches above: use a regular expression search for the blanks and build the output string in a buffer as you find them. That wouldn’t be hard and makes a good exercise for anyone interested in learning Elisp.

UPDATE [2017-04-10 Mon 13:49]: In the comments Phil remarks that string-to-list isn’t very efficient and suggests another strategy. I replied that it would be interesting to see if my (unimplemented) strategy or his would be more efficient and said that perhaps I’d try them out and report back. Phil, being Phil, took care of that before I could get around to it and go some interesting results.

For some reason his main post with the results isn’t showing even though it appears in the recent comments bar. Here’s the meat of that comment. I have to agree with Phil that it’s a bit surprising that the split-string method was the winner but that goes to show that one’s intuition about these things is most often wrong.

(length teststr)    
2070    

(length (split-string teststr " "))    
553    

(benchmark-run 10000 (double-blanks1 teststr)) ;; string-to-list    
(28.203663436 967 6.414597634999999) ;; uncompiled    
(23.110737061000002 968 8.26656119499986) ;; compiled    

(benchmark-run 10000 (double-blanks2 teststr)) ;; replace-regexp-in-string    
(21.614643389999998 1913 11.981117643999973) ;; uncompiled    
(25.317938649 1913 15.727532714000041) ;; compiled    

(benchmark-run 10000 (double-blanks3 teststr)) ;; search-forward/insert    
(8.588276816 149 0.9523469339999999) ;; uncompiled    
(8.355207331 147 1.2536677860000367) ;; compiled    

(benchmark-run 10000 (double-blanks4 teststr)) ;; split-string/mapconcat    
(7.9514880880000005 476 3.2033875379999657) ;; uncompiled    
(7.953855983 477 3.237625087999996) ;; compiled
Posted in Programming | Tagged , | 6 Comments