Bad Emacs Advice

The incomparable Mickey has a few words to say on Bad Emacs Advice. Mickey and I have been using Emacs for approximately the same amount of time and although we are both still learning, we agree that there’s some well meaning but bad advice about learning Emacs. Mickey identifies the four hot sports for bad advice:

  1. Turn off the menu and tool bars
  2. Ignore the Emacs manual
  3. Don’t bother with the tutorial
  4. Don’t use the Custom Interface

In a nice example of serendipity, I learned a couple of new things from Mickey’s post on Emacs advice. The first is that you can access the menu system from the keyboard with Meta+`. that’s probably not useful for any but the most hardcore antimouse GUI user but it’s very useful if you’re using Emacs in terminal mode.

The second revelation is that can find out what a menu item does in exactly the same you find out what a key combination does: Simply precede the menu mouse click with Ctrl+h k.

Mickey’s advice strikes me as sound. Whether or not you use the menu bar when you gain a bit of experience, it’s undoubtedly true that it can be a big help in learning Emacs. Some say the same about the tool bar but I’ve never found it useful: it’s ugly, doesn’t help you learn the shortcuts, and doesn’t have any functionality that the menu bar doesn’t. As for the manual and tutorial, advice to ignore them seems particularly ill advised to me. Why wouldn’t you want to avail yourself of comprehensive documentation on the workings of Emacs?

As for the Customize Interface, I used it a lot in my early Emacs days but don’t use it at all now except for those automatic package things that Emacs insists on inserting into the Custom Configuration and even then I exile it to custom.el so it doesn’t pollute my init.el.

I agree with Mickey about his take on bad Emacs advice. Take a look at his post to see what you think.

Posted in General | Tagged | Leave a comment

Finding the Directory of the File in a Buffer

The other day I saw this Tweet

and it reminded me of problem I had the other day: I needed to find the directory containing a file in a buffer. I was pretty sure that there was a way of doing that but I couldn’t remember what it was. There’s buffer-file-name but it’s not interactive and I couldn’t, in any event, find it in the heat of the moment.

When I saw the Tweet, I thought that was a pretty nice way of doing it but the result is less than pleasing on a Mac because it yanks focus away from Emacs and opens a finder window. After a minute’s thought I realized that a better way is to use M-! pwd. That lists the directory part of the path in the echo area so it’s just what I needed.

Posted in General | Leave a comment

Open Access at Nature

As Irreal old-timers know, I am interested in and a supporter of open access. The academic publishing industry is deeply exploitive of everyone they deal with. That includes members of the public who provide financial support for much of the research they publish but are nevertheless expected to pay hefty fees to see the results.

One of the changes that I and others have predicted was that the business model of the publishers would change to provide open access for all in exchange for a publishing fee paid by the researchers or their institutions. That seemed like a good solution but only because of my naivete. Here’s how Nature implemented that plan. The publishers will always try to game the system, whatever it is.

The TL;DR is nicely captured in this hilarious video mocking the plan. If you read the whole thread, you’ll note that Dr. Glaucomflecken says that everything in the video is accurate except for the 12 year old doing their formatting.

The video is devastating precisely because it is so true. If you weren’t already against the publishers this should do the trick. Perhaps whatever rises from the ashes of the rapidly self-immolating higher education industry will structure their tenure and promotion policies to make this sort of exploitation impossible.

Posted in General | Tagged | Leave a comment

Combining Find and Grep in Emacs

One of the classic Unix idioms is to search all files in a file hierarchy for some regular expression with a find/grep pipeline. For example, to search the lisp directory and all of its subdirectories for file containing the mapcar function, one could use

find ~/lisp -name "*.lisp" -exec grep -H mapcar {} \;

That pipeline finds every .lisp file in the hierarchy and runs grep on it looking for mapcar.

I, at least, don’t do this type of thing very much anymore because there are so many easier ways of doing so, especially from within Emacs.

Nonetheless, it’s still possible to usefully combine find and grep from within Emacs to build a Dired buffer of all the files that contain the matching regex. This tweet by
Mickey tells you how:

There’s a bit more to the command so you should take a look at the on-line documentation if you have a use for it.

Posted in General | Tagged | Leave a comment

Adding To a Keyboard Macro

Wilfred Hughes’ Emacs Command of the Day Twitter feed has a useful tip:

I’ve seen this before and may even have written about it before but I always forget about it. I’m not sure why; it could hardly be simpler: just prefix the start macro command with the universal argument.

In any event, it’s a useful reminder for me and may be for you too.

Posted in General | Tagged | Leave a comment

MELPA Surpasses a Quarter Billion Downloads

From Steve Purcell:

I’ve said this before but it bears repeating: We all owe Purcell our thanks and, if we happen to meet him, a beer. He has, virtually single-handedly, run the most important Emacs package repository. It’s a lot of work that Purcell donates to the our community and more often than not his only feedback is complaints when the rare glitch isn’t resolved quickly enough.

A quarter of a billion downloads is a lot for a community the size of ours and underscores again the tremendous amount of work required to keep things ticking along. There are currently 5,077 packages in MELPA and each one has been curated and validated by Purcell or one of his helpers.

So again, let’s all raise to toast to Purcell and if you happen to be where he is, buy him a round.

Posted in General | Tagged | Leave a comment

Red Meat Friday: SICP in JavaScript

Remember a couple of weeks ago when I declared No. Just no? Well, here’s another, even more emphatic, refusal to accept the apocalypse.

No. Just HELL no!

The thing about SICP is how simple and beautiful the code is and how precisely it demonstrates the concepts under discussion. To pretend that you could do the same with JavaScript is self delusion of the first order.

Yeah yeah, I know. There’s more code written in JavaScript than there are atoms in the universe. There are also more Ford Focuses than Rolls Royces. That doesn’t make Focus the better car or JavaScript the better language. More to the point, JavaScript is a bad fit for SICP.

I have long abhorred MIT’s decision to replace SICP with Lego robots or something but this latest outrage is an act of vandalism. If you want to learn the wisdom in SICP then learn Scheme. The whiners notwithstanding, it’s an easy language to learn. Indeed, 6.001, the MIT course in which SICP was used, didn’t have any time devoted to teaching Scheme. Students just picked it up as they went along.

If we’re going to abandon SICP as a teaching vehicle, we should at least let it rest in peace and not desecrate its corpse.

Posted in General | Tagged | Leave a comment

Automating Your Job

One of my favorite bits of—obviously apocryphal—Lisp folklore is the story of the invention of macros. The TL;DR is a that some senior Lisp developers got tired of writing the same boilerplate code all the time so that started using abbreviations for the pieces of boilerplate and hired a junior developer to translate the abbreviations into normal Lisp. After a while, according to the story, the junior developer realized he could just write some code to do the translations automatically so he added that code to the Lisp compiler and Lisp Macros were born. It worked so well that he soon saw there was no reason for him to oversee things so he retired to the beach while still getting paid. The senior developers just assumed he was still there slaving away at the translations.

I’ve always loved that story so this real life analog really resonated. It’s an apparently true story of an IT specialist working for a law firm who was tasked with handling digital evidence for the firm. That’s probably more involved than you most of you realize but our hero soon came to realize it was not an 8-hour job. Even more, he discovered that he could automate the whole process with some simple scripts,

So when COVID struck and he started working from home, he simply used his scripts to do the work and spent his time playing computer games and hacking on his side projects. There may be some ethical issues here but there may also not be any. After all, the job he was hired to do is getting done and the firm seems happy.

Regardless, I just love the real life example of the Lisp Macro story. I always considered it a delightful fantasy but it has, it seems, come to life.

Posted in General | Tagged | Leave a comment

Corner Quotes

John D. Cook has a useful post on using “corner quotes” (⌜ ⌟) to delimit regular expressions in text. As Cook says, it makes a lot of sense especially when the regular expression begins or ends with a space. Cook’s port deals with using Unicode for the corner quotes but it’s also easy to do in Emacs.

In vanilla Emacs, the way to do it is to specify TOP LEFT CORNER and BOTTOM RIGHT CORNER with insert-char through the Ctrl+x 8 binding. If you have Ivy installed, you can also use the lceil and rfloor entities through ivy-insert-org-entity a handy function that I stole from John Kitchin’s Scimax.

(defun ivy-insert-org-entity ()
  "Insert an org-entity using ivy."
  (interactive)
  (ivy-read "Entity: " (loop for element in (append org-entities org-entities-user)
                             when (not (stringp element))
                             collect
                             (cons 
                              (format "%10s | %s | %s | %s"
                                      (car element) ;name
                                      (nth 1 element) ; latex
                                      (nth 3 element) ; html
                                      (nth 6 element)) ;utf-8
                              element))
            :require-match t
            :action '(1
                      ("u" (lambda (element) (insert (nth 6 (cdr element)))) "utf-8")
                      ("o" (lambda (element) (insert "\\" (cadr element))) "org-entity")
                      ("l" (lambda (element) (insert (nth 1 (cdr element)))) "latex")
                      ("h" (lambda (element) (insert (nth 3 (cdr element)))) "html"))))

The latter method uses left and right floor and ceiling entities (⌈ ⌋) rather than the corner entities but the results are almost the same. At least they are if the regular expression doesn’t contain a floor or ceiling operator.

I usually just set the regular expression in a constant width font but as Cook notes that doesn’t work as well when the regex begins or ends with a space. This seems to me to be a good convention that we should consider adopting.

Posted in General | Tagged , | Leave a comment

The UK Plans an Anti-encryption Campaign

Rolling Stone has an article on a planned UK Campaign against end-to-end encryption. Of course, after the University of Virginia rape story debacle, everything they report should be viewed, um, critically. That said, the story is disturbing.

The Home Office has reportedly hired the M&C Saatchi advertising agency to concoct what can only be termed a disingenuous advertising campaign to discredit end-to-end encryption in general and FaceBook’s plan to implement it in WhatsApp—its messaging app—in particular.

You can read the article to discover some of the stunts they have planned but the whole campaign is based on the usual Four Horsemen of the Infocalypse and especially how that nasty encryption makes it impossible to “protect the children”™.

As always in this type of action, the Home Office is pretending that it’s possible to provide a backdoor key that only the good guys can use. Virtually every cryptography expert says that’s impossible and there’s nothing in the government’s past record in protecting these types of secrets that suggests it will be any different with a backdoor key. One former government security executive described it as “the digital equivalent of alchemy”.

All governments hate end-to-end encrypted messaging apps because it allows citizens to keep their private business private and how can the nannies do their job if they can’t snoop on what you’re saying? They’ll bring up “think of the children”, drugs, terrorism and all the other boogeymen as if encryption were somehow unique in its use by criminals. I hope my cousins in the UK tell them to get lost.

Posted in General | Tagged | Leave a comment