Groovy-Emacs-Modes / groovy-emacs-modes

A groovy major mode, grails minor mode, and a groovy inferior mode.
84 stars 39 forks source link

Incorrect highlighting when two slashes are found in the middle of a triple quote #104

Closed djha-skin closed 6 years ago

djha-skin commented 6 years ago

I encountered this problem while editing groovy scripts for Jenkins.

image

After the "comment" part where the groovy mode messes up, the rest of the file is interpreted as if it was groovy, instead of interpreting it as a triple-quoted string, which messes indenting and other stuff up.

Any workarounds or obvious fixes?

Wilfred commented 6 years ago

It looks like the triple-single-quoted string after additional_upgrade_options is being treated as a "..." string. Note that ${deploy_env} is highlighted as normal code, not as interpolation.

I can't reproduce this -- I've tried writing a snippet based on your screenshot, but without success:


x = '''"
foo "bar" 'bar'

'''
y = 123

sh '''
foo''' + '''"
foo "${bar}"
$'
//foo
"'''

Could you provide a code sample that I can copy-and-paste? Feel free to replace any sensitive bits with foo and bar as appropriate. I suspect you only need the punctuation to reproduce.

djha-skin commented 6 years ago

Here you go. This is from a Jenkinsfile Shared Library file:

def call(body) {
    // evaluate the body block, and collect configuration into the object
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    // now build, based on the configuration provided
    pipeline {
        agent any
        parameters {
            string(defaultValue: "", description: '', name: 'blue_whale')
            string(defaultValue: "", description: '', name: 'bark_bark')
            string(defaultValue: "", description: '', name: 'bow_tie')

        }
        stages {
            stage('build') {
                steps {
                    script {
                        if (config.build_script) {
                            sh config.build_script
                        }
                    }
                    script {
                        sh '''
                        set -ex
                        rm -rf *.tgz
                        echo "Deploying to: '${blue_whale}'"
                        if [ ! -f "./Jenkinsfile" ]
                        then
                            echo "This script must be run from the root of the repo." >&2
                            exit 1
                        fi
                        tree_roots=${PWD}
                        if [ -z "${blue_whale}" ]
                        then
                            blue_whale="''' + default_blue_whale + '''"
                        fi
                        if [ -z "${bark_bark}" ]
                        then
                            bark_bark="''' + default_bark_bark + '''"
                        fi
                        bow_tie_options="''' + bow_tie_options + '''"
                        if [ -z "${buck_tooth}" ]
                        then
                            buck_tooth="''' + buck_tooth + '''"
                        fi
                        name=$(cat name)
                        if [ -d "${tree_roots}/foo/${blue_whale}" -a \\
                           ! -f "${tree_roots}/bar/${blue_whale}.yaml" ]
                        then
                            if echo "${blue_whale}" | grep -qE '^(qa|beta|prod|tools)$'
                            then
                                repo_prefix="${blue_whale}"
                            else
                                repo_prefix="cloudnative"
                            fi
                            batty_path="${tree_roots}/batty/${blue_whale}"
                            cd "${batty_path}"
                            snoopdog_url="https://example.com/foo"
                            batty_repo="${snoopdog_url}/${repo_prefix}-foo-local"
                            batty_index="${batty_repo}/foo"
                            batty_config="${batty_repo}/bar"
                            degasolv_configs="-c ${baz}"
                            if [ ! -f "./quxx" ]
                            then
                                echo "${PWD}/quxx is not present." >&2
                                echo "Cannot continue." >&2
                                exit 1
                            fi'''
                            }
                            }
                            }
                            }
                            }
                            }
vincekd commented 6 years ago

works fine for me: image

What version of the mode are you using? Also, have you tried disabling all other modes and just testing with groovy-mode enabled?

djha-skin commented 6 years ago

Version:

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

Installed packages (C-x list-packages):

  auctex             11.90.0       installed             Integrated environment for *TeX*
  auto-complete      20161029.643  installed             Auto Completion for GNU Emacs
  cider              20170119.47   installed             Clojure Interactive Development Environment that Rocks
  cmake-mode         20160928.505  installed             major-mode for editing CMake sources
  eshell-did-you-... 20150915.1252 installed             command not found ("did you mean…" feature) in Eshell
  eshell-up          20170425.1037 installed             Quickly go to a specific parent directory in eshell
  gnuplot            20141231.1337 installed             drive gnuplot from within emacs
  gnuplot-mode       20151122.2339 installed             Major mode for editing gnuplot scripts
  go-mode            20161231.1134 installed             Major mode for the Go programming language
  groovy-imports     20161003.151  installed             Code for dealing with Groovy imports
  groovy-mode        20180109.718  installed             Major mode for Groovy source files
  icicles            20170118.2321 installed             Minibuffer input completion and cycling.
  itail              20170823.1629 installed             An interactive tail mode
  json-mode          20170719.2205 installed             Major mode for editing JSON files.
  magit              20170119.1803 installed             A Git porcelain inside Emacs
  python-mode        20170117.455  installed             Python major mode
  quack              20160410.207  installed             enhanced support for editing and running Scheme code
  real-auto-save     20150701.815  installed             Automatically save your all your buffers/files at regular intervals.
  shell-switcher     20161028.2252 installed             Provide fast switching between shell buffers.
  tuareg             20170109.1459 installed             OCaml mode for Emacs.
  vagrant-tramp      20160427.1632 installed             Vagrant method for TRAMP
  xterm-color        20170102.1525 installed             ANSI & XTERM 256 color support
  async              20161103.1036 dependency            Asynchronous processing in Emacs
  caml               20151009.845  dependency            No description available.
  clojure-mode       20161221.523  dependency            Major mode for Clojure code
  dash               20161121.55   dependency            A modern list library for Emacs
  epl                20150517.433  dependency            Emacs Package Library
  esh-help           20170730.2157 dependency            Add some help functions and support for Eshell
  exec-path-from-... 20170508.4    dependency            Get environment variables such as $PATH from the shell
  git-commit         20170112.334  dependency            Edit Git commit messages
  json-reformat      20160212.53   dependency            Reformatting tool for JSON
  json-snatcher      20150511.2047 dependency            Grabs the path to JSON values in a JSON file
  magit-popup        20170104.924  dependency            Define prefix-infix-suffix command combos
  markdown-mode      20170823.1201 dependency            Major mode for Markdown-formatted text
  markdown-mode+     20170320.1404 dependency            extra functions for markdown-mode
  pcache             20170105.1414 dependency            persistent caching for Emacs.
  pkg-info           20150517.443  dependency            Information about packages
  popup              20160709.729  dependency            Visual Popup User Interface
  queue              0.1.1         dependency            Queue data structure
  s                  20170428.1026 dependency            The long lost Emacs string manipulation library.
  seq                2.19          dependency            Sequence manipulation functions
  spinner            1.7.3         dependency            Add spinners and progress-bars to the mode-line for ongoing operations
  with-editor        20170111.609  dependency            Use the Emacsclient as $EDITOR

Minor modes (C-h + C-m):

Enabled minor modes: Async-Bytecomp-Package Auto-Composition
Auto-Compression Auto-Encryption Auto-Revert Column-Number
Diff-Auto-Refine Electric-Indent File-Name-Shadow Font-Lock
Global-Auto-Complete Global-Font-Lock Global-Git-Commit Global-Linum
Global-Whitespace Line-Number Linum Magit-Auto-Revert Menu-Bar
Mouse-Wheel Real-Auto-Save Shell-Dirtrack Shell-Switcher Show-Paren
Tool-Bar Tooltip Transient-Mark

(Information about these minor modes follows the major mode info.)

Groovy mode:
Cannot open doc string file "/Users/djhaskin987/.emacs.d/elpa/groovy-mode-20170731.150/groovy-mode.elc"


Async-Bytecomp-Package minor mode (no indicator):
Byte compile asynchronously packages installed with package.el.
Async compilation of packages can be controlled by
‘async-bytecomp-allowed-packages’.

(fn &optional ARG)

Auto-Composition minor mode (no indicator):
Toggle Auto Composition mode.
With a prefix argument ARG, enable Auto Composition mode if ARG
is positive, and disable it otherwise.  If called from Lisp,
enable the mode if ARG is omitted or nil.

When Auto Composition mode is enabled, text characters are
automatically composed by functions registered in
‘composition-function-table’.

You can use ‘global-auto-composition-mode’ to turn on
Auto Composition mode in all buffers (this is the default).

Auto-Compression minor mode (no indicator):
Toggle Auto Compression mode.
With a prefix argument ARG, enable Auto Compression mode if ARG
is positive, and disable it otherwise.  If called from Lisp,
enable the mode if ARG is omitted or nil.

Auto Compression mode is a global minor mode.  When enabled,
compressed files are automatically uncompressed for reading, and
compressed when writing.

Auto-Encryption minor mode (no indicator):
Toggle automatic file encryption/decryption (Auto Encryption mode).
With a prefix argument ARG, enable Auto Encryption mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

(fn &optional ARG)

Auto-Revert minor mode (indicator ARev):
Toggle reverting buffer when the file changes (Auto Revert mode).
With a prefix argument ARG, enable Auto Revert mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Auto Revert mode is a minor mode that affects only the current
buffer.  When enabled, it reverts the buffer when the file on
disk changes.

When a buffer is reverted, a message is generated.  This can be
suppressed by setting ‘auto-revert-verbose’ to nil.

Use ‘global-auto-revert-mode’ to automatically revert all buffers.
Use ‘auto-revert-tail-mode’ if you know that the file will only grow
without being changed in the part that is already in the buffer.

(fn &optional ARG)

Column-Number minor mode (no indicator):
Toggle column number display in the mode line (Column Number mode).
With a prefix argument ARG, enable Column Number mode if ARG is
positive, and disable it otherwise.

If called from Lisp, enable the mode if ARG is omitted or nil.

(fn &optional ARG)

Diff-Auto-Refine minor mode (no indicator):
Toggle automatic diff hunk highlighting (Diff Auto Refine mode).
With a prefix argument ARG, enable Diff Auto Refine mode if ARG
is positive, and disable it otherwise.  If called from Lisp,
enable the mode if ARG is omitted or nil.

Diff Auto Refine mode is a buffer-local minor mode used with
‘diff-mode’.  When enabled, Emacs automatically highlights
changes in detail as the user visits hunks.  When transitioning
from disabled to enabled, it tries to refine the current hunk, as
well.

(fn &optional ARG)

Electric-Indent minor mode (no indicator):
Toggle on-the-fly reindentation (Electric Indent mode).
With a prefix argument ARG, enable Electric Indent mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

When enabled, this reindents whenever the hook ‘electric-indent-functions’
returns non-nil, or if you insert a character from ‘electric-indent-chars’.

This is a global minor mode.  To toggle the mode in a single buffer,
use ‘electric-indent-local-mode’.

File-Name-Shadow minor mode (no indicator):
Toggle file-name shadowing in minibuffers (File-Name Shadow mode).
With a prefix argument ARG, enable File-Name Shadow mode if ARG
is positive, and disable it otherwise.  If called from Lisp,
enable the mode if ARG is omitted or nil.

File-Name Shadow mode is a global minor mode.  When enabled, any
part of a filename being read in the minibuffer that would be
ignored (because the result is passed through
‘substitute-in-file-name’) is given the properties in
‘file-name-shadow-properties’, which can be used to make that
portion dim, invisible, or otherwise less visually noticeable.

Font-Lock minor mode (no indicator):
Toggle syntax highlighting in this buffer (Font Lock mode).
With a prefix argument ARG, enable Font Lock mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

When Font Lock mode is enabled, text is fontified as you type it:

 - Comments are displayed in ‘font-lock-comment-face’;
 - Strings are displayed in ‘font-lock-string-face’;
 - Certain other expressions are displayed in other faces
   according to the value of the variable ‘font-lock-keywords’.

To customize the faces (colors, fonts, etc.) used by Font Lock for
fontifying different parts of buffer text, use M-x customize-face.

You can enable Font Lock mode in any major mode automatically by
turning on in the major mode’s hook.  For example, put in your
~/.emacs:

 (add-hook 'c-mode-hook 'turn-on-font-lock)

Alternatively, you can use Global Font Lock mode to automagically
turn on Font Lock mode in buffers whose major mode supports it
and whose major mode is one of ‘font-lock-global-modes’.  For
example, put in your ~/.emacs:

 (global-font-lock-mode t)

Where major modes support different levels of fontification, you
can use the variable ‘font-lock-maximum-decoration’ to specify
which level you generally prefer.  When you turn Font Lock mode
on/off the buffer is fontified/defontified, though fontification
occurs only if the buffer is less than ‘font-lock-maximum-size’.

To add your own highlighting for some major mode, and modify the
highlighting selected automatically via the variable
‘font-lock-maximum-decoration’, you can use
‘font-lock-add-keywords’.

To fontify a buffer, without turning on Font Lock mode and
regardless of buffer size, you can use M-x font-lock-fontify-buffer.

To fontify a block (the function or paragraph containing point,
or a number of lines around point), perhaps because modification
on the current line caused syntactic change on other lines, you
can use M-o M-o.

You can set your own default settings for some mode, by setting a
buffer local value for ‘font-lock-defaults’, via its mode hook.

The above is the default behavior of ‘font-lock-mode’; you may
specify your own function which is called when ‘font-lock-mode’
is toggled via ‘font-lock-function’. 

Global-Auto-Complete minor mode (no indicator):
Toggle Auto-Complete mode in all buffers.
With prefix ARG, enable Global Auto-Complete mode if ARG is positive;
otherwise, disable it.  If called from Lisp, enable the mode if
ARG is omitted or nil.

Auto-Complete mode is enabled in all buffers where
‘auto-complete-mode-maybe’ would do it.
See ‘auto-complete-mode’ for more information on Auto-Complete mode.

Global-Font-Lock minor mode (no indicator):
Toggle Font-Lock mode in all buffers.
With prefix ARG, enable Global Font-Lock mode if ARG is positive;
otherwise, disable it.  If called from Lisp, enable the mode if
ARG is omitted or nil.

Font-Lock mode is enabled in all buffers where
‘turn-on-font-lock-if-desired’ would do it.
See ‘font-lock-mode’ for more information on Font-Lock mode.

Global-Git-Commit minor mode (no indicator):
Edit Git commit messages.
This global mode arranges for ‘git-commit-setup’ to be called
when a Git commit message file is opened.  That usually happens
when Git uses the Emacsclient as $GIT_EDITOR to have the user
provide such a commit message.

(fn &optional ARG)

Global-Linum minor mode (no indicator):
Toggle Linum mode in all buffers.
With prefix ARG, enable Global Linum mode if ARG is positive;
otherwise, disable it.  If called from Lisp, enable the mode if
ARG is omitted or nil.

Linum mode is enabled in all buffers where
‘linum-on’ would do it.
See ‘linum-mode’ for more information on Linum mode.

(fn &optional ARG)

Global-Whitespace minor mode (indicator WS):
Toggle whitespace visualization globally (Global Whitespace mode).
With a prefix argument ARG, enable Global Whitespace mode if ARG
is positive, and disable it otherwise.

If called from Lisp, also enables the mode if ARG is omitted or nil,
and toggles it if ARG is ‘toggle’.

See also ‘whitespace-style’, ‘whitespace-newline’ and
‘whitespace-display-mappings’.

Line-Number minor mode (no indicator):
Toggle line number display in the mode line (Line Number mode).
With a prefix argument ARG, enable Line Number mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Line numbers do not appear for very large buffers and buffers
with very long lines; see variables ‘line-number-display-limit’
and ‘line-number-display-limit-width’.

(fn &optional ARG)

Linum minor mode (no indicator):
Toggle display of line numbers in the left margin (Linum mode).
With a prefix argument ARG, enable Linum mode if ARG is positive,
and disable it otherwise.  If called from Lisp, enable the mode
if ARG is omitted or nil.

Linum mode is a buffer-local minor mode.

(fn &optional ARG)

Magit-Auto-Revert minor mode (no indicator):
Toggle Magit Auto Revert mode.
With a prefix argument ARG, enable Magit Auto Revert mode if ARG
is positive, and disable it otherwise.  If called from Lisp,
enable the mode if ARG is omitted or nil.

Magit Auto Revert mode is a global minor mode that reverts
buffers associated with a file that is located inside a Git
repository when the file changes on disk.  Use ‘auto-revert-mode’
to revert a particular buffer.  Or use ‘global-auto-revert-mode’
to revert all file-visiting buffers, not just those that visit
a file located inside a Git repository.

This global mode works by turning on the buffer-local mode
‘auto-revert-mode’ at the time a buffer is first created.  The
local mode is turned on if the visited file is being tracked in
a Git repository at the time when the buffer is created.

If ‘magit-auto-revert-tracked-only’ is non-nil (the default),
then only tracked files are reverted.  But if you stage a
previously untracked file using ‘magit-stage’, then this mode
notices that.

Unlike ‘global-auto-revert-mode’, this mode never reverts any
buffers that are not visiting files.

The behavior of this mode can be customized using the options
in the ‘autorevert’ and ‘magit-autorevert’ groups.

This function calls the hook ‘magit-auto-revert-mode-hook’.

Menu-Bar minor mode (no indicator):
Toggle display of a menu bar on each frame (Menu Bar mode).
With a prefix argument ARG, enable Menu Bar mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
Menu Bar mode if ARG is omitted or nil.

This command applies to all frames that exist and frames to be
created in the future.

Mouse-Wheel minor mode (no indicator):
Toggle mouse wheel support (Mouse Wheel mode).
With a prefix argument ARG, enable Mouse Wheel mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Real-Auto-Save minor mode (indicator RAS):
Save your buffers automatically.

Shell-Dirtrack minor mode (no indicator):
Toggle directory tracking in this shell buffer (Shell Dirtrack mode).
With a prefix argument ARG, enable Shell Dirtrack mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

The ‘dirtrack’ package provides an alternative implementation of
this feature; see the function ‘dirtrack-mode’.

(fn &optional ARG)

Shell-Switcher minor mode (no indicator):
Toggle shell-switcher mode.
Interactively with no argument, this command toggles the mode. A
positive prefix argument enables the mode, any other prefix
argument disables it. From Lisp, argument omitted or nil enables
the mode, ‘toggle’ toggles the state.

When shell-switcher mode is enabled, switching and creating shell
buffers is just a matter of calling
C-'. Then, you can type the last key
of this key binding again to continue switching. Additionally,
see commands C-x 4 ' and
C-M-'.

(fn &optional ARG)

Show-Paren minor mode (no indicator):
Toggle visualization of matching parens (Show Paren mode).
With a prefix argument ARG, enable Show Paren mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Show Paren mode is a global minor mode.  When enabled, any
matching parenthesis is highlighted in ‘show-paren-style’ after
‘show-paren-delay’ seconds of Emacs idle time.

Tool-Bar minor mode (no indicator):
Toggle the tool bar in all graphical frames (Tool Bar mode).
With a prefix argument ARG, enable Tool Bar mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
Tool Bar mode if ARG is omitted or nil.

See ‘tool-bar-add-item’ and ‘tool-bar-add-item-from-menu’ for
conveniently adding tool bar items.

Tooltip minor mode (no indicator):
Toggle Tooltip mode.
With a prefix argument ARG, enable Tooltip mode if ARG is positive,
and disable it otherwise.  If called from Lisp, enable the mode
if ARG is omitted or nil.

When this global minor mode is enabled, Emacs displays help
text (e.g. for buttons and menu items that you put the mouse on)
in a pop-up window.

When Tooltip mode is disabled, Emacs displays help text in the
echo area, instead of making a pop-up window.

Transient-Mark minor mode (no indicator):
Toggle Transient Mark mode.
With a prefix argument ARG, enable Transient Mark mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
Transient Mark mode if ARG is omitted or nil.

Transient Mark mode is a global minor mode.  When enabled, the
region is highlighted with the ‘region’ face whenever the mark
is active.  The mark is "deactivated" by changing the buffer,
and after certain other operations that set the mark but whose
main purpose is something else--for example, incremental search,
<, and >.

You can also deactivate the mark by typing C-g or
M-ESC ESC.

Many commands change their behavior when Transient Mark mode is
in effect and the mark is active, by acting on the region instead
of their usual default part of the buffer’s text.  Examples of
such commands include M-;, M-x flush-lines, M-x keep-lines,
M-x query-replace, M-%, s-:, and C-x u.
To see the documentation of commands which are sensitive to the
Transient Mark mode, invoke C-h d and type "transient"
or "mark.*active" at the prompt.

(fn &optional ARG)
Wilfred commented 6 years ago

Works fine for me too.

djha-skin commented 6 years ago

well, if the answer is "There's something wrong with your environment", that's fine with me :)