markdown.el
(defun insert-until-last (string) | |
"Insert string until column" | |
(let* ((end (save-excursion | |
(previous-line) | |
(end-of-line) | |
(current-column))) | |
(count (if (not (zerop (current-column))) | |
(- end (current-column)) | |
end))) | |
(dotimes (c count) | |
(insert string)))) | |
(defun insert-equals (&optional arg) | |
"Insert equals until the same column number as last line" | |
(interactive) | |
(insert-until-last "=")) | |
(defun insert-backticks (&optional arg) | |
"Insert three backticks for Markdown use" | |
(interactive) | |
(if (region-active-p) | |
(when (> (region-end) (region-beginning)) | |
(save-excursion (goto-char (region-beginning)) | |
(insert "```\n")) | |
(save-excursion (goto-char (region-end)) | |
(insert "```")) | |
(deactivate-mark)) | |
(progn | |
(insert "``````") | |
(backward-char 3)))) | |
(defun insert-hyphens (&optional arg) | |
"Insert hyphens until the same column number as last line" | |
(interactive) | |
(insert-until-last "-")) | |
(defun insert-anchor (&optional arg) | |
(interactive "p") | |
(insert "<a name=\"\"></a>") | |
(backward-char 6)) | |
(define-key global-map (kbd "M-g =") 'insert-equals) | |
(define-key global-map (kbd "M-g `") 'insert-backticks) | |
(define-key global-map (kbd "M-g -") 'insert-hyphens) | |
(define-key global-map (kbd "M-g =") 'insert-anchor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment