From 7ff95cafdcf85b5048e5ec51f5fd51a176e3d97e Mon Sep 17 00:00:00 2001 From: smihica Date: Tue, 12 Mar 2013 10:50:02 +0900 Subject: Created emmet branch. --- src/init.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/init.el (limited to 'src/init.el') diff --git a/src/init.el b/src/init.el new file mode 100644 index 0000000..b5d2efe --- /dev/null +++ b/src/init.el @@ -0,0 +1,58 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Code: + +(defconst zencoding-mode:version "0.5.1") + +;; Include the trie data structure for caching +;(require 'zencoding-trie) + +(require 'cl) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Generic parsing macros and utilities + +(defmacro zencoding-aif (test-form then-form &rest else-forms) + "Anaphoric if. Temporary variable `it' is the result of test-form." + `(let ((it ,test-form)) + (if it ,then-form ,@(or else-forms '(it))))) + +(defmacro zencoding-pif (test-form then-form &rest else-forms) + "Parser anaphoric if. Temporary variable `it' is the result of test-form." + `(let ((it ,test-form)) + (if (not (eq 'error (car it))) ,then-form ,@(or else-forms '(it))))) + +(defmacro zencoding-parse (regex nums label &rest body) + "Parse according to a regex and update the `input' variable." + `(zencoding-aif (zencoding-regex ,regex input ',(number-sequence 0 nums)) + (let ((input (elt it ,nums))) + ,@body) + `,`(error ,(concat "expected " ,label)))) + +(defmacro zencoding-run (parser then-form &rest else-forms) + "Run a parser and update the input properly, extract the parsed + expression." + `(zencoding-pif (,parser input) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + ,@(or else-forms '(it)))) + +(defmacro zencoding-por (parser1 parser2 then-form &rest else-forms) + "OR two parsers. Try one parser, if it fails try the next." + `(zencoding-pif (,parser1 input) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + (zencoding-pif (,parser2 input) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + ,@else-forms))) + +(defun zencoding-regex (regexp string refs) + "Return a list of (`ref') matches for a `regex' on a `string' or nil." + (if (string-match (concat "^" regexp "\\([^\n]*\\)$") string) + (mapcar (lambda (ref) (match-string ref string)) + (if (sequencep refs) refs (list refs))) + nil)) -- cgit v1.2.3 From 918e5420388bded0dd6b3656cc2fe9f4ba9c0649 Mon Sep 17 00:00:00 2001 From: smihica Date: Thu, 21 Mar 2013 11:41:55 +0900 Subject: [add] Added CSS transform functions. --- src/init.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/init.el') diff --git a/src/init.el b/src/init.el index b5d2efe..c9038fd 100644 --- a/src/init.el +++ b/src/init.el @@ -9,6 +9,14 @@ (require 'cl) +(defmacro zencoding-defparameter (symbol &optional initvalue docstring) + `(progn + (defvar ,symbol nil ,docstring) + (setq ,symbol ,initvalue))) + +(defun zencoding-join-string (lis joiner) + (mapconcat 'identity lis joiner)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generic parsing macros and utilities -- cgit v1.2.3 From 4713a355010ff4a51e53470c2e8c101bbdaf177b Mon Sep 17 00:00:00 2001 From: smihica Date: Sat, 18 May 2013 17:56:33 +0900 Subject: Some trivial improvements. --- src/init.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/init.el') diff --git a/src/init.el b/src/init.el index c9038fd..b2fd434 100644 --- a/src/init.el +++ b/src/init.el @@ -17,6 +17,16 @@ (defun zencoding-join-string (lis joiner) (mapconcat 'identity lis joiner)) +(defun zencoding-get-keys-of-hash (hash) + (let ((ks nil)) + (maphash #'(lambda (k v) (setq ks (cons k ks))) hash) + ks)) + +(defun zencoding-get-vals-of-hash (hash) + (let ((vs nil)) + (maphash #'(lambda (k v) (setq vs (cons v vs))) hash) + vs)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generic parsing macros and utilities -- cgit v1.2.3