comparison lisp/ediff-help.el @ 16247:a0940ace16a3

Initial revision
author Michael Kifer <kifer@cs.stonybrook.edu>
date Fri, 20 Sep 1996 01:08:36 +0000
parents
children 0b9d9cbf3cd4
comparison
equal deleted inserted replaced
16246:4e00938cd261 16247:a0940ace16a3
1 ;;; ediff-help.el --- Code related to the contents of Ediff help buffers
2
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Code:
25
26 (require 'ediff-init)
27
28 ;; Compiler pacifier start
29 (defvar ediff-multiframe)
30 (and noninteractive
31 (eval-when-compile
32 (let ((load-path (cons (expand-file-name ".") load-path)))
33 (load-file "ediff-init.el"))))
34 ;; end pacifier
35
36 ;; Help messages
37
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.")
51
52 (defconst ediff-long-help-message-compare3
53 "
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| | ! -update diff regions
58 C-l -recenter | ## -ignore whitespace |
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 |
62 "
63 "Help message usually used for 3-way comparison.
64 Normally, not a user option. See `ediff-help-message' for details.")
65
66 (defconst ediff-long-help-message-compare2
67 "
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| | ! -update diff regions
72 C-l -recenter | ## -ignore whitespace |
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 |
76 "
77 "Help message usually used for 2-way comparison.
78 Normally, not a user option. See `ediff-help-message' for details.")
79
80 (defconst ediff-long-help-message-narrow2
81 "
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| % -narrow/widen buffs | ! -update diff regions
86 C-l -recenter | ## -ignore whitespace |
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 |
90 "
91 "Help message when comparing windows or regions line-by-line.
92 Normally, not a user option. See `ediff-help-message' for details.")
93
94 (defconst ediff-long-help-message-word-mode
95 "
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 | |
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 |
104 "
105 "Help message when comparing windows or regions word-by-word.
106 Normally, not a user option. See `ediff-help-message' for details.")
107
108 (defconst ediff-long-help-message-merge
109 "
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 "
120 "Help message during merging.
121 Normally, not a user option. See `ediff-help-message' for details.")
122
123 ;; The actual long help message.
124 (ediff-defvar-local ediff-long-help-message ""
125 "Normally, not a user option. See `ediff-help-message' for details.")
126
127 (defconst ediff-brief-message-string
128 "? -quick help "
129 "Contents of the brief help message.")
130 ;; The actual brief help message
131 (ediff-defvar-local ediff-brief-help-message ""
132 "Normally, not a user option. See `ediff-help-message' for details.")
133
134 (ediff-defvar-local ediff-brief-help-message-function nil
135 "The brief help message that the user can customize.
136 If the user sets this to a parameter-less function, Ediff will use it to
137 produce the brief help message. This function must return a string.")
138 (ediff-defvar-local ediff-long-help-message-function nil
139 "The long help message that the user can customize.
140 See `ediff-brief-help-message-function' for more.")
141
142 (defvar ediff-use-long-help-message nil
143 "*If t, Ediff displays a long help message. Short help message otherwise.")
144
145 ;; The actual help message.
146 (ediff-defvar-local ediff-help-message ""
147 "The actual help message.
148 Normally, the user shouldn't touch this. However, if you want Ediff to
149 start up with different help messages for different jobs, you can change
150 the value of this variable and the variables `ediff-help-message-*' in
151 `ediff-startup-hook'.")
152
153
154 ;; the keymap that defines clicks over the quick help regions
155 (defvar ediff-help-region-map (make-sparse-keymap))
156
157 (define-key
158 ediff-help-region-map
159 (if ediff-emacs-p [mouse-2] [button2])
160 'ediff-help-for-quick-help)
161
162 ;; runs in the control buffer
163 (defun ediff-set-help-overlays ()
164 (goto-char (point-min))
165 (let (overl beg end cmd)
166 (while (re-search-forward " *\\([^ \t\n|]+\\||\\) +-[^|\n]+" nil 'noerror)
167 (setq beg (match-beginning 0)
168 end (match-end 0)
169 cmd (buffer-substring (match-beginning 1) (match-end 1)))
170 (setq overl (ediff-make-overlay beg end))
171 (if ediff-emacs-p
172 (ediff-overlay-put overl 'mouse-face 'highlight)
173 (ediff-overlay-put overl 'highlight t))
174 (ediff-overlay-put overl 'ediff-help-info cmd))))
175
176
177 (defun ediff-help-for-quick-help ()
178 "Explain Ediff commands in more detail."
179 (interactive)
180 (ediff-barf-if-not-control-buffer)
181 (let ((ctl-buf (current-buffer))
182 (pos (ediff-event-point last-command-event))
183 overl cmd)
184
185 (if ediff-xemacs-p
186 (setq overl (extent-at pos (current-buffer) 'ediff-help-info)
187 cmd (ediff-overlay-get overl 'ediff-help-info))
188 (setq cmd (car (mapcar (function (lambda (elt)
189 (overlay-get elt 'ediff-help-info)))
190 (overlays-at pos)))))
191
192 (if (not (stringp cmd))
193 (error "Hmm... I don't see an Ediff command around here..."))
194
195 (ediff-documentation "Quick Help Commands")
196
197 (let (case-fold-search)
198 (cond ((string= cmd "?") (re-search-forward "^`\\?'"))
199 ((string= cmd "G") (re-search-forward "^`G'"))
200 ((string= cmd "E") (re-search-forward "^`E'"))
201 ((string= cmd "wd") (re-search-forward "^`wd'"))
202 ((string= cmd "wx") (re-search-forward "^`wa'"))
203 ((string= cmd "a/b") (re-search-forward "^`a'"))
204 ((string= cmd "x") (re-search-forward "^`a'"))
205 ((string= cmd "xy") (re-search-forward "^`ab'"))
206 ((string= cmd "p,DEL") (re-search-forward "^`p'"))
207 ((string= cmd "n,SPC") (re-search-forward "^`n'"))
208 ((string= cmd "j") (re-search-forward "^`j'"))
209 ((string= cmd "gx") (re-search-forward "^`ga'"))
210 ((string= cmd "!") (re-search-forward "^`!'"))
211 ((string= cmd "*") (re-search-forward "^`\\*'"))
212 ((string= cmd "m") (re-search-forward "^`m'"))
213 ((string= cmd "|") (re-search-forward "^`|'"))
214 ((string= cmd "@") (re-search-forward "^`@'"))
215 ((string= cmd "h") (re-search-forward "^`h'"))
216 ((string= cmd "r") (re-search-forward "^`r'"))
217 ((string= cmd "rx") (re-search-forward "^`ra'"))
218 ((string= cmd "##") (re-search-forward "^`##'"))
219 ((string= cmd "#f/#h") (re-search-forward "^`#f'"))
220 ((string= cmd "X") (re-search-forward "^`A'"))
221 ((string= cmd "v/V") (re-search-forward "^`v'"))
222 ((string= cmd "</>") (re-search-forward "^`<'"))
223 ((string= cmd "~") (re-search-forward "^`~'"))
224 ((string= cmd "i") (re-search-forward "^`i'"))
225 ((string= cmd "D") (re-search-forward "^`D'"))
226 ((string= cmd "R") (re-search-forward "^`R'"))
227 ((string= cmd "M") (re-search-forward "^`M'"))
228 ((string= cmd "z/q") (re-search-forward "^`z'"))
229 ((string= cmd "%") (re-search-forward "^`%'"))
230 ((string= cmd "C-l") (re-search-forward "^`C-l'"))
231 ((string= cmd "$") (re-search-forward "^`\\$'"))
232 ((string= cmd "/") (re-search-forward "^`/'"))
233 ((string= cmd "&") (re-search-forward "^`&'"))
234 ((string= cmd "s") (re-search-forward "^`s'"))
235 ((string= cmd "+") (re-search-forward "^`\\+'"))
236 ((string= cmd "=") (re-search-forward "^`='"))
237 (t (error "Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer")))
238 ) ; let case-fold-search
239 ))
240
241
242 ;; assuming we are in control window, calculate length of the first line in
243 ;; help message
244 (defun ediff-help-message-line-length ()
245 (save-excursion
246 (goto-char (point-min))
247 (if ediff-use-long-help-message
248 (next-line 1))
249 (end-of-line)
250 (current-column)))
251
252
253 (defun ediff-indent-help-message ()
254 (let* ((shift (/ (max 0 (- (window-width (selected-window))
255 (ediff-help-message-line-length)))
256 2))
257 (str (make-string shift ?\ )))
258 (save-excursion
259 (goto-char (point-min))
260 (while (< (point) (point-max))
261 (insert str)
262 (beginning-of-line)
263 (forward-line 1)))))
264
265
266 ;; compose the help message as a string
267 (defun ediff-set-help-message ()
268 (setq ediff-long-help-message
269 (cond ((and ediff-long-help-message-function
270 (or (symbolp ediff-long-help-message-function)
271 (consp ediff-long-help-message-function)))
272 (funcall ediff-long-help-message-function))
273 (ediff-word-mode
274 (concat ediff-long-help-message-head
275 ediff-long-help-message-word-mode
276 ediff-long-help-message-tail))
277 (ediff-narrow-job
278 (concat ediff-long-help-message-head
279 ediff-long-help-message-narrow2
280 ediff-long-help-message-tail))
281 (ediff-merge-job
282 (concat ediff-long-help-message-head
283 ediff-long-help-message-merge
284 ediff-long-help-message-tail))
285 (ediff-diff3-job
286 (concat ediff-long-help-message-head
287 ediff-long-help-message-compare3
288 ediff-long-help-message-tail))
289 (t
290 (concat ediff-long-help-message-head
291 ediff-long-help-message-compare2
292 ediff-long-help-message-tail))))
293 (setq ediff-brief-help-message
294 (cond ((and ediff-brief-help-message-function
295 (or (symbolp ediff-brief-help-message-function)
296 (consp ediff-brief-help-message-function)))
297 (funcall ediff-brief-help-message-function))
298 ((stringp ediff-brief-help-message-function)
299 ediff-brief-help-message-function)
300 ((ediff-multiframe-setup-p) ediff-brief-message-string)
301 (t ; long brief msg, not multiframe --- put in the middle
302 ediff-brief-message-string)
303 ))
304 (setq ediff-help-message (if ediff-use-long-help-message
305 ediff-long-help-message
306 ediff-brief-help-message))
307 (run-hooks 'ediff-display-help-hook))
308
309 (provide 'ediff-help)
310
311 ;;; ediff-help.el ends here