all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vladimir Panteleev <git@thecybershadow.net>
To: 25541@debbugs.gnu.org
Cc: Vladimir Panteleev <git@thecybershadow.net>
Subject: bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode
Date: Thu, 26 Jan 2017 04:36:22 +0000	[thread overview]
Message-ID: <20170126043624.14326-2-git@thecybershadow.net> (raw)
In-Reply-To: <20170126043624.14326-1-git@thecybershadow.net>

* lisp/progmodes/bat-mode.el: Match word and symbol constituents when
looking for variable names to fontify; also, correct the syntax table
and mark the equal sign (=) character as punctuation.
* test/lisp/progmodes/bat-mode-tests.el: Add test script for bat-mode.
---
 lisp/progmodes/bat-mode.el            |  7 ++--
 test/lisp/progmodes/bat-mode-tests.el | 63 +++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 test/lisp/progmodes/bat-mode-tests.el

diff --git a/lisp/progmodes/bat-mode.el b/lisp/progmodes/bat-mode.el
index 156331cf86..77b97ac6ff 100644
--- a/lisp/progmodes/bat-mode.el
+++ b/lisp/progmodes/bat-mode.el
@@ -82,11 +82,11 @@ bat-font-lock-keywords
          (2 font-lock-constant-face t))
         ("^:[^:].*"
          . 'bat-label-face)
-        ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\w+\\)"
+        ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
          (2 font-lock-variable-name-face))
-        ("%\\(\\w+\\)%?"
+        ("%\\(\\(\\sw\\|\\s_\\)+\\)%?"
          (1 font-lock-variable-name-face))
-        ("!\\(\\w+\\)!?"                ; delayed-expansion !variable!
+        ("!\\(\\(\\sw\\|\\s_\\)+\\)!?"  ; delayed-expansion !variable!
          (1 font-lock-variable-name-face))
         ("[ =][-/]+\\(\\w+\\)"
          (1 font-lock-type-face append))
@@ -130,6 +130,7 @@ bat-mode-syntax-table
     (modify-syntax-entry ?{ "_" table)
     (modify-syntax-entry ?} "_" table)
     (modify-syntax-entry ?\\ "." table)
+    (modify-syntax-entry ?= "." table)
     table))
 
 (defconst bat--syntax-propertize
diff --git a/test/lisp/progmodes/bat-mode-tests.el b/test/lisp/progmodes/bat-mode-tests.el
new file mode 100644
index 0000000000..c78827db80
--- /dev/null
+++ b/test/lisp/progmodes/bat-mode-tests.el
@@ -0,0 +1,63 @@
+;;; bat-mode-tests.el --- Tests for bat-mode.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Vladimir Panteleev <vladimir@thecybershadow.net>
+;; Keywords:
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'bat-mode)
+(require 'htmlfontify)
+
+(defun bat-test-fontify (str)
+  "Fontify STR in `bat-mode' to a HTML string using `htmlfontify' and return it."
+  (with-temp-buffer
+    (insert str)
+    (bat-mode)
+    (let ((hfy-optimizations '(body-text-only merge-adjacent-tags)))
+      (with-current-buffer (htmlfontify-buffer) (buffer-string)))))
+
+(ert-deftest bat-test-fontification-var-decl ()
+  "Test fontification of variable declarations."
+  (should
+   (equal
+    (bat-test-fontify "set a_b-c{d}e=f")
+    "<span class=\"builtin\">set</span> <span class=\"variable-name\">a_b-c{d}e</span>=f")))
+
+(ert-deftest bat-test-fontification-var-exp ()
+  "Test fontification of variable expansions."
+  (should
+   (equal
+    (bat-test-fontify "echo %a_b-c{d}e%")
+    "<span class=\"builtin\">echo</span> %<span class=\"variable-name\">a_b-c{d}e</span>%")))
+
+(ert-deftest bat-test-fontification-var-delayed-exp ()
+  "Test fontification of delayed variable expansions."
+  (should
+   (equal
+    (bat-test-fontify "echo !a_b-c{d}e!")
+    "<span class=\"builtin\">echo</span> !<span class=\"variable-name\">a_b-c{d}e</span>!")))
+
+(provide 'bat-tests)
+;;; bat-mode-tests.el ends here
-- 
2.11.0






  reply	other threads:[~2017-01-26  4:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
2017-01-26  4:36 ` Vladimir Panteleev [this message]
2017-01-26  4:36 ` bug#25541: [PATCH 2/3] Fix fill-paragraph for comments in bat-mode Vladimir Panteleev
2017-01-26  4:36 ` bug#25541: [PATCH 3/3] Improve iteration variable fontification " Vladimir Panteleev
2017-01-27  9:57 ` bug#25541: [PATCH] Some small bat-mode fixes Eli Zaretskii
2017-01-27 10:02   ` Vladimir Panteleev
2017-01-27 10:34     ` Eli Zaretskii
2017-02-10  9:30 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170126043624.14326-2-git@thecybershadow.net \
    --to=git@thecybershadow.net \
    --cc=25541@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.