Org Mode Folding

As every Org user knows, you can use Shift+Tab to cycle the folding of an Org file among OVERVIEW, CONTENTS, and ALL. That’s really handy and something I use all the time.

Yesterday, I learned something new from this Emacs Stack Exchange entry. What happens if you want to unfold, say, the first 3 headers? It’s Emacs so of course there’s a way to do that. All you have to do is specify a numeric prefix argument, \(n\), and the first \(n\) subtrees and the contents of the \(n^{\text{th}}\) level will be displayed.

You probably won’t need that very often but sometimes it’s just what you need and very useful.

Posted in General | Tagged , | Leave a comment

The Map Library

Recently I’ve written about Wilfred Hughes’ ht library for dealing with hash tables and Nic Ferrier’s kv library for dealing with alists and plists. Nicolas Petton commented that there is also the map library, which is built into Emacs as of version 25.2.

What makes Petton’s map library unique is that the functions will operate on alists, hash tables, or arrays so you don’t need to worry about separate functions for each data type. The functions do the expected things such as getting and putting values, mapping over key/value pairs, filtering, and so on.

Unfortunately, there doesn’t appear to be any documentation but it’s easy to look at the source to see what functions are available. The DOC strings do a good job of explaining what each function does.

If you have code that uses two or more of the supported data types, you should consider the map library. It provides a consistent set of functions that operate on them all. In particular, it makes it easy to change the data type of a variable because most of the code to manipulate it will be the same. As with the ht and kv libraries, the names of the functions and the ordering of the arguments are consistent and intuitive. That makes it easy to remember them.

Posted in General | Tagged | 4 Comments

Shannon’s Six Steps to Problem Solving

I’ve written a couple of posts about Rob Goodman’s and Jimmy Soni’s book on Claude Shannon [1, 2]. If you haven’t read the articles that those posts link to, I urge you to do so. Shannon was a fascinating man and a problem solving machine.

In a Business Insider article, Goodman and Soni report on a talk about Shannon’s 6 steps to problem solving that he gave to his Bell Labs colleagues. Most of us aren’t Shannon-level geniuses but his six steps are relevant to the work we do. Briefly, those steps are

  1. Simplify.
  2. Learn and think about similar problems and solutions.
  3. Approach a problem from different angles.
  4. Break the problem into small parts.
  5. Solve the problem backwards: from solution to problem.
  6. Extend your solution as far as it will go.

That list probably seems facile but the article expands on each step and offers examples. It’s definitely worth your time to take a look at the article. You may find some of the strategies useful in your own problem solving.

Posted in General | Tagged | Leave a comment

The kv Library

The other day I wrote about Wilfred Hughes’ hash table library. In the comments, Noonian Atall remarked that Nic Ferrier also has a key/value library (kv) that’s worth taking a looking at.

Whereas Hughes’ ht library is primarily concerned with hash tables, Ferrier’s kv library deals primarily with alists, although it does provide functions for converting between alists and hash tables. As with the ht library, kv provides some naming consistency and saves writing simple conversion and access functions. If you work a lot with alists, you should take a look at this library and see if it can save you some time and work.

Posted in General | Tagged | 4 Comments

The Ugliest Editor Theme Ever Conceived?

Betteridge’s law notwithstanding, I’m pretty sure it would be hard to devise a theme uglier than this one. PLEASE NOTE: That is definitely not a challenge.

It looks like something a particularly silly seventh grader would come up with. All that’s missing are little hearts over the ‘i’s.

Yeah, I get that the perpetrator was just fooling around but somethings are too horrible to see the light of day.

Posted in General | Tagged | 1 Comment

Elisp Hash Table Library

If you like the simplicity and regularity that libraries such as s for strings and dash for lists provide, you should take a look at Wilfred Hughes’ ht library for working with hash tables.

Hash tables are, of course, built-in to Emacs Lisp so the library isn’t introducing any new functionality but it does offer these advantages as listed in the README:

A consistent naming scheme
If you aren’t using hash tables all the time, it’s hard to remember the function names because they seem entirely unrelated to each other. In the ht library, the names all have the form ht-X, when X is usually a verb (such as create) that describes what the function does
A natural and consistent argument ordering
Again, this makes it easier to remember how to use the functions. Of course, eldoc can help here too.
The mutation functions return nil
As in Scheme, these functions end in !. Examples are ht-set! to add a key/value pair to the hash table and ht-remove! to remove a key/value pair.
A more comprehensive set of functions for hash table operations
These make common operations more convenient by providing a function for them so you don’t have to write additional code

The library looks pretty nice if you don’t mind using non-standard names for the operations. Of course, that’s part of the point. The names make more sense and help you remember them. My only complaint with the new names is that the predicates (ht-contains?, ht-equal?, …) end with ? rather than the conventional (for Elisp) -p. (Yes, yes, I know; The ? makes more sense but the -p is a long standing convention worth respecting.)

Posted in General | Tagged , | 1 Comment

Happy Birthday Linux

Linux is 26 today. What started as a little hobby project that even Linus didn’t expect to amount to much has grown into one of the most important operating systems in use today and arguably of all time. Our world1 would be vastly different without it.

Footnotes:

1

By “our world,” I mean the world of engineers and technical people but the case could be made that the statement applies to the “world” in general.

Posted in General | Tagged , | Leave a comment

Nist Password Guidelines

As most of you probably know, NIST recently updated their password guidelines. The three big changes are:

  1. Use long easy to remember passwords. Don’t worry so much about mixing in numbers and special characters.
  2. Don’t expire your users’ passwords—it only encourages bad password practices.
  3. For all but low-risk applications, use two-factor authentication.

The IEEE Spectrum has a Q&A with Paul Grassi, the author of the new guidelines. It’s a quick and easy read and will give you some valuable guidance as to dealing with your own passwords. He doesn’t mention password managers, which I still believe the be the best solution for generating high-entropy passwords and managing them safely.

If you want more information, take a look at the actual guidelines. They’re long and detailed and written in bureaucratese but cover all the material.

Posted in General | Tagged | 5 Comments

Marking a Word

Today I learned something new. Or, rather, I got hit in the head with a cluebat. Peter Hwang asked how he could mark the word at point. Manuel Uberti answered that he usually uses Ctrl+Meta+SPC, which I always think of as marking the s-expression at point. Of course, that’s where the cluebat comes in because, duh, an atom is an s-expression too.

On most keyboards, it’s easier to type Ctrl+Meta+SPC that it is to type Meta+@. At least it is for me. The nice thing is you can mark subsequent words by repeating the Ctrl+Meta+SPC.

On the other hand, both methods mark from point to the end of the word so if point is in the middle of the word, you may not get what you want. You can mark the word that the point is in with er/expand-region, Magnar Sveen’s excellent semantic marking utility. The problem with er/expand-region is that it’s usually hard to mark subsequent words because it will look for the smallest enclosing semantic unit, which is probably not the next word.

So my (new) strategy is to use er/expand-region to mark the word containing the point and then Ctrl+Meta+SPC to mark subsequent words if I need to. That means I have to switch from Ctrl+=, my binding for er/expand-region, to Ctrl+Meta+SPC, but that doesn’t seem as awkward as the other methods I’ve tried.

Posted in General | Tagged | 4 Comments

Ivy Initial Input String

If you’re an Ivy user—and you should be—you’ve probably noticed that sometimes the Ivy prompt will have an initial “^” so that the search will be anchored at the beginning of line. This happens depending on the command that called the ivy-read routine. If Ivy guesses wrong, you can always remove the “^” or add one.

Sometimes, though, it always guesses wrong for your particular work flow. I’ve just learned from this Emacs subreddit question that you can, to an extent, control when the “^” is appended to the prompt. Actually, you can specify any string to prepend.

The decision as to what to append is controlled by the ivy-initial-inputs-alist. Again, you can easily correct the default action at the time of the call so unless you have a situation where Ivy is always guessing wrong, it’s probably not worth changing the default value of ivy-initial-inputs-alist.

Posted in General | Tagged | Leave a comment