unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Support variable-unquoting syntax in bat-mode
@ 2018-03-14  8:37 Jostein Kjønigsen
  2018-03-14 14:15 ` Vladimir Panteleev
  2018-03-14 16:22 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Jostein Kjønigsen @ 2018-03-14  8:37 UTC (permalink / raw)
  To: emacs-devel, Vladimir Panteleev, Eli Zaretskii

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

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

jostein@kjonigsen.net 🍵 jostein@gmail.com
https://jostein.kjonigsen.net


[-- Attachment #2: Type: text/html, Size: 2891 bytes --]

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

* Re: Support variable-unquoting syntax in bat-mode
  2018-03-14  8:37 Support variable-unquoting syntax in bat-mode Jostein Kjønigsen
@ 2018-03-14 14:15 ` Vladimir Panteleev
  2018-03-14 16:22 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Vladimir Panteleev @ 2018-03-14 14:15 UTC (permalink / raw)
  To: jostein, emacs-devel, Eli Zaretskii

Hi Jostein,

On 2018-03-14 08:37, Jostein Kjønigsen wrote:
> 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?

AFAIK, argument substitution follows the same rules as for "FOR" 
variable references. Run "for /?" or "help for" in a Windows command 
prompt to get a description of it.

E.g. %~dp1 means to get the unquoted drive and path of the first argument.

-- 
Best regards,
  Vladimir



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

* Re: Support variable-unquoting syntax in bat-mode
  2018-03-14  8:37 Support variable-unquoting syntax in bat-mode Jostein Kjønigsen
  2018-03-14 14:15 ` Vladimir Panteleev
@ 2018-03-14 16:22 ` Eli Zaretskii
  2018-03-14 20:48   ` Jostein Kjønigsen
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2018-03-14 16:22 UTC (permalink / raw)
  To: jostein; +Cc: vladimir, emacs-devel

> From: Jostein Kjønigsen <jostein@secure.kjonigsen.net>
> Date: Wed, 14 Mar 2018 09:37:29 +0100
> 
> 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))

I think this will break the test suite for bat-mode.el.  Did you run
it after applying the change?

> 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?

That's because in the likes of "%~dp1" we want only "1" to be
highlighted as variable name.  With your change, "~dp1" will be
highlighted in its entirety.

How about the patch below instead?

--- lisp/progmodes/bat-mode.el~	2018-01-03 13:09:15.000000000 +0200
+++ lisp/progmodes/bat-mode.el	2018-03-14 17:10:44.238856900 +0200
@@ -84,6 +84,8 @@
          . 'bat-label-face)
         ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
          (2 font-lock-variable-name-face))
+        ("%~\\([1-9]\\)"
+         (1 font-lock-variable-name-face))
         ("%\\([^%~ \n]+\\)%?"
          (1 font-lock-variable-name-face))
         ("!\\([^!%~ \n]+\\)!?"  ; delayed-expansion !variable!



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

* Re: Support variable-unquoting syntax in bat-mode
  2018-03-14 16:22 ` Eli Zaretskii
@ 2018-03-14 20:48   ` Jostein Kjønigsen
  2018-03-15 13:25     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Jostein Kjønigsen @ 2018-03-14 20:48 UTC (permalink / raw)
  To: Eli Zaretskii, jostein; +Cc: vladimir, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1603 bytes --]

Hey Eli.

Thanks for the quick reply!

On Wed, Mar 14, 2018, at 5:22 PM, Eli Zaretskii wrote:
> I think this will break the test suite for bat-mode.el.  Did you run
> it after applying the change?

I honestly just tested it inside a running Emacs sessions, but I will
make sure to run "make check" before making concrete change-requests in
the future.
> That's because in the likes of "%~dp1" we want only "1" to be
> highlighted as variable name.  With your change, "~dp1" will be
> highlighted in its entirety.

That makes sense. I can appreciate that.

> How about the patch below instead?
> 
> --- lisp/progmodes/bat-mode.el~ 2018-01-03 13:09:15.000000000 +0200
> +++ lisp/progmodes/bat-mode.el 2018-03-14 17:10:44.238856900 +0200
> @@ -84,6 +84,8 @@
>           . 'bat-label-face)
>         ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
>           (2 font-lock-variable-name-face))
> +        ("%~\\([1-9]\\)"
> +         (1 font-lock-variable-name-face))
>         ("%\\([^%~ \n]+\\)%?"
>           (1 font-lock-variable-name-face))
>         ("!\\([^!%~ \n]+\\)!?"  ; delayed-expansion !variable!

That works for me, and running "make check", it seems all tests
still pass.
If I were to amend this in any way, it would be extending  the range
check from 0 (zero) to 9, (as opposed 1 to 9).
%  is the program being executed, and in certain cases a normal
%  parameter to extract (for instance in generic logging-statements).
--
 Regards
Jostein Kjønigsen

jostein@kjonigsen.net 🍵 jostein@gmail.com
https://jostein.kjonigsen.net




[-- Attachment #2: Type: text/html, Size: 2948 bytes --]

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

* Re: Support variable-unquoting syntax in bat-mode
  2018-03-14 20:48   ` Jostein Kjønigsen
@ 2018-03-15 13:25     ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2018-03-15 13:25 UTC (permalink / raw)
  To: jostein; +Cc: vladimir, emacs-devel

> From: Jostein Kjønigsen <jostein@secure.kjonigsen.net>
> Cc: emacs-devel@gnu.org, vladimir@thecybershadow.net
> Date: Wed, 14 Mar 2018 21:48:53 +0100
> 
>  --- lisp/progmodes/bat-mode.el~ 2018-01-03 13:09:15.000000000 +0200
>  +++ lisp/progmodes/bat-mode.el 2018-03-14 17:10:44.238856900 +0200
>  @@ -84,6 +84,8 @@
>            . 'bat-label-face)
>          ("\\_<\\(defined\\|set\\)\\_>[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)"
>            (2 font-lock-variable-name-face))
>  +        ("%~\\([1-9]\\)"
>  +         (1 font-lock-variable-name-face))
>          ("%\\([^%~ \n]+\\)%?"
>            (1 font-lock-variable-name-face))
>          ("!\\([^!%~ \n]+\\)!?"  ; delayed-expansion !variable!
> 
> That works for me, and running "make check", it seems all tests still pass.
> 
> If I were to amend this in any way, it would be extending  the range check from 0 (zero) to 9, (as opposed 1 to
> 9).
> 
> %0  is the program being executed, and in certain cases a normal parameter to extract (for instance in
> generic logging-statements).

Right, fixed to use 0 and pushed to the master branch, including a
test for this new feature.

Thanks.



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

end of thread, other threads:[~2018-03-15 13:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-14  8:37 Support variable-unquoting syntax in bat-mode Jostein Kjønigsen
2018-03-14 14:15 ` Vladimir Panteleev
2018-03-14 16:22 ` Eli Zaretskii
2018-03-14 20:48   ` Jostein Kjønigsen
2018-03-15 13:25     ` 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).