For the English part of the blog, see Content AND Presentation.

2017-07-22 TeX-parse-macro

In one of my earlier posts I promised to show how to prevent AUCTeX from putting braces after a command inserted with TeX-insert-macro.

The point is, you shouldn’t be really using TeX-insert-macro at all. It is an interactive function doing things you wouldn’t want to do in an Elisp program, like running TeX-after-insert-macro-hook (or maybe you would? I’m not sure…). Anyway, while admittedly it is suited to be run non-interactively (it contains a (when (interactive-p) ...) clause), here’s a slightly better idea: use the TeX-parse-macro function. It takes two arguments: a string (macro name, without the leading backslash) and a list describing its arguments. See its docstring to learn what are the possibilities; for my case, saying (TeX-parse-macro "pause" '(0)) worked very well. (The '(0) says that there should be no braces after \pause; it is in the list, because each element of that list corresponds to an argument (in the TeX sense) of \pause. Try something like e.g. (TeX-parse-macro "usepackage" '([t] nil)) for a foretaste of what is possible.)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX, CategoryLaTeX

Comments on this page

2017-07-15 org-duration-format and other clock-related settings

As I mentioned many times, I use the clocking feature of Org-mode a lot. At first, I used org-clock-display (C-c C-x C-d) to see how much time I spent on various things. This command temporarily shows times for various subtrees in your current buffers. By default, it shows the time for the current year, but I set the org-clock-display-default-range variable to today. (Alternatively, I could train myself to use the C-u prefix – this I only learned recently.) See the docstring of org-clock-display to learn even more.

However, some time ago I started using clock reports. They are really cool, since they have a lot of options to tailor them to suit exactly your needs. One thing, however, that bugged me, was that times longer than 24 hours were displayed as xd hh:mm. Since I have quite a few long-running projects which require several dozen hours to complete, it was really annoying. I searched the internet, and finally found out about the org-duration-format variable. It allows for very flexible setting of the format in which durations are displayed (both with org-clock-display and in clock reports).

But wait, there’s more! There is also the org-duration-units variable. It is an alist, which by default contains among its entries the expression ("d" . 1440). See its docstring to learn how to change it so that it will use 8-hour days, 5-day weeks etc. (this way, 17 hours can be expressed as “2 days and 1 hour”, for instance). Cool!

Another variable I found worth customizing is org-clock-mode-line-total. By default it is auto, which means the same as all for non-repeating tasks (and I don’t usually clock repeating tasks anyway). I prefer to set it to today, so that I can see the time I spent on the current task today in the modeline. (Since my workflow includes setting minimal time spent on various things every day, this makes sense.)

And another thing I have in my setup is setting org-clock-out-remove-zero-time-clocks to t. I am not sure why this is not the default.

Happy clocking!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

2017-07-09 current-prefix-arg

A question that popped some time ago on one of the Emacs-related mailing lists was how to “simulate” interactive code P (that is, capital “P”), in a more complicated, s-expression form of interactive.

Recall that P as an interactive code yields the raw prefix argument. This may be nil (if no prefix argument was given), an integer (when there was a regular, numeric prefix argument), the symbol - (that is, a minus), in case of C-u - etc., or a list with one element, which is always a power of four, and its four-base log is then the number if times C-u was pressed. (The “raw” prefix argument can be converted to a regular number with the prefix-numeric-value function, quite surprisingly written in C and not Elisp.)

Now the interactive form argument can be also an s-expression; it is then evaluated to obtain the list of arguments for the interactive command being called.

There are a few nifty tricks with interactive. (One of them is a simple way to detect whether a function was called interactively or not.)

But what if you need an s-expression, but you also want to get the raw prefix argument as one of the arguments? (Say you want your command to read some argument using read-string, but also to detect things like C-u C-u as opposed to C-u 16.) The answer is simple: you just consult the variable current-prefix-arg.

But that’s not the whole story. There are two more variables like this one: prefix-arg and last-prefix-arg. The meaning of the latter is clear: it is the value of prefix argument for the previous command. (I am not sure why it may be useful, but in case you need it, it is there. It doesn’t seem to be used anywhere in Emacs sources.) The former is probably something you should never touch: if set, it will become the prefix argument for the next command. In case you are wondering, why on earth anyone would want to override what C-u does, the answer is: C-u is actually bound to universal-argument, which works exactly by setting prefix-argument. And looking at the implementation of universal-argument, which is – perhaps surprisingly – implemented in Elisp, not C, one wonders what would break if we changed the behavior of C-u, so that e.g. pressing it twice would yield (9) instead of (16) etc. (Spoiler: probably a lot of things.) For extra fun, look up universal-argument (and a few of its sister commands) in the Elisp reference. When introducing them, it says: The following commands exist to set up prefix arguments for the following command. Do not call them for any other reason. Of course, the only thing you want to do after reading that is trying them out in your own code;-). Also, reading through simple.el where these and related commands (also, the universal-argument-map keymap!) are defined is a fun experience.

I am not sure whether all this machinery is good design. It is clever for sure. I would not be able to come up with anything better, either. But it makes my head spin.

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page