Skip to content

Instantly share code, notes, and snippets.

@ebzzry ebzzry/markdown.el
Last active Aug 3, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.