Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

More imenu entries (for javascript, vuejs style) #886

Open
vindarel opened this Issue Jun 7, 2017 · 3 comments

Comments

Projects
None yet
2 participants

vindarel commented Jun 7, 2017 edited

Hi,
Currently the imenu shows some html tags. I'd like it to show javascript functions, including in vuejs files.

I've seen web-mode-imenu-regexp-list and web-mode-imenu-index and it looks to me they are specially crafted to catch html tags (as seen in http://web-mode.org/doc/imenu.txt). So it is very unclear to me how to add regular imenu entries.

I have a regexp, checked with the regexp builder:

(setq imenu-generic-expression
         '(("methods" "^\\s-*\\([a-zA-Z0-9_]+\\): function" 1)))

(also I don't know how to override the existing entries and use just that. I tried:

(add-hook 'web-mode-hook
       (lambda ()
          (set (make-local-variable imenu-generic-expression)
               '(("methods" "^\\s-*\\([a-zA-Z0-9_]+\\): function" 1))
                 )))

as discussed on emacswiki and SE with no luck.)

An example code:

    data: function() {
      return {
        page: 1,
      };
    },

    props: {
      title: String,
      url: String,
    },

    computed: {
      entries() {
        log("hello");
      },

    methods: {
      previousPage: function () {
        // ...
      },

there would be functions and data to catch, hence a few imenu regexps to write. We could even have a menu title with "computed", "methods" and other functions defined elsewhere.

How can we do that in web-mode ?

imenu doc: https://www.gnu.org/software/emacs/manual/html_node/elisp/Imenu.html

To try things out I also did

    ;; imenu-create-index-function 'web-mode-imenu-index
    imenu-generic-expression '(("methods" "^\\s-*\\([a-zA-Z0-9_]+\\): function" 1))

but I can't see any change…

@fxbois fxbois added the minor mode label Jul 9, 2017

Note: by launching emacs with emacs -Q, web-mode shows me all the JS functions. There's a pb on my side.

This question is then a little feature request: in vue-mode, be able to see "data", "props", "computed" and "methods" entries (which are not only functions).

Owner

fxbois commented Oct 26, 2017

@vindarel could you give me more details please (some examples)

yes, for the little feature, given my example code, it would be to also catch "props", "entries" which are not functions and are not caught presently. Also it would be to put "entries" into a "computed" subgroup and to have a "methods" subgroup.

Is that better ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment