ediff-help.el 13 KB

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