From: Andreas Gerler Date: Mon, 2 Nov 2015 13:49:13 +0000 (+0100) Subject: adding smart comma X-Git-Url: http://git.bundesbrandschatzamt.de/?a=commitdiff_plain;h=4871e10931bd5f8eb6e3ec846a9704cd2f54931c;p=emacsconfig.git adding smart comma --- diff --git a/bba.org b/bba.org index 52d03b9e..b37478fd 100644 --- a/bba.org +++ b/bba.org @@ -1873,6 +1873,26 @@ combine key strokes to access commands even faster. (defalias 'tp 'transpose-paragraphs) #+END_SRC +* [[http://mbork.pl/2015-10-31_Smart_comma_and_other_punctuation][smart comma]] + +Thanks to Marcin Borkowski for this code snippet. + +#+BEGIN_SRC emacs-lisp +(defun smart-self-insert-punctuation (count) + "If COUNT=1 and the point is after a space, insert the relevant +character before any spaces." + (interactive "p") + (if (and (= count 1) + (eq (char-before) ?\s)) + (save-excursion + (skip-chars-backward " ") + (self-insert-command 1)) + (self-insert-command count))) + +(global-set-key "," #'smart-self-insert-punctuation) + +#+END_SRC + * key bindings #+BEGIN_SRC emacs-lisp (define-key global-map (kbd "M-@") 'cycle-spacing)