“Smart” Quotes in Emacs
smart-quotes.elsmartly enables automatic insertion of correctly curled single or double quotation marks inemacs.This is typographically nice, but can be deadly in Unicode-enabled programming languages where a
"string starting with a dumb-quote, but terminated by a smart one”
is unterminated for the parser but looks terminated for the human reader. And pressingC-vat front/end of every string gets exhausting.Disabling smart quotes for certain modes is easy:
(defun my/smquoteoff () (smart-quote-mode 0)) (add-hook 'emacs-lisp-mode 'my/smquoteoff) (add-hook 'python-mode 'my/smquoteoff)But what about literate programming, as for example in
org-babelcodeblocks? The buffer is inorg-mode, definitely not a programming mode, but the blocks inside#+begin/end_srcare:* About strings [...] Some “smart” statement about /strings/ #+begin_src s = "dumbly quoted string"; ... #+end_src
org-modehas a predicate to check if point is inside such a code block, namedorg-in-src-block-p, but how to use it without rewritingsmart-quotes.el?Emacs' lisp
advice-addto the rescue! This is Aspect-oriented programming, where a functiongis wrapped in another functionf. It has a:before-until“combinator”, which evalsgonly iffreturnsnilwhen run withg's parameters.In this case:
(defun _my/verb-double-quote (&rest r) (if (org-in-src-block-p) (progn (insert-char #x22) t) nil)) (advice-add 'smart-quotes-insert-double :before-until #'_my/verb-double-quote)
smart-quotes-insert-doublenow depends onorg-in-src-block-pbeing false, otherwise ASCII char0x22, i.e", is inserted.Single quotes are left as an ‘exercise for the reader’.
Mon, 18 Mar 2024
[/quotes]
permanent link
From William Gaddis' J R
Since you're not here to learn anything,
but to be taught
so you can pass these tests,
knowledge has to be organized
so it can be taught,
and it has to be reduced to information
so it can be organized.
Do you follow that?
In other words
this leads you to assume that organization
is an inherent property of the knowledge itself,
and that disorder and chaos
are simply irrelevant forces
that threaten it from outside.
In fact it's exactly the opposite.
Order is simply a thin, perilous condition
we try to impose on the basic reality of chaos.
William Gaddis, J R
Wed, 16 Jan 2019
[/quotes]
permanent link