/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to contrib/emacs/brz-mode.el

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;;; bzr.el -- version control commands for Bazaar-NG.
 
1
;;; brz.el -- version control commands for Breezy.
2
2
;;; Copyright 2005  Luke Gorrie <luke@member.fsf.org>
3
3
;;;
4
 
;;; bzr.el is free software distributed under the terms of the GNU
 
4
;;; brz.el is free software distributed under the terms of the GNU
5
5
;;; General Public Licence, version 2. For details see the file
6
6
;;; COPYING in the GNU Emacs distribution.
7
7
;;;
16
16
 
17
17
;;;; Configurables
18
18
 
19
 
(defvar bzr-command-prefix "\C-cb"
 
19
(defvar brz-command-prefix "\C-cb"
20
20
  ;; This default value breaks the Emacs rules and uses a sequence
21
21
  ;; reserved for the user's own custom bindings. That's not good but
22
22
  ;; I can't think of a decent standard one. -luke (14/Mar/2005)
23
 
  "Prefix sequence for bzr-mode commands.")
24
 
 
25
 
(defvar bzr-command "bzr"
26
 
  "*Shell command to execute bzr.")
27
 
 
28
 
(defvar bzr-buffer "*bzr-command*"
29
 
  "Buffer for user-visible bzr command output.")
 
23
  "Prefix sequence for brz-mode commands.")
 
24
 
 
25
(defvar brz-command "brz"
 
26
  "*Shell command to execute brz.")
 
27
 
 
28
(defvar brz-buffer "*brz-command*"
 
29
  "Buffer for user-visible brz command output.")
30
30
 
31
31
;;;; Minor-mode
32
32
 
33
 
(define-minor-mode bzr-mode
34
 
  "\\{bzr-mode-map}"
 
33
(define-minor-mode brz-mode
 
34
  "\\{brz-mode-map}"
35
35
  nil
36
 
  " bzr"
 
36
  " brz"
37
37
  ;; Coax define-minor-mode into creating a keymap.
38
38
  ;; We'll fill it in manually though because define-minor-mode seems
39
39
  ;; hopeless for changing bindings without restarting Emacs.
40
 
  `((,bzr-command-prefix . fake)))
41
 
 
42
 
(defvar bzr-mode-commands-map nil
43
 
  "Keymap for bzr-mode commands.
44
 
This map is bound to a prefix sequence in `bzr-mode-map'.")
45
 
 
46
 
(defconst bzr-command-keys '(("l" bzr-log)
47
 
                             ("d" bzr-diff)
48
 
                             ("s" bzr-status)
49
 
                             ("c" bzr-commit))
50
 
  "Keys to bind in `bzr-mode-commands-map'.")
51
 
 
52
 
(defun bzr-init-command-keymap ()
53
 
  "Bind the bzr-mode keys.
 
40
  `((,brz-command-prefix . fake)))
 
41
 
 
42
(defvar brz-mode-commands-map nil
 
43
  "Keymap for brz-mode commands.
 
44
This map is bound to a prefix sequence in `brz-mode-map'.")
 
45
 
 
46
(defconst brz-command-keys '(("l" brz-log)
 
47
                             ("d" brz-diff)
 
48
                             ("s" brz-status)
 
49
                             ("c" brz-commit))
 
50
  "Keys to bind in `brz-mode-commands-map'.")
 
51
 
 
52
(defun brz-init-command-keymap ()
 
53
  "Bind the brz-mode keys.
54
54
This command can be called interactively to redefine the keys from
55
 
`bzr-commands-keys'."
 
55
`brz-commands-keys'."
56
56
  (interactive)
57
 
  (setq bzr-mode-commands-map (make-sparse-keymap))
58
 
  (dolist (spec bzr-command-keys)
59
 
    (define-key bzr-mode-commands-map (car spec) (cadr spec)))
60
 
  (define-key bzr-mode-map bzr-command-prefix bzr-mode-commands-map))
 
57
  (setq brz-mode-commands-map (make-sparse-keymap))
 
58
  (dolist (spec brz-command-keys)
 
59
    (define-key brz-mode-commands-map (car spec) (cadr spec)))
 
60
  (define-key brz-mode-map brz-command-prefix brz-mode-commands-map))
61
61
 
62
 
(bzr-init-command-keymap)
 
62
(brz-init-command-keymap)
63
63
 
64
64
 
65
65
;;;; Commands
66
66
 
67
 
(defun bzr-log ()
68
 
  "Run \"bzr log\" in the repository top-level."
 
67
(defun brz-log ()
 
68
  "Run \"brz log\" in the repository top-level."
69
69
  (interactive)
70
 
  (bzr "log"))
 
70
  (brz "log"))
71
71
 
72
 
(defun bzr-diff ()
73
 
  "Run \"bzr diff\" in the repository top-level."
 
72
(defun brz-diff ()
 
73
  "Run \"brz diff\" in the repository top-level."
74
74
  (interactive)
75
75
  (save-some-buffers)
76
 
  (bzr-run-command (bzr-command "diff") 'diff-mode))
 
76
  (brz-run-command (brz-command "diff") 'diff-mode))
77
77
 
78
 
(defun bzr-status ()
79
 
  "Run \"bzr diff\" in the repository top-level."
 
78
(defun brz-status ()
 
79
  "Run \"brz diff\" in the repository top-level."
80
80
  (interactive)
81
 
  (bzr "status"))
 
81
  (brz "status"))
82
82
 
83
 
(defun bzr-commit (message)
84
 
  "Run \"bzr diff\" in the repository top-level."
 
83
(defun brz-commit (message)
 
84
  "Run \"brz diff\" in the repository top-level."
85
85
  (interactive "sCommit message: ")
86
86
  (save-some-buffers)
87
 
  (bzr "commit -m %s" (shell-quote-argument message)))
 
87
  (brz "commit -m %s" (shell-quote-argument message)))
88
88
 
89
89
;;;; Utilities
90
90
 
91
 
(defun bzr (format &rest args)
92
 
  (bzr-run-command (apply #'bzr-command format args)))
93
 
 
94
 
(defun bzr-command (format &rest args)
95
 
  (concat bzr-command " " (apply #'format format args)))
96
 
 
97
 
(defun bzr-run-command (command &optional pre-view-hook)
 
91
(defun brz (format &rest args)
 
92
  (brz-run-command (apply #'brz-command format args)))
 
93
 
 
94
(defun brz-command (format &rest args)
 
95
  (concat brz-command " " (apply #'format format args)))
 
96
 
 
97
(defun brz-run-command (command &optional pre-view-hook)
98
98
  "Run COMMAND at the top-level and view the result in another window.
99
99
PRE-VIEW-HOOK is an optional function to call before entering
100
100
view-mode. This is useful to set the major-mode of the result buffer,
101
101
because if you did it afterwards then it would zap view-mode."
102
 
  (bzr-cleanup)
103
 
  (let ((toplevel (bzr-toplevel)))
104
 
    (with-current-buffer (get-buffer-create bzr-buffer)
 
102
  (brz-cleanup)
 
103
  (let ((toplevel (brz-toplevel)))
 
104
    (with-current-buffer (get-buffer-create brz-buffer)
105
105
      ;; prevent `shell-command' from printing output in a message
106
106
      (let ((max-mini-window-height 0))
107
107
        (let ((default-directory toplevel))
109
109
      (goto-char (point-min))
110
110
      (when pre-view-hook
111
111
        (funcall pre-view-hook))))
112
 
  (if (zerop (buffer-size (get-buffer bzr-buffer)))
113
 
      (message "(bzr command finished with no output.)")
114
 
    (view-buffer-other-window bzr-buffer)
 
112
  (if (zerop (buffer-size (get-buffer brz-buffer)))
 
113
      (message "(brz command finished with no output.)")
 
114
    (view-buffer-other-window brz-buffer)
115
115
    ;; Bury the buffer when dismissed.
116
 
    (with-current-buffer (get-buffer bzr-buffer)
 
116
    (with-current-buffer (get-buffer brz-buffer)
117
117
      (setq view-exit-action #'bury-buffer))))
118
118
 
119
 
(defun bzr-current-file ()
 
119
(defun brz-current-file ()
120
120
  (or (buffer-file-name)
121
121
      (error "Don't know what file to use!")))
122
122
 
123
 
(defun bzr-cleanup (&optional buffer-name)
 
123
(defun brz-cleanup (&optional buffer-name)
124
124
  "Cleanup before executing a command.
125
125
BUFFER-NAME is the command's output buffer."
126
 
  (let ((name (or buffer-name bzr-buffer)))
127
 
    (when (get-buffer bzr-buffer)
128
 
      (kill-buffer bzr-buffer))))
 
126
  (let ((name (or buffer-name brz-buffer)))
 
127
    (when (get-buffer brz-buffer)
 
128
      (kill-buffer brz-buffer))))
129
129
 
130
 
(defun bzr-toplevel ()
 
130
(defun brz-toplevel ()
131
131
  "Return the top-level directory of the repository."
132
 
  (let ((dir (bzr-find-repository)))
 
132
  (let ((dir (brz-find-repository)))
133
133
    (if dir
134
134
        (file-name-directory dir)
135
 
      (error "Can't find bzr repository top-level."))))
 
135
      (error "Can't find brz repository top-level."))))
136
136
  
137
 
(defun bzr-find-repository (&optional start-directory)
 
137
(defun brz-find-repository (&optional start-directory)
138
138
  "Return the enclosing \".bzr\" directory, or nil if there isn't one."
139
139
  (when (and (buffer-file-name)
140
140
             (file-directory-p (file-name-directory (buffer-file-name))))
144
144
      (or (car (directory-files dir t "^\\.bzr$"))
145
145
          (let ((next-dir (file-name-directory (directory-file-name dir))))
146
146
            (unless (equal dir next-dir)
147
 
              (bzr-find-repository next-dir)))))))
 
147
              (brz-find-repository next-dir)))))))
148
148
 
149
149
;;;; Hook setup
150
150
;;;
151
 
;;; Automaticaly enter bzr-mode when we open a file that's under bzr
 
151
;;; Automaticaly enter brz-mode when we open a file that's under brz
152
152
;;; control, i.e. if the .bzr directory can be found.
153
153
 
154
 
(defun bzr-find-file-hook ()
155
 
  "Enable bzr-mode if the file is inside a bzr repository."
 
154
(defun brz-find-file-hook ()
 
155
  "Enable brz-mode if the file is inside a brz repository."
156
156
  ;; Note: This function is called for every file that Emacs opens so
157
157
  ;; it mustn't make any mistakes.
158
 
  (when (bzr-find-repository) (bzr-mode 1)))
159
 
 
160
 
(add-hook 'find-file-hooks 'bzr-find-file-hook)
161
 
 
162
 
(provide 'bzr)
 
158
  (when (brz-find-repository) (brz-mode 1)))
 
159
 
 
160
(add-hook 'find-file-hooks 'brz-find-file-hook)
 
161
 
 
162
(provide 'brz)
163
163