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