-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpower-query-mode.el
96 lines (77 loc) · 3.07 KB
/
power-query-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; power-query-mode.el --- sample major mode for editing queries in the power query language. -*- coding: utf-8; lexical-binding: t; -*-
;; Copyright © 2019, by Alf Lervåg
;; Author: Alf Lervåg ([email protected])
;; Version: 1.0.0
;; Created: 28 Nov 2019
;; Keywords: languages
;; This file is not part of GNU Emacs.
;;; License:
;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 2.
;;; Commentary:
;; short description here
;; full doc on how to use here
;;; Code:
;; create the list for font-lock.
;; each category of keyword is given a particular face
(setq power-query-font-lock-keywords
(let* (
;; define several category of keywords
(x-keywords '("let" "if" "else" "then" "each" "error" "in" "type"))
(x-types '("date" "datetime"))
(x-functions '("Table.TransformColumnTypes"))
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-functions-regexp (regexp-opt x-functions 'words)))
`(
(,x-types-regexp . font-lock-type-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
;; note: order above matters, because once colored, that part won't change.
;; in general, put longer words first
)))
;;;###autoload
(define-derived-mode power-query-mode prog-mode "power-query mode"
"Major mode for editing Power Query"
;; code for syntax highlighting
(setq font-lock-defaults '((power-query-font-lock-keywords))))
(defun alf/adler32 (start end)
"Naive implementation of the Adler 32 checksum algorithm for
padding a deflated stream with zlib headres so we can inflate it
using zlib-decompress-region."
(save-excursion
(goto-char (point-min))
(let* ((a 1)
(b 0))
(while (not (eobp))
(setq a (mod (+ a (char-after)) 65521))
(setq b (mod (+ b a) 65521))
(forward-char 1))
(logior (lsh b 16) a))))
(defun alf/decompress (s)
(interactive "s")
(insert (with-temp-buffer
(toggle-enable-multibyte-characters)
(goto-char (point-min))
(insert (base64-decode-string s))
(insert (alf/adler-as-string (point-min) (point-max)))
(goto-char (point-min))
(insert-char #x78)
(insert-char #x9c)
(buffer-string))))
(defun alf/adler-as-string (start end)
"Naive implementation of the Adler 32 checksum algorithm for
padding a deflated stream with zlib headres so we can inflate it
using zlib-decompress-region."
(save-excursion
(goto-char (point-min))
(let* ((a 1)
(b 0))
(while (not (eobp))
(setq a (mod (+ a (char-after)) 65521))
(setq b (mod (+ b a) 65521))
(forward-char 1))
(string (c-int-to-char b) (c-int-to-char a)))))
;; add the mode to the `features' list
(provide 'power-query-mode)
;;; power-query-mode.el ends here