AdamNiederer / vue-mode

Emacs major mode for vue.js
GNU General Public License v2.0
328 stars 61 forks source link

Better imenu to show functions and data #58

Open vindarel opened 6 years ago

vindarel commented 6 years ago

Hi, Currently the imenu shows some html tags. I'd like it to show javascript functions, and possibly different sub-menus for computed properties or methods.

I tried something but it is 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)))

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

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

as discussed on emacswiki and SE and as seen in a couple of other packages, with no luck.

An example file:

    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.

Any ideas ?

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

edit: I tried what you can see in the following commit.

AdamNiederer commented 6 years ago

Hello,

I'm pretty unfamiliar with imenu's programming interface, but I agree that it'd be a useful addition, especially because newer extensions like treemacs are so reliant on it. Perhaps we could hijack the submodes' imenu entries for ourselves? I'd definitely be open to any ideas on that front.

vindarel commented 6 years ago

Perhaps we could hijack the submodes' imenu entries for ourselves?

well thought, but I guess it would not be the best, because we'd like to catch vue specific stuff (props, which is not a function) and cleanly organize the imenu: a section for html tags, a section for computed properties, for methods,…

I had a look at this to see how it's done: https://github.com/elixir-editors/emacs-elixir/blob/master/elixir-mode.el#L60

I'll explain what I understood so far, it may help me too :)

("methods" "^\\s-*\\([a-zA-Z0-9_]+\\): function" 1)
vindarel commented 6 years ago

Note: there's a pb on my side, I could not see imenu entries in web-mode before I loaded it in emacs -Q. It already shows all the JS functions that are present.

Adding menus for data, props, computed and methods would be added sugar.

brentreeves commented 6 years ago

Apologies if out-of-context... vindarel - could you please elaborate "could not see imenu entries in web-mode before I loaded it". In blee.vue, in Githubissues.

  • Githubissues is a development platform for aggregating issues.