summary refs log tree commit diff stats
path: root/tag-emacs
diff options
context:
space:
mode:
authorAlan Pearce2015-07-08 14:39:52 +0200
committerAlan Pearce2015-07-08 14:39:52 +0200
commit40719220d3258928c2fb6e742c9facb318d4d09d (patch)
treee1652f997404e4a8d013ba63afd0619ca2d62614 /tag-emacs
parentf666adee888c628261dbf0c54dd1d7b4b27b3940 (diff)
downloaddotfiles-40719220d3258928c2fb6e742c9facb318d4d09d.tar.lz
dotfiles-40719220d3258928c2fb6e742c9facb318d4d09d.tar.zst
dotfiles-40719220d3258928c2fb6e742c9facb318d4d09d.zip
Emacs: Add extra configuration for typopunct-mode
Diffstat (limited to 'tag-emacs')
-rw-r--r--tag-emacs/emacs.d/init.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/tag-emacs/emacs.d/init.el b/tag-emacs/emacs.d/init.el
index 0f7c886..a407ecc 100644
--- a/tag-emacs/emacs.d/init.el
+++ b/tag-emacs/emacs.d/init.el
@@ -1172,6 +1172,74 @@ symbol, not word, as I need this for programming the most."
          ("M-Z" . zap-to-char)))
 
 (req-package typopunct
+  :config (progn
+            (defconst typopunct-minus (decode-char 'ucs #x2212))
+            (defadvice typopunct-insert-typographical-dashes
+                (around minus-or-pm activate)
+              (cond
+               ((or (eq (char-before) typopunct-em-dash)
+                    (looking-back "\\([[:blank:]]\\|^\\)\\^"))
+                (delete-char -1)
+                (insert typopunct-minus))
+               ((looking-back "[^[:blank:]]\\^")
+                (insert typopunct-minus))
+               (t ad-do-it)))
+            (define-key typopunct-map "+" 'typopunct-insert-mp)
+
+            (defconst typopunct-ellipsis (decode-char 'ucs #x2026))
+            (defconst typopunct-middot   (decode-char 'ucs #xB7)) ; or 2219
+            (defun typopunct-insert-ellipsis-or-middot (arg)
+              "Change three consecutive dots to a typographical ellipsis mark."
+              (interactive "p")
+              (cond
+               ((and (= 1 arg)
+                     (eq (char-before) ?^))
+                (delete-char -1)
+                (insert typopunct-middot))
+               ((and (= 1 arg)
+                     (eq this-command last-command)
+                     (looking-back "\\.\\."))
+                (replace-match "")
+                (insert typopunct-ellipsis))
+               (t
+                (self-insert-command arg))))
+            (define-key typopunct-map "." 'typopunct-insert-ellipsis-or-middot)
+
+            (defconst typopunct-times (decode-char 'ucs #xD7))
+            (defun typopunct-insert-times (arg)
+              (interactive "p")
+              (if (and (= 1 arg) (looking-back "\\([[:blank:]]\\|^\\)\\^"))
+                  (progn (delete-char -1)
+                         (insert typopunct-times))
+                (self-insert-command arg)))
+            (define-key typopunct-map "x" 'typopunct-insert-times)
+
+            (defadvice typopunct-insert-quotation-mark (around wrap-region activate)
+              (let* ((lang (or (get-text-property (point) 'typopunct-language)
+                               typopunct-buffer-language))
+                     (omark (if single
+                                (typopunct-opening-single-quotation-mark lang)
+                              (typopunct-opening-quotation-mark lang)))
+                     (qmark (if single
+                                (typopunct-closing-single-quotation-mark lang)
+                              (typopunct-closing-quotation-mark lang))))
+                (cond
+                 (mark-active
+                  (let ((skeleton-end-newline nil)
+                        (singleo (typopunct-opening-single-quotation-mark lang))
+                        (singleq (typopunct-closing-single-quotation-mark lang)))
+                    (if (> (point) (mark))
+                        (exchange-point-and-mark))
+                    (save-excursion
+                      (while (re-search-forward (regexp-quote (string omark)) (mark) t)
+                        (replace-match (regexp-quote (string singleo)) nil nil)))
+                    (save-excursion
+                      (while (re-search-forward (regexp-quote (string qmark)) (mark) t)
+                        (replace-match (regexp-quote (string singleq)) nil nil)))
+                    (skeleton-insert (list nil omark '_ qmark) -1)))
+                 ((looking-at (regexp-opt (list (string omark) (string qmark))))
+                  (forward-char 1))
+                 (t ad-do-it)))))
   :init (progn
           (typopunct-change-language 'english t)
           (add-hook 'text-mode-hook #'typopunct-mode)))