1 /+ dub.json: 2 { 3 "name": "emacs-dman", 4 "targetType": "dynamicLibrary", 5 "dependencies": { 6 "d-emacs-module": { "path": ".." } 7 } 8 } 9 +/ 10 // How to test 11 // $ dub build --single ./dman_v2.d 12 // $ emacs -batch -l dman_test.el 13 module dman; 14 15 import emacs_module; 16 17 import core.runtime: Runtime; 18 import std.datetime.systime : Clock; 19 import std.format : format; 20 21 private enum string dman = ` 22 o o 23 | \ 24 \ ___ / 25 |,-oo\\ 26 || || < %s 27 || || 28 || // 29 ||__// 30 '--- 31 \ \ 32 / / 33 ^ ^ 34 `; 35 36 private emacs_value dmanMessage(T)(EmacsEnv env, T arg) { 37 return env.funcall("message", format!dman(arg)); 38 } 39 emacs_value dmanTime(EmacsEnv e) { return dmanMessage(e, Clock.currTime()); } 40 emacs_value dmanSay(EmacsEnv e, string s) { return dmanMessage(e, s); } 41 42 extern (C): 43 44 int plugin_is_GPL_compatible; 45 46 int emacs_module_init(emacs_runtime* ert) { 47 // Validate Emacs runtime and environment. 48 EmacsRuntime runtime = {ert}; 49 if (!runtime.ok) return 1; 50 EmacsEnv env = runtime.environment(); 51 if (!env.ok) return 2; 52 53 // Initialize D runtime. 54 // TODO(karita): Call Runtime.terminate() by emacs_env.set_user_finalizer API. 55 Runtime.initialize(); 56 dmanSay(env, "Hello Emacs from D!!"); 57 58 // Register functions. 59 env.defAlias!dmanTime("dman-time", "Dman tells you current time."); 60 env.defAlias!dmanSay("dman-say", "Dman repeats your string."); 61 return 0; 62 }