Mercurial > emacs
comparison lisp/info.el @ 7837:bad6366d4f16
(Info-complete-menu-item): New function.
(Info-menu): Use it to speed completion.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 10 Jun 1994 21:00:53 +0000 |
parents | e974be06f4f7 |
children | 1d1693211560 |
comparison
equal
deleted
inserted
replaced
7836:e55490c43ed0 | 7837:bad6366d4f16 |
---|---|
831 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n")))) | 831 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n")))) |
832 (while (setq i (string-match "\n" str i)) | 832 (while (setq i (string-match "\n" str i)) |
833 (aset str i ?\ )) | 833 (aset str i ?\ )) |
834 str)) | 834 str)) |
835 | 835 |
836 ;; No one calls this and Info-menu-item doesn't exist. | 836 ;; No one calls this. |
837 ;;(defun Info-menu-item-sequence (list) | 837 ;;(defun Info-menu-item-sequence (list) |
838 ;; (while list | 838 ;; (while list |
839 ;; (Info-menu-item (car list)) | 839 ;; (Info-menu (car list)) |
840 ;; (setq list (cdr list)))) | 840 ;; (setq list (cdr list)))) |
841 | |
842 (defun Info-complete-menu-item (string predicate action) | |
843 (let ((case-fold-search t)) | |
844 (cond ((eq action nil) | |
845 (let (completions | |
846 (pattern (concat "\n\\* \\(" | |
847 (regexp-quote string) | |
848 "[^:\t\n]*\\):"))) | |
849 (save-excursion | |
850 (set-buffer Info-complete-menu-buffer) | |
851 (goto-char (point-min)) | |
852 (while (re-search-forward pattern nil t) | |
853 (setq completions (cons (cons (format "%s" | |
854 (buffer-substring | |
855 (match-beginning 1) | |
856 (match-end 1))) | |
857 (match-beginning 1)) | |
858 completions)))) | |
859 (try-completion string completions predicate))) | |
860 ((eq action t) | |
861 (let (completions | |
862 (pattern (concat "\n\\* \\(" | |
863 (regexp-quote string) | |
864 "[^:\t\n]*\\):"))) | |
865 (save-excursion | |
866 (set-buffer Info-complete-menu-buffer) | |
867 (goto-char (point-min)) | |
868 (while (re-search-forward pattern nil t) | |
869 (setq completions (cons (cons (format "%s" | |
870 (buffer-substring | |
871 (match-beginning 1) | |
872 (match-end 1))) | |
873 (match-beginning 1)) | |
874 completions)))) | |
875 (all-completions string completions predicate))) | |
876 (t | |
877 (save-excursion | |
878 (set-buffer Info-complete-menu-buffer) | |
879 (goto-char (point-min)) | |
880 (re-search-forward (concat "\n\\* " | |
881 (regexp-quote string) | |
882 ":") | |
883 nil t)))))) | |
884 | |
841 | 885 |
842 (defun Info-menu (menu-item) | 886 (defun Info-menu (menu-item) |
843 "Go to node for menu item named (or abbreviated) NAME. | 887 "Go to node for menu item named (or abbreviated) NAME. |
844 Completion is allowed, and the menu item point is on is the default." | 888 Completion is allowed, and the menu item point is on is the default." |
845 (interactive | 889 (interactive |
850 (last nil)) | 894 (last nil)) |
851 (save-excursion | 895 (save-excursion |
852 (goto-char (point-min)) | 896 (goto-char (point-min)) |
853 (if (not (search-forward "\n* menu:" nil t)) | 897 (if (not (search-forward "\n* menu:" nil t)) |
854 (error "No menu in this node")) | 898 (error "No menu in this node")) |
855 (while (re-search-forward | 899 (setq beg (point)) |
856 "\n\\* \\([^:\t\n]*\\):" nil t) | 900 (and (< (point) p) |
857 (if (and (null default) | 901 (save-excursion |
858 (prog1 (if last (< last p) nil) | 902 (goto-char p) |
859 (setq last (match-beginning 0))) | 903 (end-of-line) |
860 (<= p last)) | 904 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t) |
861 (setq default (car (car completions)))) | 905 (setq default (format "%s" (buffer-substring |
862 (setq completions (cons (cons (buffer-substring | 906 (match-beginning 1) |
863 (match-beginning 1) | 907 (match-end 1))))))) |
864 (match-end 1)) | |
865 (match-beginning 1)) | |
866 completions))) | |
867 (if (and (null default) last | |
868 (< last p) | |
869 (<= p (progn (end-of-line) (point)))) | |
870 (setq default (car (car completions))))) | |
871 (let ((item nil)) | 908 (let ((item nil)) |
872 (while (null item) | 909 (while (null item) |
873 (setq item (let ((completion-ignore-case t)) | 910 (setq item (let ((completion-ignore-case t) |
911 (Info-complete-menu-buffer (current-buffer))) | |
874 (completing-read (if default | 912 (completing-read (if default |
875 (format "Menu item (default %s): " | 913 (format "Menu item (default %s): " |
876 default) | 914 default) |
877 "Menu item: ") | 915 "Menu item: ") |
878 completions nil t))) | 916 'Info-complete-menu-item nil t))) |
879 ;; we rely on the fact that completing-read accepts an input | 917 ;; we rely on the fact that completing-read accepts an input |
880 ;; of "" even when the require-match argument is true and "" | 918 ;; of "" even when the require-match argument is true and "" |
881 ;; is not a valid possibility | 919 ;; is not a valid possibility |
882 (if (string= item "") | 920 (if (string= item "") |
883 (if default | 921 (if default |