Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick insert file content into .org file. You can specify a history version of the file!
#+name: show-file-content
#+header: :exports none :tangle no :results value raw
#+header: :var path="./README.org" :var revision="HEAD"
#+header: :var start=1 :var end=-1
#+begin_src emacs-lisp
(substring
  (shell-command-to-string
    (format "git show %s:%s | sed -n '%d,%sp;d'"
            revision
            path
            start
            (cond ((integerp end)
                   (if (= end -1)
                       "$"
                     end))
                  ((char-or-string-p end)
                   (if (string-match "\\+\\([0-9]+\\)$" end)
                       (+ (string-to-number (match-string 1 end)) start)
                     "$"))
                  (t "$"))))
  0
  -1)
#+end_src

#+call: show-file-content(path="./src-file.c", revision="<Commit ID>", start=1, end="+10") :wrap src c

Use C-c C-c to insert results after #+call: line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment