Commit ae11bb67b3fa

Vincent Demeester <vincent+git@demeester.fr>
2014-07-20 11:15:45
org-mode src-block shortcuts & functions
1 parent 76bdc30
Changed files (1)
.emacs.d
.emacs.d/org.conf.el
@@ -75,6 +75,25 @@
 (add-to-list 'org-speed-commands-user
              '("p" ded/org-show-previous-heading-tidily))
 
+;; Source code block
+(defun org-insert-src-block (src-code-type)
+  "Insert a `SRC-CODE-TYPE' type source code block in org-mode."
+  (interactive
+   (let ((src-code-types
+          '("emacs-lisp" "python" "C" "sh" "java" "js" "clojure" "C++" "css"
+            "calc" "asymptote" "dot" "gnuplot" "ledger" "lilypond" "mscgen"
+            "octave" "oz" "plantuml" "R" "sass" "screen" "sql" "awk" "ditaa"
+            "haskell" "latex" "lisp" "matlab" "ocaml" "org" "perl" "ruby"
+            "scheme" "sqlite")))
+     (list (ido-completing-read "Source code type: " src-code-types))))
+  (progn
+    (newline-and-indent)
+    (insert (format "#+BEGIN_SRC %s\n" src-code-type))
+    (newline-and-indent)
+    (insert "#+END_SRC\n")
+    (previous-line 2)
+    (org-edit-src-code)))
+
 ;; Org Capture
 (setq org-capture-templates
       '(("t" "Todo" entry (file+headline (concat org-directory "/todos/inbox.org") "Tasks")
@@ -90,7 +109,14 @@
 (require 'org-bullets)
 (add-hook 'org-mode-hook
           '(lambda ()
-             (org-bullets-mode 1)))
+             (org-bullets-mode 1)
+             ;; keybinding for editing source code blocks
+             (local-set-key (kbd "C-c s e")
+                            'org-edit-src-code)
+             ;; keybinding for inserting code blocks
+             (local-set-key (kbd "C-c s i")
+                            'org-insert-src-block)
+             ))
 
 (require 'org-protocol)
 ;; (require 'org-mine)