contrib/mq.el
changeset 4429 3b0f73edee57
parent 4428 fa51e66117b4
child 5081 ea7b982b6c08
equal deleted inserted replaced
4428:fa51e66117b4 4429:3b0f73edee57
    37   :group 'mercurial)
    37   :group 'mercurial)
    38 
    38 
    39 (defcustom mq-edit-finish-hook nil
    39 (defcustom mq-edit-finish-hook nil
    40   "Hook run before a patch description is finished up with."
    40   "Hook run before a patch description is finished up with."
    41   :type 'sexp
    41   :type 'sexp
       
    42   :group 'mercurial)
       
    43 
       
    44 (defcustom mq-signoff-address nil
       
    45   "Address with which to sign off on a patch."
       
    46   :type 'string
    42   :group 'mercurial)
    47   :group 'mercurial)
    43 
    48 
    44 
    49 
    45 ;;; Internal variables.
    50 ;;; Internal variables.
    46 
    51 
    70 (define-key mq-global-map "=" 'mq-diff)
    75 (define-key mq-global-map "=" 'mq-diff)
    71 (define-key mq-global-map "r" 'mq-refresh)
    76 (define-key mq-global-map "r" 'mq-refresh)
    72 (define-key mq-global-map "e" 'mq-refresh-edit)
    77 (define-key mq-global-map "e" 'mq-refresh-edit)
    73 (define-key mq-global-map "i" 'mq-new)
    78 (define-key mq-global-map "i" 'mq-new)
    74 (define-key mq-global-map "n" 'mq-next)
    79 (define-key mq-global-map "n" 'mq-next)
       
    80 (define-key mq-global-map "o" 'mq-signoff)
    75 (define-key mq-global-map "p" 'mq-previous)
    81 (define-key mq-global-map "p" 'mq-previous)
    76 (define-key mq-global-map "s" 'mq-edit-series)
    82 (define-key mq-global-map "s" 'mq-edit-series)
    77 (define-key mq-global-map "t" 'mq-top)
    83 (define-key mq-global-map "t" 'mq-top)
    78 
    84 
    79 (add-minor-mode 'mq-mode 'mq-mode)
    85 (add-minor-mode 'mq-mode 'mq-mode)
    82 ;;; Refresh edit mode keymap.
    88 ;;; Refresh edit mode keymap.
    83 
    89 
    84 (defvar mq-edit-mode-map (make-sparse-keymap))
    90 (defvar mq-edit-mode-map (make-sparse-keymap))
    85 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
    91 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
    86 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
    92 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
       
    93 (define-key mq-edit-mode-map "\C-c\C-s" 'mq-signoff)
    87 
    94 
    88 
    95 
    89 ;;; Helper functions.
    96 ;;; Helper functions.
    90 
    97 
    91 (defun mq-read-patch-name (&optional source prompt force)
    98 (defun mq-read-patch-name (&optional source prompt force)
   364 	(call-process (hg-binary) nil t nil "qdiff" "--git")
   371 	(call-process (hg-binary) nil t nil "qdiff" "--git")
   365     (call-process (hg-binary) nil t nil "qdiff"))
   372     (call-process (hg-binary) nil t nil "qdiff"))
   366     (diff-mode)
   373     (diff-mode)
   367     (font-lock-fontify-buffer)))
   374     (font-lock-fontify-buffer)))
   368 
   375 
       
   376 (defun mq-signoff ()
       
   377   "Sign off on the current patch, in the style used by the Linux kernel.
       
   378 If the variable mq-signoff-address is non-nil, it will be used, otherwise
       
   379 the value of the ui.username item from your hgrc will be used."
       
   380   (interactive)
       
   381   (let ((was-editing (eq major-mode 'mq-edit-mode))
       
   382 	signed)
       
   383     (unless was-editing
       
   384       (mq-refresh-edit))
       
   385     (save-excursion
       
   386       (let* ((user (or mq-signoff-address
       
   387 		       (hg-run0 "debugconfig" "ui.username")))
       
   388 	     (signoff (concat "Signed-off-by: " user)))
       
   389 	(if (search-forward signoff nil t)
       
   390 	    (message "You have already signed off on this patch.")
       
   391 	  (goto-char (point-max))
       
   392 	  (let ((case-fold-search t))
       
   393 	    (if (re-search-backward "^Signed-off-by: " nil t)
       
   394 		(forward-line 1)
       
   395 	      (insert "\n")))
       
   396 	  (insert signoff)
       
   397 	  (message "%s" signoff)
       
   398 	  (setq signed t))))
       
   399     (unless was-editing
       
   400       (if signed
       
   401 	  (mq-edit-finish)
       
   402 	(mq-edit-kill)))))
       
   403 
   369 
   404 
   370 (provide 'mq)
   405 (provide 'mq)
   371 
   406 
   372 
   407 
   373 ;;; Local Variables:
   408 ;;; Local Variables: