Git Product home page Git Product logo

yaml-mode's Introduction

RECRUITMENTS
    I have not used emacs and this library for a long time,
    so I recruit maintainers or collaborators for all yaml-mode users.
    If you are interested in maintaining or collaborating with this library,
    please contact me.

NAME
    yaml-mode - Simple major mode to edit YAML file for emacs

REQUIREMENTS
    Emacs 24.1

SYNOPSIS
    To install, just drop this file into a directory in your
    `load-path' and (optionally) byte-compile it.  To automatically
    handle files ending in '.yml', add something like:

    (require 'yaml-mode)
    (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))

    to your .emacs file.

    Unlike python-mode, this mode follows the Emacs convention of not
    binding the ENTER key to `newline-and-indent'.  To get this
    behavior, add the key definition to `yaml-mode-hook':

    (add-hook 'yaml-mode-hook
      '(lambda ()
        (define-key yaml-mode-map "\C-m" 'newline-and-indent)))

DESCRIPTION
    yaml-mode is major mode for emacs.

INSTALL
    You can install yaml-mode typing below.

        % make
        % make install

        or

        % make PREFIX=/your/home/dir
        % make install PREFIX=/your/home/dir

SETTING
    see SYNOPSIS.

AUTHOR
    Yoshiki Kurihara <[email protected]> Copyright (C) 2010 by Free Software
    Foundation, Inc.

    This file 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.

    This file 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 <https://www.gnu.org/licenses/>.

yaml-mode's People

Contributors

antalk2 avatar arthuraa avatar canatella avatar damiencassou avatar dgutov avatar dunn avatar gvalkov avatar hi-angel avatar hparker avatar jfrederickson avatar liangfu avatar liuyinz avatar minad avatar mmckinst avatar phst avatar pkulev avatar samb avatar scop avatar skangas avatar snogge avatar strutt avatar sugyan avatar syohex avatar tarsius avatar timcharper avatar ts4z avatar wasamasa avatar wentasah avatar wilfred avatar yoshiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yaml-mode's Issues

Display current "location"

Wishlist:

In deeply nested YAML files, sometimes I get a bit lost. A way to make yaml-mode display which nested map I'm in would be wonderful!

Indent-region doesn't unindent correctly

The yaml file

backgroundOrder:
- 13
- 44
backgroundStates:
- 9
- 10
columnOrder:
- ICON
- DISTANCE

is converted to

  backgroundOrder:
    - 13
    - 44
    backgroundStates:
      - 9
      - 10
      columnOrder:
        - ICON
        - DISTANCE

Lists of dictionaries are not indented correctly

I'm seeing the following indentation behaviour when using yaml-mode:

foo:
  - bar: baz
    - foo: 1

I yaml-mode to indent like:

--- expected
foo:
  - bar: baz
  - foo: 1

This seems to be related to yaml-nested-sequence-re and the way it is being used in yaml-compute-indentation as either of the following changes fixes/changes this particular behaviour:

  1. Change yaml-nested-sequence-re to only match lines that end with :

The following regular expression results in the "correct" behaviour in this particular case.

(defconst yaml-nested-sequence-re
  (concat "^\\(?:\\(?: *- +\\)+\\|\\(:? *-$\\)\\)"
          "\\(?:" yaml-bare-scalar-re " *:\\)?$")
  "Regexp matching a line containing one or more nested YAML sequences.")
  1. Remove nested sequence check from yaml-compute-indentation

Unsurprisingly removing the yaml-nested-sequence-re check from yaml-compute-indentation to yield the following also results in the correct indentation of the snippet above.

(defun yaml-compute-indentation ()
  "Calculate the maximum sensible indentation for the current line."
  (save-excursion
    (beginning-of-line)
    (if (looking-at yaml-document-delimiter-re) 0
      (forward-line -1)
      (while (and (looking-at yaml-blank-line-re)
                  (> (point) (point-min)))
        (forward-line -1))
      (+ (current-indentation)
         (if (looking-at yaml-nested-map-re) yaml-indent-offset 0)
         (if (looking-at yaml-block-literal-re) yaml-indent-offset 0)))))

Paired with #24 it appears as if the indentation framework needs to be more context sensitive like python-mode.

Support for nested lists

Hi,

Is the following construction going to be supported (and properly indented)?

title:
-
   - foo_1: bar_1
     foo_2: bar_2
-
   - foo_3: bar_3
     foo_4: bar_4```

Rebinds C-j

yaml-mode has a binding for C-j but it's the default binding (newline-and-indent). There's no need for it for people who use C-j as the default, and for people who don't use it as the default, it breaks their binding if it's not set via a minor mode.

Personally I bind Enter to newline-and-indent and reuse C-j for something else, but yaml-mode clobbers my binding, since it's not in a minor mode.

Tab configuration not working?

With yaml-indent-offset set to 4, I get a tab in the second level of indentation, e.g.

entry:
    first:
        - 'second'

When I press to indent for "first", it works correctly. When I press to indent for "- 'second'" the cursor jumps to the correctly place, but inserts a tab instead of 8 spaces. Setting indent-tabs-mode to nil in the mode hook makes it work correctly. IMO, it should work out-of-the-box ;-)

Many thanks!

Lacks JSON Support

As of YAML 1.2, YAML is an official super of JSON (https://yaml.org/spec/1.2/spec.html), however yaml-mode formats JSON like:

{
"language": "nix",
"nix": "2.1",
"matrix": {
  "include": [
  {
  "name": "cargo pedantry",
  "script": "nix-shell --run checkPhase --arg useNix1 false -A mozilla-rust-overlay"
  },
  {
  "name": "checkPhase",
  "script": "nix-shell --run checkPhase --arg useNix1 false"
  }
  ]
  }
}

Comments ending in a colon change indentation behaviour

A comment like this stays the same after indenting the whole buffer:

# some comment
# lots of things
# more info

but adding a : and indenting the whole buffer causes indentation to change:

    # some comment:
        # lots of things
        # more info

I understand that yaml has a complex specification, so you might not be able to do much about this.

See the relevant issue on glynnforrest/salt-mode#19.

yaml comment highlight.

I have those yaml

search_page_pages_count_css: div#pagin-btm span.page-skip em

I think #pagin-btm span.page-skip em face look like a comment is strange.

Thanks.

Please, inherit `yaml-mode' from `prog-mode'

The title speaks for itself. What is the reason that you decided to inherit from fundamental-mode? Some people (including me) have things like

(add-hook 'text-mode-hook 'fci-mode)
(add-hook 'prog-mode-hook 'fci-mode)

which make life easier, and that's exactly one of those features what proper mode inheritance was intended for.

Thank you.

Maintainership

Hello,

I've seen your recruitment call and am interested in maintaining and
hacking on yaml-mode. Do you have any specific plans in mind?

Cheers
Vasilij

Ignore *.elc Files

When *.el files are compiled, they produce *.elc files, which should be ignored. Please add a line to your .gitignore to ignore *.elc files. (I use your project as a submodule in my Emacs config)

Pressing <down> makes emacs lag in some YAML files

I installed yaml-mode from Melpa stable version ``. I don't know exactly when this happens, but in some YAML files, when I hold <down>, it makes emacs use 100% CPU. This does not happen when opening a YAML file in an emacs instance started with `emacs -Q`. In that case these is no special `yaml-mode` and no such CPU usage happens when scrolling through the file. I could not construct an example file yet to make this more reproducible.
It seems there is some unusual computation going on when pressing down.

highlighting

The following snippet is weirdly highlighted. The second embedded (") character is considered a start of a string and is highlighted red until the next item in the collection:

before_script:
  - |
      case "$CXX" in #(
      g++*) CXX=g++-5.2 #(
      ;;
      clang++*) CXX=clang++-3.7
      ;;
      esac
  - |
      case "$CC" in #(
      gcc*) CXX=gcc-5.2 #(
      ;;
      clang*) CXX=clang-3.7
      ;;
      esac

Derive from prog-mode rather than text-mode

yaml-mode's derivation from text-mode causes my configuration to require more special-case hooks (and "unhooks") for yaml-mode than any other mode.

reST, HTML, Markdown, etc. (used to justify this derivation in #27) are markup languages. A document is primarily text intended for direct reading, surrounded by formal markup. YAML is, as it states, not. It's a language specifying structure, sometimes containing human-readable text (but often not).

I don't want to spellcheck anything but comments. I don't want to electrify any quotes or typographic punctuation. I want flycheck to complain loudly about syntax errors. In every respect, I want to act like a prog-mode.

custom-theme-set-faces

Hello,

I'm trying to change colors using custom-set-faces,
But I have not achieved it, what would be the way to do it, to get a different color combination than I have in the emacs theme ...?

Thanks

Quote/apostrophe not handled correctly in all cases

PR #57 fixed apostrophe inside a word. But it broke quote handling when the previous letter is not a space. I originally didn't think of any cases where well formatted YAML quote was not prefixed with a space, but JSON style dictionaries and lists are one.

e.g.

key: ['key2': value]

Either the apostrophe detection code should handle { and [ the same way as the whitespace. Or it should detect the apostrophe case by checking if the previous character is any unicode letter.

ELPA

It would be nice to be able to pull this from the main package repositories (Emacs 24+)

Font-lock block literal spilling out

Problem

When leaving a block literal to continue a dictionary definition, the rest of the dictionary is font-locked as a string.

screen shot 2018-02-27 at 3 49 01 pm

This implies that the rest of the dictionary is part of the string literal, which is not true.

In [5]: yaml.load('''
   ...: - text: >-
   ...:     This is a block literal with font-lock spilling out
   ...:   a: 1 
   ...:   b: 2 
   ...:   c: {} 
   ...: ''')
Out[5]: 
[{'a': 1,
  'b': 2,
  'c': {},
  'text': 'This is a block literal with font-lock spilling out'}]

This is new behavior.

Current Solutions

The addition of comment symbols seems to "fix" the issue.

screen shot 2018-02-27 at 3 57 39 pm

However, when the comment symbol is deleted, the font-lock spills back in:

screen shot 2018-02-27 at 4 06 57 pm

colon broke syntax highlight

Look how nice markdown highlight below:

foo: |
  line1
  line2: <-- ooops colon cause to be as object!
  line3 <- ok again
  line4
bar:
  dsdf: null

And yaml-mode :)

screenshot

yaml-mode-syntax-propertize-function is kinda slow

I don't have an example file, but it's a typical VCR cassette recording with lots of JSON contents inside strings (meaning lots of quote characters).

(benchmark 1 '(progn (syntax-ppss-flush-cache (point-min)) (syntax-ppss (point-max))))

Prints out ~23 seconds in a 14000 line file.

Here's a profiler output after a lot of scrolling (which is very laggy):

- command-execute                                                4860  76%
 - call-interactively                                            4860  76%
  - apply                                                        4859  76%
   - call-interactively@ido-cr+-record-current-command               4859  76%
    - apply                                                      4859  76%
     - #<subr call-interactively>                                4859  76%
      - funcall-interactively                                    4859  76%
       - cua-scroll-up                                           4679  74%
        - scroll-up                                              4416  69%
         - jit-lock-function                                     4354  68%
          - jit-lock-fontify-now                                 4354  68%
           - jit-lock--run-functions                             4347  68%
            - run-hook-wrapped                                   4347  68%
             - #<compiled 0x156f9ba524b9>                        4346  68%
              - font-lock-fontify-region                         4346  68%
               - font-lock-default-fontify-region                4345  68%
                - font-lock-fontify-syntactically-region               3657  57%
                 - syntax-propertize                             3442  54%
                  - yaml-mode-syntax-propertize-function               3411  53%
                   - syntax-ppss                                 3337  52%
                      #<compiled 0x156f9ba6f345>                    1   0%

Backquotes do not work as quotes

My descriptions end up containing solo single quotes (') and text quotes ("), usually inside backticks or parentheses. These end up flipping the state of the description's string highlighting. In the following examples "oops" should not be highlighted like a string.

description: |
  'quoted' and "quoted" and '"' and "'" and `'` oops
# ' <-- reset

description: `"` oops
#"  <-- reset

image

I have two fixes. One adds a backtick to the syntax entry for a string quote so that `this` ends up highlighted, and the other causes no ' or " to start a string if it is preceded by non-space. While they work for me, they may be a bit drastic for the package proper so if I end up submitting a PR, it will speculative, maybe to serve as inspiration for something better.

Indentation of block text in indented sequence entry

Put into test.yaml the following (sorry, attaching test.yaml failed)

##
## (1) open this file
##
## (2) move to the line containing l1
##
## (3) Press TAB. First character of l1 should now be below '|', but
##     it is below the dash, i.e. not indented wrt the dash.
##
- bb:
    - |
l1

Consider adding MELPA-compatible tags

yaml-mode has several releases, but unfortunately uses a tag naming scheme that is incompatible with MELPA's logic for identifying stable packages:

Stable Packages

MELPA now includes a mechanism to build stable versions of packages given that the repositories meet the following criteria,

  1. Hosted using git or hg.
  2. Tag names are version strings compatible parseable by the version-to-list function, optionally prefixed with v, v. or v-.

Your release tags are prefixed with release-, making MELPA not recognize them. The rest of the version string is already compatible with version-to-list:

(version-to-list "0.0.10")
=> (0 0 10)

Please consider

  1. adding a second MELPA-compatible tag, e.g. v-0.0.10, to the latest release so that MELPA stable will build it, and
  2. using MELPA-compatible tags for future releases.

Opening large yaml file is too slow

I have a large yaml file of amount of 3M bytes. I was kept waiting 8 seconds when opening this file.
I found that font-lock-fontify-buffer is called in yaml-mode. It is very slow because jit-lock is not activated at major mode called time.
I remove font-lock-fontify-buffer from yaml-mode, it became quite fast.
Why is font-lock-fontify-buffer called in yaml-mode?

Broken font-locking

Single quotes in unquoted strings are not handled properly. Words followed by a colon are problematic as well.

screen shot 2014-08-29 at 2 41 42 pm

Release 0.0.17?

I think yaml-mode should make a release. I'd like to volunteer to help.

Show-Paren minor mode doesn't highlight parentheses with yaml-mode

Show-Paren is very useful when editing code in Yaml Block scalars. Unfortunately, it doesn't display the parenthesis matches.

Is there any reason to modify the yaml-mode syntax table with these 2 characters :

(modify-syntax-entry ?\( "." syntax-table)
(modify-syntax-entry ?\) "." syntax-table)

Show-Paren needs this syntax to highlight parentheses :

(modify-syntax-entry ?\( "()" yaml-mode-syntax-table)
(modify-syntax-entry ?\) ")(" yaml-mode-syntax-table)

Thanks

5th level indentation becomes TAB character

When I try to write yaml file with 5 levels, 5th level's indentation becomes TAB character instead of 8 space characters. For example, in case of below, the TAB character is preceding "Lorem ....". According to YAML specification, TAB is not allowed for level indentation.

en:
  app:
    welcome:
      body:
        Lorem ipsum dolor sit amet consectetur adipisicing
        elit, sed do eiusmod tempor incididunt ut labore et

Folding

It would be nice to have an org-mode style folding for nested keys.

elpa package is old

I installed YAML from elpa. From tromey.com, I believe. That version seems to be very old and doesn't include autoloads, so it basically doesn't work at all. Can you upload a more recent version? I know your github version contains autoloads now. Thanks for your hard work!

Tag new release?

Hi, I noticed that master at 831ef3a is 23 commits ahead of 0.0.14, and these seem like bugfixes that you'll want users to have access to. At this time, in Debian, we're preparing for the "freeze" where new versions of software cannot be imported. Would you please consider tagging a release before Christmas if you'd like Debian stable users to have access to newer than 0.0.14?

Thanks,
Nicholas

yaml-nested-map-re may match multiple lines

ac21293 says we want to filter out comments, and changed . to [^#]. However . is defined as "any single character except a newline", this change causes the match to run for many lines and breaks indentation when editing in the middle of a document. Maybe this should be [^#\n]; or is there a way to tell looking-at to consider only one line?

Unknown keyword :safe

I get this error when I start up my emacs with yaml-mode.el.

Debugger entered--Lisp error: (error "Unknown keyword :safe")
signal(error ("Unknown keyword :safe"))
error("Unknown keyword %s" :safe)
custom-handle-keyword(yaml-indent-offset :safe natnump custom-variable)
custom-declare-variable(yaml-indent-offset 2 "*Amount of offset per level of indentation." :type integer :safe natnump :group yaml)
(defcustom yaml-indent-offset 2 "*Amount of offset per level of indentation." :type (quote integer) :safe (quote natnump) :group (quote yaml))
eval-buffer(#<buffer load<2>> nil "/Users/ocarlsen/.emacs.d/lisp/yaml-mode.el" nil t) ; Reading at buffer position 2673

Wrong font lock used when highlighting an element containing a string with punctuation inside

Screen Shot 2020-09-01 at 14 32 03

This bug:

  • happens after line 46 (for some reason).
  • triggers when dealing with an array, having a quoted string that contains numbers and a colon punctuation.
  • "fixes" itself temporarily by deleting the last quote, saving, undoing, then saving again; reappears when reloading the file.
  • the highlighting of the rest of the file underneath is messed up by it.

This is especially troublesome with docker-compose.yml file where you define port mappings like:

services:
  grafana:
    image: grafana/grafana
    ports:
      - '3000:3000'

I have no idea how to investigate/fix this myself, so I'm asking for help (please) ๐Ÿ™ !

EDIT: see #82 (comment) below for an investigation done by @sulami.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.