Revert previous change - merge mistake.
[bpt/emacs.git] / lisp / ediff-help.el
CommitLineData
f49e1445
MK
1;;; ediff-help.el --- Code related to the contents of Ediff help buffers
2
0d30b337 3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
d7a0267c 4;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
f49e1445 5
50a07e18 6;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
f49e1445
MK
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
b4aa6026 12;; the Free Software Foundation; either version 3, or (at your option)
f49e1445
MK
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
22;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23;; Boston, MA 02110-1301, USA.
f49e1445 24
3afbc435
PJ
25;;; Commentary:
26
f49e1445 27;;; Code:
71296446 28
f49e1445
MK
29
30;; Compiler pacifier start
31(defvar ediff-multiframe)
ddc90f39
MK
32
33(eval-when-compile
34 (let ((load-path (cons (expand-file-name ".") load-path)))
35 (or (featurep 'ediff-init)
36 (load "ediff-init.el" nil nil 'nosuffix))
37 ))
f49e1445
MK
38;; end pacifier
39
ddc90f39
MK
40(require 'ediff-init)
41
f49e1445
MK
42;; Help messages
43
44(defconst ediff-long-help-message-head
45 " Move around | Toggle features | Manipulate
46=====================|===========================|============================="
47 "The head of the full help message.")
48(defconst ediff-long-help-message-tail
49 "=====================|===========================|=============================
71296446
JB
50 R -show registry | = -compare regions | M -show session group
51 D -diff output | E -browse Ediff manual| G -send bug report
52 i -status info | ? -help off | z/q -suspend/quit
f49e1445
MK
53-------------------------------------------------------------------------------
54For help on a specific command: Click Button 2 over it; or
55 Put the cursor over it and type RET."
56 "The tail of the full-help message.")
57
58(defconst ediff-long-help-message-compare3
59 "
60p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y
61n,SPC -next diff | h -hilighting | rx -restore buf X's old diff
71296446 62 j -jump to diff | @ -auto-refinement | * -refine current region
b6178721
MK
63 gx -goto X's point| ## -ignore whitespace | ! -update diff regions
64 C-l -recenter | #c -ignore case |
71296446
JB
65 v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
66 </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
f49e1445
MK
67 ~ -rotate buffers| m -wide display |
68"
69 "Help message usually used for 3-way comparison.
3af0304a 70Normally, not a user option. See `ediff-help-message' for details.")
71296446 71
f49e1445
MK
72(defconst ediff-long-help-message-compare2
73 "
74p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A
75n,SPC -next diff | h -hilighting | rx -restore buf X's old diff
71296446 76 j -jump to diff | @ -auto-refinement | * -refine current region
b6178721
MK
77 gx -goto X's point| ## -ignore whitespace | ! -update diff regions
78 C-l -recenter | #c -ignore case |
71296446
JB
79 v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
80 </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
81 ~ -swap variants | m -wide display |
f49e1445
MK
82"
83 "Help message usually used for 2-way comparison.
3af0304a 84Normally, not a user option. See `ediff-help-message' for details.")
71296446 85
f49e1445
MK
86(defconst ediff-long-help-message-narrow2
87 "
88p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A
89n,SPC -next diff | h -hilighting | rx -restore buf X's old diff
71296446 90 j -jump to diff | @ -auto-refinement | * -refine current region
b6178721
MK
91 gx -goto X's point| ## -ignore whitespace | ! -update diff regions
92 C-l -recenter | #c -ignore case | % -narrow/widen buffs
71296446
JB
93 v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
94 </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
95 ~ -swap variants | m -wide display |
f49e1445
MK
96"
97 "Help message when comparing windows or regions line-by-line.
3af0304a 98Normally, not a user option. See `ediff-help-message' for details.")
71296446 99
f49e1445
MK
100(defconst ediff-long-help-message-word-mode
101 "
102p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y
103n,SPC -next diff | h -hilighting | rx -restore buf X's old diff
71296446 104 j -jump to diff | |
b6178721
MK
105 gx -goto X's point| % -narrow/widen buffs | ! -recompute diffs
106 C-l -recenter | #c -ignore case |
71296446
JB
107 v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
108 </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
109 ~ -swap variants | m -wide display |
f49e1445
MK
110"
111 "Help message when comparing windows or regions word-by-word.
3af0304a 112Normally, not a user option. See `ediff-help-message' for details.")
71296446 113
f49e1445
MK
114(defconst ediff-long-help-message-merge
115 "
116p,DEL -previous diff | | -vert/horiz split | x -copy buf X's region to C
117n,SPC -next diff | h -hilighting | r -restore buf C's old diff
71296446
JB
118 j -jump to diff | @ -auto-refinement | * -refine current region
119 gx -goto X's point| ## -ignore whitespace | ! -update diff regions
120 C-l -recenter | #f/#h -focus/hide regions | + -combine diff regions
121 v/V -scroll up/dn | X -read-only in buf X | wx -save buf X
122 </> -scroll lt/rt | m -wide display | wd -save diff output
123 ~ -swap variants | s -shrink window C | / -show ancestor buff
124 | $$ -show clashes only | & -merge w/new default
3af0304a 125 | $* -skip changed regions |
f49e1445 126"
3af0304a
MK
127 "Help message for merge sessions.
128Normally, not a user option. See `ediff-help-message' for details.")
f49e1445
MK
129
130;; The actual long help message.
131(ediff-defvar-local ediff-long-help-message ""
3af0304a 132 "Normally, not a user option. See `ediff-help-message' for details.")
71296446 133
f49e1445 134(defconst ediff-brief-message-string
899a431b 135 " Type ? for help"
f49e1445
MK
136 "Contents of the brief help message.")
137;; The actual brief help message
138(ediff-defvar-local ediff-brief-help-message ""
3af0304a 139 "Normally, not a user option. See `ediff-help-message' for details.")
71296446 140
f49e1445
MK
141(ediff-defvar-local ediff-brief-help-message-function nil
142 "The brief help message that the user can customize.
143If the user sets this to a parameter-less function, Ediff will use it to
3af0304a 144produce the brief help message. This function must return a string.")
f49e1445
MK
145(ediff-defvar-local ediff-long-help-message-function nil
146 "The long help message that the user can customize.
147See `ediff-brief-help-message-function' for more.")
148
7d027816
MK
149(defcustom ediff-use-long-help-message nil
150 "*If t, Ediff displays a long help message. Short help message otherwise."
151 :type 'boolean
152 :group 'ediff-window)
f49e1445
MK
153
154;; The actual help message.
155(ediff-defvar-local ediff-help-message ""
156 "The actual help message.
3af0304a 157Normally, the user shouldn't touch this. However, if you want Ediff to
f49e1445
MK
158start up with different help messages for different jobs, you can change
159the value of this variable and the variables `ediff-help-message-*' in
71296446 160`ediff-startup-hook'.")
f49e1445
MK
161
162
163;; the keymap that defines clicks over the quick help regions
164(defvar ediff-help-region-map (make-sparse-keymap))
165
166(define-key
167 ediff-help-region-map
168 (if ediff-emacs-p [mouse-2] [button2])
169 'ediff-help-for-quick-help)
170
171;; runs in the control buffer
172(defun ediff-set-help-overlays ()
173 (goto-char (point-min))
174 (let (overl beg end cmd)
175 (while (re-search-forward " *\\([^ \t\n|]+\\||\\) +-[^|\n]+" nil 'noerror)
176 (setq beg (match-beginning 0)
177 end (match-end 0)
178 cmd (buffer-substring (match-beginning 1) (match-end 1)))
179 (setq overl (ediff-make-overlay beg end))
180 (if ediff-emacs-p
181 (ediff-overlay-put overl 'mouse-face 'highlight)
182 (ediff-overlay-put overl 'highlight t))
183 (ediff-overlay-put overl 'ediff-help-info cmd))))
184
185
186(defun ediff-help-for-quick-help ()
187 "Explain Ediff commands in more detail."
188 (interactive)
189 (ediff-barf-if-not-control-buffer)
ddc90f39 190 (let ((pos (ediff-event-point last-command-event))
f49e1445
MK
191 overl cmd)
192
50a07e18
MK
193 (ediff-cond-compile-for-xemacs-or-emacs
194 ;; xemacs
195 (setq overl (extent-at pos (current-buffer) 'ediff-help-info)
196 cmd (ediff-overlay-get overl 'ediff-help-info))
197 ;; emacs
198 (setq cmd (car (mapcar (lambda (elt)
199 (overlay-get elt 'ediff-help-info))
200 (overlays-at pos))))
201 )
71296446 202
f49e1445 203 (if (not (stringp cmd))
3af0304a 204 (error "Hmm... I don't see an Ediff command around here..."))
71296446 205
f49e1445 206 (ediff-documentation "Quick Help Commands")
71296446 207
f49e1445
MK
208 (let (case-fold-search)
209 (cond ((string= cmd "?") (re-search-forward "^`\\?'"))
210 ((string= cmd "G") (re-search-forward "^`G'"))
211 ((string= cmd "E") (re-search-forward "^`E'"))
212 ((string= cmd "wd") (re-search-forward "^`wd'"))
213 ((string= cmd "wx") (re-search-forward "^`wa'"))
214 ((string= cmd "a/b") (re-search-forward "^`a'"))
215 ((string= cmd "x") (re-search-forward "^`a'"))
216 ((string= cmd "xy") (re-search-forward "^`ab'"))
217 ((string= cmd "p,DEL") (re-search-forward "^`p'"))
218 ((string= cmd "n,SPC") (re-search-forward "^`n'"))
219 ((string= cmd "j") (re-search-forward "^`j'"))
220 ((string= cmd "gx") (re-search-forward "^`ga'"))
221 ((string= cmd "!") (re-search-forward "^`!'"))
222 ((string= cmd "*") (re-search-forward "^`\\*'"))
223 ((string= cmd "m") (re-search-forward "^`m'"))
224 ((string= cmd "|") (re-search-forward "^`|'"))
225 ((string= cmd "@") (re-search-forward "^`@'"))
226 ((string= cmd "h") (re-search-forward "^`h'"))
227 ((string= cmd "r") (re-search-forward "^`r'"))
228 ((string= cmd "rx") (re-search-forward "^`ra'"))
229 ((string= cmd "##") (re-search-forward "^`##'"))
b6178721 230 ((string= cmd "#c") (re-search-forward "^`#c'"))
f49e1445
MK
231 ((string= cmd "#f/#h") (re-search-forward "^`#f'"))
232 ((string= cmd "X") (re-search-forward "^`A'"))
233 ((string= cmd "v/V") (re-search-forward "^`v'"))
234 ((string= cmd "</>") (re-search-forward "^`<'"))
235 ((string= cmd "~") (re-search-forward "^`~'"))
236 ((string= cmd "i") (re-search-forward "^`i'"))
237 ((string= cmd "D") (re-search-forward "^`D'"))
238 ((string= cmd "R") (re-search-forward "^`R'"))
239 ((string= cmd "M") (re-search-forward "^`M'"))
240 ((string= cmd "z/q") (re-search-forward "^`z'"))
241 ((string= cmd "%") (re-search-forward "^`%'"))
242 ((string= cmd "C-l") (re-search-forward "^`C-l'"))
3af0304a
MK
243 ((string= cmd "$$") (re-search-forward "^`\\$\\$'"))
244 ((string= cmd "$*") (re-search-forward "^`\\$\\*'"))
f49e1445
MK
245 ((string= cmd "/") (re-search-forward "^`/'"))
246 ((string= cmd "&") (re-search-forward "^`&'"))
247 ((string= cmd "s") (re-search-forward "^`s'"))
248 ((string= cmd "+") (re-search-forward "^`\\+'"))
249 ((string= cmd "=") (re-search-forward "^`='"))
250 (t (error "Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer")))
251 ) ; let case-fold-search
252 ))
253
254
255;; assuming we are in control window, calculate length of the first line in
256;; help message
257(defun ediff-help-message-line-length ()
258 (save-excursion
259 (goto-char (point-min))
260 (if ediff-use-long-help-message
97546017 261 (forward-line 1))
f49e1445
MK
262 (end-of-line)
263 (current-column)))
71296446 264
f49e1445
MK
265
266(defun ediff-indent-help-message ()
267 (let* ((shift (/ (max 0 (- (window-width (selected-window))
268 (ediff-help-message-line-length)))
269 2))
270 (str (make-string shift ?\ )))
271 (save-excursion
272 (goto-char (point-min))
273 (while (< (point) (point-max))
274 (insert str)
275 (beginning-of-line)
276 (forward-line 1)))))
71296446 277
f49e1445
MK
278
279;; compose the help message as a string
280(defun ediff-set-help-message ()
281 (setq ediff-long-help-message
282 (cond ((and ediff-long-help-message-function
283 (or (symbolp ediff-long-help-message-function)
284 (consp ediff-long-help-message-function)))
285 (funcall ediff-long-help-message-function))
71296446 286 (ediff-word-mode
f49e1445
MK
287 (concat ediff-long-help-message-head
288 ediff-long-help-message-word-mode
289 ediff-long-help-message-tail))
290 (ediff-narrow-job
291 (concat ediff-long-help-message-head
292 ediff-long-help-message-narrow2
293 ediff-long-help-message-tail))
71296446 294 (ediff-merge-job
f49e1445
MK
295 (concat ediff-long-help-message-head
296 ediff-long-help-message-merge
297 ediff-long-help-message-tail))
298 (ediff-diff3-job
299 (concat ediff-long-help-message-head
300 ediff-long-help-message-compare3
301 ediff-long-help-message-tail))
71296446 302 (t
f49e1445
MK
303 (concat ediff-long-help-message-head
304 ediff-long-help-message-compare2
305 ediff-long-help-message-tail))))
71296446 306 (setq ediff-brief-help-message
f49e1445
MK
307 (cond ((and ediff-brief-help-message-function
308 (or (symbolp ediff-brief-help-message-function)
309 (consp ediff-brief-help-message-function)))
310 (funcall ediff-brief-help-message-function))
311 ((stringp ediff-brief-help-message-function)
312 ediff-brief-help-message-function)
313 ((ediff-multiframe-setup-p) ediff-brief-message-string)
314 (t ; long brief msg, not multiframe --- put in the middle
315 ediff-brief-message-string)
316 ))
317 (setq ediff-help-message (if ediff-use-long-help-message
318 ediff-long-help-message
319 ediff-brief-help-message))
320 (run-hooks 'ediff-display-help-hook))
321
55d7ff38 322;;;###autoload
3af0304a
MK
323(defun ediff-customize ()
324 (interactive)
325 (customize-group "ediff"))
326
f49e1445 327
b6178721
MK
328(provide 'ediff-help)
329
330
ab5796a9 331;;; arch-tag: 05659813-7fcf-4274-964f-d2f577431a9d
f49e1445 332;;; ediff-help.el ends here