diff options
| author | Karl Heuer | 1999-08-10 16:49:49 +0000 |
|---|---|---|
| committer | Karl Heuer | 1999-08-10 16:49:49 +0000 |
| commit | ce288cb6819ef8be713674ffb87c7b65020bd90d (patch) | |
| tree | 4ff9ec4a7c1b87c5ff0e06ff514acc9d09f61551 | |
| parent | 114d3e869f50dcdfe32badc371ee6d818f2920bf (diff) | |
| download | emacs-ce288cb6819ef8be713674ffb87c7b65020bd90d.tar.gz emacs-ce288cb6819ef8be713674ffb87c7b65020bd90d.zip | |
(info-lookup-guess-c-symbol): Use skip-syntax-backward.
(info-lookup-guess-default): Simplified and cleaned up.
(info-lookup-guess-default*): Preserve point.
| -rw-r--r-- | lisp/info-look.el | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/lisp/info-look.el b/lisp/info-look.el index 9b0a0c2ed11..9440097cf87 100644 --- a/lisp/info-look.el +++ b/lisp/info-look.el | |||
| @@ -482,54 +482,53 @@ If optional argument QUERY is non-nil, query for the help mode." | |||
| 482 | result)) | 482 | result)) |
| 483 | 483 | ||
| 484 | (defun info-lookup-guess-default (topic mode) | 484 | (defun info-lookup-guess-default (topic mode) |
| 485 | "Pick up default item at point (with favor to look back). | 485 | "Return a guess for a symbol to look up, based on text around point. |
| 486 | Return nil if there is nothing appropriate." | 486 | Try all related modes applicable to TOPIC and MODE. |
| 487 | Return nil if there is nothing appropriate in the buffer near point." | ||
| 487 | (let ((modes (info-lookup->all-modes topic mode)) | 488 | (let ((modes (info-lookup->all-modes topic mode)) |
| 488 | (start (point)) guess whitespace) | 489 | guess) |
| 489 | (while (and (not guess) modes) | 490 | (while (and (not guess) modes) |
| 490 | (setq guess (info-lookup-guess-default* topic (car modes)) | 491 | (setq guess (info-lookup-guess-default* topic (car modes)) |
| 491 | modes (cdr modes)) | 492 | modes (cdr modes))) |
| 492 | (goto-char start)) | ||
| 493 | ;; Collapse whitespace characters. | 493 | ;; Collapse whitespace characters. |
| 494 | (and guess (concat (delete nil (mapcar (lambda (ch) | 494 | (when guess |
| 495 | (if (or (char-equal ch ? ) | 495 | (let ((pos 0)) |
| 496 | (char-equal ch ?\t) | 496 | (while (string-match "[ \t\n]+" guess pos) |
| 497 | (char-equal ch ?\n)) | 497 | (setq pos (1+ (match-beginning 0))) |
| 498 | (if (not whitespace) | 498 | (setq guess (replace-match " " t t guess))))) |
| 499 | (setq whitespace ? )) | 499 | guess)) |
| 500 | (setq whitespace nil) ch)) | ||
| 501 | guess)))))) | ||
| 502 | 500 | ||
| 503 | (defun info-lookup-guess-default* (topic mode) | 501 | (defun info-lookup-guess-default* (topic mode) |
| 504 | (let ((case-fold-search (info-lookup->ignore-case topic mode)) | 502 | (let ((case-fold-search (info-lookup->ignore-case topic mode)) |
| 505 | (rule (or (info-lookup->parse-rule topic mode) | 503 | (rule (or (info-lookup->parse-rule topic mode) |
| 506 | (info-lookup->regexp topic mode))) | 504 | (info-lookup->regexp topic mode))) |
| 507 | (start (point)) end regexp subexp result) | 505 | (start (point)) end regexp subexp result) |
| 508 | (if (symbolp rule) | 506 | (save-excursion |
| 509 | (setq result (funcall rule)) | 507 | (if (symbolp rule) |
| 510 | (if (consp rule) | 508 | (setq result (funcall rule)) |
| 511 | (setq regexp (car rule) | 509 | (if (consp rule) |
| 512 | subexp (cdr rule)) | 510 | (setq regexp (car rule) |
| 513 | (setq regexp rule | 511 | subexp (cdr rule)) |
| 514 | subexp 0)) | 512 | (setq regexp rule |
| 515 | (skip-chars-backward " \t\n") (setq end (point)) | 513 | subexp 0)) |
| 516 | (while (and (re-search-backward regexp nil t) | 514 | (skip-chars-backward " \t\n") (setq end (point)) |
| 517 | (looking-at regexp) | 515 | (while (and (re-search-backward regexp nil t) |
| 518 | (>= (match-end 0) end)) | 516 | (looking-at regexp) |
| 519 | (setq result (match-string subexp))) | 517 | (>= (match-end 0) end)) |
| 520 | (if (not result) | 518 | (setq result (match-string subexp))) |
| 521 | (progn | 519 | (if (not result) |
| 522 | (goto-char start) | 520 | (progn |
| 523 | (skip-chars-forward " \t\n") | 521 | (goto-char start) |
| 524 | (and (looking-at regexp) | 522 | (skip-chars-forward " \t\n") |
| 525 | (setq result (match-string subexp)))))) | 523 | (and (looking-at regexp) |
| 524 | (setq result (match-string subexp))))))) | ||
| 526 | result)) | 525 | result)) |
| 527 | 526 | ||
| 528 | (defun info-lookup-guess-c-symbol () | 527 | (defun info-lookup-guess-c-symbol () |
| 529 | "Get the C symbol at point." | 528 | "Get the C symbol at point." |
| 530 | (condition-case nil | 529 | (condition-case nil |
| 531 | (progn | 530 | (progn |
| 532 | (backward-sexp) | 531 | (skip-syntax-backward "w_") |
| 533 | (let ((start (point)) prefix name) | 532 | (let ((start (point)) prefix name) |
| 534 | ;; Test for a leading `struct', `union', or `enum' keyword | 533 | ;; Test for a leading `struct', `union', or `enum' keyword |
| 535 | ;; but ignore names like `foo_struct'. | 534 | ;; but ignore names like `foo_struct'. |