Merge remote branch 'refs/remotes/nex3/new-extension-api'

This commit is contained in:
Phil Jackson 2010-08-20 16:15:49 +01:00
commit 6c8b19edd0
3 changed files with 64 additions and 113 deletions

View file

@ -155,11 +155,12 @@ If USE-CACHE is non nil, use the cached information."
(when (magit-svn-enabled) (when (magit-svn-enabled)
(magit-run-git-async "svn" "fetch"))) (magit-run-git-async "svn" "fetch")))
(defvar magit-svn-extension-keys (define-prefix-command 'magit-svn-prefix 'magit-svn-map)
`((,(kbd "N r") . magit-svn-rebase) (define-key magit-svn-map (kbd "r") 'magit-svn-rebase)
(,(kbd "N c") . magit-svn-dcommit) (define-key magit-svn-map (kbd "c") 'magit-svn-dcommit)
(,(kbd "N f") . magit-svn-remote-update) (define-key magit-svn-map (kbd "f") 'magit-svn-remote-update)
(,(kbd "N s") . magit-svn-find-rev))) (define-key magit-svn-map (kbd "s") 'magit-svn-find-rev)))
(define-key magit-map (kbd "N") 'magit-svn-prefix)
(easy-menu-define magit-svn-extension-menu (easy-menu-define magit-svn-extension-menu
nil nil
@ -168,18 +169,14 @@ If USE-CACHE is non nil, use the cached information."
["Rebase" magit-svn-rebase (magit-svn-enabled)] ["Rebase" magit-svn-rebase (magit-svn-enabled)]
["Fetch" magit-svn-remote-update (magit-svn-enabled)] ["Fetch" magit-svn-remote-update (magit-svn-enabled)]
["Commit" magit-svn-dcommit (magit-svn-enabled)])) ["Commit" magit-svn-dcommit (magit-svn-enabled)]))
(easy-menu-add-item 'magit-mode-menu '("Extensions") magit-svn-extension-menu)
(defvar magit-svn-extension-inserters (add-hook magit-after-insert-unpulled-commits
'((:after unpulled-commits (lambda () (magit-insert-svn-unpulled t))) (lambda () (magit-insert-svn-unpulled t)))
(:after unpushed-commits (lambda () (magit-insert-svn-unpushed t))))) (add-hook magit-after-insert-unpushed-commits
(lambda () (magit-insert-svn-unpushed t)))
(defvar magit-svn-extension (add-hook 'magit-remote-string-hook 'magit-svn-remote-string)
(make-magit-extension :keys magit-svn-extension-keys
:menu magit-svn-extension-menu
:insert magit-svn-extension-inserters
:remote-string 'magit-svn-remote-string))
(magit-install-extension magit-svn-extension)
(provide 'magit-svn) (provide 'magit-svn)
;;; magit-svn.el ends here ;;; magit-svn.el ends here

View file

@ -73,27 +73,19 @@
"Topics:" 'magit-topgit-wash-topics "Topics:" 'magit-topgit-wash-topics
"branch" "-v")) "branch" "-v"))
(defvar magit-topgit-extension-inserters (magit-add-action (item info "discard")
'((:after stashes magit-insert-topics))) ((topic)
(when (yes-or-no-p "Discard topic? ")
(magit-run* (list magit-topgit-executable "delete" "-f" info)
nil nil nil t))))
(defvar magit-topgit-extension-actions (magit-add-action (item info "visit")
'(("discard" ((topic) ((topic)
(when (yes-or-no-p "Discard topic? ") (magit-checkout info)))
(magit-run* (list magit-topgit-executable "delete" "-f" info)
nil nil nil t))))
("visit" ((topic)
(magit-checkout info)))))
(defvar magit-topgit-extension-commands (add-hook 'magit-after-insert-stashes 'magit-insert-topics)
'((create-branch . magit-topgit-create-branch) (add-hook 'magit-create-branch-command-hook 'magit-topgit-create-branch)
(pull . magit-topgit-pull))) (add-hook 'magit-pull-command-hook 'magit-topgit-pull)
(defvar magit-topgit-extension
(make-magit-extension :actions magit-topgit-extension-actions
:insert magit-topgit-extension-inserters
:commands magit-topgit-extension-commands))
(magit-install-extension magit-topgit-extension)
(provide 'magit-topgit) (provide 'magit-topgit)
;;; magit-topgit.el ends here ;;; magit-topgit.el ends here

120
magit.el
View file

@ -359,10 +359,6 @@ Many Magit faces inherit from this one by default."
(make-variable-buffer-local 'magit-submode) (make-variable-buffer-local 'magit-submode)
(put 'magit-submode 'permanent-local t) (put 'magit-submode 'permanent-local t)
(eval-when-compile
(defun magit-dynamic-clauses-helper (clauses context)
`(((magit-dynamic-clauses ,clauses ,context) t))))
(defun magit-use-region-p () (defun magit-use-region-p ()
(if (fboundp 'use-region-p) (if (fboundp 'use-region-p)
(use-region-p) (use-region-p)
@ -1237,8 +1233,8 @@ TITLE is the displayed title of the section."
(defmacro magit-define-inserter (sym arglist &rest body) (defmacro magit-define-inserter (sym arglist &rest body)
(declare (indent defun)) (declare (indent defun))
(let ((fun (intern (format "magit-insert-%s" sym))) (let ((fun (intern (format "magit-insert-%s" sym)))
(before (intern (format "magit-insert-%s:before-hook" sym))) (before (intern (format "magit-before-insert-%s-hook" sym)))
(after (intern (format "magit-insert-%s:after-hook" sym))) (after (intern (format "magit-after-insert-%s-hook" sym)))
(doc (format "Insert items for `%s'." sym))) (doc (format "Insert items for `%s'." sym)))
`(defun ,fun ,arglist `(defun ,fun ,arglist
,doc ,doc
@ -1288,23 +1284,6 @@ TITLE is the displayed title of the section."
(equal (car prefix) (car list)) (equal (car prefix) (car list))
(magit-prefix-p (cdr prefix) (cdr list)))))) (magit-prefix-p (cdr prefix) (cdr list))))))
(defun magit-inline-clause (clause context)
(if (eq (car clause) t)
clause
(let ((prefix (reverse (car clause)))
(body (cdr clause)))
`((magit-prefix-p ',prefix ,context)
,@body))))
(defun magit-dynamic-clauses (clauses context)
(let* ((c (car clauses))
(prefix (reverse (car c)))
(body (cadr c)))
(cond ((magit-prefix-p prefix context)
(eval body))
(t
(magit-dynamic-clauses (cdr clauses) context)))))
(defmacro magit-section-case (head &rest clauses) (defmacro magit-section-case (head &rest clauses)
"Make different action depending of current section. "Make different action depending of current section.
@ -1314,42 +1293,65 @@ HEAD is (SECTION INFO &optional OPNAME),
OPNAME is a string that will be used to describe current action, OPNAME is a string that will be used to describe current action,
CLAUSES is a list of CLAUSE, each clause is (SECTION-TYPE &BODY) CLAUSES is a list of CLAUSE, each clause is (SECTION-TYPE &BODY)
where SECTION-TYPE describe section where BODY will be run." where SECTION-TYPE describe section where BODY will be run.
This returns non-nil if some section matches. If no section
matches, this returns nil if no OPNAME was given and throws an
error otherwise."
(declare (indent 1)) (declare (indent 1))
(let ((section (car head)) (let ((section (car head))
(info (cadr head)) (info (cadr head))
(type (make-symbol "*type*")) (type (make-symbol "*type*"))
(context (make-symbol "*context*")) (context (make-symbol "*context*"))
(extra (make-symbol "*extra*"))
(opname (caddr head))) (opname (caddr head)))
`(let* ((,section (magit-current-section)) `(let* ((,section (magit-current-section))
(,info (magit-section-info ,section)) (,info (magit-section-info ,section))
(,type (magit-section-type ,section)) (,type (magit-section-type ,section))
(,context (magit-section-context-type ,section)) (,context (magit-section-context-type ,section)))
(,extra (magit-get-extensions-actions ,opname)))
(cond ,@(mapcar (lambda (clause) (cond ,@(mapcar (lambda (clause)
(if (eq (car clause) t) (if (eq (car clause) t)
clause `(,@clause t)
(let ((prefix (reverse (car clause))) (let ((prefix (reverse (car clause)))
(body (cdr clause))) (body (cdr clause)))
`((magit-prefix-p ',prefix ,context) `((magit-prefix-p ',prefix ,context)
,@body)))) ,@body
t))))
clauses) clauses)
,@(magit-dynamic-clauses-helper extra context) ,@(when opname
,@(if opname `(((run-hook-with-args-until-success
`(((not ,type) ',(make-symbol (format "magit-%s-action-hook" opname)))
(error "Nothing to %s here" ,opname)) t)
(t ((not ,type)
(error "Can't %s a %s" (error "Nothing to %s here" ,opname))
,opname (t
(or (get ,type 'magit-description) (error "Can't %s a %s"
,type))))))))) ,opname
(or (get ,type 'magit-description)
,type)))))))))
(defmacro magit-section-action (head &rest clauses) (defmacro magit-section-action (head &rest clauses)
(declare (indent 1)) (declare (indent 1))
`(magit-with-refresh `(magit-with-refresh
(magit-section-case ,head ,@clauses))) (magit-section-case ,head ,@clauses)))
(defmacro magit-add-action (head &rest clauses)
"Add additional actions to a pre-existing operator.
The syntax is identical to `magit-section-case', except that
OPNAME is mandatory and specifies the operation to which to add
the actions."
(declare (indent 1))
(let ((section (car head))
(info (cadr head))
(type (caddr head)))
`(add-hook ',(make-symbol (format "magit-%s-action-hook" type))
(lambda ()
,(macroexpand
;; Don't pass in the opname so we don't recursively
;; run the hook again, and so we don't throw an
;; error if no action matches.
`(magit-section-case (,section ,info)
,@clauses))))))
(defun magit-wash-sequence (func) (defun magit-wash-sequence (func)
"Run FUNC until end of buffer is reached. "Run FUNC until end of buffer is reached.
@ -1360,7 +1362,7 @@ FUNC should leave point at the end of the modified region"
(defmacro magit-define-command (sym arglist &rest body) (defmacro magit-define-command (sym arglist &rest body)
(declare (indent defun)) (declare (indent defun))
(let ((fun (intern (format "magit-%s" sym))) (let ((fun (intern (format "magit-%s" sym)))
(hook (intern (format "magit-%s:functions" sym))) (hook (intern (format "magit-%s-command-hook" sym)))
(doc (format "Command for `%s'." sym)) (doc (format "Command for `%s'." sym))
(inter nil) (inter nil)
(instr body)) (instr body))
@ -4294,46 +4296,6 @@ With prefix force the removal even it it hasn't been merged."
(magit-list-buffers)) (magit-list-buffers))
'string=))) 'string=)))
;; Extensions
(defvar magit-active-extensions '())
(defstruct magit-extension
keys menu actions insert remote-string commands)
(defun magit-install-extension (ext)
(add-to-list 'magit-active-extensions ext)
(let ((keys (magit-extension-keys ext))
(menu (magit-extension-menu ext))
(actions (magit-extension-actions ext))
(insert (magit-extension-insert ext))
(remote-string (magit-extension-remote-string ext))
(commands (magit-extension-commands ext)))
(when keys
(mapc (lambda (x) (define-key magit-mode-map (car x) (cdr x)))
keys))
(when menu
(easy-menu-add-item 'magit-mode-menu '("Extensions") menu))
(when insert
(mapc (lambda (x)
(destructuring-bind (position reference hook) x
(add-hook (intern (format "magit-insert-%s%s-hook"
reference position))
hook)))
insert))
(when remote-string
(add-hook 'magit-remote-string-hook remote-string))
(when commands
(mapc (lambda (x)
(add-hook (intern (format "magit-%s:functions" (car x)))
(cdr x)))
commands))))
(defun magit-get-extensions-actions (action)
(mapcar (lambda (ext)
(cadr (assoc action (magit-extension-actions ext))))
magit-active-extensions))
(provide 'magit) (provide 'magit)
;;; magit.el ends here ;;; magit.el ends here