Journal

2024-02-26 A simple trick with URL parsing in plain text emails

Today I only have a very short tip I thought up a few days ago. If
you sometimes send URL via emails (like me), and you absolutely hate
HTML emails (like me), there is a common and annoying problem. If the
URL you send is the last thing in a sentence, and you want to be
correct and end that sentence with a period (or other punctuation), a
lot of email clients will treat that punctuation as part of the URL,
and of course such “modified” URL won’t work for the recipient. I
usually solved that by putting a space between the URL and the period
– not 100% correct, but I could live with that. A few days ago it
occurred to me that there is another, slightly hackish way to solve my
issue. From now on I’m using a hash instead of a space. Assuming
that the website I link to doesn’t have any element with the id~ of a
period (or any other weird thing like an exclamation mark, of a period
followed by a closing parenthesis etc.), the punctuation will be
ignored by the browser, but I won’t need to put any space before the
end-sentence period.

You’re welcome!

CategoryEnglish, CategoryBlog

Comments on this page

2024-02-17 Opening external drives in Dired

I use external drives pretty often – for backups, for moving files between machines, and for storing mp4 files, for example. I’ve been using UDisks for quite some time now. It automounts an external drive under the /run/media/$USER/VolumeName directory (where VolumeName is different for each drive, of course).

I also use Dired as my main file manager. As most Emacsers know, it’s far from shiny, but it’s incredibly powerful, especially combined with some other Emacs features.

One problem I have is that when I insert a drive into one of the USB ports, I’d like to be able to open it in Dired. I could of course create a bookmark pointing to it, but I don’t want to maintain a seperate bookmark for every drive I use. I could also bookmark the /run/media/mbork directory, but then I’d have to press one more key to get to the VolumeName directory. I figured that I could create a function which opens Dired in the root directory of my drive, assuming that it’s the only mounted one. (If there are more mounted drives – which means more directories under /run/media/mbork – the function should allow me to select one of them.) Of course, I could probably go even further, detect that a drive was mounted and open its directory in Dired automatically, but that might be a bit too much. Sometimes I don’t want to do anything with the drive (for example, when I use it only to make my daily backups), and sometimes I might be doing something else (for example reading or writing), and Emacs suddenly switching to another buffer would not be helpful.

Anyway, here’s some Lisp code I wrote in about 10 minutes.

(defcustom automount-directory (format "/run/media/%s" user-login-name)
  "Directory under which drives are automounted.")

(defun automount-open-in-dired ()
  "Open the automounted drive in Dired.
If there is more than one, let the user choose."
  (interactive)
  (let ((dirs (directory-files automount-directory nil "^[^.]")))
    (dired (file-name-concat
            automount-directory 
            (cond ((null dirs)
                   (error "No drives mounted at the moment"))
                  ((= (length dirs) 1)
                   (car dirs))
                  (t
                   (completing-read "Open in dired: " dirs nil t)))))))

And of course, if you want to learn to code your own convenience commands like this, as usual I recommend Introduction to programming in Emacs Lisp by the late Robert J. Chassell as an appetizer, and my book, Hacking your way around in Emacs, as the next course.

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2024-02-12 Finding Bible quotes

I often have the need to find some particular quote of the Bible – either I am reading some religious text or I want to link to some passage on my blog. What I miss is the ability to quickly see the relevant passage, open it in a browser and create an Org mode link to it.

Me being me, I’d like to do all of this from the comfort of Emacs (naturally). I found a few Emacs packages with similar functionality, but they all have the same main issue: they do not support the Catholic Bible. (And even if they had, they do not seem to have the features I’d like to have.)

Of course, I set out to write my own. It is a very simple package, with one command, nab-open-place. It asks for the Bible book name (with autocompletion) and the chapter number; with a prefix argument, it also asks for the verse number. It then opens the selected place in the browser, puts the link to it on the top of the kill ring, and optionally stores an Org mode link in org-stored-links so that it can be inserted using org-insert-link (C-c C-l).

Note that it doesn’t have any error checking, and will happily create a link to the 10000th chapter (or 10000th verse) etc. – this does not bother me, and it’s quite a bit of work to add that (I’d basically need a database containing precise information about the number of chapters in every book and the number of verses in every chapter). I hope that even this very simple package will make my life easier (and the next opportunity to use it will happen quite soon when I write the next post at Crimson Eleven Delight Petrichor).

One last thought is that I’d like to have a similar tool for the most popular Polish translation of the Bible, the Millennium Bible. Unfortunately, links to various books and chapters there don’t follow a simple pattern like the New American Bible, so I put that on a backburner. Maybe some other day…

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode, CategoryFaith

Comments on this page

More...