diff --git a/contrib/emacs/README.md b/contrib/emacs/README.md new file mode 100644 index 000000000..e0d196f9a --- /dev/null +++ b/contrib/emacs/README.md @@ -0,0 +1,29 @@ +
+

Emacs Hurl

+ +Emacs major mode for Hurl. + +
+ +--- + +## 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")) +``` diff --git a/contrib/emacs/hurl-mode.el b/contrib/emacs/hurl-mode.el new file mode 100644 index 000000000..9553adf82 --- /dev/null +++ b/contrib/emacs/hurl-mode.el @@ -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 diff --git a/contrib/emacs/test-syntax.hurl b/contrib/emacs/test-syntax.hurl new file mode 100644 index 000000000..5a8847c49 --- /dev/null +++ b/contrib/emacs/test-syntax.hurl @@ -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 +```