comparison lisp/help-mode.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 ;;; help-mode.el --- `help-mode' used by *Help* buffers 1 ;;; help-mode.el --- `help-mode' used by *Help* buffers
2 2
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002 3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2004
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: help, internal 7 ;; Keywords: help, internal
8 8
148 'help-function (lambda (fun file) 148 'help-function (lambda (fun file)
149 (require 'find-func) 149 (require 'find-func)
150 ;; Don't use find-function-noselect because it follows 150 ;; Don't use find-function-noselect because it follows
151 ;; aliases (which fails for built-in functions). 151 ;; aliases (which fails for built-in functions).
152 (let ((location 152 (let ((location
153 (if (bufferp file) (cons file fun) 153 (cond
154 (find-function-search-for-symbol fun nil file)))) 154 ((bufferp file) (cons file fun))
155 ((string-match "\\`src/\\(.*\\.c\\)" file)
156 (help-find-C-source fun (match-string 1 file) 'fun))
157 (t (find-function-search-for-symbol fun nil file)))))
155 (pop-to-buffer (car location)) 158 (pop-to-buffer (car location))
156 (goto-char (cdr location)))) 159 (goto-char (cdr location))))
157 'help-echo (purecopy "mouse-2, RET: find function's definition")) 160 'help-echo (purecopy "mouse-2, RET: find function's definition"))
158 161
159 (define-button-type 'help-variable-def 162 (define-button-type 'help-variable-def
160 :supertype 'help-xref 163 :supertype 'help-xref
161 'help-function (lambda (var &optional file) 164 'help-function (lambda (var &optional file)
162 (let ((location 165 (let ((location
163 (find-variable-noselect var file))) 166 (cond
167 ((string-match "\\`src/\\(.*\\.c\\)" file)
168 (help-find-C-source var (match-string 1 file) 'var))
169 (t (find-variable-noselect var file)))))
164 (pop-to-buffer (car location)) 170 (pop-to-buffer (car location))
165 (goto-char (cdr location)))) 171 (goto-char (cdr location))))
166 'help-echo (purecopy"mouse-2, RET: find variable's definition")) 172 'help-echo (purecopy"mouse-2, RET: find variable's definition"))
167 173
168 174
211 (defconst help-xref-symbol-regexp 217 (defconst help-xref-symbol-regexp
212 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" 218 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
213 "\\(function\\|command\\)\\|" 219 "\\(function\\|command\\)\\|"
214 "\\(face\\)\\|" 220 "\\(face\\)\\|"
215 "\\(symbol\\)\\|" 221 "\\(symbol\\)\\|"
216 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)\\s-+\\)?" 222 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)"
223 "[ \t\n]+\\)?"
217 ;; Note starting with word-syntax character: 224 ;; Note starting with word-syntax character:
218 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")) 225 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
219 "Regexp matching doc string references to symbols. 226 "Regexp matching doc string references to symbols.
220 227
221 The words preceding the quoted symbol can be used in doc strings to 228 The words preceding the quoted symbol can be used in doc strings to
228 when help commands related to multilingual environment (e.g., 235 when help commands related to multilingual environment (e.g.,
229 `describe-coding-system') are invoked.") 236 `describe-coding-system') are invoked.")
230 237
231 238
232 (defconst help-xref-info-regexp 239 (defconst help-xref-info-regexp
233 (purecopy "\\<[Ii]nfo[ \t\n]+node[ \t\n]+`\\([^']+\\)'") 240 (purecopy "\\<[Ii]nfo[ \t\n]+\\(node\\|anchor\\)[ \t\n]+`\\([^']+\\)'")
234 "Regexp matching doc string references to an Info node.") 241 "Regexp matching doc string references to an Info node.")
235 242
236 ;;;###autoload 243 ;;;###autoload
237 (defun help-setup-xref (item interactive-p) 244 (defun help-setup-xref (item interactive-p)
238 "Invoked from commands using the \"*Help*\" buffer to install some xref info. 245 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
276 283
277 Find cross-reference information in a buffer and activate such cross 284 Find cross-reference information in a buffer and activate such cross
278 references for selection with `help-follow'. Cross-references have 285 references for selection with `help-follow'. Cross-references have
279 the canonical form `...' and the type of reference may be 286 the canonical form `...' and the type of reference may be
280 disambiguated by the preceding word(s) used in 287 disambiguated by the preceding word(s) used in
281 `help-xref-symbol-regexp'. 288 `help-xref-symbol-regexp'. Faces only get cross-referenced if
289 preceded or followed by the word `face'. Variables without
290 variable documentation do not get cross-referenced, unless
291 preceded by the word `variable' or `option'.
282 292
283 If the variable `help-xref-mule-regexp' is non-nil, find also 293 If the variable `help-xref-mule-regexp' is non-nil, find also
284 cross-reference information related to multilingual environment 294 cross-reference information related to multilingual environment
285 \(e.g., coding-systems). This variable is also used to disambiguate 295 \(e.g., coding-systems). This variable is also used to disambiguate
286 the type of reference as the same way as `help-xref-symbol-regexp'. 296 the type of reference as the same way as `help-xref-symbol-regexp'.
304 (unwind-protect 314 (unwind-protect
305 (progn 315 (progn
306 ;; Info references 316 ;; Info references
307 (save-excursion 317 (save-excursion
308 (while (re-search-forward help-xref-info-regexp nil t) 318 (while (re-search-forward help-xref-info-regexp nil t)
309 (let ((data (match-string 1))) 319 (let ((data (match-string 2)))
310 (save-match-data 320 (save-match-data
311 (unless (string-match "^([^)]+)" data) 321 (unless (string-match "^([^)]+)" data)
312 (setq data (concat "(emacs)" data)))) 322 (setq data (concat "(emacs)" data))))
313 (help-xref-button 1 'help-info data)))) 323 (help-xref-button 2 'help-info data))))
314 ;; Mule related keywords. Do this before trying 324 ;; Mule related keywords. Do this before trying
315 ;; `help-xref-symbol-regexp' because some of Mule 325 ;; `help-xref-symbol-regexp' because some of Mule
316 ;; keywords have variable or function definitions. 326 ;; keywords have variable or function definitions.
317 (if help-xref-mule-regexp 327 (if help-xref-mule-regexp
318 (save-excursion 328 (save-excursion
340 (while (re-search-forward help-xref-symbol-regexp nil t) 350 (while (re-search-forward help-xref-symbol-regexp nil t)
341 (let* ((data (match-string 8)) 351 (let* ((data (match-string 8))
342 (sym (intern-soft data))) 352 (sym (intern-soft data)))
343 (if sym 353 (if sym
344 (cond 354 (cond
345 ((match-string 3) ; `variable' &c 355 ((match-string 3) ; `variable' &c
346 (and (boundp sym) ; `variable' doesn't ensure 356 (and (boundp sym) ; `variable' doesn't ensure
347 ; it's actually bound 357 ; it's actually bound
348 (help-xref-button 8 'help-variable sym))) 358 (help-xref-button 8 'help-variable sym)))
349 ((match-string 4) ; `function' &c 359 ((match-string 4) ; `function' &c
350 (and (fboundp sym) ; similarly 360 (and (fboundp sym) ; similarly
351 (help-xref-button 8 'help-function sym))) 361 (help-xref-button 8 'help-function sym)))
352 ((match-string 5) ; `face' 362 ((match-string 5) ; `face'
353 (and (facep sym) 363 (and (facep sym)
354 (help-xref-button 8 'help-face sym))) 364 (help-xref-button 8 'help-face sym)))
355 ((match-string 6)) ; nothing for `symbol' 365 ((match-string 6)) ; nothing for `symbol'
356 ((match-string 7) 366 ((match-string 7)
357 ;; this used: 367 ;;; this used:
358 ;; #'(lambda (arg) 368 ;;; #'(lambda (arg)
359 ;; (let ((location 369 ;;; (let ((location
360 ;; (find-function-noselect arg))) 370 ;;; (find-function-noselect arg)))
361 ;; (pop-to-buffer (car location)) 371 ;;; (pop-to-buffer (car location))
362 ;; (goto-char (cdr location)))) 372 ;;; (goto-char (cdr location))))
363 (help-xref-button 8 'help-function-def sym)) 373 (help-xref-button 8 'help-function-def sym))
374 ((facep sym)
375 (if (save-match-data (looking-at "[ \t\n]+face\\W"))
376 (help-xref-button 8 'help-face sym)))
364 ((and (boundp sym) (fboundp sym)) 377 ((and (boundp sym) (fboundp sym))
365 ;; We can't intuit whether to use the 378 ;; We can't intuit whether to use the
366 ;; variable or function doc -- supply both. 379 ;; variable or function doc -- supply both.
367 (help-xref-button 8 'help-symbol sym)) 380 (help-xref-button 8 'help-symbol sym))
368 ((boundp sym) 381 ((and
382 (boundp sym)
383 (or
384 (documentation-property
385 sym 'variable-documentation)
386 (condition-case nil
387 (documentation-property
388 (indirect-variable sym)
389 'variable-documentation)
390 (cyclic-variable-indirection nil))))
369 (help-xref-button 8 'help-variable sym)) 391 (help-xref-button 8 'help-variable sym))
370 ((fboundp sym) 392 ((fboundp sym)
371 (help-xref-button 8 'help-function sym)) 393 (help-xref-button 8 'help-function sym)))))))
372 ((facep sym)
373 (help-xref-button 8 'help-face sym)))))))
374 ;; An obvious case of a key substitution: 394 ;; An obvious case of a key substitution:
375 (save-excursion 395 (save-excursion
376 (while (re-search-forward 396 (while (re-search-forward
377 ;; Assume command name is only word characters 397 ;; Assume command name is only word characters
378 ;; and dashes to get things like `use M-x foo.'. 398 ;; and dashes to get things like `use M-x foo.'.
410 (set-syntax-table stab)) 430 (set-syntax-table stab))
411 ;; Delete extraneous newlines at the end of the docstring 431 ;; Delete extraneous newlines at the end of the docstring
412 (goto-char (point-max)) 432 (goto-char (point-max))
413 (while (and (not (bobp)) (bolp)) 433 (while (and (not (bobp)) (bolp))
414 (delete-char -1)) 434 (delete-char -1))
435 (insert "\n")
415 ;; Make a back-reference in this buffer if appropriate. 436 ;; Make a back-reference in this buffer if appropriate.
416 (when help-xref-stack 437 (when help-xref-stack
417 (insert "\n\n") 438 (insert "\n")
418 (help-insert-xref-button help-back-label 'help-back 439 (help-insert-xref-button help-back-label 'help-back
419 (current-buffer)))) 440 (current-buffer))
441 (insert "\n")))
420 ;; View mode steals RET from us. 442 ;; View mode steals RET from us.
421 (set (make-local-variable 'minor-mode-overriding-map-alist) 443 (set (make-local-variable 'minor-mode-overriding-map-alist)
422 (list (cons 'view-mode help-xref-override-view-map))) 444 (list (cons 'view-mode help-xref-override-view-map)))
423 (set-buffer-modified-p old-modified)))) 445 (set-buffer-modified-p old-modified))))
424 446
590 (help-do-xref pos #'help-xref-interned (list sym)))))) 612 (help-do-xref pos #'help-xref-interned (list sym))))))
591 613
592 614
593 (provide 'help-mode) 615 (provide 'help-mode)
594 616
617 ;;; arch-tag: 850954ae-3725-4cb4-8e91-0bf6d52d6b0b
595 ;;; help-mode.el ends here 618 ;;; help-mode.el ends here