Content AND Presentation

2018-03-18 My Org-mode hydra

I mentioned a lot of times that I am a big fan of Org-mode clocking feature. Even if I clock some things only for myself, I find it useful to learn how much time I actually need for some task. This is often surprising – for example, I think most people are completely unaware of how much you can accomplish by spending five to ten minutes every day on something (notice the “every day” part!).

Of course, I want my clocking to be as smooth as possible. Since I do not use Org-mode for writing everything – I know LaTeX fairly well and I use it for quite a few things – it means that I cannot just C-x C-c C-i wherever I am when I start writing.

My first solution to that was to bind C-x C-c C-i to a suitable function globally. Some time later, however, I decided to use hydra to launch a few Org-mode related commands.

(defhydra hydra-org (:color blue :timeout 12 :columns 4)
  "Org commands"
  ("i" (lambda () (interactive) (org-clock-in '(4))) "Clock in")
  ("o" org-clock-out "Clock out")
  ("q" org-clock-cancel "Cancel a clock")
  ("<f10>" org-clock-in-last "Clock in the last task")
  ("j" (lambda () (interactive) (org-clock-goto '(4))) "Go to a clock") 
  ("m" make-this-message-into-an-org-todo-item "Flag and capture this message"))
(global-set-key (kbd "<f10>") 'hydra-org/body)

This way, I can just press f10 twice to clock back in the last task, or press f10 i to clock in to something else, or do a few other things. (Notice that I have my command to capture emails here, too. Actually, I have a bit more, but I will blog about the other two entries in this hydra some other day.)

Have a good time clocking!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

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


CategoryEnglish, CategoryBlog