Skip to content

Instantly share code, notes, and snippets.

@ebzzry
Last active August 3, 2019 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebzzry/1206a1922805a872713bdaf2e8c419f5 to your computer and use it in GitHub Desktop.
Save ebzzry/1206a1922805a872713bdaf2e8c419f5 to your computer and use it in GitHub Desktop.
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