doomemacs/init/init-text.el

27 lines
1.3 KiB
EmacsLisp
Raw Normal View History

2014-09-05 17:08:40 -04:00
(provide 'init-text)
2014-08-07 18:35:22 -04:00
2014-08-29 22:37:25 -04:00
(use-package markdown-mode
2014-08-07 18:35:22 -04:00
:mode (("\\.md\\'" . markdown-mode)
("/README\\'" . markdown-mode))
2014-09-20 16:54:04 -04:00
:pre-load
2014-08-21 03:33:30 -04:00
(progn
2014-09-20 16:54:04 -04:00
(defvar markdown-regex-del "\\(^\\|[^\\]\\)\\(\\(~\\{2\\}\\)\\([^ \n \\]\\|[^ \n ]\\(?:.\\|\n[^\n]\\)*?[^\\ ]\\)\\(\\3\\)\\)")
(defun markdown-insert-del ()
"Insert markup to make a region or word bold.
If there is an active region, make the region bold. If the point
is at a non-bold word, make the word bold. If the point is at a
bold word or phrase, remove the bold markup. Otherwise, simply
insert bold delimiters and place the cursor in between them."
(interactive)
(let ((delim "~~"))
(if (markdown-use-region-p)
;; Active region
(let ((bounds (markdown-unwrap-things-in-region
(region-beginning) (region-end)
markdown-regex-del 2 4)))
(markdown-wrap-or-insert delim delim nil (car bounds) (cdr bounds)))
;; Bold markup removal, bold word at point, or empty markup insertion
(if (thing-at-point-looking-at markdown-regex-del)
(markdown-unwrap-thing-at-point nil 2 4)
(markdown-wrap-or-insert delim delim 'word nil nil)))))))