GithubHelp home page GithubHelp logo

yaml-imenu.el's Introduction

yaml-imenu.el

This package enhances the imenu support in yaml-mode. It generates an index containing a full list of keys that contain any child, with key names in the dot-separated path form like jobs.build.docker and ja.activerecord.attributes.user.nickname. It shines best with which-function-mode enabled.

Requirements

This package depends on Ruby for parsing YAML documents to obtain location information of each node. Ruby >=2.5 works out of the box; if you have an older version of Ruby, run the following command to install the latest version of psych, the YAML parser:

% gem install psych --user

The parser only parses a document without evaluating it, so there should be no security concerns.

Configuration

Add the following line to your init file:

(yaml-imenu-enable)

In Emacs 27 and later, the result of add-log-current-defun takes precedence over the imenu index in which-function. To fix this, add the following snippet:

(defun which-function-from-imenu-index ()
  "Call the imenu-index part in `which-function'.

It is a fallback for when which-func-functions and `add-log-current-defun' return nil."
  (let (which-func-functions)
    (letf (((symbol-function 'add-log-current-defun)
            (lambda () nil)))
      (which-function))))

;; `add-log-current-defun' returns a not so meaningful result in some
;; major modes when the default `add-log-current-defun-function'
;; happens to match a random line that is not really a function
;; definition.  It is often much more desirable to find a function
;; name from an imenu index in those modes.  Results are also used by
;; `which-function-mode'.
(defun enable-add-log-current-defun-using-which-function ()
  (setq-local add-log-current-defun-function 'which-function-from-imenu-index))

(add-hook 'yaml-mode-hook
          'enable-add-log-current-defun-using-which-function)

Usage

A precise YAML node path list this package provides is especially useful when dealing with a large YAML file.

With which-func-mode enabled, you can always see at a glance where you are. In this example, the "YAML path" is shown in the header line instead of the mode line by customizing header-line-format.

With which-func-mode

Using helm-imenu, it is extremely easy to navigate to anywhere you want to go.

With helm-imenu

Author

Copyright (c) 2018-2021 Akinori MUSHA.

Licensed under the 2-clause BSD license. See LICENSE.txt for details.

Visit GitHub Repository for the latest information.

yaml-imenu.el's People

Contributors

knu avatar

Stargazers

Ev Dolzhenko avatar Nao Yamada avatar Anders K. Pettersen avatar  avatar Vedang Manerikar avatar Paul Haerle avatar  avatar Oleg Pykhalov avatar Adam Shannon avatar Terje Larsen avatar

Watchers

 avatar James Cloos avatar  avatar

yaml-imenu.el's Issues

Error: json-read: JSON readtable error: 117

Steps to reproduce

# FILE /tmp/fruits.yaml
---
fruit:
  apple: '$ 1.00'
$ emacs -Q \
  --load /path/to/yaml-mode.el  \
  --load /path/to/yaml-imenu.el

M-x yaml-imenu-enable RET

C-x C-f /tmp/fruits.yaml RET

M-x imenu RET

  json-read: JSON readtable error: 117

Symbol's function definition is void: loop

I ran into this error because I had didn't have (require 'cl) in my init.el. After adding it everything was fine. I'm not sure if you feel like this is something that should be fixed or just needs mentioning in the Readme.

I though I'd mention it here to see what you think. If you want me to submit a pull request, just let me know.

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.