2018-03-10 A tip on yanking

I have a few longer posts in the works, but for today I want to share a simple trick. We Emacs users all know and love the kill ring, and many of us know about M-y (yank-pop) and even C-u ... C-y (i.e., a numeric argment to yank). For those who don’t know: C-u 1 C-y is equivalent to plain C-y, but C-u 2 C-y (or just C-2 C-y) inserts the previous killed text (much like C-y M-y), and also marks it as the current one. With higher arguments, it inserts earlier kills.

However, you can also give non-positive arguments to C-y. For instance, C-0 C-y yanks the oldest kill (assuming you haven’t yet made your kill ring overflow, which depends on the kill-ring-max variable, defaulting to 60, and that you haven’t messed up the kill ring with M-y or prefix arguments to C-y.) Also, C-- C-y inserts the second earliest kill in history (under the same assumptions).

I don’t know how useful it is – you can always say C-y M-- M-y for that, too – but if you need it, it’s there. (One use-case would be when you yanked something from back in the history and then want to get back to something killed later.) Also, if you find yourself inserting various texts repeatedly, you might want to check out registers, which can hold arbitrary texts or even other useful things. And if you need to insert texts with variable elements (or cannot memorize one-letter register names), Yasnippet might be for you.

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2018-03-03 pdf-annot-print-annotation-functions and Windows newlines

Some time ago I wrote about how I use Andreas Politz’s excellent pdf-tools to work with annotated pdfs. I still think this is great, but there was one thing that annoyed me a lot. Multiline annotations made on Windows (I guess) displayed with ^M in place of newlines. That is unfortunate, and I sometimes manually changed them to ^J (i.e., newlines). It dawned upon me, however, that being a programmer, I should be able to do something better about it. So I went to see what function is responsible for displaying annotations. I wasn’t sure whether I’ll advise or modify it (well, I had a slight hope for a hook…) – but what I found surpassed my expectations! It turns out that pdf-tools already has support for modifying annotations before display by running a series of functions on the annotation; the first one to “work” (look up the pdf-annot-print-annotation-functions variable to learn more) is used.

Also, there is one thing in the default value of this variable that really looks interesting – it checks (using a rather simplistic way, I admit) whether the annotation is written in LaTeX, and if yes, uses LaTeX to render it (you need dvipng installed for this to work). This way, you can even have formatting (including math formulæ) in your annotations!

So, the only thing I had to do was to write a function to replace my “returns” with proper newlines.

(defun pdf-annot-convert-return-to-newline (annot)
  "Convert ^M's in STRING to ^J's."
   "\r" "\n"
   (pdf-annot-get annot 'contents)
   t t))
(eval-after-load 'pdf-annot
  (lambda ()

Notice how I pass a lambda instead of a quoted form to eval-after-load – I have recently learned that trick from Chris Wellons. (If I didn’t do that, I’d effectively overwrite pdf-annot-print-annotation-functions.)

Also, this doesn’t affect the way the annotation is displayed after clicking on it. This makes sense, since this way of showing it is intended for editing, so you might want to see its exact value, without any modifications. My use-case, which is the list of annotations displayed with C-c C-a l (which displays both the list and the annotation the point is on), is covered, as is the tooltip.

It’s much better now!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX, CategoryLaTeX

Comments on this page

2018-02-25 Simple way of assigning formulas to fields and columns in Org tables

Today I’m going to share a simple trick concerning Org-mode spreadsheet tables. I knew that I could press C-u C-c = in an Org-mode table cell to install a formula in that cell (or C-c = to install a column formula). However, there is a simpler way: you can just type := followed by the formula and press TAB, RET or C-c C-c. (Without a colon, it installs a column formula.) Very handy! (And it was in the manual all along… Once more I learned that at least skimming through the manual from time to time is a good idea!)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page