From d45cce921b81893f307f1e1b4feee7d3402a0ce1 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Mon, 1 Apr 2019 09:40:36 +1300 Subject: [PATCH] Add do-what-I-mean mode to psql. --- src/bin/psql/dwim-mode.el | 11 +++++++ src/include/lib/emacs_lisp_interpreter.h | 40 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/bin/psql/dwim-mode.el create mode 100644 src/include/lib/emacs_lisp_interpreter.h diff --git a/src/bin/psql/dwim-mode.el b/src/bin/psql/dwim-mode.el new file mode 100644 index 0000000000..637dabaf1e --- /dev/null +++ b/src/bin/psql/dwim-mode.el @@ -0,0 +1,11 @@ +(defun do-what-i-mean (command) + ,-.-,-, + _/ / / / /) + ,' `. ,'') + _/(@) `. `./ ,') + (____,` \:`-. \ ,') + (_ /::::} / `.) + \ ,' :,-' ,)\ `.) + `. ,') `..) + \-....-'\ \) hjw + `-`-`-`-` ) diff --git a/src/include/lib/emacs_lisp_interpreter.h b/src/include/lib/emacs_lisp_interpreter.h new file mode 100644 index 0000000000..54247e9ce4 --- /dev/null +++ b/src/include/lib/emacs_lisp_interpreter.h @@ -0,0 +1,40 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define evalquote[fn;x] = apply[fn;x;NIL] + +#define apply[fn;x;a] = \ + [atom[fn] -> [eq[fn;CAR] -> caar[x]; \ + eq[fn;CDR] -> cdar[x]; \ + eq[fn;CONS] -> cons[car[x];cadr[x]]; \ + eq[fn;ATOM] -> atom[car[x]]; \ + eq[fn;EQ] -> eq[car[x];cadr[x]]; \ + T -> apply[eval[fn;a];x;a]]; \ + eq[car[fn];LAMBDA] -> eval[caddr[fn];pairlis[cadr[fn];x;a]]; \ + eq[car[fn];LABEL] -> apply[caddr[fn];x;cons[cons[cadr[fn]; \ + caddr[fn]];a]]] + +#define eval[e;a] = [atom[e] -> cdr[assoc[e;a]]; \ + atom[car[e]] -> \ + [eq[car[e],QUOTE] -> cadr[e]; \ + eq[car[e];COND] -> evcon[cdr[e];a]; \ + T -> apply[car[e];evlis[cdr[e];a];a]]; \ + T -> apply[car[e];evlis[cdr[e];a];a]] + +#define evcon[c;a] = [eval[caar[c];a] -> eval[cadar[c];a]; \ + T -> evcon[cdr[c];a]] + +#define evlis[m;a] = [null[m] -> NIL; \ + T -> cons[eval[car[m];a];evlis[cdr[m];a]]] -- 2.21.0