Преглед на файлове

ob-rust, abbrevs, macros

George Jones преди 6 години
родител
ревизия
d33fa09218
променени са 3 файла, в които са добавени 58 реда и са изтрити 0 реда
  1. 6 0
      gmj-savedKeyboardMacros.org
  2. 1 0
      gmj_emacs_abbrev.el
  3. 51 0
      ob-rust.el

+ 6 - 0
gmj-savedKeyboardMacros.org

@@ -59,3 +59,9 @@
    [escape ?b escape ?b escape ?b escape ?b escape ?b escape ?b ?\C-  escape ?f escape ?f escape ?f escape ?w escape ?f escape ?f escape ?f escape ?f escape ?f escape ?b escape ?b ?\C-y ?_ escape ?b escape ?b escape ?b ?\C-p])
 
 #+END_SRC
+
+#+BEGIN_SRC emacs-lisp
+(fset 'gmj-trim-line
+   "\M-\\\C-e\M-\\\C-n\C-a")
+
+#+END_SRC

+ 1 - 0
gmj_emacs_abbrev.el

@@ -0,0 +1 @@
+(define-global-abbrev "8sv" "\"${}\"") ; insert a shell shell varaible reference

+ 51 - 0
ob-rust.el

@@ -0,0 +1,51 @@
+;;; ob-rust.el --- org-babel functions for rust evaluation
+
+;; Copyright (C) 2015 ZHOU Feng
+
+;; Author: ZHOU Feng <zf.pascal@gmail.com>
+;; URL: http://github.com/zweifisch/ob-rust
+;; Keywords: org babel rust
+;; Version: 0.0.1
+;; Created: 29th May 2015
+;; Package-Requires: ((org "8"))
+
+;;; Commentary:
+;;
+;; org-babel functions for rust evaluation
+;;
+
+;;; Code:
+(require 'ob)
+
+(defun org-babel-execute:rust (body params)
+  (ob-rust-eval (ob-rust-prep body)))
+
+(defun ob-rust-eval (body)
+  (let ((src-tmp (org-babel-temp-file "rust-"))
+        (output-tmp (org-babel-temp-file "rustc-")))
+    (with-temp-file src-tmp (insert body))
+    (shell-command-to-string
+     (format "rustc -A dead_code -o %s %s && %s"
+             output-tmp src-tmp output-tmp))))
+
+(defun ob-rust-prep (body)
+  (with-current-buffer (get-buffer-create "*ob-rust-src*")
+    (erase-buffer)
+    (insert "fn main() {\n")
+    (insert body)
+    (goto-char (point-max))
+    (beginning-of-line)
+    (while (looking-at "\\(^[\t ]*//\\|^[\t ]*$\\)")
+      (forward-line -1))
+    (if (looking-at "[\t ]*\\(println\\|}\\)")
+        (end-of-line)
+      (insert "println!(\"{:?}\", ")
+      (when (search-forward-regexp ";[\t ]*$" nil t)
+        (replace-match "" t t))
+      (end-of-line)
+      (insert ");"))
+    (insert "\n}")
+    (buffer-string)))
+
+(provide 'ob-rust)
+;;; ob-rust.el ends here