I have check-parens set to a save hook for my files, my Markdown files in particular, to alert me about unbalanced parentheses. They are almost always errors, and this has saved me from a great many errors involving Markdown links inside parenthetical asides:
;In Markdown files, there are few excuses for unbalanced delimiters
(add-hook 'markdown-mode-hook
(lambda ()
(when buffer-file-name
(add-hook 'after-save-hook
'check-parens
nil t))))
I've noticed that I have similar issues with quoting - I will drop a trailing quote, or I will forget to convert single and doubles appropriately, etc. (This sometimes overlaps with link errors when I put paper titles into the tooltip.) There's little more reason for imbalanced "s than there are for (s or )s, and it's the same task check-parens is already doing. So naturally I'd like to have check-parens cover quotes as well.
But I can't seem to do so! The right way seems to involve hacking the Markdown syntax table, but nothing I try seems to work –
(modify-syntax-entry ?\" "(\"" markdown-mode-syntax-table)
(modify-syntax-entry ?\" ")\"" markdown-mode-syntax-table)
(modify-syntax-entry ?\" "$\"" markdown-mode-syntax-table)
(modify-syntax-entry ?\" "^\"" markdown-mode-syntax-table)
(modify-syntax-entry ?\" ".\"" markdown-mode-syntax-table)
(modify-syntax-entry ?' "\"" markdown-mode-syntax-table)
etc etc etc. They all either do nothing or cause check-parens to spit out errors early in the file where as far as I can tell everything works just fine.
I've read through a number of links on the topic and the C-h f documentation for modify-syntax-entry:
- http://www.emacswiki.org/emacs/ParenthesisMatching#toc1
- https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-for-Strings.html
- http://www.emacswiki.org/emacs/EmacsSyntaxTable
- http://zvon.org/other/elisp/Output/SEC561.html
- http://www.chemie.fu-berlin.de/chemnet/use/info/elisp/elisp_32.html
- http://www.delorie.com/gnu/docs/elisp-manual-21/elisp_350.html
and asked on #emacs, to no avail.
(The version is Emacs 24.0.93.1 on Debian unstable.)