]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
adding smart comma
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 2 Nov 2015 13:49:13 +0000 (14:49 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 2 Nov 2015 13:49:13 +0000 (14:49 +0100)
bba.org

diff --git a/bba.org b/bba.org
index 52d03b9e5845c6a038712ccad815c9533a8f6612..b37478fdcef24cc34ca554a2c15271e4f72fb4a0 100644 (file)
--- 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)