purcell / envrc

Emacs support for direnv which operates buffer-locally
378 stars 35 forks source link

Major mode for .envrc files #10

Closed leungbk closed 4 years ago

leungbk commented 4 years ago

The direnv.el package has the following:

;;;###autoload
(define-derived-mode direnv-envrc-mode
  sh-mode "envrc"
  "Major mode for .envrc files as used by direnv.

Since .envrc files are shell scripts, this mode inherits from sh-mode.
\\{direnv-envrc-mode-map}")

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.envrc\\'" . direnv-envrc-mode))

I feel like this package should include a major mode for .envrc files as well.

purcell commented 4 years ago

Yep, probably so.

manuel-uberti commented 4 years ago

Could this benefit of some extra font locking as well? I am doing it like this at the moment:

(defvar mu-direnv-keywords
    '("MANPATH_add" "PATH_add" "direnv_layout_dir" "direnv_load" "dotenv"
      "expand_path" "find_up" "has" "join_args" "layout" "load_prefix"
      "log_error" "log_status" "path_add" "rvm" "source_env" "source_up"
      "use" "use_guix" "use_nix" "user_rel_path" "watch_file")
    "Useful direnv keywords to be highlighted.")

  (define-derived-mode mu-direnv-rc-mode sh-mode "envrc"
    "Major mode for .envrc files."
    (font-lock-add-keywords
     nil `((,(regexp-opt mu-direnv-keywords 'symbols)
            (0 font-lock-keyword-face)))))

Edit: sorry, this is for direnv-mode, but still something like this for envrc-file-mode could be useful I guess. :)

purcell commented 4 years ago

Done, thanks @manuel-uberti !

manuel-uberti commented 4 years ago

Awesome. :)