Skip to content

Commit

Permalink
Rename :on' to :initialize'
Browse files Browse the repository at this point in the history
  • Loading branch information
papaeye committed Jan 16, 2015
1 parent a1712be commit 43ee0cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions navbar.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ It is necessary to run `navbar-initialize' to reflect the change of
(push (pop body) extra-keywords))))
`(navbar-define-item
,item (quote ,mode) ,doc
:get ,getter :on ,func-on
:get ,getter :initialize ,func-on
:hooks (list ,@(nreverse hooks))
,@(nreverse extra-keywords))))

Expand Down Expand Up @@ -184,13 +184,13 @@ If KEY is `nil', all items are updated by their `:get' functions."
(setq item (list :key t :cache item)))
(let ((key (plist-get item :key))
(value (copy-tree item))
(func-on (plist-get item :on))
(func-init (plist-get item :initialize))
(hooks (plist-get item :hooks)))
(push (cons key value) navbar-item-alist)
(dolist (hook hooks)
(add-hook (car hook) (cdr hook)))
(when (and func-on (symbol-value key))
(funcall func-on)))))
(when (and func-init (symbol-value key))
(funcall func-init)))))

(defun navbar-deinitialize ()
"Remove functions from hooks and clean up `navbar-item-alist'."
Expand Down
21 changes: 11 additions & 10 deletions test/navbar-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@
nil
:mode-on 'navbar-test--mode-on-func
:mode-off 'navbar-test--mode-off-func)
(should (equal navbarx-foo (list :key 'navbar-test-mode
:get 'ignore
:on 'navbar-test--mode-on-func
:hooks navbar-test--mode-hooks)))))
(should (equal navbarx-foo
(list :key 'navbar-test-mode
:get 'ignore
:initialize 'navbar-test--mode-on-func
:hooks navbar-test--mode-hooks)))))

;;;; `navbar-item-cache-put'

Expand Down Expand Up @@ -292,7 +293,7 @@

(ert-deftest navbar-initialize/call-on-func-if-key-is-non-nil ()
(navbar-test-save-item-list
(setq navbar-item-list `((:key t :on navbar-test--mode-on-func)))
(setq navbar-item-list `((:key t :initialize navbar-test--mode-on-func)))
(unwind-protect
(progn
(navbar-initialize)
Expand All @@ -301,7 +302,7 @@

(ert-deftest navbar-initialize/dont-call-on-func-if-key-is-nil ()
(navbar-test-save-item-list
(setq navbar-item-list `((:key nil :on navbar-test--mode-on-func)))
(setq navbar-item-list `((:key nil :initialize navbar-test--mode-on-func)))
(unwind-protect
(progn
(navbar-initialize)
Expand Down Expand Up @@ -469,9 +470,9 @@
(navbar-test-save-item-list
(setq navbar-item-list
(list (list :key t :cache "foo"
:on (lambda () (navbar-update nil t)))))
:initialize (lambda () (navbar-update nil t)))))
(navbar-test-with-mode
;; Call `:on' function by `navbar-initialize'.
;; Call `:initialize' function by `navbar-initialize'.
;; It is necessary to run `navbar-make-window' before that.
)))

Expand All @@ -497,7 +498,7 @@
(should (= (length navbarx-time) 8))
(should (eq (plist-get navbarx-time :key) 'display-time-mode))
(should (eq (plist-get navbarx-time :get) 'navbarx-time-get))
(should (eq (plist-get navbarx-time :on) 'navbarx-time-on))
(should (eq (plist-get navbarx-time :initialize) 'navbarx-time-on))
(should (equal (plist-get navbarx-time :hooks)
'((display-time-mode-on-hook . navbarx-time-on)
(display-time-mode-off-hook . navbarx-time-off)))))
Expand All @@ -509,7 +510,7 @@
(should (= (length navbarx-elscreen) 8))
(should (eq (plist-get navbarx-elscreen :key) 'elscreen-mode))
(should (eq (plist-get navbarx-elscreen :get) 'navbarx-elscreen-get))
(should (eq (plist-get navbarx-elscreen :on) 'navbarx-elscreen-on))
(should (eq (plist-get navbarx-elscreen :initialize) 'navbarx-elscreen-on))
(should (equal (plist-get navbarx-elscreen :hooks)
'((elscreen-mode-on-hook . navbarx-elscreen-on)
(elscreen-mode-off-hook . navbarx-elscreen-off))))))
Expand Down

0 comments on commit 43ee0cb

Please sign in to comment.