Taking notes in markdown: insert a part of a screenshot

I have recently switched to Spacemacs with markdown-mode to write everything markdown-related, especially making notes for whatever things I am fiddling with. While ‘markdown-mode’ is amazing, there is one feature I miss, that is: ‘pasting’ a part of a screenshot into a markdown file by saving it somewhere and generating a correct link. It is a huge waste of time and concentration to do it by hand.

I have written a little helper to automatize it:

  (defun my-markdown-screenshot ()
    "Prompt a name, grab an area of screen, save it in 'assets' folder and
    insert a link into markdown."

    (setq filename
             (file-name-directory buffer-file-name)
             (read-string "Image name: " )
             (format-time-string "%Y%m%d_%H%M%S")  ".png"))
    (call-process "import" nil nil nil filename)
    (insert (concat "![](" filename ")"))

It uses imagemagick to grab an area. You can switch to another desktop by using keyboard. I have tested it only on my Linux machine thought.

Note the assets directory should exist.

Related Posts

When functions dissolve

Writing essays

Variance in programming languages

Advice for programming students

Why every programming student should learn Coq

Bigger sphere inside of a smaller one

Memory in CompCert: overview

A beautiful intuition on associativity

On teaching mathematics -- a summary of Kudryavtsev's book

On teaching programmers and mathematicians