Controlling Where Isearch Starts Searching

Today I learned a new Emacs trick from Emacs Dwelling. Well, new to me. It turns out it’s been in Emacs since 28.1 so for about four and a half years.

Here’s the problem. When you call isearch it starts searching at the current point location to the bottom of the file. You can cause it to wrap around and continue searching at the top of the file but this isn’t always convenient. As a result, many people always start their search by moving to the top of the buffer first. But this isn’t always convenient either. For example, if you quit the search you go back to the top of the file, not where you started.

Sometimes you want a bit more control: perhaps you want to start at the first match or the last match and if you quit, you’d like to be back where you started. Well this is Emacs so of course you can do that. The nice thing is that it’s already built in. There are no packages to install, you just enable it my setting isearch-allow-motion to t.

You can start the search at any of:

  1. The current point position
  2. The first match in the file
  3. The last match in the file
  4. The first match before the window
  5. The first match after the window

Take a look at the Emacs Dwelling post to see the details and how to invoke the extra behavior. I don’t know why this hasn’t become the default. If you don’t use the extra capabilities, everything works exactly as before.

Posted in General | Tagged | Leave a comment

Analyzing Emacs News

Sacha Chua has a nice post that describes something that I really like: taking some data that she’s collected and analysing it to extract useful information. For some reason I really like that sort of thing and am always doing it myself with my own data.

In Chua’s case, she wanted to know how many Emacs News entries she’s written and plot them over time. It’s a little more difficult than you might think. First of all, she didn’t have the complete Emacs News index so she had to recreate the missing parts by converting the HTML entries into Org mode. She did that with a standard Unix pipeline using Pandoc.

Once she had everything in Org mode, she wrote some Elisp to extract the needed information and put it in a table. From there, it was easy to produce a graph showing how may entries she wrote by year. You can even see the years her daughter was a toddler because the number of entries went down for a couple of years. As Chua says, “Babies sleep a lot; toddlers, not so much.”

Take a look at Chua’s post to see all the code and the final graph. The data is mostly useful only for Chua just as mine is useful mostly for me but the way she goes about analyzing the data is useful to anyone that needs to take some data and massage it.

Posted in General | Tagged , | Leave a comment

Variables In Org Capture

Martin Schell has an excellent post on building and using Org capture templates. What’s interesting about his approach is that his template prompts for certain information—customer ID and site location in his example—captures that information in some local variables, and uses those variables to customize the capture for the particular customer.

His two main tools for doing this are:

  1. The %^{PROMPT|A|B|...} placeholder to prompt for data.
  2. The %(EXP) placeholder to execute the Elisp expression EXP.

He wrote some helper functions to deal with setting and accessing local variables. The first, ms/set-var, prompts the user for the value of a variable, creates the variable, sets its value, and returns the value. This is different from the %^{...} placeholder in that it captures the value of the user’s answer for later use. The other helper functions make use of the captured variables.

Take a look at Schell’s post to see the functions and how the whole thing hangs together. His needs may be more complicated than normal but the ideas he uses to solve them are handy and applicable to many—even simpler—situations.

I’ve used all the placeholders that uses in my own templates but the idea of capturing a variable for later reuse in the template is new to me. It’s a neat idea and definitely worth knowing.

Posted in General | Tagged , | Leave a comment

Success!

I’ve successfully updated PHP so although I will continue to monitor
things, everything looks fine. Let me know if you experience any problems.

Posted in Administrivia | Tagged | Leave a comment

Site Update

For some time, WordPress has been nattering at me to update PHP. I’ve been avoiding that because I’m afraid something will go wrong and the site will go offline but the recent PHP exploits have convinced me that it’s time to act. I queried my site provider and they assure me that the process is simple and direct so I’m going to do it right after I publish this.

That’s a bit silly, of course, because if something does goes wrong you probably won’t see this post either. I’ll wait a bit so that the post can get into RSS so at least I’ll be leaving some breadcrumbs.

In any event, I hope to be seeing you on the other side but if Irreal disappears for a while that’s why. Be assured that I’ll be doing everything I can to get things working again.

Posted in Administrivia | Leave a comment

Dictating Into Emacs

Sacha Chua has a really nice post on dictating into Emacs. She starts by quoting Matt Weber on how he writes better than he speaks. Chua can relate and so can I. We both feel the same way. As I’ve said before, “…my written thoughts are always much better organized than my spoken ones…”.

Being who she is, Chua resolved to fix this by arranging to dictate her posts into Emacs. As you can imagine, she encountered all sorts of problems along the way but was mainly able to find solutions for them. You can check her post—and Weber’s—to see how they’re doing that.

When I read Chua’s post, I thought, “maybe I should do that too” but then I realized that I don’t want to dictate my text. The truth is, I enjoy writing a lot more than I do speaking and I especially enjoy writing with Emacs. Although it’s not always obvious, I do a lot of revising on my posts as I write them and I usually try to make a final editing pass at least one day after I’ve written them. Speaking, on the other hands, feels more like “one and done” to me. I know that I could dictate a post and then edit the result but it’s not the same. And in any event, as I say, I enjoy writing a lot more than I enjoy talking.

I suppose, as Chua says, the day may come when ever encroaching old age, disease, or accident may make typing hard or impossible and I may be forced to consider dictation but until then, I’m happy to continue typing my text.

Posted in General | Tagged | Leave a comment

The iPhone Duo

There’s a tremendous amount of excitement about Apple’s new foldable iPhone, the Duo. A grown journalist squealed like a teenager when she saw John Ternus sporting one at a recent event. Apple is claiming that demand is so high that fulfillment wait times on orders could be as long as 3 months.

I hate to be the guy raining on everyone’s parade but I don’t get it. Rumors of an Apple foldable phone have been around for years but I always hoped they weren’t true. I’d much rather Apple devote its time to improving the regular iPhone or perhaps finally taking HomeKit seriously. The results from other manufacturers where not encouraging. All their foldable offerings were a disaster, some barely surviving their unboxing. Apple says they’ve solved all those problems but this thing has a foldable screen and it’s hard to believe it’s not going to have problems with all those repeated foldings and unfoldings.

Regardless, why would you want a folding phone? I just don’t see the attraction. John Gruber suggests an answer. The Duo, he says, is a terrible phone, far worse than any phone Apple has ever made. But he notes that what it does have going for it is that it’s a great tablet that folds up and fits in your pocket. If that’s what you’re looking for, maybe the Duo is right for you. If what you want is a phone, any recent iPhone is a much better bet. I agree with all that but I can’t get over the idea that the Duo is just a stunt.

Posted in General | Tagged | Leave a comment

Bloom Filters To The Rescue

Cristi Cretan has a very nice post on using Bloom filters to reduce system load. The TL;DR is that his team had a system that used a database to determine if they had seen a certain file before. That’s pretty straightforward but the requests were bursty and even though they had some front ends mediating the requests, it sometimes overloaded the database.

When Cretan looked at the requests, he discovered that the answer was almost always that the file was unknown. That suggested filtering the requests to avoid the expensive database lookup if the file didn’t exist. That’s a perfect case for the application of a Bloom filter. The idea is that that you hash the file identifier with a set of hash functions and set a corresponding bit for each function. On lookup, if the corresponding bit for each hash function is set, it’s likely that the value is in the set. More to the point, if any of the hash values come up with an unset bit, it’s a sure sign that the value is not in the set.

The salient point is that if any hash function comes up with an unset bit, it’s absolutely certain that the value is not in the set and the expensive database search can be avoided. You can see the details in Cretan’s post.

As I said, this is a nice application of Bloom filters but I have a couple of observations. First, Cretan got push back from his colleagues on the grounds that Bloom filters are probabilistic and the application demanded certainty. That push back speaks poorly of his colleagues as it reveals their lack of understanding of how Bloom filters work in the negative case.

Second, it’s not clear to me that a Bloom filter is needed here. To a first approximation, a single hash function should be sufficient here since we’re only interested in the negative case. It might be that a single hash function would have too many false positives and that multiple hash functions reduces that problem.

Regardless, the application of Blooms filters is just what this problem needed and it did, indeed, reduce system requirements.

Posted in General | Tagged | Leave a comment

A Small Improvement

As you all know by now, I really hate being spied on by web sites and other on-line entities. I’m pretty sure this misbehavior won’t be legal much longer but I’m equally sure that the on-line advertising industry won’t go gentle into that good night and will find ways to nibble around the edges of whatever laws get passed.

Happily, there’s Magic Lasso which pretty much solves the problem for Safari users. That would be the end of the story except that I use XWidgets with mu4e to read HTML emails and Elfeed entries through the wonderful elfeed-webkit. They work nicely but now Magic Lasso is no longer filtering their content so cookies and trackers are being accumulated. For the longest time I couldn’t find where they were being stored. I finally stumbled on its location and discovered that it was a simple text file that could simply be deleted.

The problem was that I had to remember to do it and more specifically, where the file was located. I finally stopped being stupid and wrote a simple function to delete the file:

(defun jcs-kill-cookies ()
  "Delete the cookies from Webkit"
  (interactive)
  (delete-file ".emacs.d/url/cookies")
  (message "Cookies deleted."))

It’s almost too simple to bother showing.

While I was at it, I also called jcs-kill-cookies when I quit elfeed so I don’t have to remember to do it manually. All of this is trivial, of course, but it’s another example of sanding down your workflow to make it as simple as possible. Now things pretty much take care of themselves. I suppose I should figure out a way to delete cookies after email too but for now I’m happy that the problem is mostly solved.

Posted in General | Tagged | Leave a comment

The Takete-Maluma Effect

Many years ago when I was still an undergraduate, I took a general psychology course as one of those annoying Liberal Arts electives that nerds—even at technical schools—are forced to endure. It turned out that I enjoyed it but now remember only one thing from it: the takete-maluma effect. The idea is that you are shown two shapes, one jagged and one rounded, and asked which is takete and which is maluma. It turned out that virtually all human beings, regardless of background and spoken language, chose takete for the jagged shape and maluma for the round one. You can see the shapes at the link above. It’s amazing how this stuck with me all those years. I misremembered maluma as being spelled “malumba” but otherwise recalled everything exactly.

The thing that’s striking about the effect is how universal it is. The only exceptions are people with certain physical defects and some people on the autism spectrum. Everyone else agrees: takete is jagged, maluma is rounded. Now it turns out that even dogs agree. Some researchers from the University of Parma in Italy reproduced the experiment for dogs. You can read the details at the link. The the words are different—bouba and kiki—but the results are amazingly consistent with but not as perfect as those for humans. What is it about these sounds that suggest a shape even to animals?

Posted in General | Tagged | Leave a comment