[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Support variable-unquoting syntax in bat-mode
From: |
Jostein Kjønigsen |
Subject: |
Support variable-unquoting syntax in bat-mode |
Date: |
Wed, 14 Mar 2018 09:37:29 +0100 |
Hey everyone.
For those of us still stuck meddling with Windows batch-files, these scripts are definitely not getting cleaner or smaller with time.
In such batch-files there are various ways to extract script-parameters provided by the script/function caller. The most common syntax is percentage + a numeral, that is %1 represents the first script/function parameter. Etc.
But when parameters contains spaces, they have to be quoted by the caller. The variable/parameter then contains the quote, and to further process them inside your script, they typically need to be unquoted first.
To do unquoting, you typically use the variable unquote syntax: %~1
In latest Emacs this syntax is not correctly highlighted. Applying the following patch seems to fix this:
diff --git a/lisp/progmodes/bat-mode.el b/lisp/progmodes/bat-mode.el
index 102c318..b2edf64 100644
--- a/lisp/progmodes/bat-mode.el
+++ b/lisp/progmodes/bat-mode.el
@@ -84,7 +84,7 @@ bat-font-lock-keywords
. 'bat-label-face)
("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
(2 font-lock-variable-name-face))
- ("%\\([^%~ \n]+\\)%?"
+ ("%\\([^% \n]+\\)%?"
(1 font-lock-variable-name-face))
That seems to work for me, but ~ seems like a odd special case to put in there in the first place, so I would assume it was intentionally put there. Anyone have any background on this?
If not, does anyone object to this change? And if not, how do I get it merged into master? :)
--
Regards
Jostein Kjønigsen
- Support variable-unquoting syntax in bat-mode,
Jostein Kjønigsen <=