-
Recent Posts
Links
Archives
- May 2025
- April 2025
- March 2025
- February 2025
- January 2025
- December 2024
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- March 2021
- February 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
Categories
Meta
Anchored Transpose
Thanks to Tim Stewart, I stumbled across the anchored-transpose
package. You can think of it as a generalization of the other transpose functions such as transpose-chars
, transpose-words
, transpose-sexps
, and the other less used transposition functions. Instead of transposing around the point, anchored-transpose
lets you specify an arbitrary anchor region to pivot around.
Here’s an example of its use: suppose I have
First DO this and then do that.
and I want
First do that and then DO this.
To do that
- Select a region that covers the things you want to swap and everything in between.
- Call
anchored-transpose
. - Select the anchor region. That is everything in between what you want to transpose.
- Call
anchored-transpose
again.
For our example, we first select the region
DO this and then do that
and call anchored-transpose
. Then select
and then
and call anchored-transpose
again.
You can also swap two disjoint regions by selecting one, calling anchored-transpose
, selecting the other, and calling anchored-transpose
again. You can specify the two regions in any order. You can also select the entire phrase and anchor phrase in the first example in either order.
I often want to swap parts of a sentence or even several sentences so anchored-transpose
is a real win for me. I’ve mapped it to 【Hyper+t】 to make it easy to call.
You can get anchored-transpose
from Melpa.
Disappointment
Richard Posner is a 7th Circuit Federal Judge. He’s always struck me as the ideal jurist. Informed not only on the law but in many other areas, especially economics. More than a Judge, he’s an intellectual and perhaps even a polymath.
I was really saddened, therefore, to see this piece on BoingBoing detailing some of Posner’s shocking remarks on privacy. Among other things, Posner thinks that the NSA should be given carte blanche “to vacuum all the trillions of bits of information that are crawling through the electronic worldwide networks”, that privacy is over rated, and that he’s shocked that any company would be allowed to build a device that the government can’t search.
These statements—and more, read the post—are shocking and profoundly disappointing. I expected more from Posner and hope that the rest of the judiciary rejects his views.
Diacritical Mark in Emacs
I recently ran across this old post from Emacs master Mickey. In it, Mickey explores ways to enter diacritical marks in Emacs. For example, if you want resume to be rendered (properly) as résumé you need to know how to convince Emacs to do that.
It turns out that there’s at least three ways of doing it. To get the ‘é’ character, I usually just type 【Ctrl+x 8 ' e】 but I could also type 【Ctrl+x 8 Return】 LATIN SMALL LETTER E ACUTE
or if I know the codepoint, 【Ctrl+x 8 Return】 e9
.
If you’ve used Emacs for any length of time and needed to enter diacritical marks, you’re probably familiar with these methods. Mickey has a third way that I didn’t know about: you can use multilingual text input along with TeX input mode. If you’re writing a document with a lot of diacriticals, this method may be your best bet. Head on over to Mickey’s post for the details.
My Solution to the Changing Times Challenge
Last week, I posted an EmacsGolf challenge on changing times to 24-hour notation. Most of the solutions were much like mine: they used query-replace-regexp
with a complicated regular expression and an even more complex replacement expression. One trick that most responders missed was using \#n
to get the nth subexpression as a number. That avoids needing to call string-to-int
or something similar.
That said, my solution was to call query-replace-regexp
with
\([0-9][0-9]?!\):\([0-9][0-9]!\)\([ap]!\)
as the regular expression to search for and
\,(format "%02d:%s" (if (equal \3 "p") (+ \#1 12) \#1) \2)
as the replacement expression.
David Ongaro had a really great (and surprising) solution leveraging the date handling functions of Emacs Calc. It’s nice because it avoids the horrendous regular expression that the rest of us used and simplified the replacement. Very clever.
Happy Birthday!
Today in history: Ada Lovelace was born. Computer programmers rejoice! pic.twitter.com/NKpYBxZMjd
— Digi-Key (@digikey) December 11, 2014
Names
Yesterday, I wrote about name spaces in Emacs Lisp and mentioned Artur Malabarba’s names package. In a nice example of serendipity, Malabarba has just published a post that explains what the names package is all about1.
The basic idea is that you wrap your Elisp package in a define-namespace
macro and write your code as if you were in a private name space. That is, you needn’t worry about adding the package name to every symbol that might be seen externally. This is pretty much what I was describing in footnote 3: internally all symbols are specified and accessed without worrying about the package name. Externally, the package name must be prepended to access those symbols.
The nice thing about the package is that it has no impact on existing code. Everything still works as before. When you’re writing new code you can choose to use define-namespace
and dispense with worrying about adding the package name to all of your variables and functions. The define-namespace
macro will take care of doing that for you.
You might think this could be risky—think about how you would write that macro—but Malabarba has already used it in two packages that he’s released to ELPA. When you read his post you will see that he’s considered the edge cases.
This package is really an accomplishment. Head on over and see if you don’t agree. It may even help put the eternal fretting about Emacs name spaces to rest.
Footnotes:
1
We don’t coordinate these things. Really.
Name Spaces in Emacs Lisp
Whenever Emacs Hackers come together to discuss what the most urgently needed enhancements to Emacs are, some sort of module system is always mentioned. In terms of Common Lisp, the idea is to add a (Common Lisp) package system to Elisp1.
It seems like a no-brainer. The current system seems to be a mess where we’re forced to add the module name to each package symbol2 so they don’t leak into other modules. It’s something that I never really questioned until I read RMS’s explanation for why Elisp doesn’t implement name spaces.
RMS takes a lesson from his efforts in implementing the Common Lisp package system back in the 1980’s. He says that although the idea sounds nice, it doesn’t really do what you need it to do: you almost always have to add the module name to each exported symbol anyway so the extra complexity in the language isn’t worth it. He decided that for Emacs you might as well just add the package name to the symbol and do away with all the name space machinery.
When I first read that, I thought it was obviously wrong. On further reflection, I think that RMS had it right. Suppose you have two Emacs packages that implement an insert-results
function. If you want to call insert-results
, you clearly you have to specify which function to use; you have to specify the package name. But how do you know whether there’s another package that exports the same function name? Maybe you’re not loading it today but will tomorrow or the next day. Just to be sure, you better specify the package name every time.
See what happens? You can either specify some-package:insert-results
or some-package-insert-results
. It’s the same amount of work for the user either way but in one case the package writer has to deal with the name space machinery. Yes, name spaces do protect internal variables and functions but maybe Malabarba’s names package is good enough for that.
Of course there are many intermediate modules systems that might fit well3, but it’s clear to me that the Common Lisp package system is not what we need. What do you think?
Footnotes:
1
The Common Lisp package system implements name spaces. This is different from the Emacs package system, which deals with obtaining and loading 3rd party packages.
2
Although Artur Malabarba’s names package can help here.
3
Maybe that within a package source file all the symbols are accessible without the package name, but externally the package name has to be specified.
Debugging With yasnippet
Bin Chen has an excellent post on adding debug statements into source code using yasnippet
. Us old timers are used to adding printf
statements into our code to create an audit trail of the execution. There are, of course, modern tools that obviate the need for these statements but sometimes they’re just what you need to do a quick check. The nice thing is that the strategy works with any language.
Chen’s idea is to leverage yasnippet
to insert the debug statements with as little effort as possible. His post uses javascript as the example language but, as he remarks, the same idea works for any language. It’s easy to underestimate how flexible yasnippet
can be. The examples that Chen gives shows how it can extract a lot of information from the source code. This makes it possible to insert an entire debugging statement with a minimum of input. See Chen’s post for examples of this.
Even if you’re not interested in debugging, Chen’s post will give you some ideas about using yasnippet
in non-trivial ways. I highly recommend his post.
Sacha Chats with Karl Voit
Sacha Chua has a new Emacs Chat up. This time it’s with Karl Voit. It’s a really interesting chat. Voit is concerned with managing personal information and uses Org Mode and some custom scripts to do that.
One set of scripts, Memacs, captures information from his email, SMS, RSS-feeds, blog posts, bank statements, and VCS commits and exports them into Org format so that they can be included in his Org files. The result is a sort of diary of that records all his appointments, phone calls, text messages, tweets, work product, and other noteworthy events that happened on any given date. That makes it easy to ask easy questions such as, “What was I doing on June 2, 2009?” as well as more difficult questions such as, “Who called me on the day I met my girl friend?” and the like. Org mode makes queries like these easy even if you don’t remember the date you met your girl friend.
Voit also describes his home-grown blogging system, lazyblorg. A nice feature of lazyblorg
is that he can write a blog post in any Org file and export it to his blog. Thus, if he’s working in the Org file associated with one of one of his projects, he can write the post about what’s he doing in situ and publish it. If he’s working in some other file and wants to blog about it, he just writes the post and published it. As a result, his blog posts are associated with the files they’re about. Very handy.
Later in the chat, Voit talks about using yasnippet
to semi-automate repetitive chores. The example he gives is organizing trips to a local comedy club with like-minded friends. The snippet captures all the details of the outing including the when, where, and who of the act as well as dates he should send initial and reminder emails to his friends.
If you’re interested in organizing your life and capturing the details for later research, you should watch this chat and check out some of Voit’s software.