John D. Cook has a useful post on using “corner quotes” (⌜ ⌟) to delimit regular expressions in text. As Cook says, it makes a lot of sense especially when the regular expression begins or ends with a space. Cook’s port deals with using Unicode for the corner quotes but it’s also easy to do in Emacs.
In vanilla Emacs, the way to do it is to specify TOP LEFT CORNER
and BOTTOM RIGHT CORNER
with insert-char
through the Ctrl+x 8 binding. If you have Ivy installed, you can also use the lceil
and rfloor
entities through ivy-insert-org-entity
a handy function that I stole from John Kitchin’s Scimax.
(defun ivy-insert-org-entity () "Insert an org-entity using ivy." (interactive) (ivy-read "Entity: " (loop for element in (append org-entities org-entities-user) when (not (stringp element)) collect (cons (format "%10s | %s | %s | %s" (car element) ;name (nth 1 element) ; latex (nth 3 element) ; html (nth 6 element)) ;utf-8 element)) :require-match t :action '(1 ("u" (lambda (element) (insert (nth 6 (cdr element)))) "utf-8") ("o" (lambda (element) (insert "\\" (cadr element))) "org-entity") ("l" (lambda (element) (insert (nth 1 (cdr element)))) "latex") ("h" (lambda (element) (insert (nth 3 (cdr element)))) "html"))))
The latter method uses left and right floor
and ceiling
entities (⌈ ⌋) rather than the corner entities but the results are almost the same. At least they are if the regular expression doesn’t contain a floor or ceiling operator.
I usually just set the regular expression in a constant width font but as Cook notes that doesn’t work as well when the regex begins or ends with a space. This seems to me to be a good convention that we should consider adopting.