/ [latexrefman] / trunk / ltx-help.el
To checkout: svn checkout http://svn.gnu.org.ua/sources/latexrefman/trunk/ltx-help.el
Puszcza

Contents of /trunk/ltx-help.el

Parent Directory Parent Directory | Revision Log Revision Log


Revision 553 - (show annotations)
Mon Nov 21 11:58:42 2016 UTC (4 years, 5 months ago) by vincentb1
File size: 11573 byte(s)
Restore license text without @include-sion

* latex2e-fr.texi (copying): Restore license text without @include'sion of
license.texi, make it delimited by @comment's.
(dircategory): fix `LaTeX2e-fr' -> `latex2e-fr'
(throughout document): Use proper unbreakable space before colons.
(tabular, \newtheorem): typoes.
(\address): @var{...} instead of @code{...} for the argument  + typoes.
(\cc): typoes + add example from latex2e.texi
(\closing): typo.
(\signature): Typoes, translate @var name.
(Command line): Typoes.

* latex2e.texi: Restore license text without @inclusion of
license.texi, make it delimited by @comment's.
(\cc): Add `, as in:' before example.

* ltx-help.el (latex-help-file): Make this variable a defcustom
for selecting the manuel translation.

1 ;;; ltx-help.el --- Lookup latex commands in info pages.
2
3 ;; Authors: Peter Galbraith <rhogee@bathybius.meteo.mcgill.ca> or <galbrth@ac.dal.ca>
4 ;; Christian Lynbech <lynbech@daimi.aau.dk>
5 ;; Martin Sjolin <marsj@ida.liu.se>
6 ;; Boris Goldowsky <boris@cs.rochester.edu>
7 ;; Maintainer: as part of latexrefman, http://home.gna.org/latexrefman/
8 ;; Updated: 25 April 2013
9 ;; Keywords: help, latex, info
10
11
12 ;;; Commentary:
13
14 ;; Use the function latex-help to look up a latex command or
15 ;; environment in the latex online manual. If point is at such a
16 ;; command, this will be the default.
17
18 ;; The Texinfo document that this code works with is at
19 ;; http://ctan.org/pkg/latex2e-help-texinfo.
20
21 ;; Installation:
22 ;;
23 ;; Add the following piece of code to your .emacs
24 ;; (define-key help-map "\C-l" 'latex-help)
25 ;;
26 ;; to bind latex-help to C-h C-l. To load latex-help when loading AUC-TeX or
27 ;; some other LaTeX/TeX mode and bind the it to C-C i key, add the the following
28 ;; to you .emacs:
29 ;;
30 ;; (add-hook 'Latex-mode-hook
31 ;; (function (lambda ()
32 ;; (define-key LaTeX-mode-map "\C-ci" 'latex-help))))
33 ;;
34 ;; or if you do not have add-hook (a very nice package):
35 ;;
36 ;; (setq Latex-mode-hook
37 ;; (function (lambda ()
38 ;; (define-key LaTeX-mode-map "\C-ci" 'latex-help))))
39 ;;
40 ;;
41
42 ;;; Change Log:
43
44 ;;Mar 4, 1994 <lynbech@daimi.aau.dk>:
45 ;; Changed to my personal preferences. I have changed the function
46 ;; names. I have changed it to take a parameter, rather than just
47 ;; taking the current word. I am also basing it on the index rather
48 ;; than the node names.
49 ;;
50 ;;Mar 10, 1994 <marsj@ida.liu.se>:
51 ;; Added definition of current-word if not present.
52 ;; Made default value pick up a leading \ if apropriate
53 ;;
54 ;;Mar 11, 1994 <lynbech@daimi.aau.dk>:
55 ;; Changed the name of current-word into latex-help-guess. This
56 ;; eliminates the need for the embedded defun.
57 ;; Also made describe-latex work more like describe-function in its
58 ;; way of using default values. Now you must press return at an
59 ;; empty prompt to get the listed default (if any).
60 ;;
61 ;;Mar 10, 1994 <marsj@ida.liu.se>:
62 ;; Rewrote part of the describe-latex command to use the prefix
63 ;; argument, changed latex-help-get-cmd-obarray to return the
64 ;; the new array and test if it is empty or not. Add information
65 ;; concerning where to find the latex.texi file and emacs 18 info.el
66 ;;
67 ;;Mar 28, 1994 <boris@cs.rochester.edu>:
68 ;; * rewrote describe-latex's command-reading code; it did not
69 ;; default correctly on my system.
70 ;; * Added latex-help-hist, for completion history.
71 ;; * Modified it to use show-temp-buffer, if defined, so that it will
72 ;; display the help buffer in accord with user preferences.
73 ;; * Renamed describe-latex to latex-help, for consistency with other names.
74 ;; * Removed unneeded (interactive) specs for latex-help-guess and
75 ;; latex-help-get-cmd-obarray.
76 ;; * Added autoload cookies.
77 ;; * Doc fix.
78 ;;
79 ;;Mar 29, 1994 <marsj@ida.liu.se>:
80 ;; * made it working under epoch/emacs-18 by calling
81 ;; completion-read without the last argument.
82 ;; * made prompting similar to emacs help
83 ;; * moved add-hook and define keys to installation section, since
84 ;; the settings conflict with my own keybindings. Also, the key
85 ;; binding should be chosen by the end user.
86 ;;
87 ;; Wed Mar 30 08:45:50 1994 LYNBECH
88 ;; * Changed file layout to conform to FSF's standards
89 ;; * Tweaked latex-help-guess to include any leading backslashes
90 ;; * Inversed the meaning of the prefix argument. Now default is
91 ;; to switch buffers. Also added new variable `latex-help-split-window'
92 ;; to allow window splitting always.
93 ;; * Minor doc fixes
94 ;;
95 ;; Wed Apr 6 08:34:08 1994 LYNBECH
96 ;; * fixed latex-help-guess to be more faithful to the lexical rules
97 ;; of TeX. The result is not especially elegant.
98 ;;
99 ;;Apr 16, 1994 <abraham@iesd.auc.dk>:
100 ;; Changed the name to `ltx-help.el'.
101 ;;
102 ;; Sat Apr 1 1995 Torsten Martinsen (torsten@kom.auc.dk)
103 ;; Changed obarray to an alist where the car of each cons cell is the
104 ;; command name, and the cdr is the Info node describing that
105 ;; command. This implementation has the following advantages:
106 ;; - we don't need to have a lot of small redundant Info nodes; instead,
107 ;; we can use the Texinfo function index mechanism.
108 ;; - the alist is dynamically sized, so this version will work regardless
109 ;; of how many LaTeX commands the Info file contains.
110 ;; Added info on LaTeX2e Info file.
111 ;;
112 ;; Mon Apr 15 1996 Torsten Martinsen (bullestock@dk-online.dk)
113 ;; Changed node 'List of Commands' to 'Command Index' as suggested by
114 ;; Ralf Fassel <ralf@natlab.research.philips.com>.
115 ;;
116 ;; Mon Apr 22 1996 Torsten Martinsen (bullestock@dk-online.dk)
117 ;; When running under FSF Emacs, use (buffer-substring-no-properties)
118 ;; instead of (buffer-substring) as suggested by Kurt Hornik
119 ;; <hornik@ci.tuwien.ac.at>. Also removed Emacs 18 support.
120 ;;
121 ;; Thu Jun 12 2008 Karl Berry (karl@freefriends.org)
122 ;; Change latex-help-file to "(latex2e)", so our names are consistent.
123 ;; Doc updates.
124 ;;
125 ;; Thu Apr 25 2013 Karl Berry (karl@freefriends.org)
126 ;; Doc updates, and install these changes:
127 ;;
128 ;; Thu Apr 25 2013 Mandar Mitra (mandar.mitra@gmail.com)
129 ;; Using with (for example) "array" goes to the top node
130 ;; of latex2e.info instead of the intended node.
131 ;;
132 ;; Thu Dec 3 2015 Kevin Ryde (user42_kevin@yahoo.com.au)
133 ;; * latex-help-get-cmd-alist don't take \:: as double-colon style index,
134 ;; and allow "(line 123)" at the end of recent makeinfo output.
135 ;; * Use buffer-substring-no-properties when exists (does in XEmacs 21.4).
136
137 ;;; Code:
138
139 (require 'info)
140
141 (defalias 'ltxh-buffer-substring
142 (if (fboundp 'buffer-substring-no-properties) ;; when available
143 'buffer-substring-no-properties
144 'buffer-substring))
145
146 (defcustom latex-help-file "(latex2e)"
147 "Select the LaTeX2e non official reference manual translation."
148 :type '(choice
149 (string :tag "English" "(latex2e)")
150 (string :tag "French" "(latex2e-fr)")
151 (string :tag "Spanish" "(latex2e-es)") ))
152
153 (defvar latex-help-split-window nil
154 "*When this is non-nil, `latex-help' will always pop up the info
155 buffer, rather than just switch to it.")
156
157 (defvar latex-help-hist nil
158 "History for latex command help")
159
160 (defconst latex-help-cmd-alist nil
161 "Alist of the commands in the index of the latex info manual,
162 used for validation and completion.")
163
164 ;;;###autoload
165 (defun latex-help (cmd split)
166 "Try to find info entry about LaTeX entity CMD.
167 CMD may be either a command or an environment.
168 If CMD is not a string, this function will prompt for it, eventually
169 with completion. If SPLIT (prefix arg.) is non-nil, latex-help will
170 pop up the Info buffer, rather than just switch to it. See also
171 variable `latex-help-split-window'."
172 (interactive
173 (list
174 (let* ((cw (latex-help-guess))
175 (cww (concat "\\" cw))
176 (cmd-alist (latex-help-get-cmd-alist))
177 (node (try-completion cw cmd-alist))
178 ; try-completion returns actual string in case of partial match
179 ; but returns t in case of exact match
180 (nodename1 (if (equal node t) cw node))
181 (nodename2 (if (equal nodename1 nil)
182 (try-completion cww cmd-alist) nodename1))
183 (guess (cond ((equal nodename2 t) cww)
184 ((equal nodename2 nil) nil)
185 (t nodename2)))
186 (val (completing-read (if guess
187 (format "Describe LaTeX command (default %s): " guess)
188 "Describe LaTeX command: ")
189 cmd-alist nil t nil
190 'latex-help-hist)))
191 (cdr (assoc (if (equal val "")
192 guess
193 val) cmd-alist)))
194 current-prefix-arg))
195 (if (not (or split latex-help-split-window))
196 (Info-goto-node (concat latex-help-file cmd))
197 (save-excursion
198 (let ((pop-up-windows t)
199 (buffer (current-buffer)))
200 (pop-to-buffer nil)
201 (Info-goto-node (concat latex-help-file cmd))
202 (if (fboundp 'show-temp-buffer)
203 (show-temp-buffer (current-buffer) t)
204 (pop-to-buffer buffer))))))
205
206 (defun latex-help-guess ()
207 "Return the word point is on as a string, if it's between two
208 word-constituent characters. If not, but it immediately follows one,
209 move back first. Otherwise, if point precedes a word constituent,
210 move forward first. Otherwise, move backwards until a word constituent
211 is found and get that word; if you reach a newline first, move forward
212 instead.
213
214 This function has been tweaked to deal better with latex commands.
215
216 Return the LaTeX command point is on as a string.
217 "
218 ;; cl: I am not claiming this to be neither elegant nor fast.
219 (save-excursion
220 (let ((oldpoint (point)) (start (point)) (end (point))
221 (wc "A-Za-z") (nwc "^A-Za-z"))
222
223 (cond
224 ((looking-at "\\\\[^A-Za-z]")
225 (setq start (point)
226 end (+ 2 (point))))
227
228 ((looking-at "\\\\[A-Za-z]+")
229 (setq start (match-beginning 0)
230 end (match-end 0)))
231
232 (t
233 (skip-chars-backward wc)
234 (skip-chars-backward "\\\\" (1- (point)))
235 (setq start (point))
236
237 (goto-char oldpoint)
238
239 (skip-chars-forward "\\\\" (1+ (point)))
240 (skip-chars-forward wc)
241 (setq end (point))
242
243 (if (and (eq start oldpoint) (eq end oldpoint))
244 (progn
245 (skip-chars-backward nwc
246 (save-excursion (beginning-of-line) (point)))
247 (if (eq (preceding-char) ?\n)
248 (progn
249 (skip-chars-forward nwc)
250 (setq start (point))
251 (skip-chars-forward "\\\\" (1+ (point)))
252 (skip-chars-forward wc)
253 (setq end (point)))
254 (setq end (point))
255 (skip-chars-backward wc)
256 (skip-chars-backward "\\\\" (1- (point)))
257 (setq start (point)))))
258 )
259 )
260 (ltxh-buffer-substring start end)))
261 )
262
263 (defun latex-help-get-cmd-alist ()
264 "Scoop up the commands in the index of the latex info manual.
265 The values are saved in `latex-help-cmd-alist' for speed."
266 ;; mm, does it contain any cached entries
267 (if (not (assoc "\\begin" latex-help-cmd-alist))
268 (save-window-excursion
269 (setq latex-help-cmd-alist nil)
270 (Info-goto-node (concat latex-help-file "Command Index"))
271 (if (re-search-forward "::$" nil t)
272 (progn
273 (end-of-buffer)
274 (while (re-search-backward "^\\* \\(.+\\)::$" nil t)
275 (setq key (ltxh-buffer-substring (match-beginning 1) (match-end 1)))
276 (setq latex-help-cmd-alist
277 (cons (cons key key) latex-help-cmd-alist))))
278 (end-of-buffer)
279 (while (re-search-backward "^\\* \\(.+\\): *\\(.+\\)\\." nil t)
280 (setq key (ltxh-buffer-substring (match-beginning 1) (match-end 1)))
281 (setq value (ltxh-buffer-substring (match-beginning 2) (match-end 2)))
282 (setq latex-help-cmd-alist
283 (cons (cons key value) latex-help-cmd-alist))))
284 ))
285 ;; and return the alist.
286 latex-help-cmd-alist
287 )
288
289 (provide 'ltx-help)
290
291 ;;; ltx-help.el ends here

Properties

Name Value
svn:eol-style native

Send suggestions and bug reports to Sergey Poznyakoff
ViewVC Help
Powered by ViewVC 1.1.20