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

2021-04-17 Multiple Help buffers

When using many Emacs’ help commands (like C-h f, or describe-function), we are presented with the *Help* buffer. It has some basic navigation commands, most importantly forward-button (TAB), hepl-follow (RET), help-go-back (l) and help-go-forward (r), and usually they are enough for me.

Some time ago, however, I had a very specific need which could not be achieved by any of them. I wanted to compare the docstrings of two similar functions. Here’s the issue – calling describe-function replaces the contents of the *Help* buffer with the docstring of the next one. I could press l and r repeatedly, of course, but I really wanted to see both docstrings at the same time.

Well, I did the first thing that came to my mind, and it just worked. I switched to the *Help* buffer, said M-x rename buffer *Help 2* RET and called describe-function again. Precisely as expected, I ended up with two help buffers. One drawback was that the “second” one did not have the help history (for some reason), but that didn’t bother me much – after I compared the docstrings I just killed it and that’s it.

This is definitely not the sort of the tip you’d need every day, but it might be helpful one day, so I decided to share it. Happy Emacs-ing!

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2021-04-10 deactivate-mark

Emacs Lisp has two entities called exactly the same – the deactivate-mark function and the deactivate-mark variable. (This is possible at all because Elisp is is a Lisp-2.) As the name suggests, they both serve the same purpose (or rather a similar one), but there seems to be a subtle difference.

The function deactivate-mark is simple – it deactivates the mark, done. The variable works in a different way, though. If a command sets it to a non-nil value, then the Emacs command loop will deactivate the mark upon exiting from that command.

You may then ask whether you should say (deactivate-mark) or (setq deactivate-mark t) in your command if you want it to deactivate the mark. The answer is (probably) that it doesn’t matter, but the main use case for the variable seems to be something else entirely. According to the docs:
All the primitives that change the buffer set deactivate-mark. […] To write Lisp code that modifies the buffer without causing deactivation of the mark at the end of the command, bind deactivate-mark to nil around the code that does the modification.

This means that if you have a command that e.g. inserts a space, the (insert " ") hidden somewhere in its code will set deactivate-mark to t and hence the mark will get deactivated after it finishes. The reason this variable exists seems to be that you may actually want the mark not to get deactivated. The manual goes on to give a simple example:

(let (deactivate-mark)
  (insert " "))

This means that insert will set deactivate-mark to t, but it will only change the local binding created by let – so after the let exits, the variable’s value will still be the previous one (which may happen to be nil, since this is what the command loop sets it to before running any command – this is not mentioned in the Elisp reference, but the docstring of the deactivate-mark variable says so).

Incidentally, this works similarly:

(let ((deactivate-mark t))
  (insert " "))

which is not intuitive, but of course makes perfect sense.

Of course, you can just say (setq deactivate-mark nil) at the end instead of playing around with let in this case, but the let trick may still be useful if you want to make the activation or deactivation of the mark more fine-grained (e.g., instead of just leaving it activated at the end of the command, you set it to some value depending on some condition at the beginning and only then insert that space, or something like that). There are probably tons of ways you can use it, but the bottom line is that its main use seems to be to prevent the deactivation of the mark (quite contrary to its name). As one of the participants in the discussion I mentioned put it:
In a nutshell: deactivating (i.e. setting to nil) deactivate-mark deactivates the mark-deactivating code. Phew ;-)

And that’s it for today!

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2021-04-04 Easter

Christ is risen! So, happy Easter for everyone! I’m looking at my Easter post from a year ago, and I stand by everything I said then. Again and again it turns out that Christ is stronger – and not only than crises and illnesses, but even than my sins and weaknesses. It was a hard year, and it seems the hardships will stay with us for some time, but it was also a year full of blessings. One thing that is now very apparent to me is that the reason this year wasn’t the greatest one of my life is not that something bad happened to me, or that not enough good things happened to me – it is because I wasn’t able to properly receive everything God gave to me, and unfortunately it was my fault…

My Lord, please give me the virtue and bravery so that I’ll be able to take everything you have to me! And I thank you so, so much for Your gifts! Let my sins not overshadow the joy today, and for the rest of my life, too!

And just in case you are a newcomer to my blog and don’t know about this little tradition, rest assurred that I will offer a decade of Rosary for everyone who reads this!

CategoryEnglish, CategoryBlog, CategoryFaith

Comments on this page