bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#28311: 25.2; Improve syntax highlighting in bat-mode


From: Anders Lindgren
Subject: bug#28311: 25.2; Improve syntax highlighting in bat-mode
Date: Thu, 31 Aug 2017 21:06:14 +0200

Hi!

I've noticed some problems with syntax highlighting in bat-mode. In addition, I have two improvement suggestions.

Problem 1:

bat-mode highlights variables surrounded by "%":s, as in "%alpha%". However, when the variable contains an underscore, as in "%alpha_beta%", only "alpha" is highlighted.

Problem 2:

Similarly, bat-mode highlights variables defined using "set". As with problem 1 above, it does not handle words with underscore. Concretely, in "set alpha_beta=value", only "alpha" is highlighted.

Problem 3:

bat-mode highlights keywords like "in". Unfortunately, it also highlights the word "in" when used as a file extension. For example "xxx alpha.in".

Improvement suggestion 1:

In bat scripts, the command "echo" can be used to print strings to the console. Unlike in shell scripts, the argument to "echo" does not require quotes. It would be nice if Emacs would highlight anything after "echo" as a string (using font-lock-string-face).

Improvement suggestion 2:

In bat scripts, variable substitution is performed inside quoted strings, for example:

    xxx "hello %alpha goodbye"

Unfortunately, emacs does not highlight this, which I hereby propose that it should.


I had plans to fix all of the above myself. Unfortunately, my Emacs todo-list is too long for my available time, so Richard S. suggested that I report this here, in case someone else would have more time than I do.

Anyway, problem 1 and 2 can probably be fixed by adapting a regexp. Problem 3 should easily be fixed by using a custom font-lock syntax table, where "." is seen as a word character, or possibly a symbol character. Improvement suggestion 1 could probably be handled by a simple rule matching echo + space + whatever and highlight "whatever" using font-lock-string-face. All of these are easy to fix.

Improvement suggestion 2 raises the bar to "medium", as it would require replacing the current rexexp rule with one written in elisp. The rule will need to use the "prepend" (not "t") override flag to add font-lock-variable-name-face to the variable name in top of the string face. However, the code must ensure that it does not do this for comments.

Side note: Typically, the "prepend" override flag is preferred over "t", as the end result will mix face properties from both the new and old faces. Concretely, I use a string face with a red foreground and a grey background. With the "prepend" flag, the variable name will be drawn using yellow from font-lock-variable-name-face but the background will still be grey, matching the rest of the string.

    -- Anders Lindgren



In GNU Emacs 25.2.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911))
 of 2017-04-21 built on builder10-9.porkrind.org
Windowing system distributor 'Apple', version 10.3.1504
Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES

Important settings:
  value of $LC_CTYPE: UTF-8
  value of $LANG: en_SE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Bat

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
next-line: End of buffer

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util help-fns help-mode cl-loaddefs pcase
cl-lib mail-prsvr mail-utils vc-dispatcher vc-svn bat-mode easymenu
time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel ns-win ucs-normalize term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame
cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote kqueue cocoa ns
multi-tty make-network-process emacs)

Memory information:
((conses 16 196862 6811)
 (symbols 48 19646 0)
 (miscs 40 53 163)
 (strings 32 15415 5200)
 (string-bytes 1 442636)
 (vectors 16 33051)
 (vector-slots 8 651956 5657)
 (floats 8 162 94)
 (intervals 56 216 0)
 (buffers 976 19))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]