Capturing the Current File Location

Marcin Borkowsi has a nice post on how to capture the current file’s location and copy it to the system clipboard. It’s just what you need for sharing information about data in a file with a colleague. By file location he means the path to the file and the line number within that file.

That doesn’t seem too hard but there are some wrinkles. First of all you want the absolute line number within the file not just the number of the line visible in the buffer. That’s pretty easy but the second problem is a bit trickier.

Sometimes, just the name of the file is not enough. It may be that two files within a project have the same name but lives under a different subdirectory. Your first thought is probably to capture the full path to the file but that isn’t optimal either. As Borkowski says, there’s no point in showing the full path on his machine. What’s needed is the path relative to the current project.

That means the path relative to the current VC repository. It’s pretty easy to get that with the vc-root-dir function. Borkowski has some code that captures the file path and line number and copies it to the system clipboard. It’s simple and can be copied and used as is or modified to meet your particular needs.

The post is definitely worth a read if only to discover how to deal with the various issues.

UPDATE [2022-06-26 Sun 14:40]: Added missing link to Borkowski’s post.

Posted in General | Tagged | Leave a comment

Having a Per Contact Email Address

I recently had my own experience of the Baader-Meinhoff Phenomena. The other day I read Karl Voit’s post from 2015 on having a separate (from) email address for each correspondent. It seemed a little odd to me. Why would I want to do that? Voit didn’t give a reason, he just said he liked to do it.

He uses Mutt as his email client and wrote a python script to interface with Mutt to automate the generation of unique from email addresses. Of course, for this to work you have to have your own domain to which you can add multiple email addresses.

But the question remains, why do this? Right after reading Voit’s post I saw this post from TyChi that provides a rationale for the practice. The post is a little rambling but the TL;DR is that it keeps companies and Web sites that you communicated with from using your email address as an identifier to tie your activities from different sites together to build a more complete dossier on you and your activities.

If you’re interested in this sort of thing and use, say, Mu4e in Emacs for your mail, it would, I’m sure, be reasonably easy to adapt Voit’s python script to Elisp and integrate it into Mu4e. The middle ground—that I use—is to generate special email addresses for sites that I don’t want spamming me. I do this by hand but an automated solution would be nice.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: Notion

Romain Slootmaekers has his own take on the Notion app:

To be fair, Notion is a pretty nice app but as I’ve written before you can do the same things with Org-mode. If you’re an Emacs user, there’s no reason to be using Notion, especially since your data is held on their servers.

Posted in General | Tagged , , | Leave a comment

Hiding Some Org Subtrees

The other day I wrote about Kaushal Modi’s post on Advice Combinators. Modi has another post that uses that information but the post is interesting in its own right. The problem is to fold (or collapse) headings having a certain property. His use case for this involves the file of his blog posts. Take a look at his post for the details.

The method Modi employs is pretty simple. He loops through all the headings with org-map-entries calling outline-hide-subtree whenever the property EXPORT-FILE-NAME is set. All that is handled by the single call to org-map-entries so it’s easy. Modi makes another pass also collapsing subtrees that are Footnotes or COMMENTS. That’s even easier being a simple re-search-forward.

Since Ctrl+c Tab does something similar in plain Org-mode, Modi decided to call his function with the binding Ctrl+u Ctrl+c Tab. He accomplished that by advising the Ctrl+c Tab function using the :before-until combinator.

To be sure, collapsing only certain headings isn’t something most of us most to do very often but it’s nice to see how to do it as well as see a nice application of an advice combinator.

Posted in General | Tagged , | Leave a comment

Paper Receipts at Drive-Thrus

You may have noticed those signs at your local fast food store offering cash or a free meal if you fail to get a receipt after you pay. Once they’re pointed out, you see them everywhere. Of course, this has nothing to do with making sure customers get a receipt for their records.

I’ve long known that the reason for this policy is to prevent store employees from canceling cash orders before they’re recorded and pocketing the customer’s payment. But I always assumed the problem was merely a case of petty employee theft and was more of a nuisance than anything else. Boy was I wrong.

Brian Krebs over at Krebs on Security has a post that shows how serious the scam can be. The post tells the story of a Jimmy John’s sandwich shop that lost almost $100,000 from the fraud and had to close temporarily.

This isn’t a megacorporation that can afford to write off fraud at that scale. It’s a mom and pop franchise that’s probably operating on the slimmest of margins. Part of the problem was that the owners didn’t have one of those signs incentivizing customers to make sure they got a receipt. They’ve remedied that, of course, but it was a $100,000 lesson.

The takeaway from this story is that even a very low tech scam can result in significant losses.

Posted in General | Tagged | Leave a comment

Advice Combinators

A really powerful Emacs feature for those who know a bit of Elisp in the ability to advise functions. Historically, the defadvice macro allowed the specification of code to run before, after, or around a function call. It’s really handy for modifying the action of a function without changing the function itself or getting into the details of how a function works. I have advice for 7 functions in my init.el, an indication that it’s more useful than you might think.

The defadvice macro has been obsoleted by the newer and more flexible advice-add and add-function macros. You’ll usually want to use advice-add because it works in more situations. The new macros support a finer grained specification of where the advice is to be applied.

Kaushal Modi over at A Scripter’s Notes has an excellent post that explains all the methods of specifying where the advice will operate. These methods are called “advice combinators”. Modi has what are essentially railway diagrams that illustrate the operation of each of the combinators. They’re an easy way of understanding what each of them does. He also has a summary table that describes in words how each of them works.

You should also take a look at the built-in add-function documentation that shows the new function that is created for each of the combinators.

Modi’s post is the best explanation of using advice that I’ve seen. You should definitely take a look at his post to see what’s possible.

Posted in General | Tagged | Leave a comment

Am I Being Watched?

If you’re paranoid, the answer is “of course”. If you aren’t paranoid, the answer is “of course”. Here’s a humorous tweet that provides the proof:

Posted in General | Tagged , | Leave a comment

Emacs and the Lindy Effect

Vivek Haldar has an observation about the expected lifetime of Emacs:

The Lindy Effect postulates that the longer some (nonperishable) entity has existed, the more likely that it will continue to exist. It’s a bit more technical so follow the link to Wikipedia if you want the details.

Nothing lasts forever, of course, so even the mighty Emacs will eventually fade away but not, if you believe in Lindy’s law, anytime soon. It make sense if you think about it: the fact that Emacs has lasted as long as it has means that it’s meeting the needs of its users and continuing to adapt to new needs so its chances for continued support from its current users and its being embraced by new users is good.

Posted in General | Tagged | Leave a comment

Highlighting

This week there were two excellent posts on highlighting in Emacs. The first was Marcin Borkowski’s post, Highlighting and de-highlighting things. He covers most of highlighting commands but not their default keybindings.

When I first saw Borkowski’s post I thought I’d write about it if only to have a handy guide to the commands. Before I could do that, Mickey Petersen published his post on the same subject matter. That post, Highlighting by Word, Line and Regexp covers a few more commands and includes their bindings. Mickey also explains how to make a set of highlightings persist in a file.

It turns out that even Irreal has plowed this ground but it was so long ago (over a decade) that I’d forgotten all about it. One nice thing about that post is that I provided a table of keybindings at the end but I didn’t cover all the commands. Below is a new table based on Mickey’s list of bindings. The purpose of many of them is obvious from the command name but take a look at Mickey’s post for what all these commands do. If you can remember the Meta+s h part, the commands are pretty mnemonic but, of course, if you use them regularly they’ll get burned into your muscle memory.

Key Sequence Command
Meta+s h . highlight-symbol-at point
Meta+s h l highlight-lines-matching-regexp
Meta+s h p highlight-phrase
Meta+s h r highlight-regexp
Meta+s h u unhighlight-regexp
Meta+s h w hi-lock-write-interactive-patterns
Meta+s h f hi-lock-find-patterns
Posted in General | Tagged | Leave a comment

Red Meat Friday: This Seems About Right

It appears Irreal’s disdain for journalists and politicians is not sui generis:

Posted in General | Tagged | Leave a comment