2

I put my custom js setting into zwb-js group in zwb-js.el, I want to use use-package to load it, it seems that zwb-js.el has been loaded, but the functions defined in zwb-js.el seems not be called auto.

This is my code:

;;; zwb-js.el --- ZWB Js configuration entry point.

;;; Commentary:

;; This file simply sets up the default load path and requires
;; the various modules defined within Emacs Prelude.

;;; Code:

(defgroup zwb-js nil
  "zwb's js setting."
  :group 'languages
  :prefix "zwb-js-")

(defcustom zwb-js-packages
  '(
    coffee-mode
    company
    company-tern
    flycheck
    js-doc
    js2-mode
    js2-refactor
    json-mode
    json-snatcher
    tern
    web-beautify
    )
  "The package zwb-js needs."
  :type 'alist
  :group 'zwb-js)

;;;###autoload
(defun zwb-js/init-package ()
  (message "debug")
  (prelude-require-packages zwb-js-packages))

(defun zwb-js/post-init-company ()
  (zwb|add-company-hook js2-mode))

(defun zwb-js/post-init-flycheck ()
  (add-hook 'js2-mode-hook  'flycheck-mode)
  (add-hook 'json-mode-hook 'flycheck-mode)
  (defun zwb|disable-js2-checks-if-flycheck-active ()
    (unless (flycheck-get-checker-for-buffer)
      (set (make-local-variable 'js2-mode-show-parse-errors) t)
      (set (make-local-variable 'js2-mode-show-strict-warnings) t)))
  (add-hook 'js2-mode-hook 'zwb|disable-js2-checks-if-flycheck-active))

(defun zwb-js/post-init-tern ()
  (add-hook 'js-mode-hook (lambda () (tern-mode t)))
  (add-to-list 'company-backends '(company-tern :with company-dabbrev-code)))

(defun zwb-js/init-js-doc ()
  (defun zwb-js/js-doc-require ()
    (require 'js-doc))
  (add-hook 'js2-mode-hook 'zwb-js/js-doc-require))

(defun zwb-js/init-js2-refactor ()
  (defun zwb-js/js2-refactor-require ()
    (require 'js2-refactor))
  (add-hook 'js2-mode-hook 'zwb-js/js2-refactor-require))

(defun zwb-js/init-js-color ()
  (setq js2-highlight-level 3)
  (defun zwb-js/rainbow-delimiters-require ()
    (require 'rainbow-delimiters)
    (rainbow-delimiters-mode))
  (dolist (hook '(js2-mode-hook js-mode-hook json-mode-hook))
    (add-hook hook 'zwb-js/rainbow-delimiters-require)))

(defun zwb-js/node-repl ()
  (setq inferior-js-program-command "node")
  (setenv "NODE_NO_READLINE" "1")
  (setq inferior-js-mode-hook (lambda () (ansi-color-for-comint-mode-on)))
  (defun zwb-js/comint-key-binding ()
    (local-set-key (kbd "C-x C-e") 'js-send-last-sexp)
    (local-set-key (kbd "C-M-x") 'js-send-last-sexp-and-go)
    (local-set-key (kbd "C-c b") 'js-send-buffer)
    (local-set-key (kbd "C-c C-b") 'js-send-buffer-and-go)
    (local-set-key (kbd "C-c l") 'js-load-file-and-go))
  (add-hook 'js2-mode-hook 'zwb-js/comint-key-binding))

(defun zwb-js/conf-js2-mode ()
  "Conf js2-mode and so on."
    (custom-set-variables
     '(js2-basic-offset 2)
     '(js2-bounce-indent-p nil))

    (setq-default js2-mode-show-parse-errors nil)
    (setq-default js2-mode-show-strict-warnings nil)

    (setq json-reformat:indent-width 2))

(defun zwb-js/js-fontlock ()
  (defvar js-font-lock-keywords
    `(("\\(function *\\)[(|[[:space:]]]?"
       (0 (progn (compose-region (match-beginning 1)
                                 (match-end 1) "\u0192")
                 nil)))
      ("[[:space:]]\\(var\\)[[:space:]]"
       (0 (progn (compose-region (match-beginning 1)
                                 (match-end 1) "\u028b ")
                 nil)))
      ("[[:space:]]\\(return\\)[[:space:]]"
       (0 (progn (compose-region (match-beginning 1)
                                 (match-end 1) "\u1d3f ")
                 nil)))
      ("\\(this\\)"
       (0 (progn (compose-region (match-beginning 1)
                                 (match-end 1) "\u0288")
                 nil)))))
  (eval-after-load 'js
    (font-lock-add-keywords
     'js2-mode js-font-lock-keywords)))

(provide 'zwb-js)
;;; zwb-js.el ends here

I can use C-h v config zwb-js-packages, so I don't know why I cann't see any defuns with M-x.

I also wrote zwb-js-autoloads.el to autoload zwb-js/init-package for test, but it seems not work.

This is my zwb-js-autoloads.el:

;;; zwb-js-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))

;;;### (autoloads nil nil ("zwb-js.el"))

(provide 'zwb-js-autoloads)
;;;***

;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; zwb-js-autoloads.el ends here

I also tried:

;;; zwb-js-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))

(autoload 'zwb-js/init-package "zwb-js" "\
Install all packages that zwb-js needs
\(fn)" nil nil)

(provide 'zwb-js-autoloads)
;;;***

;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; zwb-js-autoloads.el ends here

Loaded by personal/load-private-config.el:

(defconst zwb-private-emacs-config-path "~/.emacs.d-private/")

(eval-and-compile
  (mapc
   #'(lambda (path)
       (push (expand-file-name path zwb-private-emacs-config-path) load-path))
   '("lib""theme" "")))

(eval-and-compile
  (defvar use-package-verbose t)
  (require 'cl)
  (require 'use-package))

(use-package zwb-js
  :defer t  ;; I tried commit or uncommit it
  :load-path (lambda () (expand-file-name (concat zwb-private-emacs-config-path "lib/zwb-js")))
  :init (require 'zwb-js-autoloads))

Both of the way, I cann't get debug in *Message* buffer, which defined in zwb-js/init-package for test.

My questions are:

  1. Why I cann't see my defuns through M-x?
  2. What's the best way to use use-package to load zwb-js?
  3. How to autoload my zwb-js group?
  4. How to auto run all defun defined in zwb-js?
  5. What's defgroup's prefix used for? Would you please give me an example?

My OS version: Mac OS X 10.11.2 beta4
My Emacs version: 24.5.1 (brew emacs-mac-emacs)
My Emacs config is based on Prelude

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.