jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
376 stars 67 forks source link

universal-ctags #135

Open rofrol opened 6 years ago

rofrol commented 6 years ago

Looks like universal-ctags shows support for Elm:

$ ctags --list-languages | grep -i elm
Elm

There is also this file https://github.com/kbsymanz/ctags-elm

Which can be used like that for universal ctags:

$ mkdir ~/.ctags.d
$ cd ~/.ctags.d
$ curl -s https://raw.githubusercontent.com/kbsymanz/ctags-elm/master/.ctags -o elm.ctags

But then it shows this:

$ ctags --list-languages | grep -i elm
ctags: Warning: Language "Elm" already defined
ctags: Warning: Don't reuse the kind letter `c' in a language Elm (old: "constructor", new: "constant")
ctags: Warning: Don't reuse the kind letter `a' in a language Elm (old: "alias", new: "type-alias")
ctags: Warning: Don't reuse the kind letter `t' in a language Elm (old: "type", new: "type-cons")
ctags: Warning: Don't reuse the kind letter `t' in a language Elm (old: "type", new: "type-cons")
Elm

Windows

There is some problem with elm-mode on Windows. It just doesn't generate TAGS file.

Now I'm using this command in git bash:

$ rg --files -telm | ctags -e -L -

I'm using ctags from here https://github.com/universal-ctags/ctags-win32/releases

My config:

(use-package elm-mode
    :mode ("\\.elm\\'" . elm-mode)
    :straight t
    :init
    (progn
    (defconst elm-package-json
      "elm-package.json"
      "The name of the package JSON configuration file.")

    (defun rofrol/elm--find-dependency-file-path ()
      "Recursively search for a directory containing a package JSON file."
      (or (locate-dominating-file default-directory elm-package-json)
          (file-name-as-directory (f-dirname (buffer-file-name)))))

    (defun rofrol/elm--has-dependency-file ()
      "Check if a dependency file exists."
      (f-exists? (f-join (rofrol/elm--find-dependency-file-path) elm-package-json)))

    (defun rofrol/elm-mode-generate-tags ()
      "Generate a TAGS file for the current project."
      (interactive)
      (when (and (rofrol/elm--has-dependency-file) (eq major-mode 'elm-mode))
        (let* ((default-directory (rofrol/elm--find-dependency-file-path))
              (ctags-command "rg --files -telm | ctags -e -L -"))
              (call-process-shell-command (concat ctags-command "&") nil 0))))

    (add-hook 'after-save-hook 'rofrol/elm-mode-generate-tags nil 'make-it-local)

    (defun init-elm-mode ()
          "Disable electric-indent-mode and let indentation cycling feature work"
          (if (fboundp 'electric-indent-local-mode)
              (electric-indent-local-mode -1))
          (add-to-list 'company-backends 'company-elm)
          (setq elm-format-on-save t))

        (setq tags-revert-without-query 1)
        ;; (setq elm-tags-on-save t))

    (add-hook 'elm-mode-hook 'init-elm-mode)))
purcell commented 3 years ago

It's not clear to me if there's an action being proposed here, or an elm-mode issue being reported. Is this still on your radar, @rofrol?