Add emacs mode

This commit is contained in:
azzamsa 2022-12-16 18:26:39 +07:00 committed by jcamiel
parent 0fc18e90ea
commit 7009ffc522
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
3 changed files with 175 additions and 0 deletions

29
contrib/emacs/README.md Normal file
View File

@ -0,0 +1,29 @@
<div align="center">
<h1>Emacs Hurl</h1>
Emacs major mode for Hurl.
</div>
---
## Features
- Keyword highlight
## Installation
### Doom Emacs
in `packages.el`
``` lisp
(package! hurl-mode :recipe (:host github :repo "Orange-OpenSource/hurl"))
```
### straight.el
``` lisp
(straight-use-package
'(hurl-mode :type git :host github :repo "Orange-OpenSource/hurl"))
```

120
contrib/emacs/hurl-mode.el Normal file
View File

@ -0,0 +1,120 @@
;;; hurl-mode.el --- Major mode for hurl -*- lexical-binding: t; -*-
;; Homepage: https://github.com/Orange-OpenSource/hurl
;; Keywords: Hurl, shell
;; Package-Version: 0.1.0
;; Package-Requires: ((emacs "24"))
;; SPDX-License-Identifier: Apache License 2.0
;;; Commentary:
;; A very basic version of major mode for hurl shell.
;; Current features:
;;
;; - keyword highlight
;;
;;; Code:
(require 'cl-lib)
(eval-when-compile (require 'subr-x))
(defgroup hurl nil
"Hurl shell support."
:group 'languages)
(defcustom hurl-indent-offset 4
"Default indentation offset for Hurl."
:group 'hurl
:type 'integer
:safe 'integerp)
(defvar hurl-enable-auto-indent nil
"Controls auto-indent feature.
If the value of this variable is non-nil, whenever a word in
`hurl-auto-indent-trigger-keywords' is typed, it is indented instantly.")
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
`(set (make-local-variable ',var) ,val)))
;;; Syntax highlighting
;;; To get the commands, use `help commands | get name | | save --raw tmp'
(defconst hurl-builtins
(list
"GET"
"POST"
"PUT"
"DELETE"
"CONNECT"
"OPTIONS"
"TRACE"
"PATCH"
"header"
"status"
"jsonpath"
))
(defconst hurl-keywords
(list
"exists"
"contains"
"not"
"=="
))
;;; Add `hurl-builtin' and `hurl-keywords' to
;;; font-lock
(defconst hurl-font-lock-keywords-1
(list
;; Builtins
`( ,(rx-to-string `(and
symbol-start
(eval `(or ,@hurl-builtins))
symbol-end)
t)
.
font-lock-builtin-face)
;; Keywords
`( ,(rx-to-string `(and
symbol-start
(eval `(or ,@hurl-keywords))
symbol-end)
t)
.
font-lock-keyword-face)))
(defvar hurl-mode-syntax-table
(let ((table (make-syntax-table text-mode-syntax-table)))
(modify-syntax-entry ?\# "<" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?\" "\"\"" table)
(modify-syntax-entry ?\' "\"'" table)
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?$ "'" table)
table)
"Syntax table for `hurl-mode'.")
;;; Mode definition
;;;###autoload
(define-derived-mode hurl-mode prog-mode "Hurl"
"Major mode for editing hurl shell files."
:syntax-table hurl-mode-syntax-table
(setq-local font-lock-defaults '(hurl-font-lock-keywords-1))
(setq-local comment-start "# ")
(setq-local comment-start-skip "#+[\t ]*"))
;;;###autoload
;;; Specify major mode by file extension .hurl
(add-to-list 'auto-mode-alist '("\\.hurl\\'" . hurl-mode))
(provide 'hurl-mode)
;;; hurl-mode.el ends here

View File

@ -0,0 +1,26 @@
# This is a comment
GET http://{{host}}
Header1: Value1
Header2: a\# # value with \#
Header3: GET
HTTP/1.1 200
[Asserts]
body not contains "#" # Other comment
body not contains "[Asserts]"
body not contains "200"
body not contains "GET"
body not contains "\"\#"
POST http://example.com
{
"id": {{id}},
"message": "Hello"
}
POST http://example.com
```
Hello
```