unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25541: [PATCH] Some small bat-mode fixes
@ 2017-01-26  4:36 Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode Vladimir Panteleev
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Vladimir Panteleev @ 2017-01-26  4:36 UTC (permalink / raw)
  To: 25541

These fix a few issues with fontification and fill-paragraph in
bat-mode (used for Windows .bat and .cmd files). Tests included.






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode
  2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
@ 2017-01-26  4:36 ` Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 2/3] Fix fill-paragraph for comments " Vladimir Panteleev
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Vladimir Panteleev @ 2017-01-26  4:36 UTC (permalink / raw)
  To: 25541; +Cc: Vladimir Panteleev

* 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






^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH 2/3] Fix fill-paragraph for comments in bat-mode
  2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode Vladimir Panteleev
@ 2017-01-26  4:36 ` Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 3/3] Improve iteration variable fontification " Vladimir Panteleev
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Vladimir Panteleev @ 2017-01-26  4:36 UTC (permalink / raw)
  To: 25541; +Cc: Vladimir Panteleev

* lisp/progmodes/bat-mode.el: Set comment-start-skip.
* test/lisp/progmodes/bat-mode-tests.el: Add test.
---
 lisp/progmodes/bat-mode.el            |  1 +
 test/lisp/progmodes/bat-mode-tests.el | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lisp/progmodes/bat-mode.el b/lisp/progmodes/bat-mode.el
index 77b97ac6ff..a945d37f1d 100644
--- a/lisp/progmodes/bat-mode.el
+++ b/lisp/progmodes/bat-mode.el
@@ -176,6 +176,7 @@ bat-mode
 Run script using `bat-run' and `bat-run-args'.\n
 \\{bat-mode-map}"
   (setq-local comment-start "rem ")
+  (setq-local comment-start-skip "rem[ \t]+")
   (setq-local syntax-propertize-function bat--syntax-propertize)
   (setq-local font-lock-defaults
        '(bat-font-lock-keywords nil t)) ; case-insensitive keywords
diff --git a/test/lisp/progmodes/bat-mode-tests.el b/test/lisp/progmodes/bat-mode-tests.el
index c78827db80..335fc16ffb 100644
--- a/test/lisp/progmodes/bat-mode-tests.el
+++ b/test/lisp/progmodes/bat-mode-tests.el
@@ -59,5 +59,19 @@ bat-test-fontify
     (bat-test-fontify "echo !a_b-c{d}e!")
     "<span class=\"builtin\">echo</span> !<span class=\"variable-name\">a_b-c{d}e</span>!")))
 
+(defun bat-test-fill-paragraph (str)
+  "Return the result of invoking `fill-paragraph' on STR in a `bat-mode' buffer."
+  (with-temp-buffer
+    (bat-mode)
+    (insert str)
+    (goto-char 1)
+    (font-lock-ensure)
+    (fill-paragraph)
+    (buffer-string)))
+
+(ert-deftest bat-test-fill-paragraph-comment ()
+  "Test `fill-paragraph' in a comment block."
+  (should (equal (bat-test-fill-paragraph "rem foo\nrem bar\n") "rem foo bar\n")))
+
 (provide 'bat-tests)
 ;;; bat-mode-tests.el ends here
-- 
2.11.0






^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH 3/3] Improve iteration variable fontification in bat-mode
  2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode Vladimir Panteleev
  2017-01-26  4:36 ` bug#25541: [PATCH 2/3] Fix fill-paragraph for comments " Vladimir Panteleev
@ 2017-01-26  4:36 ` Vladimir Panteleev
  2017-01-27  9:57 ` bug#25541: [PATCH] Some small bat-mode fixes Eli Zaretskii
  2017-02-10  9:30 ` Eli Zaretskii
  4 siblings, 0 replies; 8+ messages in thread
From: Vladimir Panteleev @ 2017-01-26  4:36 UTC (permalink / raw)
  To: 25541; +Cc: Vladimir Panteleev

* lisp/progmodes/bat-mode.el: Improve fontification accuracy of
iteration/positional variables.
* test/lisp/progmodes/bat-mode-tests.el: Add tests.
---
 lisp/progmodes/bat-mode.el            | 7 +++++--
 test/lisp/progmodes/bat-mode-tests.el | 9 +++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/bat-mode.el b/lisp/progmodes/bat-mode.el
index a945d37f1d..1dd2e3757e 100644
--- a/lisp/progmodes/bat-mode.el
+++ b/lisp/progmodes/bat-mode.el
@@ -84,10 +84,13 @@ bat-font-lock-keywords
          . 'bat-label-face)
         ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
          (2 font-lock-variable-name-face))
-        ("%\\(\\(\\sw\\|\\s_\\)+\\)%?"
+        ("%\\(\\(\\sw\\|\\s_\\)+\\)%"
          (1 font-lock-variable-name-face))
-        ("!\\(\\(\\sw\\|\\s_\\)+\\)!?"  ; delayed-expansion !variable!
+        ("!\\(\\(\\sw\\|\\s_\\)+\\)!"  ; delayed-expansion !variable!
          (1 font-lock-variable-name-face))
+        ("%%\\(?:~[adfnpstxz]*\\(?:\\$\\(\\(?:\\sw\\|\\s_\\)+\\):\\)?\\)?\\([]!#$&-:?-[_-{}~]\\)"
+         (1 font-lock-variable-name-face nil t) ; PATH expansion
+         (2 font-lock-variable-name-face)) ; iteration variable or positional parameter
         ("[ =][-/]+\\(\\w+\\)"
          (1 font-lock-type-face append))
         (,(concat "\\_<" (regexp-opt COMMANDS) "\\_>") . font-lock-builtin-face)
diff --git a/test/lisp/progmodes/bat-mode-tests.el b/test/lisp/progmodes/bat-mode-tests.el
index 335fc16ffb..565718eea4 100644
--- a/test/lisp/progmodes/bat-mode-tests.el
+++ b/test/lisp/progmodes/bat-mode-tests.el
@@ -59,6 +59,15 @@ bat-test-fontify
     (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-iter-var-1 ()
+  "Test fontification of iteration variables."
+  (should
+   (equal
+    (bat-test-fontify "echo %%a\necho %%~dp1\necho %%~$PATH:I")
+    "<span class=\"builtin\">echo</span> %%<span class=\"variable-name\">a</span>
+<span class=\"builtin\">echo</span> %%~dp<span class=\"variable-name\">1</span>
+<span class=\"builtin\">echo</span> %%~$<span class=\"variable-name\">PATH</span>:<span class=\"variable-name\">I</span>")))
+
 (defun bat-test-fill-paragraph (str)
   "Return the result of invoking `fill-paragraph' on STR in a `bat-mode' buffer."
   (with-temp-buffer
-- 
2.11.0






^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH] Some small bat-mode fixes
  2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
                   ` (2 preceding siblings ...)
  2017-01-26  4:36 ` bug#25541: [PATCH 3/3] Improve iteration variable fontification " Vladimir Panteleev
@ 2017-01-27  9:57 ` Eli Zaretskii
  2017-01-27 10:02   ` Vladimir Panteleev
  2017-02-10  9:30 ` Eli Zaretskii
  4 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2017-01-27  9:57 UTC (permalink / raw)
  To: Vladimir Panteleev; +Cc: 25541

> From: Vladimir Panteleev <git@thecybershadow.net>
> Date: Thu, 26 Jan 2017 04:36:21 +0000
> 
> These fix a few issues with fontification and fill-paragraph in
> bat-mode (used for Windows .bat and .cmd files). Tests included.

Thanks.  These look good to me, but the sum total of the code exceeds
the amount we can accept without an assignment of copyright to the
FSF.  Would you be willing to do the legal paperwork needed for that?
if you will, I'll send you the form to start that rolling (off-list).





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH] Some small bat-mode fixes
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Vladimir Panteleev @ 2017-01-27 10:02 UTC (permalink / raw)
  To: Eli Zaretskii, Vladimir Panteleev; +Cc: 25541

Hi Eli,

Yes, I am interested in contributing to Emacs in the future :) Please 
hook me up.

On 2017-01-27 09:57, Eli Zaretskii wrote:
>> From: Vladimir Panteleev <git@thecybershadow.net>
>> Date: Thu, 26 Jan 2017 04:36:21 +0000
>>
>> These fix a few issues with fontification and fill-paragraph in
>> bat-mode (used for Windows .bat and .cmd files). Tests included.
>
> Thanks.  These look good to me, but the sum total of the code exceeds
> the amount we can accept without an assignment of copyright to the
> FSF.  Would you be willing to do the legal paperwork needed for that?
> if you will, I'll send you the form to start that rolling (off-list).
>

-- 
Best regards,
  Vladimir





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH] Some small bat-mode fixes
  2017-01-27 10:02   ` Vladimir Panteleev
@ 2017-01-27 10:34     ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2017-01-27 10:34 UTC (permalink / raw)
  To: Vladimir Panteleev; +Cc: git, 25541

> Cc: 25541@debbugs.gnu.org
> From: Vladimir Panteleev <thecybershadow@gmail.com>
> Date: Fri, 27 Jan 2017 10:02:57 +0000
> 
> Hi Eli,
> 
> Yes, I am interested in contributing to Emacs in the future :) Please 
> hook me up.

The form was sent off-list.

When the paperwork is done, we will install your changes.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25541: [PATCH] Some small bat-mode fixes
  2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
                   ` (3 preceding siblings ...)
  2017-01-27  9:57 ` bug#25541: [PATCH] Some small bat-mode fixes Eli Zaretskii
@ 2017-02-10  9:30 ` Eli Zaretskii
  4 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2017-02-10  9:30 UTC (permalink / raw)
  To: Vladimir Panteleev; +Cc: 25541-done

> From: Vladimir Panteleev <git@thecybershadow.net>
> Date: Thu, 26 Jan 2017 04:36:21 +0000
> 
> These fix a few issues with fontification and fill-paragraph in
> bat-mode (used for Windows .bat and .cmd files). Tests included.

Thanks, pushed to the master branch.

In the future, please make sure the commit log entries indicate the
function in which each change was made.  E.g., here:

  * lisp/progmodes/bat-mode.el: Set comment-start-skip.

the function is bat-mode, so the log entry should have said

  * lisp/progmodes/bat-mode.el (bat-mode): Set comment-start-skip.

You can use "C-x 4 a" to format the commit messages for you.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-02-10  9:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-26  4:36 bug#25541: [PATCH] Some small bat-mode fixes Vladimir Panteleev
2017-01-26  4:36 ` bug#25541: [PATCH 1/3] Improve fontification of variables in bat-mode Vladimir Panteleev
2017-01-26  4:36 ` bug#25541: [PATCH 2/3] Fix fill-paragraph for comments " 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).